diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index b17e40f27..68eaae970 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -2059,6 +2059,40 @@ do -- COORDINATE return Path, Way, GotPath end + + --- Returns a table of coordinates to a destination using only roads or railroads. + -- The first point is the closest point on road of the given coordinate. + -- By default, the last point is the closest point on road of the ToCoord. Hence, the coordinate itself and the final ToCoord are not necessarily included in the path. + -- @param #COORDINATE self + -- @param #COORDINATE ToCoord Coordinate of destination. + -- @param #boolean IncludeEndpoints (Optional) Include the coordinate itself and the ToCoordinate in the path. + -- @param #boolean Railroad (Optional) If true, path on railroad is returned. Default false. + -- @return Core.Pathline#PATHLINE Pathline containing the points on road. If no path on road can be found, nil is returned or just the endpoints. + function COORDINATE:GetPathlineOnRoad(ToCoord, IncludeEndpoints, Railroad) + + -- Set road type. + local RoadType="roads" + if Railroad==true then + RoadType="railroads" + end + + -- DCS API function returning a table of vec2. + local path = land.findPathOnRoads(RoadType, self.x, self.z, ToCoord.x, ToCoord.z) + + if IncludeEndpoints then + path=path or {} + table.insert(path, 1, self:GetVec2()) + table.insert(path, ToCoord:GetVec2()) + end + + local pathline=nil + if path then + pathline=PATHLINE:NewFromVec2Array(RoadType, path) + end + + return pathline + end + --- Gets the surface type at the coordinate. -- @param #COORDINATE self diff --git a/Moose Development/Moose/Core/Vector.lua b/Moose Development/Moose/Core/Vector.lua index 4cd588061..ce8ab3631 100644 --- a/Moose Development/Moose/Core/Vector.lua +++ b/Moose Development/Moose/Core/Vector.lua @@ -133,7 +133,7 @@ VECTOR = { --- VECTOR class version. -- @field #string version -VECTOR.version="0.0.3" +VECTOR.version="0.1.0" --- VECTOR unique ID _VECTORID=0 @@ -147,7 +147,7 @@ VECTOR.__index = VECTOR ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO: 3D rotation --- TODO: Markers +-- DONE: Markers -- TODO: Documentation ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -966,10 +966,9 @@ function VECTOR:GetPathOnRoad(Vec) local vec1=self:GetVec2() local vec2=Vec:GetVec2() - local path=nil - local vec2points=land.findPathOnRoads("roads", vec1.x , vec1.y, vec2.x, vec2.y) + local path=nil if vec2points then path=PATHLINE:NewFromVec2Array("Road", vec2points) end @@ -1365,10 +1364,6 @@ end -- @param #VECTOR b Vector b. -- @return #boolean If `true`, both vectors are equal function VECTOR.__eq(a, b) - --assert(VECTOR._IsVector(a) and VECTOR._IsVector(b), "ERROR in VECTOR.__eq: wrong argument types: (expected and )") - env.info("FF __eq",showMessageBox) - BASE:I(a) - BASE:I(b) return a.x==b.x and a.y==b.y and a.z==b.z end diff --git a/Moose Development/Moose/Navigation/Beacons.lua b/Moose Development/Moose/Navigation/Beacons.lua index f22fecaf5..9c7acba8b 100644 --- a/Moose Development/Moose/Navigation/Beacons.lua +++ b/Moose Development/Moose/Navigation/Beacons.lua @@ -90,7 +90,7 @@ BEACONS = { --- BEACONS class version. -- @field #string version -BEACONS.version="0.0.4" +BEACONS.version="0.1.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- ToDo list @@ -238,6 +238,33 @@ function BEACONS:GetClosestBeacon(Coordinate, TypeID, DistMax, ExcludeList) return beacon end +--- Find closest beacons to a given coordinate. +-- @param #BEACONS self +-- @param Core.Point#COORDINATE Coordinate The reference coordinate. +-- @param #number Nmax Max number of beacons. Default 5. +-- @param #number TypeID (Optional) Only search for specific beacon types, *e.g.* `BEACON.Type.TACAN`. +-- @param #number DistMax (Optional) Max search distance in meters. +-- @return #table Table of #BEACONS.Beacon closest beacons. +function BEACONS:GetClosestBeacons(Coordinate, Nmax, TypeID, DistMax) + + Nmax=Nmax or 5 + + local closest={} + for i=1,Nmax do + + local beacon=self:GetClosestBeacon(Coordinate, TypeID, DistMax, closest) + + if beacon then + table.insert(closest, beacon) + else + break + end + + end + + return closest +end + --- Get table of all beacons, optionally of a given type. -- @param #BEACONS self -- @param #number TypeID (Optional) Only return specific beacon types, *e.g.* `BEACON.Type.TACAN`. diff --git a/Moose Development/Moose/Navigation/Point.lua b/Moose Development/Moose/Navigation/Point.lua index 5a63a8487..2c8d1e378 100644 --- a/Moose Development/Moose/Navigation/Point.lua +++ b/Moose Development/Moose/Navigation/Point.lua @@ -100,7 +100,7 @@ NAVFIX.Type={ --- NAVFIX class version. -- @field #string version -NAVFIX.version="0.0.1" +NAVFIX.version="0.1.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- ToDo list @@ -492,7 +492,7 @@ NAVAID = { --- NAVAID class version. -- @field #string version -NAVAID.version="0.0.1" +NAVAID.version="0.1.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- ToDo list diff --git a/Moose Development/Moose/Navigation/Radios.lua b/Moose Development/Moose/Navigation/Radios.lua index 7e13e57e3..f5c3e0faa 100644 --- a/Moose Development/Moose/Navigation/Radios.lua +++ b/Moose Development/Moose/Navigation/Radios.lua @@ -3,6 +3,8 @@ -- **Main Features:** -- -- * Get radio frequencies of airbases +-- * Find closest airbase radios +-- * Mark radio frequencies on F10 map -- -- === -- @@ -64,7 +66,7 @@ -- @field #RADIOS RADIOS = { ClassName = "RADIOS", - verbose = 0, + verbose = 0, radios = {}, } @@ -78,6 +80,9 @@ RADIOS = { -- @field #table sceneObjects Scenery objects. -- @field #string name Name of the airbase. -- @field Wrapper.Airbase#AIRBASE airbase Airbase. +-- @field Core.Point#COORDINATE coordinate The COORDINATE of the radio. +-- @field DCS#Vec3 vec3 3D vector. +-- @field #number markerID Marker ID. --- Radio item data structure. -- @type RADIOS.Frequency @@ -87,7 +92,7 @@ RADIOS = { --- RADIOS class version. -- @field #string version -RADIOS.version="0.0.0" +RADIOS.version="0.1.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- ToDo list @@ -112,9 +117,7 @@ function RADIOS:NewFromTable(RadioTable) for _,_radio in pairs(RadioTable) do local radio=_radio --#RADIOS.Radio - - --UTILS.PrintTableToLog(radio) - --UTILS.PrintTableToLog(radio.callsign) + -- The table structure of callsign is a bit awkward. We need to get the airbase name. local cs=radio.callsign[1] @@ -126,7 +129,6 @@ function RADIOS:NewFromTable(RadioTable) radio.name="Unknown" end - --UTILS.PrintTableToLog(radio.callsign) radio.name=self:_GetAirbaseName(airbasenames, radio.name) @@ -134,6 +136,7 @@ function RADIOS:NewFromTable(RadioTable) if radio.airbase then radio.coordinate=radio.airbase:GetCoordinate() + radio.vec3=radio.airbase:GetVec3() end -- Add to table @@ -198,6 +201,66 @@ function RADIOS:GetCoordinate(radio) return radio.coordinate end + +--- Find closest radio to a given coordinate. +-- @param #RADIOS self +-- @param Core.Point#COORDINATE Coordinate The reference coordinate. +-- @param #number DistMax (Optional) Max search distance in meters. +-- @param #table ExcludeList (Optional) List of radios to exclude. +-- @return #RADIOS.Radio The closest radio. +function RADIOS:GetClosestRadio(Coordinate, DistMax, ExcludeList) + + local radio=nil --#RADIOS.Radio + local distmin=math.huge + + ExcludeList=ExcludeList or {} + + for _,_radio in pairs(self.radios) do + local ra=_radio --#RADIOS.Radio + + if (not UTILS.IsInTable(ExcludeList, ra, "radioId")) then + + local dist=Coordinate:Get2DDistance(ra.coordinate) + + if dist