This commit is contained in:
Frank
2021-06-30 23:23:41 +02:00
parent b012c5b2aa
commit fa3e387dd1
4 changed files with 120 additions and 233 deletions

View File

@@ -1055,23 +1055,6 @@ function ARMYGROUP:onafterCruise(From, Event, To, Speed, Formation)
end end
--- On after "Stop" event.
-- @param #ARMYGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function ARMYGROUP:onafterStop(From, Event, To)
-- Handle events:
self:UnHandleEvent(EVENTS.Birth)
self:UnHandleEvent(EVENTS.Dead)
self:UnHandleEvent(EVENTS.RemoveUnit)
-- Call OPSGROUP function.
self:GetParent(self).onafterStop(self, From, Event, To)
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Routing -- Routing
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@@ -2079,26 +2079,6 @@ function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n)
end end
--- On after "Respawn" event.
-- @param #FLIGHTGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param #table Template The template used to respawn the group.
function FLIGHTGROUP:onafterRespawn(From, Event, To, Template)
self:T(self.lid.."Respawning group!")
local template=UTILS.DeepCopy(Template or self.template)
if self.group and self.group:InAir() then
template.lateActivation=false
self.respawning=true
self.group=self.group:Respawn(template)
end
end
--- On after "OutOfMissilesAA" event. --- On after "OutOfMissilesAA" event.
-- @param #FLIGHTGROUP self -- @param #FLIGHTGROUP self
-- @param #string From From state. -- @param #string From From state.
@@ -2856,44 +2836,6 @@ function FLIGHTGROUP:onafterFuelCritical(From, Event, To)
end end
end end
--- On after "Stop" event.
-- @param #FLIGHTGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function FLIGHTGROUP:onafterStop(From, Event, To)
-- Check if group is still alive.
if self:IsAlive() then
-- Set element parking spot to FREE (after arrived for example).
if self.flightcontrol then
for _,_element in pairs(self.elements) do
local element=_element --#FLIGHTGROUP.Element
self:_SetElementParkingFree(element)
end
end
end
self.currbase=nil
-- 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)
-- Call OPSGROUP function.
self:GetParent(self).onafterStop(self, From, Event, To)
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Task functions -- Task functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -3433,14 +3375,14 @@ function FLIGHTGROUP:InitWaypoints()
self.currbase=self:GetHomebaseFromWaypoints() self.currbase=self:GetHomebaseFromWaypoints()
-- Remove the landing waypoint. We use RTB for that. It makes adding new waypoints easier as we do not have to check if the last waypoint is the landing waypoint. -- Remove the landing waypoint. We use RTB for that. It makes adding new waypoints easier as we do not have to check if the last waypoint is the landing waypoint.
if self.destbase then if self.destbase and #self.waypoints>1 then
table.remove(self.waypoints, #self.waypoints) table.remove(self.waypoints, #self.waypoints)
else else
self.destbase=self.homebase self.destbase=self.homebase
end end
-- Debug info. -- Debug info.
self:T(self.lid..string.format("Initializing %d waypoints. Homebase %s ==> %s Destination", #self.waypoints, self.homebase and self.homebase:GetName() or "unknown", self.destbase and self.destbase:GetName() or "uknown")) self:I(self.lid..string.format("Initializing %d waypoints. Homebase %s ==> %s Destination", #self.waypoints, self.homebase and self.homebase:GetName() or "unknown", self.destbase and self.destbase:GetName() or "uknown"))
-- Update route. -- Update route.
if #self.waypoints>0 then if #self.waypoints>0 then

View File

@@ -1062,22 +1062,6 @@ function NAVYGROUP:onafterCollisionWarning(From, Event, To, Distance)
self.collisionwarning=true self.collisionwarning=true
end end
--- On after Start event. Starts the NAVYGROUP FSM and event handlers.
-- @param #NAVYGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function NAVYGROUP:onafterStop(From, Event, To)
-- Handle events:
self:UnHandleEvent(EVENTS.Birth)
self:UnHandleEvent(EVENTS.Dead)
self:UnHandleEvent(EVENTS.RemoveUnit)
-- Call OPSGROUP function.
self:GetParent(self).onafterStop(self, From, Event, To)
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Routing -- Routing

View File

@@ -378,6 +378,7 @@ OPSGROUP.TaskType={
-- @field #boolean detour If true, this waypoint is not part of the normal route. -- @field #boolean detour If true, this waypoint is not part of the normal route.
-- @field #boolean intowind If true, this waypoint is a turn into wind route point. -- @field #boolean intowind If true, this waypoint is a turn into wind route point.
-- @field #boolean astar If true, this waypint was found by A* pathfinding algorithm. -- @field #boolean astar If true, this waypint was found by A* pathfinding algorithm.
-- @field #boolean temp If true, this is a temporary waypoint and will be deleted when passed. Also the passing waypoint FSM event is not triggered.
-- @field #number npassed Number of times a groups passed this waypoint. -- @field #number npassed Number of times a groups passed this waypoint.
-- @field Core.Point#COORDINATE coordinate Waypoint coordinate. -- @field Core.Point#COORDINATE coordinate Waypoint coordinate.
-- @field Core.Point#COORDINATE roadcoord Closest point to road. -- @field Core.Point#COORDINATE roadcoord Closest point to road.
@@ -2292,20 +2293,6 @@ function OPSGROUP:OnEventBirth(EventData)
local group=EventData.IniGroup local group=EventData.IniGroup
local unitname=EventData.IniUnitName local unitname=EventData.IniUnitName
if self.respawning then
self:I(self.lid.."Respawning unit "..tostring(unitname))
local function reset()
self.respawning=nil
self:_CheckGroupDone()
end
-- Reset switch in 1 sec. This should allow all birth events of n>1 groups to have passed.
-- TODO: Can I do this more rigorously?
self:ScheduleOnce(1, reset)
else
-- Set homebase if not already set. -- Set homebase if not already set.
if self.isFlightgroup then if self.isFlightgroup then
@@ -2321,7 +2308,7 @@ function OPSGROUP:OnEventBirth(EventData)
self.destbase=self.homebase self.destbase=self.homebase
end end
self:T(self.lid..string.format("EVENT: Element %s born at airbase %s==> spawned", unitname, self.homebase and self.homebase:GetName() or "unknown")) self:I(self.lid..string.format("EVENT: Element %s born at airbase %s ==> spawned", unitname, self.homebase and self.homebase:GetName() or "unknown"))
else else
self:T3(self.lid..string.format("EVENT: Element %s born ==> spawned", unitname)) self:T3(self.lid..string.format("EVENT: Element %s born ==> spawned", unitname))
end end
@@ -2336,8 +2323,6 @@ function OPSGROUP:OnEventBirth(EventData)
end end
end
--- Event function handling the crash of a unit. --- Event function handling the crash of a unit.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param Core.Event#EVENTDATA EventData Event data. -- @param Core.Event#EVENTDATA EventData Event data.
@@ -3755,7 +3740,7 @@ end
-- FSM Events -- FSM Events
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- On after "PassingWaypoint" event. --- Check if group is currently waiting.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #boolean If true, group is currently waiting. -- @param #boolean If true, group is currently waiting.
function OPSGROUP:IsWaiting() function OPSGROUP:IsWaiting()
@@ -3776,8 +3761,10 @@ function OPSGROUP:onafterWait(From, Event, To, Duration)
-- Order Group to hold. -- Order Group to hold.
self:FullStop() self:FullStop()
-- Set time stamp.
self.Twaiting=timer.getAbsTime() self.Twaiting=timer.getAbsTime()
-- Max waiting
self.dTwait=Duration self.dTwait=Duration
end end
@@ -4567,25 +4554,6 @@ function OPSGROUP:onafterElementDead(From, Event, To, Element)
end end
end end
-- Check cargo bay and declare cargo groups dead.
--[[
for groupname, carriername in pairs(self.cargoBay or {}) do
if Element.name==carriername then
local opsgroup=_DATABASE:GetOpsGroup(groupname)
if opsgroup and not (opsgroup:IsDead() or opsgroup:IsStopped()) then
for _,element in pairs(opsgroup.elements) do
-- Debug info.
self:T2(self.lid.."Cargo element dead "..element.name)
-- Trigger dead event.
opsgroup:ElementDead(element)
end
end
end
end
]]
-- Check cargo bay and declare cargo groups dead. -- Check cargo bay and declare cargo groups dead.
for _,_element in pairs(self.elements) do for _,_element in pairs(self.elements) do
@@ -4593,6 +4561,16 @@ function OPSGROUP:onafterElementDead(From, Event, To, Element)
for _,_cargo in pairs(element.cargoBay) do for _,_cargo in pairs(element.cargoBay) do
local cargo=_cargo --#OPSGROUP.MyCargo local cargo=_cargo --#OPSGROUP.MyCargo
if cargo.group and not (cargo.group:IsDead() or cargo.group:IsStopped()) then if cargo.group and not (cargo.group:IsDead() or cargo.group:IsStopped()) then
-- Remove my carrier
cargo.group:_RemoveMyCarrier()
if cargo.reserved then
-- This group was not loaded yet ==> Not cargo any more.
cargo.group.cargoStatus=OPSGROUP.CargoStatus.NOTCARGO
else
-- Carrier dead ==> cargo dead.
for _,cargoelement in pairs(cargo.group.elements) do for _,cargoelement in pairs(cargo.group.elements) do
-- Debug info. -- Debug info.
@@ -4603,12 +4581,8 @@ function OPSGROUP:onafterElementDead(From, Event, To, Element)
end end
end end
end
end
if self:IsCarrier() then end
if self.cargoTransport then
self.cargoTransport:DeadCarrierGroup(self)
end end
end end
@@ -4714,6 +4688,10 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
-- Debug output. -- Debug output.
self:I({Template=Template}) self:I({Template=Template})
--if self:IsStopped() then
--self:InitWaypoints()
--end
-- Spawn new group. -- Spawn new group.
_DATABASE:Spawn(Template) _DATABASE:Spawn(Template)
@@ -4721,6 +4699,7 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
self.isLateActivated=Template.lateActivation self.isLateActivated=Template.lateActivation
self.isUncontrolled=Template.uncontrolled self.isUncontrolled=Template.uncontrolled
-- Reset events. -- Reset events.
--self:ResetEvents() --self:ResetEvents()
@@ -4772,20 +4751,45 @@ function OPSGROUP:onafterDead(From, Event, To)
end end
-- Delete waypoints so they are re-initialized at the next spawn.
self:ClearWaypoints()
self.groupinitialized=false
-- Set cargo status to NOTCARGO.
self.cargoStatus=OPSGROUP.CargoStatus.NOTCARGO
self.carrierStatus=OPSGROUP.CarrierStatus.NOTCARRIER
-- Remove from cargo bay of carrier.
local mycarrier=self:_GetMyCarrierGroup()
if mycarrier and not mycarrier:IsDead() then
mycarrier:_DelCargobay(self)
self:_RemoveMyCarrier()
end
-- Inform all transports in the queue that this carrier group is dead now. -- Inform all transports in the queue that this carrier group is dead now.
for i,_transport in pairs(self.cargoqueue) do for i,_transport in pairs(self.cargoqueue) do
local transport=_transport --Ops.OpsTransport#OPSTRANSPORT local transport=_transport --Ops.OpsTransport#OPSTRANSPORT
transport:DeadCarrierGroup(self) transport:__DeadCarrierGroup(1, self)
end end
-- Delete waypoints so they are re-initialized at the next spawn.
self.waypoints=nil
self.groupinitialized=false
-- Stop in a sec. -- Stop in a sec.
self:__Stop(-5) self:__Stop(-5)
end end
--- On before "Stop" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onbeforeStop(From, Event, To)
if self:IsAlive() then
return false
end
return true
end
--- On after "Stop" event. --- On after "Stop" event.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
@@ -4793,6 +4797,23 @@ end
-- @param #string To To state. -- @param #string To To state.
function OPSGROUP:onafterStop(From, Event, To) function OPSGROUP:onafterStop(From, Event, To)
-- Handle events:
self:UnHandleEvent(EVENTS.Birth)
self:UnHandleEvent(EVENTS.Dead)
self:UnHandleEvent(EVENTS.RemoveUnit)
-- Handle events:
if self.isFlightgroup then
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.currbase=nil
end
-- Stop check timers. -- Stop check timers.
self.timerCheckZone:Stop() self.timerCheckZone:Stop()
self.timerQueueUpdate:Stop() self.timerQueueUpdate:Stop()
@@ -4827,18 +4848,6 @@ function OPSGROUP:_CheckCargoTransport()
local Time=timer.getAbsTime() local Time=timer.getAbsTime()
-- Cargo bay debug info. -- Cargo bay debug info.
--[[
if self.verbose>=3 then
local text=""
for cargogroupname, carriername in pairs(self.cargoBay) do
text=text..string.format("\n- %s in carrier %s", tostring(cargogroupname), tostring(carriername))
end
if text~="" then
self:I(self.lid.."Cargo bay:"..text)
end
end
]]
-- Check cargo bay and declare cargo groups dead. -- Check cargo bay and declare cargo groups dead.
if self.verbose>=0 then if self.verbose>=0 then
local text="" local text=""
@@ -5045,7 +5054,6 @@ function OPSGROUP:_AddCargobay(CargoGroup, CarrierElement, Reserved)
end end
-- Set my carrier. -- Set my carrier.
CargoGroup:_SetMyCarrier(self, CarrierElement, Reserved) CargoGroup:_SetMyCarrier(self, CarrierElement, Reserved)
@@ -5500,22 +5508,6 @@ function OPSGROUP:FindCarrierForCargo(CargoGroup)
return nil return nil
end end
--- Reserve cargo space for a cargo group.
-- @param #OPSGROUP self
-- @param #OPSGROUP CargoGroup Cargo group, which needs a carrier.
-- @return #OPSGROUP.Element Carrier able to transport the cargo.
function OPSGROUP:ReserveCargoSpace(CargoGroup)
local element=self:FindCarrierForCargo(CargoGroup)
if element then
element.reservedCargo=element.reservedCargo or {}
table.insert(element.reservedCargo, CargoGroup)
end
return nil
end
--- Set my carrier. --- Set my carrier.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #OPSGROUP CarrierGroup Carrier group. -- @param #OPSGROUP CarrierGroup Carrier group.
@@ -5688,8 +5680,7 @@ function OPSGROUP:onafterPickup(From, Event, To)
-- If this is a helo and no ZONE_AIRBASE was given, we make the helo land in the pickup zone. -- If this is a helo and no ZONE_AIRBASE was given, we make the helo land in the pickup zone.
Coordinate:SetAltitude(200) Coordinate:SetAltitude(200)
local waypoint=FLIGHTGROUP.AddWaypoint(self, Coordinate) local waypoint=FLIGHTGROUP.AddWaypoint(self, Coordinate) ; waypoint.detour=true
waypoint.detour=true
else else
self:E(self.lid.."ERROR: Carrier aircraft cannot land in Pickup zone! Specify a ZONE_AIRBASE as pickup zone") self:E(self.lid.."ERROR: Carrier aircraft cannot land in Pickup zone! Specify a ZONE_AIRBASE as pickup zone")
@@ -5733,26 +5724,6 @@ function OPSGROUP:onafterLoading(From, Event, To)
-- Loading time stamp. -- Loading time stamp.
self.Tloading=timer.getAbsTime() self.Tloading=timer.getAbsTime()
-- Create a temp array and monitor the free cargo space for each element.
local cargobay={}
for _,_element in pairs(self.elements) do
local element=_element --#OPSGROUP.Element
cargobay[element.name]=element.weightMaxCargo-element.weightCargo
end
--- Find a carrier which can load a given weight.
local function _findCarrier(weight)
local carrier=nil --#OPSGROUP.Element
for _,_element in pairs(self.elements) do
local element=_element --#OPSGROUP.Element
if cargobay[element.name]>=weight then
return element
end
end
return nil
end
--TODO: sort cargos wrt weight. --TODO: sort cargos wrt weight.
-- Loop over all cargos. -- Loop over all cargos.
@@ -5772,19 +5743,11 @@ function OPSGROUP:onafterLoading(From, Event, To)
-- Cargo MUST be inside zone or it will not be loaded! -- Cargo MUST be inside zone or it will not be loaded!
if inzone then if inzone then
-- Weight of cargo. -- Find a carrier for this cargo.
local weight=cargo.opsgroup:GetWeightTotal()
-- Find a carrier that has enough free cargo bay for this group.
local carrier=_findCarrier(weight)
local carrier=self:FindCarrierForCargo(cargo.opsgroup) local carrier=self:FindCarrierForCargo(cargo.opsgroup)
if carrier then if carrier then
-- Decrease free cargo bay.
cargobay[carrier.name]=cargobay[carrier.name]-weight
-- Set cargo status. -- Set cargo status.
cargo.opsgroup.cargoStatus=OPSGROUP.CargoStatus.ASSIGNED cargo.opsgroup.cargoStatus=OPSGROUP.CargoStatus.ASSIGNED
@@ -5918,6 +5881,23 @@ function OPSGROUP:onafterLoaded(From, Event, To)
end end
--- On before "Transport" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onbeforeTransport(From, Event, To)
if self.cargoTransport==nil then
return false
elseif self.cargoTransport:IsDelivered() then --could be if all cargo was dead on boarding
return false
end
return true
end
--- On after "Transport" event. --- On after "Transport" event.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
@@ -6011,8 +5991,7 @@ function OPSGROUP:onafterTransport(From, Event, To)
-- If this is a helo and no ZONE_AIRBASE was given, we make the helo land in the pickup zone. -- If this is a helo and no ZONE_AIRBASE was given, we make the helo land in the pickup zone.
Coordinate:SetAltitude(200) Coordinate:SetAltitude(200)
local waypoint=FLIGHTGROUP.AddWaypoint(self, Coordinate) local waypoint=FLIGHTGROUP.AddWaypoint(self, Coordinate) ; waypoint.detour=true
waypoint.detour=true
else else
self:E(self.lid.."ERROR: Carrier aircraft cannot land in Deploy zone! Specify a ZONE_AIRBASE as deploy zone") self:E(self.lid.."ERROR: Carrier aircraft cannot land in Deploy zone! Specify a ZONE_AIRBASE as deploy zone")
@@ -6461,12 +6440,10 @@ function OPSGROUP:onafterBoard(From, Event, To, CarrierGroup, Carrier)
self:ClearWaypoints() self:ClearWaypoints()
if self.isArmygroup then if self.isArmygroup then
local waypoint=ARMYGROUP.AddWaypoint(self, Coordinate) local waypoint=ARMYGROUP.AddWaypoint(self, Coordinate) ; waypoint.detour=0
waypoint.detour=true
self:Cruise() self:Cruise()
else else
local waypoint=NAVYGROUP.AddWaypoint(self, Coordinate) local waypoint=NAVYGROUP.AddWaypoint(self, Coordinate) ; waypoint.detour=0
waypoint.detour=true
self:Cruise() self:Cruise()
end end
@@ -7322,6 +7299,7 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid)
opsgroup:Cruise() opsgroup:Cruise()
else else
opsgroup:E("ERROR: waypoint.detour should be 0 or 1") opsgroup:E("ERROR: waypoint.detour should be 0 or 1")
opsgroup:FullStop()
end end
end end