Develop (#16)
* Initial Methods for SpearheadAPI * Added Spearhead API * Added Spearhead API * fixed compile for api * Added notes for API in beta * Added notes for API in beta * Added Menu to all doc pages * Added Menu to all doc pages * added it for real * added it for real * fixed develop * fixed develop * fixed develop * wip * wip * updated * work in progress * work in progress * added empty docs page * wip * removed SAR files from persistence branch * Added Blue Sams as seperate class * added initial persistance * added initial persistance * added initial persistance * added initial persistance * added initial persistance * added menu to persistence markdown * added menu to persistence markdown * added menu to persistence markdown * docs update * wip * wip * Refactor of Stage classes. * wip * wip * wip * reworked bluesam and stagebase * Added waiting stage functionality * updated docs * wip * wip * wip * updated * wip * wip * wip * refactored without issues, needs testing --------- Co-authored-by: Dutchie <54616262+dutchie032@users.noreply.github.com> Co-authored-by: dutchie032 <dutchie032> Co-authored-by: ex61wi <tim.rorije@ing.com>
This commit is contained in:
committed by
GitHub
co-authored by
Dutchie
dutchie032 <dutchie032>
ex61wi
parent
9c6a5ed217
commit
ff392e0e7e
@@ -0,0 +1,91 @@
|
||||
|
||||
---@class BlueSam
|
||||
---@field Activate fun(self: BlueSam)
|
||||
---@field private _database Database
|
||||
---@field private _logger Logger
|
||||
---@field private _zoneName string
|
||||
---@field private _blueGroups Array<SpearheadGroup>
|
||||
---@field private _cleanupUnits table<string, boolean>
|
||||
local BlueSam = {}
|
||||
|
||||
function BlueSam.New(database, logger, zoneName)
|
||||
BlueSam.__index = BlueSam
|
||||
local self = setmetatable({}, BlueSam)
|
||||
|
||||
self._database = database
|
||||
self._logger = logger
|
||||
self._zoneName = zoneName
|
||||
|
||||
self._blueGroups = {}
|
||||
self._cleanupUnits = {}
|
||||
|
||||
do
|
||||
local groups = database:getBlueSamGroupsInZone(zoneName)
|
||||
|
||||
local blueUnitsPos = {}
|
||||
local redUnitsPos = {}
|
||||
|
||||
for _, groupName in pairs(groups) do
|
||||
local SpearheadGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
if SpearheadGroup then
|
||||
|
||||
if SpearheadGroup:GetCoalition() == 2 then
|
||||
table.insert(self._blueGroups, SpearheadGroup)
|
||||
end
|
||||
|
||||
|
||||
for _, unit in pairs(SpearheadGroup:GetUnits()) do
|
||||
if SpearheadGroup:GetCoalition() == 1 then
|
||||
table.insert(blueUnitsPos, unit:getPoint())
|
||||
elseif SpearheadGroup:GetCoalition() == 2 then
|
||||
table.insert(redUnitsPos, unit:getPoint())
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
SpearheadGroup:Destroy()
|
||||
end
|
||||
|
||||
do -- check cleanup requirements
|
||||
-- Checks is any of the units are withing range (5m) of another unit.
|
||||
-- If so, make sure to add them to the cleanup list.
|
||||
|
||||
local cleanup_distance = 5
|
||||
for blueUnitName, blueUnitPos in pairs(blueUnitsPos) do
|
||||
for redUnitName, redUnitPos in pairs(redUnitsPos) do
|
||||
local distance = Spearhead.Util.VectorDistance(blueUnitPos, redUnitPos)
|
||||
env.info("distance: " .. tostring(distance))
|
||||
if distance <= cleanup_distance then
|
||||
self._cleanupUnits[redUnitName] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function BlueSam:Activate()
|
||||
for unitName, needsCleanup in pairs(self._cleanupUnits) do
|
||||
if needsCleanup == true then
|
||||
Spearhead.DcsUtil.DestroyUnit(unitName)
|
||||
else
|
||||
local deathState = Spearhead.classes.persistence.Persistence.UnitDeadState(unitName)
|
||||
if deathState and deathState.isDead == true then
|
||||
Spearhead.DcsUtil.SpawnCorpse(deathState.country_id, unitName, deathState.type, deathState.pos, deathState.heading)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, group in pairs(self._blueGroups) do
|
||||
group:Spawn()
|
||||
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.Missions.SpecialZones = BlueSam
|
||||
@@ -0,0 +1,159 @@
|
||||
|
||||
|
||||
---@class StageBase
|
||||
---@field private _database Database
|
||||
---@field private _logger Logger
|
||||
---@field private _red_groups Array<SpearheadGroup>
|
||||
---@field private _blue_groups Array<SpearheadGroup>
|
||||
---@field private _cleanup_units table<string, boolean>
|
||||
---@field private _airbase table?
|
||||
---@field private _initialSide number?
|
||||
local StageBase = {}
|
||||
|
||||
---comment
|
||||
---@param databaseManager table
|
||||
---@param logger table
|
||||
---@param airbaseId integer
|
||||
---@return StageBase
|
||||
function StageBase.New(databaseManager, logger, airbaseId)
|
||||
|
||||
StageBase.__index = StageBase
|
||||
local self = setmetatable({}, StageBase)
|
||||
|
||||
self._database = databaseManager
|
||||
self._logger = logger
|
||||
|
||||
self._red_groups = {}
|
||||
self._blue_groups = {}
|
||||
self._cleanup_units = {}
|
||||
|
||||
self._airbase = Spearhead.DcsUtil.getAirbaseById(airbaseId)
|
||||
self._initialSide = Spearhead.DcsUtil.getStartingCoalition(airbaseId)
|
||||
|
||||
do --init
|
||||
local redUnitsPos = {}
|
||||
local blueUnitsPos = {}
|
||||
|
||||
do -- fill tables
|
||||
local redGroups = databaseManager:getRedGroupsAtAirbase(airbaseId)
|
||||
if redGroups then
|
||||
for _, groupName in pairs(redGroups) do
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
table.insert(self._red_groups, shGroup)
|
||||
|
||||
for _, unit in shGroup:GetUnits() do
|
||||
redUnitsPos[unit:getName()] = unit:getPoint()
|
||||
end
|
||||
|
||||
shGroup:Destroy()
|
||||
end
|
||||
end
|
||||
|
||||
local blueGroups = databaseManager:getBlueGroupsAtAirbase(airbaseId)
|
||||
if blueGroups then
|
||||
for _, groupName in pairs(blueGroups) do
|
||||
local shGroup = Spearhead.classes.stageClasses.Groups.SpearheadGroup.New(groupName)
|
||||
table.insert(self._blue_groups, shGroup)
|
||||
|
||||
for _, unit in shGroup:GetUnits() do
|
||||
blueUnitsPos[unit:getName()] = unit:getPoint()
|
||||
end
|
||||
|
||||
shGroup:Destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do -- check cleanup requirements
|
||||
-- Checks is any of the units are withing range (5m) of another unit.
|
||||
-- If so, make sure to add them to the cleanup list.
|
||||
|
||||
local cleanup_distance = 5
|
||||
|
||||
for blueUnitName, blueUnitPos in pairs(blueUnitsPos) do
|
||||
for redUnitName, redUnitPos in pairs(redUnitsPos) do
|
||||
local distance = Spearhead.Util.VectorDistance(blueUnitPos, redUnitPos)
|
||||
env.info("distance: " .. tostring(distance))
|
||||
if distance <= cleanup_distance then
|
||||
self._cleanup_units[redUnitName] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
---@private
|
||||
function StageBase:SpawnRedUnits()
|
||||
|
||||
---comment
|
||||
---@param groups Array<SpearheadGroup>
|
||||
local spawnAsync = function(groups)
|
||||
for _, group in pairs(groups) do
|
||||
group:Spawn()
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
timer.scheduleFunction(spawnAsync, self._red_groups, timer.getTime() + 3)
|
||||
end
|
||||
|
||||
---@private
|
||||
function StageBase:CleanRedUnits()
|
||||
for _, value in pairs(self._red_groups) do
|
||||
value:SpawnCorpsesOnly()
|
||||
end
|
||||
|
||||
for _, unitName in pairs(self._cleanup_units) do
|
||||
Spearhead.DcsUtil.DestroyUnit(unitName)
|
||||
Spearhead.DcsUtil.CleanCorpse(unitName)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
---@private
|
||||
function StageBase:SpawnBlueUnits()
|
||||
|
||||
---comment
|
||||
---@param groups Array<SpearheadGroup>
|
||||
local spawnAsync = function(groups)
|
||||
for _, group in pairs(groups) do
|
||||
group:Spawn()
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
timer.scheduleFunction(spawnAsync, self._blue_groups, timer.getTime() + 3)
|
||||
end
|
||||
|
||||
function StageBase:ActivateRedStage()
|
||||
if self._initialSide == 2 and self._airbase then
|
||||
self._airbase:setCoalition(1)
|
||||
self._airbase:autoCapture(false)
|
||||
end
|
||||
self:SpawnRedUnits()
|
||||
end
|
||||
|
||||
function StageBase:ActivateBlueStage()
|
||||
if self._initialSide == 2 and self._airbase then
|
||||
self._airbase:setCoalition(2)
|
||||
end
|
||||
|
||||
self:CleanRedUnits()
|
||||
self:SpawnBlueUnits()
|
||||
|
||||
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.StageBase = StageBase
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user