mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-23 19:45:29 +00:00
Nav updates
This commit is contained in:
@@ -2059,6 +2059,40 @@ do -- COORDINATE
|
|||||||
|
|
||||||
return Path, Way, GotPath
|
return Path, Way, GotPath
|
||||||
end
|
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.
|
--- Gets the surface type at the coordinate.
|
||||||
-- @param #COORDINATE self
|
-- @param #COORDINATE self
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ VECTOR = {
|
|||||||
|
|
||||||
--- VECTOR class version.
|
--- VECTOR class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
VECTOR.version="0.0.3"
|
VECTOR.version="0.1.0"
|
||||||
|
|
||||||
--- VECTOR unique ID
|
--- VECTOR unique ID
|
||||||
_VECTORID=0
|
_VECTORID=0
|
||||||
@@ -147,7 +147,7 @@ VECTOR.__index = VECTOR
|
|||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- TODO: 3D rotation
|
-- TODO: 3D rotation
|
||||||
-- TODO: Markers
|
-- DONE: Markers
|
||||||
-- TODO: Documentation
|
-- TODO: Documentation
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -966,10 +966,9 @@ function VECTOR:GetPathOnRoad(Vec)
|
|||||||
local vec1=self:GetVec2()
|
local vec1=self:GetVec2()
|
||||||
local vec2=Vec:GetVec2()
|
local vec2=Vec:GetVec2()
|
||||||
|
|
||||||
local path=nil
|
|
||||||
|
|
||||||
local vec2points=land.findPathOnRoads("roads", vec1.x , vec1.y, vec2.x, vec2.y)
|
local vec2points=land.findPathOnRoads("roads", vec1.x , vec1.y, vec2.x, vec2.y)
|
||||||
|
|
||||||
|
local path=nil
|
||||||
if vec2points then
|
if vec2points then
|
||||||
path=PATHLINE:NewFromVec2Array("Road", vec2points)
|
path=PATHLINE:NewFromVec2Array("Road", vec2points)
|
||||||
end
|
end
|
||||||
@@ -1365,10 +1364,6 @@ end
|
|||||||
-- @param #VECTOR b Vector b.
|
-- @param #VECTOR b Vector b.
|
||||||
-- @return #boolean If `true`, both vectors are equal
|
-- @return #boolean If `true`, both vectors are equal
|
||||||
function VECTOR.__eq(a, b)
|
function VECTOR.__eq(a, b)
|
||||||
--assert(VECTOR._IsVector(a) and VECTOR._IsVector(b), "ERROR in VECTOR.__eq: wrong argument types: (expected <vector> and <vector>)")
|
|
||||||
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
|
return a.x==b.x and a.y==b.y and a.z==b.z
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ BEACONS = {
|
|||||||
|
|
||||||
--- BEACONS class version.
|
--- BEACONS class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
BEACONS.version="0.0.4"
|
BEACONS.version="0.1.0"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- ToDo list
|
-- ToDo list
|
||||||
@@ -238,6 +238,33 @@ function BEACONS:GetClosestBeacon(Coordinate, TypeID, DistMax, ExcludeList)
|
|||||||
return beacon
|
return beacon
|
||||||
end
|
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.
|
--- Get table of all beacons, optionally of a given type.
|
||||||
-- @param #BEACONS self
|
-- @param #BEACONS self
|
||||||
-- @param #number TypeID (Optional) Only return specific beacon types, *e.g.* `BEACON.Type.TACAN`.
|
-- @param #number TypeID (Optional) Only return specific beacon types, *e.g.* `BEACON.Type.TACAN`.
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ NAVFIX.Type={
|
|||||||
|
|
||||||
--- NAVFIX class version.
|
--- NAVFIX class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
NAVFIX.version="0.0.1"
|
NAVFIX.version="0.1.0"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- ToDo list
|
-- ToDo list
|
||||||
@@ -492,7 +492,7 @@ NAVAID = {
|
|||||||
|
|
||||||
--- NAVAID class version.
|
--- NAVAID class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
NAVAID.version="0.0.1"
|
NAVAID.version="0.1.0"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- ToDo list
|
-- ToDo list
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
-- **Main Features:**
|
-- **Main Features:**
|
||||||
--
|
--
|
||||||
-- * Get radio frequencies of airbases
|
-- * Get radio frequencies of airbases
|
||||||
|
-- * Find closest airbase radios
|
||||||
|
-- * Mark radio frequencies on F10 map
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
@@ -64,7 +66,7 @@
|
|||||||
-- @field #RADIOS
|
-- @field #RADIOS
|
||||||
RADIOS = {
|
RADIOS = {
|
||||||
ClassName = "RADIOS",
|
ClassName = "RADIOS",
|
||||||
verbose = 0,
|
verbose = 0,
|
||||||
radios = {},
|
radios = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +80,9 @@ RADIOS = {
|
|||||||
-- @field #table sceneObjects Scenery objects.
|
-- @field #table sceneObjects Scenery objects.
|
||||||
-- @field #string name Name of the airbase.
|
-- @field #string name Name of the airbase.
|
||||||
-- @field Wrapper.Airbase#AIRBASE airbase 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.
|
--- Radio item data structure.
|
||||||
-- @type RADIOS.Frequency
|
-- @type RADIOS.Frequency
|
||||||
@@ -87,7 +92,7 @@ RADIOS = {
|
|||||||
|
|
||||||
--- RADIOS class version.
|
--- RADIOS class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
RADIOS.version="0.0.0"
|
RADIOS.version="0.1.0"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- ToDo list
|
-- ToDo list
|
||||||
@@ -112,9 +117,7 @@ function RADIOS:NewFromTable(RadioTable)
|
|||||||
|
|
||||||
for _,_radio in pairs(RadioTable) do
|
for _,_radio in pairs(RadioTable) do
|
||||||
local radio=_radio --#RADIOS.Radio
|
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.
|
-- The table structure of callsign is a bit awkward. We need to get the airbase name.
|
||||||
local cs=radio.callsign[1]
|
local cs=radio.callsign[1]
|
||||||
@@ -126,7 +129,6 @@ function RADIOS:NewFromTable(RadioTable)
|
|||||||
radio.name="Unknown"
|
radio.name="Unknown"
|
||||||
end
|
end
|
||||||
|
|
||||||
--UTILS.PrintTableToLog(radio.callsign)
|
|
||||||
|
|
||||||
radio.name=self:_GetAirbaseName(airbasenames, radio.name)
|
radio.name=self:_GetAirbaseName(airbasenames, radio.name)
|
||||||
|
|
||||||
@@ -134,6 +136,7 @@ function RADIOS:NewFromTable(RadioTable)
|
|||||||
|
|
||||||
if radio.airbase then
|
if radio.airbase then
|
||||||
radio.coordinate=radio.airbase:GetCoordinate()
|
radio.coordinate=radio.airbase:GetCoordinate()
|
||||||
|
radio.vec3=radio.airbase:GetVec3()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add to table
|
-- Add to table
|
||||||
@@ -198,6 +201,66 @@ function RADIOS:GetCoordinate(radio)
|
|||||||
return radio.coordinate
|
return radio.coordinate
|
||||||
end
|
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<distmin and (DistMax==nil or dist<=DistMax) then
|
||||||
|
distmin=dist
|
||||||
|
radio=ra
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return radio
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Find closest radios to a given coordinate.
|
||||||
|
-- @param #RADIOS self
|
||||||
|
-- @param Core.Point#COORDINATE Coordinate The reference coordinate.
|
||||||
|
-- @param #number Nmax Max number of radios. Default 5.
|
||||||
|
-- @param #number DistMax (Optional) Max search distance in meters.
|
||||||
|
-- @return #table Table of #RADIOS.Radio closest radios.
|
||||||
|
function RADIOS:GetClosestRadios(Coordinate, Nmax, DistMax)
|
||||||
|
|
||||||
|
Nmax=Nmax or 5
|
||||||
|
|
||||||
|
local closest={}
|
||||||
|
for i=1,Nmax do
|
||||||
|
|
||||||
|
local radio=self:GetClosestRadio(Coordinate, DistMax, closest)
|
||||||
|
|
||||||
|
if radio then
|
||||||
|
table.insert(closest, radio)
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return closest
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Add markers for all radios on the F10 map.
|
--- Add markers for all radios on the F10 map.
|
||||||
-- @param #RADIOS self
|
-- @param #RADIOS self
|
||||||
-- @param #RADIOS.Radio Radio (Optional) Only this specifc radio.
|
-- @param #RADIOS.Radio Radio (Optional) Only this specifc radio.
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
--- **NAVIGATION** - Beacons of the map/theatre.
|
--- **NAVIGATION** - Towns of the map/theatre.
|
||||||
--
|
--
|
||||||
-- **Main Features:**
|
-- **Main Features:**
|
||||||
--
|
--
|
||||||
-- * Find towns of map
|
-- * Find towns of map
|
||||||
-- * Road and rail connections
|
-- * Road and rail connections
|
||||||
|
-- * Find closest town to a given coordinate
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
@@ -83,16 +84,16 @@ TOWNS = {
|
|||||||
|
|
||||||
--- TOWNS class version.
|
--- TOWNS class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
TOWNS.version="0.0.1"
|
TOWNS.version="0.1.0"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- ToDo list
|
-- ToDo list
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- TODO: A lot...
|
-- TODO: A lot...
|
||||||
-- TODO: Road connection
|
-- DONE: Road connection
|
||||||
-- TODO: Rail connection
|
-- DONE: Rail connection
|
||||||
-- TODO: Connection between towns
|
-- DONE: Connection between towns
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- Constructor(s)
|
-- Constructor(s)
|
||||||
@@ -193,14 +194,15 @@ function TOWNS:GetCoordRail(town)
|
|||||||
return town.coordRail
|
return town.coordRail
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get road connection between two towns.
|
--- Get road or rail connection between two towns.
|
||||||
-- @param #TOWNS self
|
-- @param #TOWNS self
|
||||||
-- @param #TOWNS.Town townA The town data structure.
|
-- @param #TOWNS.Town townA The town data structure.
|
||||||
-- @param #TOWNS.Town townB The town data structure.
|
-- @param #TOWNS.Town townB The town data structure.
|
||||||
-- @return #table Table containing path coordinates.
|
-- @param #boolean Railroad If `true`, find rail road connection
|
||||||
function TOWNS:GetConnectionRoad(townA, townB)
|
-- @return Core.Pathline#PATHLINE Pathline connecting the two towns on road.
|
||||||
|
function TOWNS:GetConnectionRoad(townA, townB, Railroad)
|
||||||
|
|
||||||
local path=townA.coordRoad:GetPathOnRoad(townB.coordRoad)
|
local path=townA.coordRoad:GetPathlineOnRoad(townB.coordRoad, false, Railroad)
|
||||||
|
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
@@ -208,26 +210,59 @@ end
|
|||||||
--- Find closest town to a given coordinate.
|
--- Find closest town to a given coordinate.
|
||||||
-- @param #TOWNS self
|
-- @param #TOWNS self
|
||||||
-- @param Core.Point#COORDINATE Coordinate The reference coordinate.
|
-- @param Core.Point#COORDINATE Coordinate The reference coordinate.
|
||||||
|
-- @param #number DistMax (Optional) Max search distance in meters.
|
||||||
|
-- @param #table ExcludeList (Optional) List of towns excluded from the search.
|
||||||
-- @return #TOWNS.Town The closest town.
|
-- @return #TOWNS.Town The closest town.
|
||||||
function TOWNS:GetClosestTown(Coordinate)
|
function TOWNS:GetClosestTown(Coordinate, DistMax, ExcludeList)
|
||||||
|
|
||||||
local Town=nil --#TOWNS.Town
|
local Town=nil --#TOWNS.Town
|
||||||
local distmin=math.huge
|
local distmin=math.huge
|
||||||
|
ExcludeList=ExcludeList or {}
|
||||||
|
|
||||||
for _,_town in pairs(self.towns) do
|
for _,_town in pairs(self.towns) do
|
||||||
local town=_town --#TOWNS.Town
|
local town=_town --#TOWNS.Town
|
||||||
|
|
||||||
local dist=Coordinate:Get2DDistance(town.coordinate)
|
if (not UTILS.IsInTable(ExcludeList, town, "name")) then
|
||||||
|
|
||||||
if dist<distmin then
|
local dist=Coordinate:Get2DDistance(town.coordinate)
|
||||||
distmin=dist
|
|
||||||
Town=town
|
if dist<distmin then
|
||||||
|
distmin=dist
|
||||||
|
Town=town
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return Town
|
return Town
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Find closest towns to a given coordinate.
|
||||||
|
-- @param #TOWNS self
|
||||||
|
-- @param Core.Point#COORDINATE Coordinate The reference coordinate.
|
||||||
|
-- @param #number Nmax Max number of towns. Default 5.
|
||||||
|
-- @param #number DistMax (Optional) Max search distance in meters.
|
||||||
|
-- @return #table Table of #TOWNS.Town closest towns.
|
||||||
|
function TOWNS:GetClosestTowns(Coordinate, Nmax, DistMax)
|
||||||
|
|
||||||
|
Nmax=Nmax or 5
|
||||||
|
|
||||||
|
local closest={}
|
||||||
|
for i=1,Nmax do
|
||||||
|
|
||||||
|
local town=self:GetClosestTown(Coordinate, DistMax, closest)
|
||||||
|
|
||||||
|
if town then
|
||||||
|
table.insert(closest, town)
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return closest
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get table of all towns, optionally of a given type.
|
--- Get table of all towns, optionally of a given type.
|
||||||
-- @param #TOWNS self
|
-- @param #TOWNS self
|
||||||
-- @return #table Table of towns. Each element is of type #TOWN.Town.
|
-- @return #table Table of towns. Each element is of type #TOWN.Town.
|
||||||
|
|||||||
Reference in New Issue
Block a user