* added FARP zones logic
  A and B farps (Active and Blue zone farps). 
  Read more about the specifics in the reference docs
This commit is contained in:
2025-05-08 20:14:01 +02:00
committed by GitHub
parent f08cee4314
commit eba7931824
7 changed files with 213 additions and 39 deletions
@@ -0,0 +1,106 @@
---@class FarpZone
---@field private _startingFarp boolean
---@field private _groups Array<SpearheadGroup>
---@field private _padNames Array<string>
---@field private _database Database
---@field private _logger Logger
---@field private _zoneName string
local FarpZone = {}
FarpZone.__index = FarpZone
---comment
---@param database Database
---@param logger Logger
---@param zoneName string
---@return FarpZone
function FarpZone.New(database, logger, zoneName)
FarpZone.__index = FarpZone
local self = setmetatable({}, FarpZone)
self._database = database
self._logger = logger
self._zoneName = zoneName
local split = Spearhead.Util.split_string(zoneName, "_")
if string.lower(split[2]) == "a" then
self._startingFarp = true
else
self._startingFarp = false
end
logger:debug("FARP zone name: " .. zoneName .. " startingFarp" .. tostring(self._startingFarp))
local farpData = database:getFarpDataForZone(zoneName)
self._groups = {}
self._padNames = {}
if farpData then
self._padNames = farpData.padNames
for _, groupName in pairs(farpData.groups) do
local group = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
table.insert(self._groups, group)
group:Destroy()
end
end
self:Deactivate()
return self
end
---@return boolean
function FarpZone:IsStartingFarp()
return self._startingFarp
end
function FarpZone:Activate()
self._logger:info("Activating FARP zone: " .. self._zoneName)
self:BuildUp()
self:SetPadsBlue()
end
function FarpZone:Deactivate()
self:NeutralisePads()
end
function FarpZone:BuildUp()
for _, group in pairs(self._groups) do
group:Spawn()
end
end
---@private
function FarpZone:NeutralisePads()
for _, name in pairs(self._padNames) do
local base = Airbase.getByName(name)
if base then
base:autoCapture(false) -- Disable auto capture
base:setCoalition(1) -- 1 = Red (Can't neutralise)
end
end
end
---@private
function FarpZone:SetPadsBlue()
for _, name in pairs(self._padNames) do
local base = Airbase.getByName(name)
if base then
base:autoCapture(false) -- Disable auto capture
base:setCoalition(2) -- 2 = Blue
end
end
end
if Spearhead == nil then Spearhead = {} end
if Spearhead.classes == nil then Spearhead.classes = {} end
if Spearhead.classes.stageClasses == nil then Spearhead.classes.stageClasses = {} end
if Spearhead.classes.stageClasses.SpecialZones == nil then Spearhead.classes.stageClasses.SpecialZones = {} end
Spearhead.classes.stageClasses.SpecialZones.FarpZone = FarpZone
@@ -12,6 +12,7 @@
--- @field airbases Array<StageBase>
--- @field miscGroups Array<SpearheadGroup>
--- @field maxMissions integer
--- @field farps Array<FarpZone>
--- @class StageInitData
--- @field stageZoneName string
@@ -45,7 +46,6 @@ local Stage = {}
Stage.__index = Stage
local stageDrawingId = 100
Stage.StageColors = {
INVISIBLE = { r=0, g=0, b=0, a=0 },
@@ -86,7 +86,8 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
blueSams = {},
airbases ={},
miscGroups = {},
maxMissions = stageConfig.maxMissionsPerStage
maxMissions = stageConfig.maxMissionsPerStage,
farps = {},
}
self._activeStage = -99
self._preActivated = false
@@ -101,7 +102,12 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority
self._missionPriority = missionPriority
self._stageCompleteListeners = {}
stageDrawingId = stageDrawingId + 1
local farpNames = database:getFarpNamesInStage(self.zoneName)
for _, farpName in pairs(farpNames) do
local farp = Spearhead.classes.stageClasses.SpecialZones.FarpZone.New(database, logger, farpName)
table.insert(self._db.farps, farp)
end
self._logger:info("Initiating new Stage with name: " .. self.zoneName)
@@ -364,6 +370,12 @@ function Stage:ActivateStage()
end
end
for _, farp in pairs(self._db.farps) do
if farp:IsStartingFarp() == true then
farp:Activate()
end
end
timer.scheduleFunction(self.CheckContinuousAsync, self, timer.getTime() + 3)
end
@@ -430,6 +442,12 @@ function Stage:ActivateBlueGroups()
self:OnPostBlueActivated()
end)
end
for _, farp in pairs(self._db.farps) do
if farp:IsStartingFarp() == true then
farp:Activate()
end
end
end
function Stage:ActivateBlueStage()