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,115 @@
|
||||
|
||||
|
||||
|
||||
---@class SpearheadGroup : OnUnitLostListener
|
||||
---@field groupName string
|
||||
---@field private isStatic boolean
|
||||
---@field private isSpawned boolean
|
||||
local SpearheadGroup = {}
|
||||
|
||||
function SpearheadGroup.New(groupName)
|
||||
|
||||
SpearheadGroup.__index = SpearheadGroup
|
||||
|
||||
local o = {}
|
||||
local self = setmetatable(o, SpearheadGroup)
|
||||
|
||||
self.isStatic = Spearhead.DcsUtil.IsGroupStatic(groupName) == true
|
||||
self.groupName = groupName
|
||||
self.isSpawned = false
|
||||
return self
|
||||
end
|
||||
|
||||
function SpearheadGroup:SpawnCorpsesOnly()
|
||||
|
||||
if self.isSpawned == true then return end
|
||||
|
||||
local group = Spearhead.DcsUtil.SpawnGroupTemplate(self.groupName)
|
||||
if group then
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
local deathState = Spearhead.classes.persistence.Persistence.UnitDeadState(unit:getName())
|
||||
|
||||
if deathState and deathState.isDead == true then
|
||||
Spearhead.DcsUtil.DestroyUnit(self.groupName, unit:getName())
|
||||
Spearhead.DcsUtil.SpawnCorpse(deathState.country_id, unit:getName(), deathState.type, deathState.pos, deathState.heading)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.isSpawned = true
|
||||
|
||||
end
|
||||
|
||||
function SpearheadGroup:Spawn()
|
||||
|
||||
if self.isSpawned == true then return end
|
||||
|
||||
local group = Spearhead.DcsUtil.SpawnGroupTemplate(self.groupName)
|
||||
if group then
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
local deathState = Spearhead.classes.persistence.Persistence.UnitDeadState(unit:getName())
|
||||
|
||||
if deathState and deathState.isDead == true then
|
||||
Spearhead.DcsUtil.DestroyUnit(self.groupName, unit:getName())
|
||||
Spearhead.DcsUtil.SpawnCorpse(deathState.country_id, unit:getName(), deathState.type, deathState.pos, deathState.heading)
|
||||
else
|
||||
Spearhead.Events.addOnUnitLostEventListener(unit:getName(), self)
|
||||
end
|
||||
|
||||
Spearhead.Events.addOnUnitLostEventListener(unit:getName(), self)
|
||||
end
|
||||
end
|
||||
|
||||
self.isSpawned = true
|
||||
end
|
||||
|
||||
function SpearheadGroup:Destroy()
|
||||
self.isSpawned = false
|
||||
Spearhead.DcsUtil.DestroyGroup(self.groupName)
|
||||
end
|
||||
|
||||
---comment
|
||||
---@return integer
|
||||
function SpearheadGroup:GetCoalition()
|
||||
if self.isStatic == true then
|
||||
local object = StaticObject.getByName(self.groupName)
|
||||
return object:getCoalition()
|
||||
else
|
||||
local group = Group.getByName(self.groupName)
|
||||
return group:getCoalition()
|
||||
end
|
||||
end
|
||||
|
||||
function SpearheadGroup:OnUnitLost(object)
|
||||
local name = object:getName()
|
||||
local pos = object:getPoint()
|
||||
local type = object:getDesc().typeName
|
||||
local position = object:getPosition()
|
||||
local heading = math.atan2(position.x.z, position.x.x)
|
||||
local country_id = object:getCountry()
|
||||
Spearhead.classes.persistence.Persistence.UnitKilled(name, pos, heading, type, country_id)
|
||||
end
|
||||
|
||||
---comment
|
||||
---@return table result list of objects
|
||||
function SpearheadGroup:GetUnits()
|
||||
|
||||
local result = {}
|
||||
if self.isStatic == true then
|
||||
local staticObject = StaticObject.getByName(self.groupName)
|
||||
if staticObject then
|
||||
table.insert(result, staticObject)
|
||||
end
|
||||
else
|
||||
local group = Group.getByName(self.groupName)
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
table.insert(result, unit)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
if not Spearhead.classes then Spearhead.classes = {} end
|
||||
if not Spearhead.classes.stageClasses then Spearhead.classes.stageClasses = {} end
|
||||
if not Spearhead.classes.stageClasses.Groups then Spearhead.classes.stageClasses.Groups = {} end
|
||||
Spearhead.classes.stageClasses.Groups.SpearheadGroup = SpearheadGroup
|
||||
Reference in New Issue
Block a user