mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
OPS Cargo
This commit is contained in:
parent
c50f6b72e7
commit
302018feff
@ -541,6 +541,10 @@ function ARMYGROUP:onafterSpawned(From, Event, To)
|
|||||||
-- Update position.
|
-- Update position.
|
||||||
self:_UpdatePosition()
|
self:_UpdatePosition()
|
||||||
|
|
||||||
|
-- Not dead or destroyed yet.
|
||||||
|
self.isDead=false
|
||||||
|
self.isDestroyed=false
|
||||||
|
|
||||||
if self.isAI then
|
if self.isAI then
|
||||||
|
|
||||||
-- Set default ROE.
|
-- Set default ROE.
|
||||||
|
|||||||
@ -1530,6 +1530,10 @@ function FLIGHTGROUP:onafterSpawned(From, Event, To)
|
|||||||
-- Update position.
|
-- Update position.
|
||||||
self:_UpdatePosition()
|
self:_UpdatePosition()
|
||||||
|
|
||||||
|
-- Not dead or destroyed yet.
|
||||||
|
self.isDead=false
|
||||||
|
self.isDestroyed=false
|
||||||
|
|
||||||
if self.isAI then
|
if self.isAI then
|
||||||
|
|
||||||
-- Set ROE.
|
-- Set ROE.
|
||||||
@ -2068,11 +2072,14 @@ function FLIGHTGROUP:_CheckGroupDone(delay)
|
|||||||
-- Number of cargo transports remaining.
|
-- Number of cargo transports remaining.
|
||||||
local nTransports=self:CountRemainingTransports()
|
local nTransports=self:CountRemainingTransports()
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:T(self.lid..string.format("Remaining (final=%s): missions=%d, tasks=%d, transports=%d", tostring(self.passedfinalwp), nMissions, nTasks, nTransports))
|
||||||
|
|
||||||
-- Final waypoint passed?
|
-- Final waypoint passed?
|
||||||
if self.passedfinalwp then
|
if self.passedfinalwp then
|
||||||
|
|
||||||
-- Got current mission or task?
|
-- Got current mission or task?
|
||||||
if self.currentmission==nil and self.taskcurrent==0 then
|
if self.currentmission==nil and self.taskcurrent==0 and self.cargoTransport==nil then
|
||||||
|
|
||||||
-- Number of remaining tasks/missions?
|
-- Number of remaining tasks/missions?
|
||||||
if nTasks==0 and nMissions==0 and nTransports==0 then
|
if nTasks==0 and nMissions==0 and nTransports==0 then
|
||||||
@ -2082,10 +2089,10 @@ function FLIGHTGROUP:_CheckGroupDone(delay)
|
|||||||
|
|
||||||
-- Send flight to destination.
|
-- Send flight to destination.
|
||||||
if destbase then
|
if destbase then
|
||||||
self:T(self.lid.."Passed Final WP and No current and/or future missions/task ==> RTB!")
|
self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTB!")
|
||||||
self:__RTB(-3, destbase)
|
self:__RTB(-3, destbase)
|
||||||
elseif destzone then
|
elseif destzone then
|
||||||
self:T(self.lid.."Passed Final WP and No current and/or future missions/task ==> RTZ!")
|
self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTZ!")
|
||||||
self:__RTZ(-3, destzone)
|
self:__RTZ(-3, destzone)
|
||||||
else
|
else
|
||||||
self:T(self.lid.."Passed Final WP and NO Tasks/Missions left. No DestBase or DestZone ==> Wait!")
|
self:T(self.lid.."Passed Final WP and NO Tasks/Missions left. No DestBase or DestZone ==> Wait!")
|
||||||
|
|||||||
@ -661,6 +661,10 @@ function NAVYGROUP:onafterSpawned(From, Event, To)
|
|||||||
-- Update position.
|
-- Update position.
|
||||||
self:_UpdatePosition()
|
self:_UpdatePosition()
|
||||||
|
|
||||||
|
-- Not dead or destroyed yet.
|
||||||
|
self.isDead=false
|
||||||
|
self.isDestroyed=false
|
||||||
|
|
||||||
if self.isAI then
|
if self.isAI then
|
||||||
|
|
||||||
-- Set default ROE.
|
-- Set default ROE.
|
||||||
|
|||||||
@ -32,6 +32,8 @@
|
|||||||
-- @field #boolean isAircraft If true, group is airplane or helicopter.
|
-- @field #boolean isAircraft If true, group is airplane or helicopter.
|
||||||
-- @field #boolean isNaval If true, group is ships or submarine.
|
-- @field #boolean isNaval If true, group is ships or submarine.
|
||||||
-- @field #boolean isGround If true, group is some ground unit.
|
-- @field #boolean isGround If true, group is some ground unit.
|
||||||
|
-- @field #boolean isDestroyed If true, the whole group was destroyed.
|
||||||
|
-- @field #boolean isDead If true, the whole group is dead.
|
||||||
-- @field #table waypoints Table of waypoints.
|
-- @field #table waypoints Table of waypoints.
|
||||||
-- @field #table waypoints0 Table of initial waypoints.
|
-- @field #table waypoints0 Table of initial waypoints.
|
||||||
-- @field Wrapper.Airbase#AIRBASE homebase The home base of the flight group.
|
-- @field Wrapper.Airbase#AIRBASE homebase The home base of the flight group.
|
||||||
@ -1537,7 +1539,18 @@ end
|
|||||||
-- @param #OPSGROUP self
|
-- @param #OPSGROUP self
|
||||||
-- @return #boolean If true, all units/elements of the group are dead.
|
-- @return #boolean If true, all units/elements of the group are dead.
|
||||||
function OPSGROUP:IsDead()
|
function OPSGROUP:IsDead()
|
||||||
|
if self.isDead then
|
||||||
|
return true
|
||||||
|
else
|
||||||
return self:Is("Dead")
|
return self:Is("Dead")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Check if group was destroyed.
|
||||||
|
-- @param #OPSGROUP self
|
||||||
|
-- @return #boolean If true, all units/elements of the group were destroyed.
|
||||||
|
function OPSGROUP:IsDestroyed()
|
||||||
|
return self.isDestroyed
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if FSM is stopped.
|
--- Check if FSM is stopped.
|
||||||
@ -2994,6 +3007,7 @@ end
|
|||||||
-- @param #OPSGROUP self
|
-- @param #OPSGROUP self
|
||||||
-- @return #number Number of unfinished transports in the queue.
|
-- @return #number Number of unfinished transports in the queue.
|
||||||
function OPSGROUP:CountRemainingTransports()
|
function OPSGROUP:CountRemainingTransports()
|
||||||
|
env.info("FF Count remaining transports="..#self.cargoqueue)
|
||||||
|
|
||||||
local N=0
|
local N=0
|
||||||
|
|
||||||
@ -3001,14 +3015,17 @@ function OPSGROUP:CountRemainingTransports()
|
|||||||
for _,_transport in pairs(self.cargoqueue) do
|
for _,_transport in pairs(self.cargoqueue) do
|
||||||
local transport=_transport --Ops.OpsTransport#OPSTRANSPORT
|
local transport=_transport --Ops.OpsTransport#OPSTRANSPORT
|
||||||
|
|
||||||
|
self:I(self.lid..string.format("Transport status=%s [%s]", transport:GetCarrierTransportStatus(self), transport:GetState()))
|
||||||
|
|
||||||
-- Count not delivered (executing or scheduled) assignments.
|
-- Count not delivered (executing or scheduled) assignments.
|
||||||
if transport and transport.status~=OPSGROUP.TransportStatus.DELIVERED then
|
if transport and transport:GetCarrierTransportStatus(self)==OPSTRANSPORT.Status.SCHEDULED and transport:GetState()~=OPSTRANSPORT.Status.DELIVERED then
|
||||||
|
|
||||||
N=N+1
|
N=N+1
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
env.info("FF Count remaining transports="..N)
|
||||||
return N
|
return N
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -4532,6 +4549,16 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- On after "Destroyed" event.
|
||||||
|
-- @param #OPSGROUP self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
function OPSGROUP:onafterDestroyed(From, Event, To)
|
||||||
|
self:T(self.lid..string.format("Group destroyed at t=%.3f", timer.getTime()))
|
||||||
|
self.isDestroyed=true
|
||||||
|
end
|
||||||
|
|
||||||
--- On before "Dead" event.
|
--- On before "Dead" event.
|
||||||
-- @param #OPSGROUP self
|
-- @param #OPSGROUP self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
@ -4551,9 +4578,8 @@ end
|
|||||||
function OPSGROUP:onafterDead(From, Event, To)
|
function OPSGROUP:onafterDead(From, Event, To)
|
||||||
self:T(self.lid..string.format("Group dead at t=%.3f", timer.getTime()))
|
self:T(self.lid..string.format("Group dead at t=%.3f", timer.getTime()))
|
||||||
|
|
||||||
-- Delete waypoints so they are re-initialized at the next spawn.
|
-- Is dead now.
|
||||||
self.waypoints=nil
|
self.isDead=true
|
||||||
self.groupinitialized=false
|
|
||||||
|
|
||||||
-- Cancel all missions.
|
-- Cancel all missions.
|
||||||
for _,_mission in pairs(self.missionqueue) do
|
for _,_mission in pairs(self.missionqueue) do
|
||||||
@ -4566,6 +4592,10 @@ function OPSGROUP:onafterDead(From, Event, To)
|
|||||||
|
|
||||||
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
|
||||||
@ -4922,6 +4952,7 @@ function OPSGROUP:AddOpsTransport(OpsTransport)
|
|||||||
--Add to cargo queue
|
--Add to cargo queue
|
||||||
table.insert(self.cargoqueue, OpsTransport)
|
table.insert(self.cargoqueue, OpsTransport)
|
||||||
|
|
||||||
|
self:I(self.lid.."FF adding transport to carrier, #self.cargoqueue="..#self.cargoqueue)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Delete a cargo transport assignment from the cargo queue
|
--- Delete a cargo transport assignment from the cargo queue
|
||||||
@ -5654,6 +5685,9 @@ function OPSGROUP:onafterUnloading(From, Event, To)
|
|||||||
-- Cargo was delivered (somehow).
|
-- Cargo was delivered (somehow).
|
||||||
cargo.delivered=true
|
cargo.delivered=true
|
||||||
|
|
||||||
|
-- Increase number of delivered cargos.
|
||||||
|
self.cargoTransport.Ndelivered=self.cargoTransport.Ndelivered+1
|
||||||
|
|
||||||
if carrierGroup then
|
if carrierGroup then
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -5903,11 +5937,13 @@ function OPSGROUP:onafterDelivered(From, Event, To, CargoTransport)
|
|||||||
local Task=self:GetTaskCurrent()
|
local Task=self:GetTaskCurrent()
|
||||||
self:TaskCancel(Task)
|
self:TaskCancel(Task)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
-- Army & Navy: give Cruise command to "wake up" from waiting status.
|
||||||
|
self:__Cruise(0.1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check group done.
|
-- Check group done.
|
||||||
self:I(self.lid.."All cargo delivered ==> check group done")
|
self:I(self.lid.."All cargo delivered ==> check group done")
|
||||||
self:__Cruise(0.1)
|
|
||||||
self:_CheckGroupDone(0.2)
|
self:_CheckGroupDone(0.2)
|
||||||
|
|
||||||
-- No current transport any more.
|
-- No current transport any more.
|
||||||
@ -7504,7 +7540,7 @@ end
|
|||||||
-- @return #OPSGROUP self
|
-- @return #OPSGROUP self
|
||||||
function OPSGROUP:_UpdatePosition()
|
function OPSGROUP:_UpdatePosition()
|
||||||
|
|
||||||
if self:IsAlive()~=nil then
|
if self:IsExist() then
|
||||||
|
|
||||||
-- Backup last state to monitor differences.
|
-- Backup last state to monitor differences.
|
||||||
self.positionLast=self.position or self:GetVec3()
|
self.positionLast=self.position or self:GetVec3()
|
||||||
|
|||||||
@ -38,8 +38,11 @@
|
|||||||
-- @field Core.Zone#ZONE embarkzone (Optional) Zone where the cargo is supposed to embark. Default is the pickup zone.
|
-- @field Core.Zone#ZONE embarkzone (Optional) Zone where the cargo is supposed to embark. Default is the pickup zone.
|
||||||
-- @field Core.Zone#ZONE disembarkzone (Optional) Zone where the cargo is disembarked. Default is the deploy zone.
|
-- @field Core.Zone#ZONE disembarkzone (Optional) Zone where the cargo is disembarked. Default is the deploy zone.
|
||||||
-- @field Ops.OpsGroup#OPSGROUP carrierGroup The new carrier group.
|
-- @field Ops.OpsGroup#OPSGROUP carrierGroup The new carrier group.
|
||||||
-- @field disembarkActivation Activation setting when group is disembared from carrier.
|
-- @field #boolean disembarkActivation Activation setting when group is disembared from carrier.
|
||||||
-- @field disembarkInUtero Do not spawn the group in any any state but leave it "*in utero*". For example, to directly load it into another carrier.
|
-- @field #boolean disembarkInUtero Do not spawn the group in any any state but leave it "*in utero*". For example, to directly load it into another carrier.
|
||||||
|
-- @field #number Ncargo Total number of cargo groups.
|
||||||
|
-- @field #number Ncarrier Total number of assigned carriers.
|
||||||
|
-- @field #number Ndelivered Total number of cargo groups delivered.
|
||||||
-- @extends Core.Fsm#FSM
|
-- @extends Core.Fsm#FSM
|
||||||
|
|
||||||
--- *Victory is the beautiful, bright-colored flower. Transport is the stem without which it could never have blossomed.* -- Winston Churchill
|
--- *Victory is the beautiful, bright-colored flower. Transport is the stem without which it could never have blossomed.* -- Winston Churchill
|
||||||
@ -118,6 +121,9 @@ function OPSTRANSPORT:New(GroupSet, Pickupzone, Deployzone)
|
|||||||
self.carrierGroup=nil
|
self.carrierGroup=nil
|
||||||
self.cargos={}
|
self.cargos={}
|
||||||
self.carriers={}
|
self.carriers={}
|
||||||
|
self.Ncargo=0
|
||||||
|
self.Ncarrier=0
|
||||||
|
self.Ndelivered=0
|
||||||
|
|
||||||
|
|
||||||
self:SetPriority()
|
self:SetPriority()
|
||||||
@ -168,6 +174,7 @@ function OPSTRANSPORT:AddCargoGroups(GroupSet, Pickupzone, Deployzone)
|
|||||||
|
|
||||||
if cargo then --and self:CanCargo(cargo.opsgroup)
|
if cargo then --and self:CanCargo(cargo.opsgroup)
|
||||||
table.insert(self.cargos, cargo)
|
table.insert(self.cargos, cargo)
|
||||||
|
self.Ncargo=self.Ncargo+1
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -180,6 +187,7 @@ function OPSTRANSPORT:AddCargoGroups(GroupSet, Pickupzone, Deployzone)
|
|||||||
|
|
||||||
if cargo then
|
if cargo then
|
||||||
table.insert(self.cargos, cargo)
|
table.insert(self.cargos, cargo)
|
||||||
|
self.Ncargo=self.Ncargo+1
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -249,6 +257,21 @@ function OPSTRANSPORT:SetDisembarkInUtero(InUtero)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check if an OPS group is assigned as carrier for this transport.
|
||||||
|
-- @param #OPSTRANSPORT self
|
||||||
|
-- @param Ops.OpsGroup#OPSGROUP CarrierGroup Potential carrier OPSGROUP.
|
||||||
|
-- @return #boolean If true, group is an assigned carrier.
|
||||||
|
function OPSTRANSPORT:IsCarrier(CarrierGroup)
|
||||||
|
|
||||||
|
for _,_carrier in pairs(self.carriers) do
|
||||||
|
local carrier=_carrier --Ops.OpsGroup#OPSGROUP
|
||||||
|
if carrier.groupname==CarrierGroup.groupname then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
--- Add a carrier assigned for this transport.
|
--- Add a carrier assigned for this transport.
|
||||||
-- @param #OPSTRANSPORT self
|
-- @param #OPSTRANSPORT self
|
||||||
@ -256,12 +279,20 @@ end
|
|||||||
-- @return #OPSTRANSPORT self
|
-- @return #OPSTRANSPORT self
|
||||||
function OPSTRANSPORT:_AddCarrier(CarrierGroup)
|
function OPSTRANSPORT:_AddCarrier(CarrierGroup)
|
||||||
|
|
||||||
|
if not self:IsCarrier(CarrierGroup) then
|
||||||
|
|
||||||
|
-- Increase carrier count.
|
||||||
|
self.Ncarrier=self.Ncarrier+1
|
||||||
|
|
||||||
|
-- Set trans
|
||||||
self:SetCarrierTransportStatus(CarrierGroup, OPSTRANSPORT.Status.SCHEDULED)
|
self:SetCarrierTransportStatus(CarrierGroup, OPSTRANSPORT.Status.SCHEDULED)
|
||||||
|
|
||||||
self:Scheduled()
|
self:Scheduled()
|
||||||
|
|
||||||
table.insert(self.carriers, CarrierGroup)
|
table.insert(self.carriers, CarrierGroup)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -390,9 +421,11 @@ end
|
|||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
function OPSTRANSPORT:onafterStatus(From, Event, To)
|
function OPSTRANSPORT:onafterStatus(From, Event, To)
|
||||||
|
|
||||||
|
-- Current FSM state.
|
||||||
local fsmstate=self:GetState()
|
local fsmstate=self:GetState()
|
||||||
|
|
||||||
local text=string.format("State=%s: %s --> %s", fsmstate, self.pickupzone:GetName(), self.deployzone:GetName())
|
|
||||||
|
local text=string.format("%s [%s --> %s]: Ncargo=%d/%d, Ncarrier=%d", fsmstate:upper(), self.pickupzone:GetName(), self.deployzone:GetName(), self.Ncargo, self.Ndelivered, self.Ncarrier)
|
||||||
|
|
||||||
text=text..string.format("\nCargos:")
|
text=text..string.format("\nCargos:")
|
||||||
for _,_cargo in pairs(self.cargos) do
|
for _,_cargo in pairs(self.cargos) do
|
||||||
@ -483,20 +516,34 @@ end
|
|||||||
function OPSTRANSPORT:_CheckDelivered()
|
function OPSTRANSPORT:_CheckDelivered()
|
||||||
|
|
||||||
local done=true
|
local done=true
|
||||||
|
local dead=true
|
||||||
for _,_cargo in pairs(self.cargos) do
|
for _,_cargo in pairs(self.cargos) do
|
||||||
local cargo=_cargo --Ops.OpsGroup#OPSGROUP.CargoGroup
|
local cargo=_cargo --Ops.OpsGroup#OPSGROUP.CargoGroup
|
||||||
|
|
||||||
if cargo.delivered then
|
if cargo.delivered then
|
||||||
-- This one is delivered.
|
-- This one is delivered.
|
||||||
elseif cargo.opsgroup==nil or cargo.opsgroup:IsDead() or cargo.opsgroup:IsStopped() then
|
dead=false
|
||||||
|
elseif cargo.opsgroup==nil then
|
||||||
|
-- This one is nil?!
|
||||||
|
dead=false
|
||||||
|
elseif cargo.opsgroup:IsDestroyed() then
|
||||||
|
-- This one was destroyed.
|
||||||
|
elseif cargo.opsgroup:IsDead() then
|
||||||
-- This one is dead.
|
-- This one is dead.
|
||||||
|
dead=false
|
||||||
|
elseif cargo.opsgroup:IsStopped() then
|
||||||
|
-- This one is stopped.
|
||||||
|
dead=false
|
||||||
else
|
else
|
||||||
done=false --Someone is not done!
|
done=false --Someone is not done!
|
||||||
|
dead=false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if done then
|
if dead then
|
||||||
|
--self:CargoDead()
|
||||||
|
elseif done then
|
||||||
self:Delivered()
|
self:Delivered()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user