Merge branch 'FF/Develop' into FF/Fox2

This commit is contained in:
Frank
2020-02-18 00:00:38 +01:00
2 changed files with 76 additions and 19 deletions
+14 -1
View File
@@ -251,7 +251,7 @@ end
--- Adds a Airbase based on the Airbase Name in the DATABASE. --- Adds a Airbase based on the Airbase Name in the DATABASE.
-- @param #DATABASE self -- @param #DATABASE self
-- @param #string AirbaseName The name of the airbase. -- @param #string AirbaseName The name of the airbase.
-- @return Wrapper.Airbase#AIRBASE The AIRBASE object. -- @return Wrapper.Airbase#AIRBASE Airbase object.
function DATABASE:AddAirbase( AirbaseName ) function DATABASE:AddAirbase( AirbaseName )
if not self.AIRBASES[AirbaseName] then if not self.AIRBASES[AirbaseName] then
@@ -910,6 +910,7 @@ end
--- @param #DATABASE self --- @param #DATABASE self
function DATABASE:_RegisterAirbases() function DATABASE:_RegisterAirbases()
--[[
local CoalitionsData = { AirbasesRed = coalition.getAirbases( coalition.side.RED ), AirbasesBlue = coalition.getAirbases( coalition.side.BLUE ), AirbasesNeutral = coalition.getAirbases( coalition.side.NEUTRAL ) } local CoalitionsData = { AirbasesRed = coalition.getAirbases( coalition.side.RED ), AirbasesBlue = coalition.getAirbases( coalition.side.BLUE ), AirbasesNeutral = coalition.getAirbases( coalition.side.NEUTRAL ) }
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
for DCSAirbaseId, DCSAirbase in pairs( CoalitionData ) do for DCSAirbaseId, DCSAirbase in pairs( CoalitionData ) do
@@ -920,6 +921,18 @@ function DATABASE:_RegisterAirbases()
local airbase=self:AddAirbase( DCSAirbaseName ) local airbase=self:AddAirbase( DCSAirbaseName )
end end
end end
]]
for DCSAirbaseId, DCSAirbase in pairs(world.getAirbases()) do
local DCSAirbaseName = DCSAirbase:getName()
-- This gives the incorrect value to be inserted into the airdromeID for DCS 2.5.6!
local airbaseID=DCSAirbase:getID()
local airbase=self:AddAirbase( DCSAirbaseName )
self:I(string.format("Register Airbase: %s, getID=%d, GetID=%d (unique=%d)", DCSAirbaseName, DCSAirbase:getID(), airbase:GetID(), airbase:GetID(true)))
end
return self return self
end end
+51 -7
View File
@@ -355,13 +355,9 @@ AIRBASE.TerminalType = {
-- @return Wrapper.Airbase#AIRBASE -- @return Wrapper.Airbase#AIRBASE
function AIRBASE:Register( AirbaseName ) function AIRBASE:Register( AirbaseName )
-- Inherit from POSITIONABLE. local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) ) --#AIRBASE
local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) ) --#AIRBASE
-- Set airbase name.
self.AirbaseName = AirbaseName self.AirbaseName = AirbaseName
self.AirbaseID = self:GetID(true)
-- Set airbase zone.
self.AirbaseZone = ZONE_RADIUS:New( AirbaseName, self:GetVec2(), 2500 ) self.AirbaseZone = ZONE_RADIUS:New( AirbaseName, self:GetVec2(), 2500 )
-- Get Parking data. -- Get Parking data.
@@ -406,7 +402,7 @@ function AIRBASE:FindByID(id)
for name,_airbase in pairs(_DATABASE.AIRBASES) do for name,_airbase in pairs(_DATABASE.AIRBASES) do
local airbase=_airbase --#AIRBASE local airbase=_airbase --#AIRBASE
local aid=airbase:GetID() local aid=tonumber(airbase:GetID(true))
if aid==id then if aid==id then
return airbase return airbase
@@ -474,6 +470,54 @@ function AIRBASE.GetAllAirbases(coalition, category)
return airbases return airbases
end end
--- Get ID of the airbase.
-- @param #AIRBASE self
-- @param #boolean unique (Optional) If true, ships will get a negative sign as the unit ID might be the same as an airbase ID. Default off!
-- @return #number The airbase ID.
function AIRBASE:GetID(unique)
if self.AirbaseID then
return unique and self.AirbaseID or math.abs(self.AirbaseID)
else
for DCSAirbaseId, DCSAirbase in pairs(world.getAirbases()) do
-- Get the airbase name.
local AirbaseName = DCSAirbase:getName()
-- This gives the incorrect value to be inserted into the airdromeID for DCS 2.5.6!
local airbaseID=tonumber(DCSAirbase:getID())
-- No way AFIK to get the DCS version. So we check if the event exists. That should tell us if we are on DCS 2.5.6 or prior to that.
if world.event.S_EVENT_KILL and world.event.S_EVENT_KILL>0 and self:GetAirbaseCategory()==Airbase.Category.AIRDROME then
-- We have to take the key value of this loop!
airbaseID=DCSAirbaseId
-- Now another quirk: for Caucasus, we need to add 11 to the key value to get the correct ID. See https://forums.eagle.ru/showpost.php?p=4210774&postcount=11
if UTILS.GetDCSMap()==DCSMAP.Caucasus then
airbaseID=airbaseID+11
end
end
if AirbaseName==self.AirbaseName then
if self:GetAirbaseCategory()==Airbase.Category.SHIP then
-- Ships get a negative sign as their unit number might be the same as the ID of another airbase.
return unique and -airbaseID or airbaseID
else
return airbaseID
end
end
end
end
return nil
end
--- Returns a table of parking data for a given airbase. If the optional parameter *available* is true only available parking will be returned, otherwise all parking at the base is returned. Term types have the following enumerated values: --- Returns a table of parking data for a given airbase. If the optional parameter *available* is true only available parking will be returned, otherwise all parking at the base is returned. Term types have the following enumerated values:
-- --