ARMYGROUP

Added parameter to delay init group
This commit is contained in:
Frank 2023-10-31 10:45:56 +01:00
parent 375a564446
commit bd9022c010
3 changed files with 83 additions and 69 deletions

View File

@ -2043,82 +2043,90 @@ end
-- @param #ARMYGROUP self -- @param #ARMYGROUP self
-- @param #table Template Template used to init the group. Default is `self.template`. -- @param #table Template Template used to init the group. Default is `self.template`.
-- @return #ARMYGROUP self -- @return #ARMYGROUP self
function ARMYGROUP:_InitGroup(Template) function ARMYGROUP:_InitGroup(Template, Delay)
-- First check if group was already initialized. if Delay and Delay>0 then
if self.groupinitialized then self:ScheduleOnce(Delay, ARMYGROUP._InitGroup, self, Template, 0)
self:T(self.lid.."WARNING: Group was already initialized! Will NOT do it again!")
return
end
-- Get template of group.
local template=Template or self:_GetTemplate()
-- Ground are always AI.
self.isAI=true
-- Is (template) group late activated.
self.isLateActivated=template.lateActivation
-- Ground groups cannot be uncontrolled.
self.isUncontrolled=false
-- Max speed in km/h.
self.speedMax=self.group:GetSpeedMax()
-- Is group mobile?
if self.speedMax>3.6 then
self.isMobile=true
else else
self.isMobile=false
end
-- Cruise speed in km/h
self.speedCruise=self.speedMax*0.7
-- Group ammo.
self.ammo=self:GetAmmoTot()
-- Radio parameters from template.
self.radio.On=false -- Radio is always OFF for ground.
self.radio.Freq=133
self.radio.Modu=radio.modulation.AM
-- Set default radio.
self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On)
-- Get current formation from first waypoint.
self.option.Formation=template.route.points[1].action
-- Set default formation to "on road".
self.optionDefault.Formation=ENUMS.Formation.Vehicle.OnRoad
-- Default TACAN off. -- First check if group was already initialized.
self:SetDefaultTACAN(nil, nil, nil, nil, true) if self.groupinitialized then
self.tacan=UTILS.DeepCopy(self.tacanDefault) self:T(self.lid.."WARNING: Group was already initialized! Will NOT do it again!")
return
end
self:I(self.lid.."FF Initializing Group")
-- Units of the group. -- Get template of group.
local units=self.group:GetUnits() local template=Template or self:_GetTemplate()
-- Ground are always AI.
self.isAI=true
-- Is (template) group late activated.
self.isLateActivated=template.lateActivation
-- Ground groups cannot be uncontrolled.
self.isUncontrolled=false
-- Max speed in km/h.
self.speedMax=self.group:GetSpeedMax()
-- Is group mobile?
if self.speedMax>3.6 then
self.isMobile=true
else
self.isMobile=false
end
-- Cruise speed in km/h
self.speedCruise=self.speedMax*0.7
-- Group ammo.
self.ammo=self:GetAmmoTot()
-- Radio parameters from template.
self.radio.On=false -- Radio is always OFF for ground.
self.radio.Freq=133
self.radio.Modu=radio.modulation.AM
-- Set default radio.
self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On)
-- Get current formation from first waypoint.
self.option.Formation=template.route.points[1].action
-- Set default formation to "on road".
self.optionDefault.Formation=ENUMS.Formation.Vehicle.OnRoad
-- DCS group. -- Default TACAN off.
local dcsgroup=Group.getByName(self.groupname) self:SetDefaultTACAN(nil, nil, nil, nil, true)
local size0=dcsgroup:getInitialSize() self.tacan=UTILS.DeepCopy(self.tacanDefault)
-- Units of the group.
local units=self.group:GetUnits()
-- DCS group.
local dcsgroup=Group.getByName(self.groupname)
local size0=dcsgroup:getInitialSize()
local u=dcsgroup:getUnits()
-- Quick check.
if #units~=size0 then
self:T(self.lid..string.format("ERROR: Got #units=%d but group consists of %d units! u=%d", #units, size0, #u))
end
-- Add elemets.
for _,unit in pairs(units) do
local unitname=unit:GetName()
self:_AddElementByName(unitname)
end
-- Quick check. -- Init done.
if #units~=size0 then self.groupinitialized=true
self:T(self.lid..string.format("ERROR: Got #units=%d but group consists of %d units!", #units, size0))
end end
-- Add elemets.
for _,unit in pairs(units) do
local unitname=unit:GetName()
self:_AddElementByName(unitname)
end
-- Init done.
self.groupinitialized=true
return self return self
end end

View File

@ -1768,6 +1768,8 @@ function OPSGROUP:GetDCSUnit(UnitNumber)
if DCSGroup then if DCSGroup then
local unit=DCSGroup:getUnit(UnitNumber or 1) local unit=DCSGroup:getUnit(UnitNumber or 1)
return unit return unit
else
self:E(self.lid..string.format("ERROR: DCS group does not exist! Cannot get unit"))
end end
return nil return nil
@ -3517,9 +3519,11 @@ function OPSGROUP:OnEventBirth(EventData)
local element=self:GetElementByName(unitname) local element=self:GetElementByName(unitname)
if element and element.status~=OPSGROUP.ElementStatus.SPAWNED then if element and element.status~=OPSGROUP.ElementStatus.SPAWNED then
-- Debug info. -- Debug info.
self:T(self.lid..string.format("EVENT: Element %s born ==> spawned", unitname)) self:T(self.lid..string.format("EVENT: Element %s born ==> spawned", unitname))
self:T2(self.lid..string.format("DCS unit=%s isExist=%s", tostring(EventData.IniDCSUnit:getName()), tostring(EventData.IniDCSUnit:isExist()) ))
-- Set element to spawned state. -- Set element to spawned state.
self:ElementSpawned(element) self:ElementSpawned(element)

View File

@ -305,6 +305,8 @@ function GROUP:GetDCSObject()
if DCSGroup then if DCSGroup then
return DCSGroup return DCSGroup
else
env.error("ERROR: Could not get DCS group object!")
end end
return nil return nil