Nav updates

This commit is contained in:
Frank
2025-10-31 19:13:36 +01:00
parent bef805d694
commit 7cc18b8082
6 changed files with 185 additions and 31 deletions
+34
View File
@@ -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
+3 -8
View File
@@ -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 <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
end
+28 -1
View File
@@ -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`.
+2 -2
View File
@@ -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
+69 -6
View File
@@ -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<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.
-- @param #RADIOS self
-- @param #RADIOS.Radio Radio (Optional) Only this specifc radio.
+49 -14
View File
@@ -1,9 +1,10 @@
--- **NAVIGATION** - Beacons of the map/theatre.
--- **NAVIGATION** - Towns of the map/theatre.
--
-- **Main Features:**
--
-- * Find towns of map
-- * Road and rail connections
-- * Find closest town to a given coordinate
--
-- ===
--
@@ -83,16 +84,16 @@ TOWNS = {
--- TOWNS class version.
-- @field #string version
TOWNS.version="0.0.1"
TOWNS.version="0.1.0"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ToDo list
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: A lot...
-- TODO: Road connection
-- TODO: Rail connection
-- TODO: Connection between towns
-- DONE: Road connection
-- DONE: Rail connection
-- DONE: Connection between towns
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Constructor(s)
@@ -193,14 +194,15 @@ function TOWNS:GetCoordRail(town)
return town.coordRail
end
--- Get road connection between two towns.
--- Get road or rail connection between two towns.
-- @param #TOWNS self
-- @param #TOWNS.Town townA The town data structure.
-- @param #TOWNS.Town townB The town data structure.
-- @return #table Table containing path coordinates.
function TOWNS:GetConnectionRoad(townA, townB)
-- @param #boolean Railroad If `true`, find rail road connection
-- @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
end
@@ -208,26 +210,59 @@ end
--- Find closest town to a given coordinate.
-- @param #TOWNS self
-- @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.
function TOWNS:GetClosestTown(Coordinate)
function TOWNS:GetClosestTown(Coordinate, DistMax, ExcludeList)
local Town=nil --#TOWNS.Town
local distmin=math.huge
ExcludeList=ExcludeList or {}
for _,_town in pairs(self.towns) do
local town=_town --#TOWNS.Town
local dist=Coordinate:Get2DDistance(town.coordinate)
if (not UTILS.IsInTable(ExcludeList, town, "name")) then
if dist<distmin then
distmin=dist
Town=town
local dist=Coordinate:Get2DDistance(town.coordinate)
if dist<distmin then
distmin=dist
Town=town
end
end
end
return Town
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.
-- @param #TOWNS self
-- @return #table Table of towns. Each element is of type #TOWN.Town.