cap config implemented in cap groups and bases
This commit is contained in:
@@ -18,21 +18,6 @@ function CapBase:new(airbaseId, database, logger, capConfig, stageConfig)
|
|||||||
o.logger = logger
|
o.logger = logger
|
||||||
o.activeStage = 0
|
o.activeStage = 0
|
||||||
o.capConfig = capConfig
|
o.capConfig = capConfig
|
||||||
|
|
||||||
if capConfig == nil then
|
|
||||||
capConfig = {}
|
|
||||||
table.insert(Spearhead.MissionEditingWarnings,"CapConfig is nil")
|
|
||||||
else
|
|
||||||
if capConfig.minSpeed == nil then Spearhead.MissionEditingWarnings("CapConfig.minSpeed is nil") end
|
|
||||||
if capConfig.maxSpeed == nil then Spearhead.MissionEditingWarnings("CapConfig.maxSpeed is nil") end
|
|
||||||
if capConfig.minAlt == nil then Spearhead.MissionEditingWarnings("CapConfig.minAlt is nil") end
|
|
||||||
if capConfig.maxAlt == nil then Spearhead.MissionEditingWarnings("CapConfig.maxAlt is nil") end
|
|
||||||
if capConfig.minDurationOnStation == nil then Spearhead.MissionEditingWarnings("CapConfig.minDurationOnStation is nil") end
|
|
||||||
if capConfig.maxDurationOnStation == nil then Spearhead.MissionEditingWarnings("CapConfig.maxDurationOnStation is nil") end
|
|
||||||
if capConfig.rearmDelay == nil then Spearhead.MissionEditingWarnings("CapConfig.rearmDelay is nil") end
|
|
||||||
if capConfig.deathDelay == nil then Spearhead.MissionEditingWarnings("CapConfig.deathDelay is nil") end
|
|
||||||
end
|
|
||||||
|
|
||||||
o.activeCapStages = (stageConfig or {}).capActiveStages or 10
|
o.activeCapStages = (stageConfig or {}).capActiveStages or 10
|
||||||
|
|
||||||
o.lastStatesByName = {}
|
o.lastStatesByName = {}
|
||||||
|
|||||||
@@ -140,17 +140,7 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
|
|||||||
o.markedForDespawn = false
|
o.markedForDespawn = false
|
||||||
|
|
||||||
--config
|
--config
|
||||||
o.capConfig = {}
|
o.capConfig = capConfig
|
||||||
|
|
||||||
if not capConfig then capConfig = {} end
|
|
||||||
o.capConfig.maxDeviationRange = capConfig.maxDeviationRange
|
|
||||||
o.capConfig.minSpeed = (capConfig.minSpeed or 400) * 0.514444
|
|
||||||
o.capConfig.maxSpeed = (capConfig.maxSpeed or 500) * 0.514444
|
|
||||||
o.capConfig.minAlt = (capConfig.minAlt or 8000) * 0.3048
|
|
||||||
o.capConfig.maxAlt = (capConfig.maxAlt or 27000) * 0.3048
|
|
||||||
o.capConfig.minDurationOnStation = capConfig.minDurationOnStation or 600
|
|
||||||
o.capConfig.maxDurationOnstation = capConfig.maxDurationOnStation or 1800
|
|
||||||
o.capConfig.rearmDelay = capConfig.rearmDelay or 300
|
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param self table
|
---@param self table
|
||||||
@@ -168,7 +158,7 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
|
|||||||
o.StartRearm = function(self)
|
o.StartRearm = function(self)
|
||||||
self:SpawnOnTheRamp()
|
self:SpawnOnTheRamp()
|
||||||
self:SetState(CapGroup.GroupState.REARMING)
|
self:SetState(CapGroup.GroupState.REARMING)
|
||||||
timer.scheduleFunction(SetReadyOnRampAsync, self, timer.getTime() + self.capConfig.rearmDelay - RESPAWN_AFTER_TOUCHDOWN_SECONDS)
|
timer.scheduleFunction(SetReadyOnRampAsync, self, timer.getTime() + self.capConfig:getRearmDelay() - RESPAWN_AFTER_TOUCHDOWN_SECONDS)
|
||||||
end
|
end
|
||||||
|
|
||||||
o.SpawnOnTheRamp = function(self)
|
o.SpawnOnTheRamp = function(self)
|
||||||
@@ -203,7 +193,7 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
|
|||||||
o.SendRTB = function(self)
|
o.SendRTB = function(self)
|
||||||
local group = Group.getByName(self.groupName)
|
local group = Group.getByName(self.groupName)
|
||||||
if group and group:isExist() then
|
if group and group:isExist() then
|
||||||
local speed = math.random(self.capConfig.minSpeed, self.capConfig.maxSpeed)
|
local speed = math.random(self.capConfig:getMinSpeed(), self.capConfig:getMaxSpeed())
|
||||||
local rtbTask, errormessage = Spearhead.RouteUtil.CreateRTBMission(self.groupName, self.airbaseId, speed)
|
local rtbTask, errormessage = Spearhead.RouteUtil.CreateRTBMission(self.groupName, self.airbaseId, speed)
|
||||||
if rtbTask then
|
if rtbTask then
|
||||||
timer.scheduleFunction(setTaskAsync, { task = rtbTask, groupName = self.groupName, logger = self.logger }, timer.getTime() + 3)
|
timer.scheduleFunction(setTaskAsync, { task = rtbTask, groupName = self.groupName, logger = self.logger }, timer.getTime() + 3)
|
||||||
@@ -236,21 +226,17 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
|
|||||||
local controller = group:getController()
|
local controller = group:getController()
|
||||||
local capPoints = database:getCapRouteInZone(stageZoneNumber, self.airbaseId)
|
local capPoints = database:getCapRouteInZone(stageZoneNumber, self.airbaseId)
|
||||||
|
|
||||||
local altitude = math.random(self.capConfig.minAlt, self.capConfig.maxAlt)
|
local altitude = math.random(self.capConfig:getMinAlt(), self.capConfig:getMaxAlt())
|
||||||
local speed = math.random(self.capConfig.minSpeed, self.capConfig.maxSpeed)
|
local speed = math.random(self.capConfig:getMinSpeed(), self.capConfig:getMaxSpeed())
|
||||||
local attackHelos = false
|
local attackHelos = false
|
||||||
local deviationDistance = self.capConfig.maxDeviationRange
|
local deviationDistance = self.capConfig:getMaxDeviationRange()
|
||||||
local capTask
|
local capTask
|
||||||
if self.state == CapGroup.GroupState.ONRAMP or self.onStationSince == 0 then
|
if self.state == CapGroup.GroupState.ONRAMP or self.onStationSince == 0 then
|
||||||
controller:setCommand({
|
controller:setCommand({
|
||||||
id = 'Start',
|
id = 'Start',
|
||||||
params = {}
|
params = {}
|
||||||
})
|
})
|
||||||
local duration = math.random(self.capConfig.minDurationOnStation, self.capConfig
|
local duration = math.random(self.capConfig:getMinDurationOnStation(), self.capConfig:getmaxDurationOnStation())
|
||||||
.maxDurationOnstation)
|
|
||||||
self.logger:debug("random schedule min: " ..
|
|
||||||
tostring(self.capConfig.minDurationOnStation or "nil") ..
|
|
||||||
" max: " .. tostring(self.capConfig.maxDurationOnstation or "nil") .. " actual " .. duration)
|
|
||||||
self.currentCapTaskingDuration = duration
|
self.currentCapTaskingDuration = duration
|
||||||
|
|
||||||
|
|
||||||
@@ -273,7 +259,7 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
|
|||||||
---@param airdomeId any
|
---@param airdomeId any
|
||||||
o.SendToAirbase = function(self, airdomeId)
|
o.SendToAirbase = function(self, airdomeId)
|
||||||
self.airbaseId = airdomeId
|
self.airbaseId = airdomeId
|
||||||
local speed = math.random(self.capConfig.minSpeed, self.capConfig.maxSpeed)
|
local speed = math.random(self.capConfig:getMinSpeed(), self.capConfig:getMaxSpeed())
|
||||||
local rtbTask = Spearhead.RouteUtil.CreateRTBMission(self.groupName, airdomeId, speed)
|
local rtbTask = Spearhead.RouteUtil.CreateRTBMission(self.groupName, airdomeId, speed)
|
||||||
local group = Group.getByName(self.groupName)
|
local group = Group.getByName(self.groupName)
|
||||||
local controller = group:getController()
|
local controller = group:getController()
|
||||||
@@ -345,7 +331,7 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
|
|||||||
if self.markedForDespawn == true then
|
if self.markedForDespawn == true then
|
||||||
self:Despawn()
|
self:Despawn()
|
||||||
else
|
else
|
||||||
local delay = self.capConfig.deathDelay - self.capConfig.rearmDelay + RESPAWN_AFTER_TOUCHDOWN_SECONDS
|
local delay = self.capConfig:getDeathDelay() - self.capConfig:getRearmDelay() + RESPAWN_AFTER_TOUCHDOWN_SECONDS
|
||||||
timer.scheduleFunction(DelayedStartRearm, { self = self }, timer.getTime() + delay)
|
timer.scheduleFunction(DelayedStartRearm, { self = self }, timer.getTime() + delay)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,31 +10,44 @@ function CapConfig:new()
|
|||||||
|
|
||||||
local enabled = SpearheadConfig.CapConfig.enabled or true
|
local enabled = SpearheadConfig.CapConfig.enabled or true
|
||||||
---@return boolean
|
---@return boolean
|
||||||
o.isEnabled = function() return enabled == true end
|
o.isEnabled = function(self) return enabled == true end
|
||||||
|
|
||||||
local minSpeed = tonumber(SpearheadConfig.CapConfig.minSpeed) or 400
|
local minSpeed = (tonumber(SpearheadConfig.CapConfig.minSpeed) or 400) * 0.514444
|
||||||
---@return number
|
---@return number
|
||||||
o.getMinSpeed = function() return minSpeed end
|
o.getMinSpeed = function(self) return minSpeed end
|
||||||
|
|
||||||
local maxSpeed = tonumber(SpearheadConfig.CapConfig.maxSpeed) or 400
|
local maxSpeed = (tonumber(SpearheadConfig.CapConfig.maxSpeed) or 400) * 0.514444
|
||||||
---@return number
|
---@return number
|
||||||
o.getMaxSpeed = function() return maxSpeed end
|
o.getMaxSpeed = function(self) return maxSpeed end
|
||||||
|
|
||||||
local minAlt = tonumber(SpearheadConfig.CapConfig.minAlt) or 18000
|
local minAlt = (tonumber(SpearheadConfig.CapConfig.minAlt) or 18000) * 0.3048
|
||||||
---@return number
|
---@return number
|
||||||
o.getMinAlt = function() return minAlt end
|
o.getMinAlt = function(self) return minAlt end
|
||||||
|
|
||||||
local maxAlt = tonumber(SpearheadConfig.CapConfig.maxAlt) or 28000
|
local maxAlt = (tonumber(SpearheadConfig.CapConfig.maxAlt) or 28000) * 0.3048
|
||||||
---@return number
|
---@return number
|
||||||
o.getMaxAlt = function() return maxAlt end
|
o.getMaxAlt = function(self) return maxAlt end
|
||||||
|
|
||||||
|
local minDurationOnStation = 1200
|
||||||
|
---@return number
|
||||||
|
o.getMinDurationOnStation = function(self) return minDurationOnStation end
|
||||||
|
|
||||||
|
local maxDurationOnStation = 2700
|
||||||
|
---@return number
|
||||||
|
o.getmaxDurationOnStation = function(self) return maxDurationOnStation end
|
||||||
|
|
||||||
|
local maxDeviationRange = 20 * 1852;
|
||||||
|
---@return number
|
||||||
|
o.getMaxDeviationRange = function(self) return maxDeviationRange end
|
||||||
|
|
||||||
local rearmDelay = tonumber(SpearheadConfig.CapConfig.rearmDelay) or 600
|
local rearmDelay = tonumber(SpearheadConfig.CapConfig.rearmDelay) or 600
|
||||||
---@return number
|
---@return number
|
||||||
o.getRearmDelay = function() return rearmDelay end
|
o.getRearmDelay = function(self) return rearmDelay end
|
||||||
|
|
||||||
local deathDelay = tonumber(SpearheadConfig.CapConfig.deathDelay) or 1800
|
local deathDelay = tonumber(SpearheadConfig.CapConfig.deathDelay) or 1800
|
||||||
---@return number
|
---@return number
|
||||||
o.getDeathDelay = function() return deathDelay end
|
o.getDeathDelay = function(self) return deathDelay end
|
||||||
|
o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.INFO
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
end
|
end
|
||||||
|
|||||||
+21
-8
@@ -4,37 +4,50 @@ SpearheadConfig = {
|
|||||||
CapConfig = {
|
CapConfig = {
|
||||||
--quickly enable of disable the entire CAP Logic
|
--quickly enable of disable the entire CAP Logic
|
||||||
--(you can also just rename all units to not be named "CAP_")
|
--(you can also just rename all units to not be named "CAP_")
|
||||||
enabled = true,
|
enabled = true, -- default true
|
||||||
|
|
||||||
--min ground speed for CAP aircraft during patrol
|
--min ground speed for CAP aircraft during patrol
|
||||||
-- unit: knots
|
-- unit: knots
|
||||||
minSpeed = 400,
|
minSpeed = 400, -- default 400
|
||||||
|
|
||||||
--max speed for CAP aircraft during patrol
|
--max speed for CAP aircraft during patrol
|
||||||
-- unit: knots
|
-- unit: knots
|
||||||
maxSpeed = 500,
|
maxSpeed = 500, -- default 500
|
||||||
|
|
||||||
--minAlt for aircraft on patrol
|
--minAlt for aircraft on patrol
|
||||||
-- unit: feet
|
-- unit: feet
|
||||||
minAlt = 18000,
|
minAlt = 18000, -- default 18000
|
||||||
|
|
||||||
--maxAlt for aircraft on patrol
|
--maxAlt for aircraft on patrol
|
||||||
-- unit: feet
|
-- unit: feet
|
||||||
maxAlt = 28000,
|
maxAlt = 28000, -- default 28000
|
||||||
|
|
||||||
--Delay for aircraft from touchdown to off the chocks.
|
--Delay for aircraft from touchdown to off the chocks.
|
||||||
-- unit: seconds
|
-- unit: seconds
|
||||||
rearmDelay = 600,
|
rearmDelay = 600, -- default 600
|
||||||
|
|
||||||
--Delay for aircraft from death to takeoff.
|
--Delay for aircraft from death to takeoff.
|
||||||
--When the seconds remaining is the same at the rearmDelay it will be spawned on the ramp and follow the rearm logic.
|
--When the seconds remaining is the same at the rearmDelay it will be spawned on the ramp and follow the rearm logic.
|
||||||
-- !! Can not be lower than rearmDelay
|
-- !! Can not be lower than rearmDelay
|
||||||
-- unit: seconds
|
-- unit: seconds
|
||||||
deathDelay = 1800,
|
deathDelay = 1800, -- default 1800
|
||||||
},
|
},
|
||||||
|
|
||||||
StageConfig = {
|
StageConfig = {
|
||||||
-- currently no configurable options
|
|
||||||
|
-- management of stages and its missions.
|
||||||
|
-- This is not related to CAP managers which will continue to work even if stage management is disabled
|
||||||
|
enabled = true, -- default true
|
||||||
|
|
||||||
|
--Will draw the active and the next stage
|
||||||
|
drawStages = true, -- default true
|
||||||
|
|
||||||
|
--AutoStages will continue to the next stage automatically on completion of the missions within the stage.
|
||||||
|
-- If you want to make it so the next stage triggers only when you want to disable it here and manually implement the actions needed.
|
||||||
|
--[[
|
||||||
|
TODO: Add manual stage transition documentation
|
||||||
|
]]
|
||||||
|
autoStages = true --default true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,22 +2,8 @@
|
|||||||
local dbLogger = Spearhead.LoggerTemplate:new("database", Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
local dbLogger = Spearhead.LoggerTemplate:new("database", Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
||||||
local databaseManager = Spearhead.DB:new(dbLogger)
|
local databaseManager = Spearhead.DB:new(dbLogger)
|
||||||
|
|
||||||
local capConfig = {
|
local capConfig = Spearhead.internal.configuration.CapConfig:new();
|
||||||
maxDeviationRange = 32186, --20NM -- sets max deviation before flight starts pulling back,
|
local stageConfig = Spearhead.internal.configuration.StageConfig:new();
|
||||||
minSpeed = 400,
|
|
||||||
maxSpeed = 500,
|
|
||||||
minAlt = 18000,
|
|
||||||
maxAlt = 28000,
|
|
||||||
minDurationOnStation = 1800,
|
|
||||||
maxDurationOnStation = 2700,
|
|
||||||
rearmDelay = 600,
|
|
||||||
deathDelay = 1800,
|
|
||||||
logLevel = Spearhead.LoggerTemplate.LogLevelOptions.INFO
|
|
||||||
}
|
|
||||||
|
|
||||||
local stageConfig = {
|
|
||||||
logLevel = Spearhead.LoggerTemplate.LogLevelOptions.INFO
|
|
||||||
}
|
|
||||||
|
|
||||||
Spearhead.internal.GlobalCapManager.start(databaseManager, capConfig, stageConfig)
|
Spearhead.internal.GlobalCapManager.start(databaseManager, capConfig, stageConfig)
|
||||||
Spearhead.internal.GlobalStageManager.start(databaseManager, stageConfig)
|
Spearhead.internal.GlobalStageManager.start(databaseManager, stageConfig)
|
||||||
|
|||||||
Reference in New Issue
Block a user