Reviewed-on: #49 Co-authored-by: dutchie031 <timrorije@gmail.com>
This commit was merged in pull request #49.
This commit is contained in:
@@ -2,7 +2,6 @@ local Util = require("classes.util.Util")
|
||||
local CapGroup = require("classes.capClasses.airGroups.CapGroup")
|
||||
local SweepGroup = require("classes.capClasses.airGroups.SweepGroup")
|
||||
local InterceptGroup = require("classes.capClasses.airGroups.InterceptGroup")
|
||||
local RunwayBombingTracker = require("classes.capClasses.runwayBombing.RunwayBombingTracker")
|
||||
local SpearheadEvents = require("classes.spearhead_events")
|
||||
local RunwayStrikeMission = require("classes.stageClasses.missions.RunwayStrikeMission")
|
||||
|
||||
@@ -37,12 +36,11 @@ end
|
||||
---@param database Database
|
||||
---@param logger table
|
||||
---@param capConfig table
|
||||
---@param stageConfig table
|
||||
---@param runwayBombingTracker RunwayBombingTracker
|
||||
---@param detectionManager DetectionManager
|
||||
---@param spawnManager SpawnManager
|
||||
---@return CapBase
|
||||
function CapBase.new(airbaseName, database, logger, capConfig, stageConfig, runwayBombingTracker, detectionManager, spawnManager)
|
||||
function CapBase.new(airbaseName, database, logger, capConfig, runwayBombingTracker, detectionManager, spawnManager)
|
||||
CapBase.__index = CapBase
|
||||
local self = setmetatable({}, { __index = CapBase }) --[[@as CapBase]]
|
||||
|
||||
@@ -61,7 +59,7 @@ function CapBase.new(airbaseName, database, logger, capConfig, stageConfig, runw
|
||||
|
||||
local baseData = database:getAirbaseDataForZone(airbaseName)
|
||||
if baseData and baseData.CapGroups then
|
||||
for key, name in pairs(baseData.CapGroups) do
|
||||
for _, name in pairs(baseData.CapGroups) do
|
||||
local capGroup = CapGroup.New(name, capConfig, logger, spawnManager)
|
||||
if capGroup then
|
||||
self.capGroupsByName[name] = capGroup
|
||||
@@ -70,7 +68,7 @@ function CapBase.new(airbaseName, database, logger, capConfig, stageConfig, runw
|
||||
end
|
||||
|
||||
if baseData and baseData.SweepGroups then
|
||||
for key, name in pairs(baseData.SweepGroups) do
|
||||
for _, name in pairs(baseData.SweepGroups) do
|
||||
local sweepGroup = SweepGroup.New(name, capConfig, logger, spawnManager)
|
||||
if sweepGroup then
|
||||
self.sweepGroupsByName[name] = sweepGroup
|
||||
@@ -79,7 +77,7 @@ function CapBase.new(airbaseName, database, logger, capConfig, stageConfig, runw
|
||||
end
|
||||
|
||||
if baseData and baseData.InterceptGroups then
|
||||
for key, name in pairs(baseData.InterceptGroups) do
|
||||
for _, name in pairs(baseData.InterceptGroups) do
|
||||
local interceptGroup = InterceptGroup.New(name, capConfig, logger, detectionManager, spawnManager)
|
||||
if interceptGroup then
|
||||
self.interceptGroupsByName[name] = interceptGroup
|
||||
@@ -97,7 +95,6 @@ function CapBase.new(airbaseName, database, logger, capConfig, stageConfig, runw
|
||||
SpearheadEvents.AddStageNumberChangedListener(self)
|
||||
|
||||
timer.scheduleFunction(CheckStateContinuous, self, timer.getTime() + 15)
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -127,7 +124,7 @@ end
|
||||
|
||||
function CapBase:SpawnIfApplicable()
|
||||
self.logger:debug("Check spawns for airbase " .. self.airbaseName)
|
||||
for groupName, capGroup in pairs(self.capGroupsByName) do
|
||||
for _, capGroup in pairs(self.capGroupsByName) do
|
||||
local targetStage = capGroup:GetZoneIDWhenStageID(tostring(self.activeStage))
|
||||
|
||||
if targetStage ~= nil and capGroup:GetState() == "UnSpawned" then
|
||||
@@ -135,7 +132,7 @@ function CapBase:SpawnIfApplicable()
|
||||
end
|
||||
end
|
||||
|
||||
for groupName, sweepGroup in pairs(self.sweepGroupsByName) do
|
||||
for _, sweepGroup in pairs(self.sweepGroupsByName) do
|
||||
local targetStage = sweepGroup:GetZoneIDWhenStageID(tostring(self.activeStage))
|
||||
|
||||
if targetStage ~= nil and sweepGroup:GetState() == "UnSpawned" then
|
||||
@@ -143,7 +140,7 @@ function CapBase:SpawnIfApplicable()
|
||||
end
|
||||
end
|
||||
|
||||
for groupName, interceptGroup in pairs(self.interceptGroupsByName) do
|
||||
for _, interceptGroup in pairs(self.interceptGroupsByName) do
|
||||
local targetStage = interceptGroup:GetZoneIDWhenStageID(tostring(self.activeStage))
|
||||
|
||||
if targetStage ~= nil and interceptGroup:GetState() == "UnSpawned" then
|
||||
@@ -154,8 +151,9 @@ end
|
||||
|
||||
function CapBase:CheckAndScheduleCAP()
|
||||
self.logger:debug("Check taskings for airbase " .. self.airbaseName)
|
||||
|
||||
---@type table<string, number>
|
||||
local countPerStage = {}
|
||||
---@type table<string, number>
|
||||
local requiredPerStage = {}
|
||||
|
||||
local airbase = Airbase.getByName(self.airbaseName)
|
||||
@@ -170,7 +168,7 @@ function CapBase:CheckAndScheduleCAP()
|
||||
if group:IsBackup() == true then
|
||||
local state = group:GetState()
|
||||
if state == "InTransit" or state == "OnStation" or state == "RtbInTen" then
|
||||
|
||||
|
||||
local supposedTargetZoneID = group:GetZoneIDWhenStageID(activeStageID)
|
||||
local currentTargetZone = group:GetCurrentTargetZoneID()
|
||||
|
||||
@@ -192,7 +190,7 @@ function CapBase:CheckAndScheduleCAP()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if countPerStage[supposedTargetZoneID] == nil then
|
||||
countPerStage[supposedTargetZoneID] = 0
|
||||
end
|
||||
@@ -231,7 +229,7 @@ function CapBase:CheckAndScheduleCAP()
|
||||
countPerStage[supposedZone] = countPerStage[supposedZone] + 1
|
||||
end
|
||||
elseif state == "InTransit" or state == "OnStation" then
|
||||
|
||||
|
||||
if supposedZone ~= group:GetCurrentTargetZoneID() then
|
||||
if countPerStage[supposedZone] < requiredPerStage[supposedZone] then
|
||||
local triggerZone = self.database:GetCapZoneForZoneID(supposedZone)
|
||||
@@ -273,7 +271,7 @@ function CapBase:CheckAndScheduleCAP()
|
||||
if triggerZone then
|
||||
group:SendToZone(triggerZone, supposedZone, airbase)
|
||||
end
|
||||
|
||||
|
||||
countPerStage[supposedZone] = countPerStage[supposedZone] + 1
|
||||
end
|
||||
end
|
||||
@@ -312,8 +310,7 @@ function CapBase:CheckAndScheduleIntercept()
|
||||
|
||||
self.logger:debug("Check intercept taskings for airbase " .. self.airbaseName)
|
||||
|
||||
local interceptZoneIDs = {}
|
||||
|
||||
---@type table<string, boolean>
|
||||
local interceptZoneIDs = {}
|
||||
|
||||
local airbase = Airbase.getByName(self.airbaseName)
|
||||
@@ -321,7 +318,7 @@ function CapBase:CheckAndScheduleIntercept()
|
||||
return nil
|
||||
end
|
||||
|
||||
for name, group in pairs(self.interceptGroupsByName) do
|
||||
for _, group in pairs(self.interceptGroupsByName) do
|
||||
local targetZoneID = group:GetZoneIDWhenStageID(tostring(self.activeStage))
|
||||
if targetZoneID then
|
||||
interceptZoneIDs[targetZoneID] = true
|
||||
@@ -357,7 +354,7 @@ function CapBase:CheckAndScheduleIntercept()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---RATIO. Amount of enemy fighters required per zone before another group gets added.
|
||||
local ratio = 4 -- Ratio of units to intercept per zone, can be adjusted
|
||||
|
||||
@@ -379,7 +376,6 @@ function CapBase:CheckAndScheduleIntercept()
|
||||
if total < required then
|
||||
for _, group in pairs(self.interceptGroupsByName) do
|
||||
if total < required then
|
||||
local zoneID = group:GetZoneIDWhenStageID(tostring(self.activeStage))
|
||||
if group:GetState() == "ReadyOnTheRamp" then
|
||||
group:SendToInterceptUnits(targets, name, airbase)
|
||||
total = total + 1
|
||||
|
||||
Reference in New Issue
Block a user