This commit is contained in:
Applevangelist
2021-09-24 18:37:13 +02:00
parent 50c74d0852
commit 06dc9a732e

View File

@@ -17,6 +17,7 @@
-- @field #table CategoryName Names of airbase categories. -- @field #table CategoryName Names of airbase categories.
-- @field #string AirbaseName Name of the airbase. -- @field #string AirbaseName Name of the airbase.
-- @field #number AirbaseID Airbase ID. -- @field #number AirbaseID Airbase ID.
-- @field Core.Zone#ZONE AirbaseZone Circular zone around the airbase with a radius of 2500 meters. For ships this is a ZONE_UNIT object.
-- @field #number category Airbase category. -- @field #number category Airbase category.
-- @field #table descriptors DCS descriptors. -- @field #table descriptors DCS descriptors.
-- @field #boolean isAirdrome Airbase is an airdrome. -- @field #boolean isAirdrome Airbase is an airdrome.
@@ -526,19 +527,19 @@ function AIRBASE:Register(AirbaseName)
-- Inherit everything from positionable. -- Inherit everything from positionable.
local self=BASE:Inherit(self, POSITIONABLE:New(AirbaseName)) --#AIRBASE local self=BASE:Inherit(self, POSITIONABLE:New(AirbaseName)) --#AIRBASE
-- Set airbase name. -- Set airbase name.
self.AirbaseName=AirbaseName self.AirbaseName=AirbaseName
-- Set airbase ID. -- Set airbase ID.
self.AirbaseID=self:GetID(true) self.AirbaseID=self:GetID(true)
-- Get descriptors. -- Get descriptors.
self.descriptors=self:GetDesc() self.descriptors=self:GetDesc()
-- Category. -- Category.
self.category=self.descriptors and self.descriptors.category or Airbase.Category.AIRDROME self.category=self.descriptors and self.descriptors.category or Airbase.Category.AIRDROME
-- Set category. -- Set category.
if self.category==Airbase.Category.AIRDROME then if self.category==Airbase.Category.AIRDROME then
self.isAirdrome=true self.isAirdrome=true
@@ -549,17 +550,23 @@ function AIRBASE:Register(AirbaseName)
else else
self:E("ERROR: Unknown airbase category!") self:E("ERROR: Unknown airbase category!")
end end
self:_InitParkingSpots() self:_InitParkingSpots()
local vec2=self:GetVec2() local vec2=self:GetVec2()
-- Init coordinate. -- Init coordinate.
self:GetCoordinate() self:GetCoordinate()
if vec2 then if vec2 then
-- TODO: For ships we need a moving zone. if self.isShip then
self.AirbaseZone=ZONE_RADIUS:New( AirbaseName, vec2, 2500 ) local unit=UNIT:FindByName(AirbaseName)
if unit then
self.AirbaseZone=ZONE_UNIT:New(AirbaseName, unit, 2500)
end
else
self.AirbaseZone=ZONE_RADIUS:New(AirbaseName, vec2, 2500)
end
else else
self:E(string.format("ERROR: Cound not get position Vec2 of airbase %s", AirbaseName)) self:E(string.format("ERROR: Cound not get position Vec2 of airbase %s", AirbaseName))
end end
@@ -693,7 +700,7 @@ function AIRBASE:GetID(unique)
local airbaseID=tonumber(DCSAirbase:getID()) local airbaseID=tonumber(DCSAirbase:getID())
local airbaseCategory=self:GetAirbaseCategory() local airbaseCategory=self:GetAirbaseCategory()
if AirbaseName==self.AirbaseName then if AirbaseName==self.AirbaseName then
if airbaseCategory==Airbase.Category.SHIP or airbaseCategory==Airbase.Category.HELIPAD then if airbaseCategory==Airbase.Category.SHIP or airbaseCategory==Airbase.Category.HELIPAD then
-- Ships get a negative sign as their unit number might be the same as the ID of another airbase. -- Ships get a negative sign as their unit number might be the same as the ID of another airbase.
@@ -932,16 +939,16 @@ function AIRBASE:_InitParkingSpots()
-- Init table. -- Init table.
self.parking={} self.parking={}
self.parkingByID={} self.parkingByID={}
self.NparkingTotal=0 self.NparkingTotal=0
self.NparkingTerminal={} self.NparkingTerminal={}
for _,terminalType in pairs(AIRBASE.TerminalType) do for _,terminalType in pairs(AIRBASE.TerminalType) do
self.NparkingTerminal[terminalType]=0 self.NparkingTerminal[terminalType]=0
end end
-- Put coordinates of parking spots into table. -- Put coordinates of parking spots into table.
for _,spot in pairs(parkingdata) do for _,spot in pairs(parkingdata) do
-- New parking spot. -- New parking spot.
local park={} --#AIRBASE.ParkingSpot local park={} --#AIRBASE.ParkingSpot
park.Vec3=spot.vTerminalPos park.Vec3=spot.vTerminalPos
@@ -952,15 +959,15 @@ function AIRBASE:_InitParkingSpots()
park.TerminalID0=spot.Term_Index_0 park.TerminalID0=spot.Term_Index_0
park.TerminalType=spot.Term_Type park.TerminalType=spot.Term_Type
park.TOAC=spot.TO_AC park.TOAC=spot.TO_AC
self.NparkingTotal=self.NparkingTotal+1 self.NparkingTotal=self.NparkingTotal+1
for _,terminalType in pairs(AIRBASE.TerminalType) do for _,terminalType in pairs(AIRBASE.TerminalType) do
if self._CheckTerminalType(terminalType, park.TerminalType) then if self._CheckTerminalType(terminalType, park.TerminalType) then
self.NparkingTerminal[terminalType]=self.NparkingTerminal[terminalType]+1 self.NparkingTerminal[terminalType]=self.NparkingTerminal[terminalType]+1
end end
end end
self.parkingByID[park.TerminalID]=park self.parkingByID[park.TerminalID]=park
table.insert(self.parking, park) table.insert(self.parking, park)
end end
@@ -984,7 +991,7 @@ function AIRBASE:GetParkingSpotsTable(termtype)
-- Get parking data of all spots (free or occupied) -- Get parking data of all spots (free or occupied)
local parkingdata=self:GetParkingData(false) local parkingdata=self:GetParkingData(false)
-- Get parking data of all free spots. -- Get parking data of all free spots.
local parkingfree=self:GetParkingData(true) local parkingfree=self:GetParkingData(true)
@@ -1001,17 +1008,26 @@ function AIRBASE:GetParkingSpotsTable(termtype)
-- Put coordinates of parking spots into table. -- Put coordinates of parking spots into table.
local spots={} local spots={}
for _,_spot in pairs(parkingdata) do for _,_spot in pairs(parkingdata) do
if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) then if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) then
local spot=self:_GetParkingSpotByID(_spot.Term_Index) local spot=self:_GetParkingSpotByID(_spot.Term_Index)
spot.Free=_isfree(_spot) -- updated if spot then
spot.TOAC=_spot.TO_AC -- updated
spot.Free=_isfree(_spot) -- updated
table.insert(spots, spot) spot.TOAC=_spot.TO_AC -- updated
table.insert(spots, spot)
else
self:E(string.format("ERROR: Parking spot %s is nil!", tostring(_spot.Term_Index)))
end
end end
end end
return spots return spots
@@ -1032,14 +1048,14 @@ function AIRBASE:GetFreeParkingSpotsTable(termtype, allowTOAC)
for _,_spot in pairs(parkingfree) do for _,_spot in pairs(parkingfree) do
if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) and _spot.Term_Index>0 then if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) and _spot.Term_Index>0 then
if (allowTOAC and allowTOAC==true) or _spot.TO_AC==false then if (allowTOAC and allowTOAC==true) or _spot.TO_AC==false then
local spot=self:_GetParkingSpotByID(_spot.Term_Index) local spot=self:_GetParkingSpotByID(_spot.Term_Index)
spot.Free=true -- updated spot.Free=true -- updated
spot.TOAC=_spot.TO_AC -- updated spot.TOAC=_spot.TO_AC -- updated
table.insert(freespots, spot) table.insert(freespots, spot)
end end
end end
end end
@@ -1118,7 +1134,9 @@ end
-- @param #table parkingdata (Optional) Parking spots data table. If not given it is automatically derived from the GetParkingSpotsTable() function. -- @param #table parkingdata (Optional) Parking spots data table. If not given it is automatically derived from the GetParkingSpotsTable() function.
-- @return #table Table of coordinates and terminal IDs of free parking spots. Each table entry has the elements .Coordinate and .TerminalID. -- @return #table Table of coordinates and terminal IDs of free parking spots. Each table entry has the elements .Coordinate and .TerminalID.
function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nspots, parkingdata) function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nspots, parkingdata)
if group and group:IsAlive() then
-- Init default -- Init default
scanradius=scanradius or 50 scanradius=scanradius or 50
if scanunits==nil then if scanunits==nil then
@@ -1291,6 +1309,10 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius,
-- Retrun spots we found, even if there were not enough. -- Retrun spots we found, even if there were not enough.
return validspots return validspots
else
return {}
end
end end
--- Check black and white lists. --- Check black and white lists.
@@ -1392,7 +1414,7 @@ function AIRBASE:GetRunwayData(magvar, mark)
-- Get spawn points on runway. These can be used to determine the runway heading. -- Get spawn points on runway. These can be used to determine the runway heading.
local runwaycoords=self:GetParkingSpotsCoordinates(AIRBASE.TerminalType.Runway) local runwaycoords=self:GetParkingSpotsCoordinates(AIRBASE.TerminalType.Runway)
-- Debug: For finding the numbers of the spawn points belonging to each runway. -- Debug: For finding the numbers of the spawn points belonging to each runway.
if false then if false then
for i,_coord in pairs(runwaycoords) do for i,_coord in pairs(runwaycoords) do
@@ -1411,7 +1433,7 @@ function AIRBASE:GetRunwayData(magvar, mark)
-- Airbase name. -- Airbase name.
local name=self:GetName() local name=self:GetName()
-- Exceptions -- Exceptions
if name==AIRBASE.Nevada.Jean_Airport or if name==AIRBASE.Nevada.Jean_Airport or
@@ -1424,36 +1446,36 @@ function AIRBASE:GetRunwayData(magvar, mark)
-- 1-->4, 2-->3, 3-->2, 4-->1 -- 1-->4, 2-->3, 3-->2, 4-->1
exception=1 exception=1
elseif UTILS.GetDCSMap()==DCSMAP.Syria and N>=2 and elseif UTILS.GetDCSMap()==DCSMAP.Syria and N>=2 and
name~=AIRBASE.Syria.Minakh and name~=AIRBASE.Syria.Minakh and
name~=AIRBASE.Syria.Damascus and name~=AIRBASE.Syria.Damascus and
name~=AIRBASE.Syria.Khalkhalah and name~=AIRBASE.Syria.Khalkhalah and
name~=AIRBASE.Syria.Marj_Ruhayyil and name~=AIRBASE.Syria.Marj_Ruhayyil and
name~=AIRBASE.Syria.Beirut_Rafic_Hariri then name~=AIRBASE.Syria.Beirut_Rafic_Hariri then
-- 1-->3, 2-->4, 3-->1, 4-->2 -- 1-->3, 2-->4, 3-->1, 4-->2
exception=2 exception=2
end end
--- Function returning the index of the runway coordinate belonding to the given index i. --- Function returning the index of the runway coordinate belonding to the given index i.
local function f(i) local function f(i)
local j local j
if exception==1 then if exception==1 then
j=N-(i-1) -- 1-->4, 2-->3 j=N-(i-1) -- 1-->4, 2-->3
elseif exception==2 then elseif exception==2 then
if i<=N2 then if i<=N2 then
j=i+N2 -- 1-->3, 2-->4 j=i+N2 -- 1-->3, 2-->4
else else
j=i-N2 -- 3-->1, 4-->3 j=i-N2 -- 3-->1, 4-->3
end end
else else
if i%2==0 then if i%2==0 then
@@ -1461,9 +1483,9 @@ function AIRBASE:GetRunwayData(magvar, mark)
else else
j=i+1 -- odd 1-->2, 3-->4 j=i+1 -- odd 1-->2, 3-->4
end end
end end
-- Special case where there is no obvious order. -- Special case where there is no obvious order.
if name==AIRBASE.Syria.Beirut_Rafic_Hariri then if name==AIRBASE.Syria.Beirut_Rafic_Hariri then
if i==1 then if i==1 then
@@ -1496,7 +1518,7 @@ function AIRBASE:GetRunwayData(magvar, mark)
j=2 j=2
end end
end end
return j return j
end end
@@ -1505,7 +1527,7 @@ function AIRBASE:GetRunwayData(magvar, mark)
-- Get the other spawn point coordinate. -- Get the other spawn point coordinate.
local j=f(i) local j=f(i)
-- Debug info. -- Debug info.
--env.info(string.format("Runway i=%s j=%s (N=%d #runwaycoord=%d)", tostring(i), tostring(j), N, #runwaycoords)) --env.info(string.format("Runway i=%s j=%s (N=%d #runwaycoord=%d)", tostring(i), tostring(j), N, #runwaycoords))