AB v0.95wip

This commit is contained in:
Frank
2019-02-06 00:12:24 +01:00
parent 83ed456c29
commit 70d1f96681
3 changed files with 49 additions and 33 deletions
+3 -3
View File
@@ -1615,12 +1615,12 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
-- Get parking data. -- Get parking data.
local parkingdata=SpawnAirbase:GetParkingSpotsTable(termtype) local parkingdata=SpawnAirbase:GetParkingSpotsTable(termtype)
self:T2(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype))) self:E(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype)))
for _,_spot in pairs(parkingdata) do for _,_spot in pairs(parkingdata) do
self:T2(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d", self:E(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d",
SpawnAirbase:GetName(), _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy)) SpawnAirbase:GetName(), _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy))
end end
self:T(string.format("%s at %s: free parking spots = %d - number of units = %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), nfree, nunits)) self:E(string.format("%s at %s: free parking spots = %d - number of units = %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), nfree, nunits))
-- Set this to true if not enough spots are available for emergency air start. -- Set this to true if not enough spots are available for emergency air start.
local _notenough=false local _notenough=false
@@ -1719,12 +1719,12 @@ WAREHOUSE.Quantity = {
} }
--- Warehouse database. Note that this is a global array to have easier exchange between warehouses. --- Warehouse database. Note that this is a global array to have easier exchange between warehouses.
-- @type WAREHOUSE.db -- @type _WAREHOUSEDB
-- @field #number AssetID Unique ID of each asset. This is a running number, which is increased each time a new asset is added. -- @field #number AssetID Unique ID of each asset. This is a running number, which is increased each time a new asset is added.
-- @field #table Assets Table holding registered assets, which are of type @{Functional.Warehouse#WAREHOUSE.Assetitem}.# -- @field #table Assets Table holding registered assets, which are of type @{Functional.Warehouse#WAREHOUSE.Assetitem}.#
-- @field #number WarehouseID Unique ID of the warehouse. Running number. -- @field #number WarehouseID Unique ID of the warehouse. Running number.
-- @field #table Warehouses Table holding all defined @{#WAREHOUSE} objects by their unique ids. -- @field #table Warehouses Table holding all defined @{#WAREHOUSE} objects by their unique ids.
WAREHOUSE.db = { _WAREHOUSEDB = {
AssetID = 0, AssetID = 0,
Assets = {}, Assets = {},
WarehouseID = 0, WarehouseID = 0,
@@ -1835,10 +1835,10 @@ function WAREHOUSE:New(warehouse, alias)
self.warehouse=warehouse self.warehouse=warehouse
-- Increase global warehouse counter. -- Increase global warehouse counter.
WAREHOUSE.db.WarehouseID=WAREHOUSE.db.WarehouseID+1 _WAREHOUSEDB.WarehouseID=_WAREHOUSEDB.WarehouseID+1
-- Set unique ID for this warehouse. -- Set unique ID for this warehouse.
self.uid=WAREHOUSE.db.WarehouseID self.uid=_WAREHOUSEDB.WarehouseID
-- As Kalbuth found out, this would fail when using SPAWNSTATIC https://forums.eagle.ru/showthread.php?p=3703488#post3703488 -- As Kalbuth found out, this would fail when using SPAWNSTATIC https://forums.eagle.ru/showthread.php?p=3703488#post3703488
--self.uid=tonumber(warehouse:GetID()) --self.uid=tonumber(warehouse:GetID())
@@ -1854,7 +1854,7 @@ function WAREHOUSE:New(warehouse, alias)
self.spawnzone=ZONE_RADIUS:New(string.format("Warehouse %s spawn zone", self.warehouse:GetName()), warehouse:GetVec2(), 250) self.spawnzone=ZONE_RADIUS:New(string.format("Warehouse %s spawn zone", self.warehouse:GetName()), warehouse:GetVec2(), 250)
-- Add warehouse to database. -- Add warehouse to database.
WAREHOUSE.db.Warehouses[self.uid]=self _WAREHOUSEDB.Warehouses[self.uid]=self
----------------------- -----------------------
--- FSM Transitions --- --- FSM Transitions ---
@@ -2933,7 +2933,7 @@ end
-- @param #number uid The unique ID of the warehouse. -- @param #number uid The unique ID of the warehouse.
-- @return #WAREHOUSE The warehouse object or nil if no warehouse exists. -- @return #WAREHOUSE The warehouse object or nil if no warehouse exists.
function WAREHOUSE:FindWarehouseInDB(uid) function WAREHOUSE:FindWarehouseInDB(uid)
return WAREHOUSE.db.Warehouses[uid] return _WAREHOUSEDB.Warehouses[uid]
end end
--- Find nearest warehouse in service, i.e. warehouses which are not started, stopped or destroyed are not considered. --- Find nearest warehouse in service, i.e. warehouses which are not started, stopped or destroyed are not considered.
@@ -2977,7 +2977,7 @@ function WAREHOUSE:FindNearestWarehouse(MinAssets, Descriptor, DescriptorValue,
-- Loop over all warehouses. -- Loop over all warehouses.
local nearest=nil local nearest=nil
local distmin=nil local distmin=nil
for wid,warehouse in pairs(WAREHOUSE.db.Warehouses) do for wid,warehouse in pairs(_WAREHOUSEDB.Warehouses) do
local warehouse=warehouse --#WAREHOUSE local warehouse=warehouse --#WAREHOUSE
-- Distance from this warehouse to the other warehouse. -- Distance from this warehouse to the other warehouse.
@@ -3029,7 +3029,7 @@ function WAREHOUSE:FindAssetInDB(group)
if aid~=nil then if aid~=nil then
local asset=WAREHOUSE.db.Assets[aid] local asset=_WAREHOUSEDB.Assets[aid]
self:E({asset=asset}) self:E({asset=asset})
if asset==nil then if asset==nil then
self:_ErrorMessage(string.format("ERROR: Asset for group %s not found in the data base!", group:GetName()), 0) self:_ErrorMessage(string.format("ERROR: Asset for group %s not found in the data base!", group:GetName()), 0)
@@ -3210,7 +3210,7 @@ end
-- @param #string Event Event. -- @param #string Event Event.
-- @param #string To To state. -- @param #string To To state.
function WAREHOUSE:onafterStatus(From, Event, To) function WAREHOUSE:onafterStatus(From, Event, To)
self:I(self.wid..string.format("Checking status of warehouse %s. Current FSM state %s. Global warehouse assets = %d.", self.alias, self:GetState(), #WAREHOUSE.db.Assets)) self:I(self.wid..string.format("Checking status of warehouse %s. Current FSM state %s. Global warehouse assets = %d.", self.alias, self:GetState(), #_WAREHOUSEDB.Assets))
-- Check if any pending jobs are done and can be deleted from the -- Check if any pending jobs are done and can be deleted from the
self:_JobDone() self:_JobDone()
@@ -3726,10 +3726,10 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay,
local asset={} --#WAREHOUSE.Assetitem local asset={} --#WAREHOUSE.Assetitem
-- Increase asset unique id counter. -- Increase asset unique id counter.
WAREHOUSE.db.AssetID=WAREHOUSE.db.AssetID+1 _WAREHOUSEDB.AssetID=_WAREHOUSEDB.AssetID+1
-- Set parameters. -- Set parameters.
asset.uid=WAREHOUSE.db.AssetID asset.uid=_WAREHOUSEDB.AssetID
asset.templatename=templategroupname asset.templatename=templategroupname
asset.template=UTILS.DeepCopy(_DATABASE.Templates.Groups[templategroupname].Template) asset.template=UTILS.DeepCopy(_DATABASE.Templates.Groups[templategroupname].Template)
asset.category=Category asset.category=Category
@@ -3755,7 +3755,7 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay,
end end
-- Add asset to global db. -- Add asset to global db.
WAREHOUSE.db.Assets[asset.uid]=asset _WAREHOUSEDB.Assets[asset.uid]=asset
-- Add asset to the table that is retured. -- Add asset to the table that is retured.
table.insert(assets,asset) table.insert(assets,asset)
+34 -18
View File
@@ -4253,7 +4253,7 @@ function AIRBOSS:_ScanCarrierZone()
local unit=_unit --Wrapper.Unit#UNIT local unit=_unit --Wrapper.Unit#UNIT
-- Necessary conditions to be met: -- Necessary conditions to be met:
local airborne=unit:IsAir() and unit:InAir() local airborne=unit:IsAir() --and unit:InAir()
local inzone=unit:IsInZone(self.zoneCCA) local inzone=unit:IsInZone(self.zoneCCA)
local friendly=self:GetCoalition()==unit:GetCoalition() local friendly=self:GetCoalition()==unit:GetCoalition()
local carrierac=self:_IsCarrierAircraft(unit) local carrierac=self:_IsCarrierAircraft(unit)
@@ -5000,9 +5000,6 @@ function AIRBOSS:_CollapseMarshalStack(flight, nopattern)
-- Only collapse stacks above the new pattern flight. -- Only collapse stacks above the new pattern flight.
if mstack>stack then if mstack>stack then
-- OLD: New stack is old stack minus one.
--local newstack=mstack-1
-- NEW: Is this now right as we allow more flights per stack? -- NEW: Is this now right as we allow more flights per stack?
-- TODO: Question is, does the stack collapse if the lower stack is completely empty or do aircraft descent if just one flight leaves. -- TODO: Question is, does the stack collapse if the lower stack is completely empty or do aircraft descent if just one flight leaves.
@@ -5327,6 +5324,10 @@ function AIRBOSS:_PrintQueue(queue, name)
local alt=UTILS.MetersToFeet(self:_GetMarshalAltitude(stack, case)) local alt=UTILS.MetersToFeet(self:_GetMarshalAltitude(stack, case))
text=text..string.format(" stackalt=%d ft", alt) text=text..string.format(" stackalt=%d ft", alt)
end end
for j,_element in pairs(flight.elements) do
local element=_element --#AIRBOSS.FlightElement
text=text..string.format("\n (%d) %s (%s): ai=%s, ballcall=%s, recovered=%s", j, element.onboard, element.unitname, tostring(element.ai), tostring(element.ballcall), tostring(element.recovered))
end
end end
end end
self:T(self.lid..text) self:T(self.lid..text)
@@ -5383,13 +5384,14 @@ function AIRBOSS:_CreateFlightGroup(group)
local units=group:GetUnits() local units=group:GetUnits()
for i,_unit in pairs(units) do for i,_unit in pairs(units) do
local unit=_unit --Wrapper.Unit#UNIT local unit=_unit --Wrapper.Unit#UNIT
local name=unit:GetName()
local element={} --#AIRBOSS.FlightElement local element={} --#AIRBOSS.FlightElement
element.unit=unit element.unit=unit
element.onboard=flight.onboardnumbers[name] element.unitname=unit:GetName()
element.onboard=flight.onboardnumbers[element.unitname]
element.ballcall=false element.ballcall=false
element.ai=not self:_IsHumanUnit(unit) element.ai=not self:_IsHumanUnit(unit)
text=text..string.format("\n[%d] %s onboard #%s, AI=%s", i, name, tostring(element.onboard), tostring(element.ai)) element.recovered=false
text=text..string.format("\n[%d] %s onboard #%s, AI=%s", i, element.unitname, tostring(element.onboard), tostring(element.ai))
table.insert(flight.elements, element) table.insert(flight.elements, element)
end end
self:T(self.lid..text) self:T(self.lid..text)
@@ -5548,8 +5550,9 @@ end
--- Get element in flight. --- Get element in flight.
-- @param #AIRBOSS self -- @param #AIRBOSS self
-- @param #string unitname Name of the unit. -- @param #string unitname Name of the unit.
-- @return #AIRBOSS.FlightElement Element of the flight. -- @return #AIRBOSS.FlightElement Element of the flight or nil.
-- @return #number Element index. -- @return #number Element index or nil.
-- @return #AIRBOSS.FlightGroup The Flight group or nil
function AIRBOSS:_GetFlightElement(unitname) function AIRBOSS:_GetFlightElement(unitname)
-- Get the unit. -- Get the unit.
@@ -5569,7 +5572,7 @@ function AIRBOSS:_GetFlightElement(unitname)
local element=_element --#AIRBOSS.FlightElement local element=_element --#AIRBOSS.FlightElement
if element.unit:GetName()==unitname then if element.unit:GetName()==unitname then
return element, i return element, i, flight
end end
end end
@@ -5577,7 +5580,7 @@ function AIRBOSS:_GetFlightElement(unitname)
end end
end end
return nil, nil return nil, nil, nil
end end
--- Get element in flight. --- Get element in flight.
@@ -5587,7 +5590,7 @@ end
function AIRBOSS:_RemoveFlightElement(unitname) function AIRBOSS:_RemoveFlightElement(unitname)
-- Get table index. -- Get table index.
local element,idx=self:_GetFlightElement(unitname) local element,idx, flight=self:_GetFlightElement(unitname)
if idx then if idx then
table.remove(flight.elements, idx) table.remove(flight.elements, idx)
@@ -5655,7 +5658,7 @@ end
-- @return #boolean If true, all elements landed. -- @return #boolean If true, all elements landed.
function AIRBOSS:_CheckAllRecovered(flight) function AIRBOSS:_CheckAllRecovered(flight)
for _,_element in pair(flight.elements) do for _,_element in pairs(flight.elements) do
local element=_element --#AIROBSS.FlightElement local element=_element --#AIROBSS.FlightElement
if not element.recovered then if not element.recovered then
return false return false
@@ -6314,7 +6317,13 @@ function AIRBOSS:OnEventLand(EventData)
end end
-- AI always lands ==> remove unit from flight group and queues. -- AI always lands ==> remove unit from flight group and queues.
self:_RemoveUnitFromFlight(EventData.IniUnit) self:_RecoveredElement(EventData.IniUnit)
local flight=self:_GetFlightFromGroupInQueue(EventData.IniGroup, self.flights)
local allrecovered=self:_CheckAllRecovered(flight)
if allrecovered then
self:_RemoveFlightFromQueue(self.Qpattern, flight)
end
--self:_RemoveUnitFromFlight(EventData.IniUnit)
end end
end end
@@ -10372,8 +10381,14 @@ function AIRBOSS:_Debrief(playerData)
-- Player landed and is not in air anymore. -- Player landed and is not in air anymore.
if playerData.landed and not playerData.unit:InAir() then if playerData.landed and not playerData.unit:InAir() then
-- TODO: This is not 100% correct if player group has some AI units. But we do it anyway since otherwise player will -- Set recovered flag.
self:_RemoveFlightFromQueue(self.Qpattern, playerData) self:_RecoveredElement(playerData.unit)
local allrecovered=self:_CheckAllRecovered(playerData)
if allrecovered then
self:_RemoveFlightFromQueue(self.Qpattern, playerData)
end
end end
-- Increase number of passes. -- Increase number of passes.
@@ -10689,7 +10704,8 @@ function AIRBOSS:CarrierTurnIntoWind(time, vdeck)
-- Return to coordinate if collision is detected. -- Return to coordinate if collision is detected.
self.Creturnto=self:GetCoordinate() self.Creturnto=self:GetCoordinate()
-- Let the carrier make a detour from its route but return to its current position. -- Let the carrier make a detour from its route but return to its current position.
-- TODO: Add downwind speed
self:CarrierDetour(pos1, speedknots, true) self:CarrierDetour(pos1, speedknots, true)
-- Set switch that we are currently turning into the wind. -- Set switch that we are currently turning into the wind.
@@ -13089,7 +13105,7 @@ function AIRBOSS:_DisplayCarrierWeather(_unitname)
-- Get atmospheric data at carrier location. -- Get atmospheric data at carrier location.
local T=coord:GetTemperature() local T=coord:GetTemperature()
local P=coord:GetPressure() local P=coord:GetPressure()
local Wd,Ws=coord:GetWind() local Wd,Ws=coord:GetWind(50)
-- Get Beaufort wind scale. -- Get Beaufort wind scale.
local Bn,Bd=UTILS.BeaufortScale(Ws) local Bn,Bd=UTILS.BeaufortScale(Ws)