- Improved respawn behaviour
This commit is contained in:
Frank 2024-12-08 22:47:16 +01:00
parent 7e8555d6b7
commit ee880a893e
4 changed files with 236 additions and 238 deletions

View File

@ -2049,12 +2049,14 @@ end
--- Initialize group parameters. Also initializes waypoints if self.waypoints is nil.
-- @param #ARMYGROUP self
-- @param #table Template Template used to init the group. Default is `self.template`.
-- @param #number Delay Delay in seconds before group is initialized. Default `nil`, *i.e.* instantaneous.
-- @return #ARMYGROUP self
function ARMYGROUP:_InitGroup(Template, Delay)
if Delay and Delay>0 then
self:ScheduleOnce(Delay, ARMYGROUP._InitGroup, self, Template, 0)
else
-- 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!")
@ -2177,7 +2179,6 @@ function ARMYGROUP:_InitGroup(Template, Delay)
self:_AddElementByName(unitname)
end
-- Init done.
self.groupinitialized=true
end

View File

@ -3803,8 +3803,13 @@ end
--- Initialize group parameters. Also initializes waypoints if self.waypoints is nil.
-- @param #FLIGHTGROUP self
-- @param #table Template Template used to init the group. Default is `self.template`.
-- @param #number Delay Delay in seconds before group is initialized. Default `nil`, *i.e.* instantaneous.
-- @return #FLIGHTGROUP self
function FLIGHTGROUP:_InitGroup(Template)
function FLIGHTGROUP:_InitGroup(Template, Delay)
if Delay and Delay>0 then
self:ScheduleOnce(Delay, FLIGHTGROUP._InitGroup, self, Template, 0)
else
-- First check if group was already initialized.
if self.groupinitialized then
@ -3911,6 +3916,7 @@ function FLIGHTGROUP:_InitGroup(Template)
-- Init done.
self.groupinitialized=true
end
return self
end

View File

@ -1841,8 +1841,14 @@ end
--- Initialize group parameters. Also initializes waypoints if self.waypoints is nil.
-- @param #NAVYGROUP self
-- @param #table Template Template used to init the group. Default is `self.template`.
-- @param #number Delay Delay in seconds before group is initialized. Default `nil`, *i.e.* instantaneous.
-- @return #NAVYGROUP self
function NAVYGROUP:_InitGroup(Template)
function NAVYGROUP:_InitGroup(Template, Delay)
if Delay and Delay>0 then
-- Delayed call
self:ScheduleOnce(Delay, NAVYGROUP._InitGroup, self, Template, 0)
else
-- First check if group was already initialized.
if self.groupinitialized then
@ -1915,6 +1921,7 @@ function NAVYGROUP:_InitGroup(Template)
-- Init done.
self.groupinitialized=true
end
return self
end

View File

@ -7760,7 +7760,7 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
-- Despawn old group. Dont trigger any remove unit event since this is a respawn.
self:Despawn(0, true)
--self:Despawn(0, true)
else
@ -7777,13 +7777,16 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
end
-- Debug output.
self:T({Template=Template})
self:T2({Template=Template})
-- Spawn new group.
self.group=_DATABASE:Spawn(Template)
--self.group=_DATABASE:Spawn(Template)
local countryID=self.group:GetCountry()
local categoryID=self.group:GetCategory()
local dcsgroup=coalition.addGroup(countryID, categoryID, Template)
-- Set DCS group and controller.
self.dcsgroup=self:GetDCSGroup()
self.dcsgroup=dcsgroup or self:GetDCSGroup()
self.controller=self.dcsgroup:getController()
-- Set activation and controlled state.
@ -7794,7 +7797,6 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
self.isDead=false
self.isDestroyed=false
self.groupinitialized=false
self.wpcounter=1
self.currentwp=1
@ -7802,8 +7804,8 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
-- Init waypoints.
self:_InitWaypoints()
-- Init Group.
self:_InitGroup(Template)
-- Init Group. This call is delayed because NAVY groups did not like to be initialized just yet (group did not contain any units).
self:_InitGroup(Template, 0.1)
-- Reset events.
--self:ResetEvents()
@ -7830,24 +7832,6 @@ end
-- @param #string To To state.
function OPSGROUP:onafterDamaged(From, Event, To)
self:T(self.lid..string.format("Group damaged at t=%.3f", timer.getTime()))
--[[
local lifemin=nil
for _,_element in pairs(self.elements) do
local element=_element --#OPSGROUP.Element
if element.status~=OPSGROUP.ElementStatus.DEAD and element.status~=OPSGROUP.ElementStatus.INUTERO then
local life, life0=self:GetLifePoints(element)
if lifemin==nil or life<lifemin then
lifemin=life
end
end
end
if lifemin and lifemin/self.life<0.5 then
self:RTB()
end
]]
end
--- On after "Destroyed" event.