- Taxiways
This commit is contained in:
Frank 2023-09-11 16:54:10 +02:00
parent f8d91798e3
commit cffada1a1e
2 changed files with 86 additions and 9 deletions

View File

@ -1015,7 +1015,7 @@ function ASTAR:GetPathline(ExcludeStartNode, ExcludeEndNode)
for _,_note in pairs(nodes) do
local note=_note --#ASTAR.Node
pathline:AddPointFromVec3(note.coordinate)
local point=pathline:AddPointFromVec3(note.coordinate)
end
@ -1026,8 +1026,7 @@ end
--- Get pathlines from nodes.
-- @param #ASTAR self
-- @param #boolean ExcludeStartNode If *true*, do not include start node in found path. Default is to include it.
-- @param #boolean ExcludeEndNode If *true*, do not include end node in found path. Default is to include it.
-- @param #table Nodes Given nodes.
-- @return #table Table of PATHLINES used in the path.
function ASTAR:GetPathlinesFromNodes(Nodes)
@ -1037,25 +1036,29 @@ function ASTAR:GetPathlinesFromNodes(Nodes)
for i=1,#Nodes do
local node=Nodes[i] --#ASTAR.Node
-- Pathline.
local pathline=node.pathline
if pathline and i>1 and i<#Nodes then
-- Previous and next nodes.
local n=Nodes[i-1] --#ASTAR.Node
local N=Nodes[i+1] --#ASTAR.Node
-- Check if previous and next nodes are
-- Check if previous and next nodes are on the same pathline.
-- If only one point in beteen is of another pathline, this is a junction and we dont actually switch to the other pathline.
if n.pathline and N.pathline and n.pathline.name==N.pathline.name and n.pathline.name~=pathline.name then
env.info("FF 100 "..pathline.name)
pathline=n.pathline
end
end
-- Add pathline to table (if it is not already in).
if not UTILS.IsAnyInTable(pathlines, {pathline}, "name") then
env.info(string.format("Adding pathline %s", pathline.name, tostring(UTILS.IsAnyInTable(pathlines, pathline))))
--if not UTILS.IsAnyInTable(pathlines, {pathline}, "name") then
--env.info(string.format("Adding pathline %s", pathline.name, tostring(UTILS.IsAnyInTable(pathlines, pathline))))
-- We do not want to add the same pathline two times in a row.
if #pathlines==0 or (#pathlines>0 and pathlines[#pathlines].name~=pathline.name) then
table.insert(pathlines, pathline)
end
end

View File

@ -31,6 +31,7 @@
-- @field #AIRBASE.Runway runwayLanding Runway used for landing.
-- @field #AIRBASE.Runway runwayTakeoff Runway used for takeoff.
-- @field Wrapper.Storage#STORAGE storage The DCS warehouse storage.
-- @field #table taxiways Taxiways stored as PATHLINEs.
-- @extends Wrapper.Positionable#POSITIONABLE
--- Wrapper class to handle the DCS Airbase objects:
@ -73,6 +74,7 @@ AIRBASE = {
[Airbase.Category.SHIP] = "Ship",
},
activerwyno = nil,
taxiways = {},
}
--- Enumeration to identify the airbases in the Caucasus region.
@ -1193,6 +1195,78 @@ function AIRBASE:IsShip()
return self.isShip
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Taxi ways
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Add a taxiway from a given PATHLINE.
-- @param #AIRBASE self
-- @param Core.Pathline#PATHLINE TaxiPathline Pathline of the taxi way.
-- @param #string Name Name of the taxi way, *e.g.* "Alpha", or "Alpha-Kilo".
-- @return #boolean If `true`, silent mode is enabled.
function AIRBASE:AddTaxiway(TaxiPathline, Name)
self.taxiways[Name]=TaxiPathline
end
--- Find the shortest path using taxiways to get from given coodinates A to B on the airbase.
-- Note that the taxi ways have to be manually added with the `AIRBASE:AddTaxiway()` function.
-- @param #AIRBASE self
-- @param Core.Point#COORDINATE StartCoord Start coordinate.
-- @param Core.Point#COORDINATE EndCoord End coordinate.
-- @return Core.Pathline#PATHLINE Shortest path on taxiways from `StartCoord` to `EndCoord`.
-- @return #table Table of used taxi way pathlines.
function AIRBASE:FindTaxiwaysFromAtoB(StartCoord, EndCoord)
-- Create A* pathfinding.
local astar=ASTAR:New()
-- Add pathlines of taxiways of airport.
for _,_taxiway in pairs(self.taxiways) do
local taxiway=_taxiway --Core.Pathline#PATHLINE
astar:AddNodeFromPathlineName(taxiway)
end
-- Set cost function.
astar:SetCostDist2D()
-- Set valid neighbours to be on the same pathline or at most 10 meters between nodes to jump from one pathline/taxiway to another.
astar:SetValidNeighbourPathline(10)
-- Set start and end coordinates.
astar:SetStartCoordinate(StartCoord)
astar:SetEndCoordinate(EndCoord)
-- Get pathline.
local taxipath, nodes=astar:GetPathline()
local taxiways=astar:GetPathlinesFromNodes(nodes)
return taxipath, taxiways
end
--- Find the shortest path using taxiways to get from given parking spot to the starting point of a runway.
-- Note that the taxi ways have to be manually added with the `AIRBASE:AddTaxiway()` function.
-- @param #AIRBASE self
-- @param #AIRBASE.ParkingSpot ParkingSport Parking spot.
-- @param #AIRBASE.Runway Runway The runway. If none is given, we take the active runway for takeoff.
-- @return Core.Pathline#PATHLINE Shortest path on taxiways from `StartCoord` to `EndCoord`.
-- @return #table Table of used taxi way pathlines.
function AIRBASE:FindTaxiwaysParkingToRunway(ParkingSpot, Runway)
Runway=Runway or self:GetActiveRunwayTakeoff()
local StartCoord=ParkingSpot.Coordinate
local EndCoord=Runway.position
local taxipath, taxiways=self:FindTaxiwaysFromAtoB(StartCoord,EndCoord)
return taxipath, taxiways
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Parking
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------