From bd9022c01097486fca40e24306db198346db43c4 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 31 Oct 2023 10:45:56 +0100 Subject: [PATCH] ARMYGROUP Added parameter to delay init group --- Moose Development/Moose/Ops/ArmyGroup.lua | 144 ++++++++++++---------- Moose Development/Moose/Ops/OpsGroup.lua | 6 +- Moose Development/Moose/Wrapper/Group.lua | 2 + 3 files changed, 83 insertions(+), 69 deletions(-) diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index 1bbad51e8..ac893ae85 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -2043,82 +2043,90 @@ end -- @param #ARMYGROUP self -- @param #table Template Template used to init the group. Default is `self.template`. -- @return #ARMYGROUP self -function ARMYGROUP:_InitGroup(Template) +function ARMYGROUP:_InitGroup(Template, Delay) - -- First check if group was already initialized. - if self.groupinitialized then - 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 + if Delay and Delay>0 then + self:ScheduleOnce(Delay, ARMYGROUP._InitGroup, self, Template, 0) 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. - self:SetDefaultTACAN(nil, nil, nil, nil, true) - self.tacan=UTILS.DeepCopy(self.tacanDefault) + -- First check if group was already initialized. + if self.groupinitialized then + 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. - local units=self.group:GetUnits() + -- 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 + 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. - local dcsgroup=Group.getByName(self.groupname) - local size0=dcsgroup:getInitialSize() + -- Default TACAN off. + self:SetDefaultTACAN(nil, nil, nil, nil, true) + 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. - if #units~=size0 then - self:T(self.lid..string.format("ERROR: Got #units=%d but group consists of %d units!", #units, size0)) + -- Init done. + self.groupinitialized=true end - -- Add elemets. - for _,unit in pairs(units) do - local unitname=unit:GetName() - self:_AddElementByName(unitname) - end - - - -- Init done. - self.groupinitialized=true - return self end diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index ba562e542..2f423a8fa 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -1768,6 +1768,8 @@ function OPSGROUP:GetDCSUnit(UnitNumber) if DCSGroup then local unit=DCSGroup:getUnit(UnitNumber or 1) return unit + else + self:E(self.lid..string.format("ERROR: DCS group does not exist! Cannot get unit")) end return nil @@ -3517,9 +3519,11 @@ function OPSGROUP:OnEventBirth(EventData) local element=self:GetElementByName(unitname) if element and element.status~=OPSGROUP.ElementStatus.SPAWNED then - + -- Debug info. 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. self:ElementSpawned(element) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index faeb810a5..6d67c46dd 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -305,6 +305,8 @@ function GROUP:GetDCSObject() if DCSGroup then return DCSGroup + else + env.error("ERROR: Could not get DCS group object!") end return nil