This commit is contained in:
Frank
2020-09-06 00:18:20 +02:00
parent 5ad30277ba
commit 18e192b235
4 changed files with 144 additions and 72 deletions

View File

@@ -2571,18 +2571,6 @@ function AUFTRAG:onafterAssetDead(From, Event, To, Asset)
end end
end end
-- Asset belonged to an airwing.
if self.airwing then
if self.Ncasualties==self.Nelements then
-- All elements were destroyed ==> Asset is gone.
self.airwing:RemoveAssetFromSquadron(Asset)
else
-- Not all assets were destroyed (despawn) ==> Add asset back to airwing.
self.airwing:AddAsset(Asset.flightgroup.group, 1)
end
end
-- Delete asset from mission. -- Delete asset from mission.
self:DelAsset(Asset) self:DelAsset(Asset)

View File

@@ -46,7 +46,7 @@
-- @field #boolean ishelo If true, the is a helicopter group. -- @field #boolean ishelo If true, the is a helicopter group.
-- @field #number callsignName Callsign name. -- @field #number callsignName Callsign name.
-- @field #number callsignNumber Callsign number. -- @field #number callsignNumber Callsign number.
-- @field #number Ndestroyed Number of destroyed units. -- @field #boolean despawnAfterLanding If true, group is despawned after landed at an airbase.
-- --
-- @extends Ops.OpsGroup#OPSGROUP -- @extends Ops.OpsGroup#OPSGROUP
@@ -133,7 +133,6 @@ FLIGHTGROUP = {
Tparking = nil, Tparking = nil,
menu = nil, menu = nil,
ishelo = nil, ishelo = nil,
Ndestroyed = 0,
} }
@@ -497,6 +496,14 @@ function FLIGHTGROUP:SetFuelCriticalRTB(switch)
return self return self
end end
--- Enable that the group is despawned after landing. This can be useful to avoid DCS taxi issues with other AI or players or jamming taxiways.
-- @param #FLIGHTGROUP self
-- @return #FLIGHTGROUP self
function FLIGHTGROUP:SetDespawnAfterLanding()
self.despawnAfterLanding=true
return self
end
--- Check if flight is parking. --- Check if flight is parking.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
@@ -1557,6 +1564,10 @@ function FLIGHTGROUP:onafterLanded(From, Event, To, airbase)
-- Add flight to taxiinb queue. -- Add flight to taxiinb queue.
self.flightcontrol:SetFlightStatus(self, FLIGHTCONTROL.FlightStatus.TAXIINB) self.flightcontrol:SetFlightStatus(self, FLIGHTCONTROL.FlightStatus.TAXIINB)
end end
if self.despawnAfterLanding then
self:Despawn()
end
end end
@@ -1602,6 +1613,18 @@ function FLIGHTGROUP:onafterDead(From, Event, To)
self.flightcontrol:_RemoveFlight(self) self.flightcontrol:_RemoveFlight(self)
self.flightcontrol=nil self.flightcontrol=nil
end end
if self.Ndestroyed==#self.elements then
if self.squadron then
-- All elements were destroyed ==> Asset group is gone.
self.squadron:DelGroup(self.groupname)
end
else
if self.airwing then
-- Not all assets were destroyed (despawn) ==> Add asset back to airwing.
self.airwing:AddAsset(self.group, 1)
end
end
-- Call OPSGROUP function. -- Call OPSGROUP function.
self:GetParent(self).onafterDead(self, From, Event, To) self:GetParent(self).onafterDead(self, From, Event, To)
@@ -2407,31 +2430,16 @@ function FLIGHTGROUP:onafterStop(From, Event, To)
end end
-- Destroy group. No event is generated. -- Destroy group. No event is generated.
self.group:Destroy(false) -- DISABLED for now. Should use :Despawn() or :Destroy() which then calls stop.
--self.group:Destroy(false)
end end
-- Handle events:
self:UnHandleEvent(EVENTS.Birth)
self:UnHandleEvent(EVENTS.EngineStartup)
self:UnHandleEvent(EVENTS.Takeoff)
self:UnHandleEvent(EVENTS.Land)
self:UnHandleEvent(EVENTS.EngineShutdown)
self:UnHandleEvent(EVENTS.PilotDead)
self:UnHandleEvent(EVENTS.Ejection)
self:UnHandleEvent(EVENTS.Crash)
self:UnHandleEvent(EVENTS.RemoveUnit)
-- Stop check timers.
self.timerCheckZone:Stop()
self.timerQueueUpdate:Stop()
-- Stop FSM scheduler.
self.CallScheduler:Clear()
-- Remove flight from data base. -- Remove flight from data base.
_DATABASE.FLIGHTGROUPS[self.groupname]=nil _DATABASE.FLIGHTGROUPS[self.groupname]=nil
self:I(self.lid.."STOPPED! Unhandled events, cleared scheduler and removed from database.")
-- Call OPSGROUP function.
self:GetParent(self).onafterStop(self, From, Event, To)
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@@ -40,7 +40,7 @@
-- @field #string attribute Generalized attribute. -- @field #string attribute Generalized attribute.
-- @field #number speedMax Max speed in km/h. -- @field #number speedMax Max speed in km/h.
-- @field #number speedCruise Cruising speed in km/h. -- @field #number speedCruise Cruising speed in km/h.
-- @field #number speedWp Speed to the next waypoint in km/h. -- @field #number speedWp Speed to the next waypoint in m/s.
-- @field #boolean passedfinalwp Group has passed the final waypoint. -- @field #boolean passedfinalwp Group has passed the final waypoint.
-- @field #number wpcounter Running number counting waypoints. -- @field #number wpcounter Running number counting waypoints.
-- @field #boolean respawning Group is being respawned. -- @field #boolean respawning Group is being respawned.
@@ -51,6 +51,7 @@
-- @field #boolean groupinitialized If true, group parameters were initialized. -- @field #boolean groupinitialized If true, group parameters were initialized.
-- @field #boolean detectionOn If true, detected units of the group are analyzed. -- @field #boolean detectionOn If true, detected units of the group are analyzed.
-- @field Ops.Auftrag#AUFTRAG missionpaused Paused mission. -- @field Ops.Auftrag#AUFTRAG missionpaused Paused mission.
-- @field #number Ndestroyed Number of destroyed units.
-- --
-- @field Core.Point#COORDINATE coordinate Current coordinate. -- @field Core.Point#COORDINATE coordinate Current coordinate.
-- @field Core.Point#COORDINATE position Position of the group at last status check. -- @field Core.Point#COORDINATE position Position of the group at last status check.
@@ -126,6 +127,7 @@ OPSGROUP = {
tacan = {}, tacan = {},
icls = {}, icls = {},
callsign = {}, callsign = {},
Ndestroyed = 0,
} }
--- Status of group element. --- Status of group element.
@@ -540,51 +542,73 @@ end
--- Despawn the group. The whole group is despawned and (optionally) a "Remove Unit" event is generated for all current units of the group. --- Despawn the group. The whole group is despawned and (optionally) a "Remove Unit" event is generated for all current units of the group.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #number Delay Delay in seconds before the group will be despawned. Default immediately.
-- @param #boolean NoEventRemoveUnit If true, no event "Remove Unit" is generated.
-- @return #OPSGROUP self -- @return #OPSGROUP self
function OPSGROUP:Despawn() function OPSGROUP:Despawn(Delay, NoEventRemoveUnit)
local DCSGroup=self:GetDCSGroup() if Delay and Delay>0 then
self:ScheduleOnce(Delay, OPSGROUP.Despawn, self, 0, NoEventRemoveUnit)
if DCSGroup then else
-- Destroy DCS group.
DCSGroup:destroy()
-- Get all units.
local units=self:GetDCSUnits()
-- Create a "Remove Unit" event. local DCSGroup=self:GetDCSGroup()
local EventTime=timer.getTime()
for i=1,#units do if DCSGroup then
self:CreateEventRemoveUnit(EventTime, units[i])
-- Destroy DCS group.
DCSGroup:destroy()
if not NoEventRemoveUnit then
-- Get all units.
local units=self:GetDCSUnits()
-- Create a "Remove Unit" event.
local EventTime=timer.getTime()
for i=1,#units do
self:CreateEventRemoveUnit(EventTime, units[i])
end
end
end end
end end
return self return self
end end
--- Destroy group. The whole group is despawned and a "Unit Lost" event is generated for all current units. --- Destroy group. The whole group is despawned and a *Unit Lost* for aircraft or *Dead* event for ground/naval units is generated for all current units.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #number Delay Delay in seconds before the group will be destroyed. Default immediately.
-- @return #OPSGROUP self -- @return #OPSGROUP self
function OPSGROUP:Destroy() function OPSGROUP:Destroy(Delay)
local DCSGroup=self:GetDCSGroup() if Delay and Delay>0 then
self:ScheduleOnce(Delay, OPSGROUP.Destroy, self)
if DCSGroup then else
self:I(self.lid.."Destroying group ") local DCSGroup=self:GetDCSGroup()
-- Destroy DCS group. if DCSGroup then
DCSGroup:destroy()
self:I(self.lid.."Destroying group")
-- Get all units.
local units=self:GetDCSUnits() -- Destroy DCS group.
DCSGroup:destroy()
-- Create a "Unit Lost" event.
local EventTime=timer.getTime() -- Get all units.
for i=1,#units do local units=self:GetDCSUnits()
self:CreateEventUnitLost(EventTime, units[i])
-- Create a "Unit Lost" event.
local EventTime=timer.getTime()
for i=1,#units do
if self.isAircraft then
self:CreateEventUnitLost(EventTime, units[i])
else
self:CreateEventDead(EventTime, units[i])
end
end
end end
end end
return self return self
@@ -2642,7 +2666,10 @@ function OPSGROUP:onafterElementDestroyed(From, Event, To, Element)
mission:ElementDestroyed(self, Element) mission:ElementDestroyed(self, Element)
end end
-- Increase counter.
self.Ndestroyed=self.Ndestroyed+1
-- Set element status. -- Set element status.
self:_UpdateStatus(Element, OPSGROUP.ElementStatus.DEAD) self:_UpdateStatus(Element, OPSGROUP.ElementStatus.DEAD)
@@ -2687,6 +2714,39 @@ function OPSGROUP:onafterDead(From, Event, To)
self:Stop() self:Stop()
end end
--- On after "Stop" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onafterStop(From, Event, To)
-- Handle events:
self:UnHandleEvent(EVENTS.Birth)
self:UnHandleEvent(EVENTS.EngineStartup)
self:UnHandleEvent(EVENTS.Takeoff)
self:UnHandleEvent(EVENTS.Land)
self:UnHandleEvent(EVENTS.EngineShutdown)
self:UnHandleEvent(EVENTS.PilotDead)
self:UnHandleEvent(EVENTS.Ejection)
self:UnHandleEvent(EVENTS.Crash)
self:UnHandleEvent(EVENTS.RemoveUnit)
-- Stop check timers.
self.timerCheckZone:Stop()
self.timerQueueUpdate:Stop()
-- Stop FSM scheduler.
self.CallScheduler:Clear()
if self:IsAlive() then
self:E(self.lid.."WARNING: Group is still alive! Use OPSGROUP:Destroy() or OPSGROUP:Despawn() for a clean stop")
end
-- Debug output.
self:I(self.lid.."STOPPED! Unhandled events, cleared scheduler and removed from database.")
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Internal Check Functions -- Internal Check Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@@ -448,6 +448,22 @@ function SQUADRON:DelAsset(Asset)
return self return self
end end
--- Remove airwing asset group from squadron.
-- @param #SQUADRON self
-- @param #string GroupName Name of the asset group.
-- @return #SQUADRON self
function SQUADRON:DelGroup(GroupName)
for i,_asset in pairs(self.assets) do
local asset=_asset --Ops.AirWing#AIRWING.SquadronAsset
if GroupName==asset.spawngroupname then
self:T2(self.lid..string.format("Removing asset %s", asset.spawngroupname))
table.remove(self.assets, i)
break
end
end
return self
end
--- Get name of the squadron --- Get name of the squadron
-- @param #SQUADRON self -- @param #SQUADRON self
-- @return #string Name of the squadron. -- @return #string Name of the squadron.
@@ -648,14 +664,14 @@ end
-- @param #SQUADRON self -- @param #SQUADRON self
function SQUADRON:_CheckAssetStatus() function SQUADRON:_CheckAssetStatus()
if self.verbose>=2 then if self.verbose>=2 and #self.assets>0 then
local text="" local text=""
for j,_asset in pairs(self.assets) do for j,_asset in pairs(self.assets) do
local asset=_asset --Ops.AirWing#AIRWING.SquadronAsset local asset=_asset --Ops.AirWing#AIRWING.SquadronAsset
-- Text. -- Text.
text=text..string.format("\n-[%d] %s (%s*%d): ", j, asset.spawngroupname, asset.unittype, asset.nunits) text=text..string.format("\n[%d] %s (%s*%d): ", j, asset.spawngroupname, asset.unittype, asset.nunits)
if asset.spawned then if asset.spawned then
@@ -709,7 +725,7 @@ function SQUADRON:_CheckAssetStatus()
text=text..string.format("In Stock") text=text..string.format("In Stock")
if self:IsRepaired(asset) then if self:IsRepaired(asset) then
text=text.." and Combat Ready" text=text..", Combat Ready"
else else
text=text..string.format(", Repaired in %d sec", self:GetRepairTime(asset)) text=text..string.format(", Repaired in %d sec", self:GetRepairTime(asset))