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
2c92bb9d61
commit
c0401447dd
@ -108,7 +108,7 @@
|
||||
-- @field #OPSGROUP carrierGroup Carrier group transporting this group as cargo.
|
||||
-- @field #table cargoqueue Table containing cargo groups to be transported.
|
||||
-- @field #table cargoBay Table containing OPSGROUP loaded into this group.
|
||||
-- @field #OPSGROUP.CargoTransport cargoTransport Current cargo transport assignment.
|
||||
-- @field Ops.OpsTransport#OPSTRANSPORT cargoTransport Current cargo transport assignment.
|
||||
-- @field #string cargoStatus Cargo status of this group acting as cargo.
|
||||
-- @field #string carrierStatus Carrier status of this group acting as cargo carrier.
|
||||
-- @field #number cargocounter Running number of cargo UIDs.
|
||||
@ -2999,7 +2999,7 @@ function OPSGROUP:CountRemainingTransports()
|
||||
|
||||
-- Loop over mission queue.
|
||||
for _,_transport in pairs(self.cargoqueue) do
|
||||
local transport=_transport --#OPSGROUP.CargoTransport
|
||||
local transport=_transport --Ops.OpsTransport#OPSTRANSPORT
|
||||
|
||||
-- Count not delivered (executing or scheduled) assignments.
|
||||
if transport and transport.status~=OPSGROUP.TransportStatus.DELIVERED then
|
||||
@ -4752,7 +4752,7 @@ function OPSGROUP:_CheckCargoTransport()
|
||||
|
||||
-- Loop over cargo queue and check if everything was delivered.
|
||||
for i=#self.cargoqueue,1,-1 do
|
||||
local transport=self.cargoqueue[i] --#OPSGROUP.CargoTransport
|
||||
local transport=self.cargoqueue[i] --Ops.OpsTransport#OPSTRANSPORT
|
||||
local delivered=self:_CheckDelivered(transport)
|
||||
if delivered then
|
||||
self:Delivered(transport)
|
||||
@ -4807,7 +4807,7 @@ end
|
||||
|
||||
--- Get cargo transport from cargo queue.
|
||||
-- @param #OPSGROUP self
|
||||
-- @return #OPSGROUP.CargoTransport The next due cargo transport or `nil`.
|
||||
-- @return Ops.OpsTransport#OPSTRANSPORT The next due cargo transport or `nil`.
|
||||
function OPSGROUP:_GetNextCargoTransport()
|
||||
|
||||
-- Abs. mission time in seconds.
|
||||
@ -4818,8 +4818,8 @@ function OPSGROUP:_GetNextCargoTransport()
|
||||
|
||||
-- Sort results table wrt prio and distance to pickup zone.
|
||||
local function _sort(a, b)
|
||||
local transportA=a --#OPSGROUP.CargoTransport
|
||||
local transportB=b --#OPSGROUP.CargoTransport
|
||||
local transportA=a --Ops.OpsTransport#OPSTRANSPORT
|
||||
local transportB=b --Ops.OpsTransport#OPSTRANSPORT
|
||||
local distA=transportA.pickupzone:GetCoordinate():Get2DDistance(coord)
|
||||
local distB=transportB.pickupzone:GetCoordinate():Get2DDistance(coord)
|
||||
return (transportA.prio<transportB.prio) or (transportA.prio==transportB.prio and distA<distB)
|
||||
@ -4829,7 +4829,7 @@ function OPSGROUP:_GetNextCargoTransport()
|
||||
-- Look for first mission that is SCHEDULED.
|
||||
local vip=math.huge
|
||||
for _,_cargotransport in pairs(self.cargoqueue) do
|
||||
local cargotransport=_cargotransport --#OPSGROUP.CargoTransport
|
||||
local cargotransport=_cargotransport --Ops.OpsTransport#OPSTRANSPORT
|
||||
if cargotransport.importance and cargotransport.importance<vip then
|
||||
vip=cargotransport.importance
|
||||
end
|
||||
@ -4926,12 +4926,12 @@ end
|
||||
|
||||
--- Delete a cargo transport assignment from the cargo queue
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #OPSGROUP.CargoTransport CargoTransport Cargo transport do be deleted.
|
||||
-- @param Ops.OpsTransport#OPSTRANSPORT CargoTransport Cargo transport do be deleted.
|
||||
-- @return #OPSGROUP self
|
||||
function OPSGROUP:DelCargoTransport(CargoTransport)
|
||||
|
||||
for i,_transport in pairs(self.cargoqueue) do
|
||||
local transport=_transport --#OPSGROUP.CargoTransport
|
||||
local transport=_transport --Ops.OpsTransport#OPSTRANSPORT
|
||||
if transport.uid==CargoTransport.uid then
|
||||
table.remove(self.cargoqueue, i)
|
||||
return self
|
||||
@ -4952,7 +4952,7 @@ end
|
||||
-- @param Core.Zone#ZONE Embarkzone (Optional) Zone where the cargo is going to be embarked into the transport. By default is goes to the assigned carrier unit.
|
||||
-- @param Core.Zone#ZONE Disembarkzone (Optional) Zone where the cargo disembarks to (is spawned after unloaded). Default is anywhere in the deploy zone.
|
||||
-- @param #OPSGROUP DisembarkCarrierGroup (Optional) The OPSGROUP where the cargo is directly loaded into.
|
||||
-- @return #OPSGROUP.CargoTransport Cargo transport.
|
||||
-- @return Ops.OpsTransport#OPSTRANSPORT Cargo transport.
|
||||
function OPSGROUP:CreateCargoTransport(GroupSet, Pickupzone, Deployzone, Prio, Importance, ClockStart, Embarkzone, Disembarkzone, DisembarkCarrierGroup)
|
||||
|
||||
-- Current mission time.
|
||||
@ -4967,7 +4967,7 @@ function OPSGROUP:CreateCargoTransport(GroupSet, Pickupzone, Deployzone, Prio, I
|
||||
end
|
||||
|
||||
-- Data structure.
|
||||
local transport={} --#OPSGROUP.CargoTransport
|
||||
local transport={} --Ops.OpsTransport#OPSTRANSPORT
|
||||
transport.uid=self.cargocounter
|
||||
transport.status=OPSGROUP.TransportStatus.PLANNING
|
||||
transport.pickupzone=Pickupzone
|
||||
@ -5678,7 +5678,14 @@ function OPSGROUP:onafterUnloading(From, Event, To)
|
||||
-- Delivered to deploy zone
|
||||
---
|
||||
|
||||
if not self.cargoTransport.inactiveUnload then
|
||||
if self.cargoTransport.disembarkInUtero then
|
||||
|
||||
-- Unload but keep "in utero" (no coordinate provided).
|
||||
self:Unload(cargo.opsgroup)
|
||||
|
||||
else
|
||||
|
||||
-- TODO: honor disembark zone!
|
||||
|
||||
local zoneCarrier=ZONE_RADIUS:New("Carrier", self:GetVec2(), 100)
|
||||
|
||||
@ -5687,11 +5694,8 @@ function OPSGROUP:onafterUnloading(From, Event, To)
|
||||
local Heading=math.random(0,359)
|
||||
|
||||
-- Unload.
|
||||
env.info("FF unload cargo "..cargo.opsgroup:GetName())
|
||||
self:Unload(cargo.opsgroup, Coordinate, nil, Heading)
|
||||
else
|
||||
env.info("FF unload cargo Inactive "..cargo.opsgroup:GetName())
|
||||
self:Unload(cargo.opsgroup)
|
||||
self:Unload(cargo.opsgroup, Coordinate, self.cargoTransport.disembarkActivation, Heading)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@ -5711,8 +5715,11 @@ end
|
||||
-- @param Core.Point#COORDINATE Coordinate Coordinate were the group is unloaded to.
|
||||
-- @param #number Heading Heading of group.
|
||||
function OPSGROUP:onbeforeUnload(From, Event, To, OpsGroup, Coordinate, Heading)
|
||||
--TODO: Add check if CargoGroup is cargo of this carrier.
|
||||
return true
|
||||
|
||||
-- Remove group from carrier bay. If group is not in cargo bay, function will return false and transition is denied.
|
||||
local removed=self:_DelCargobay(OpsGroup)
|
||||
|
||||
return removed
|
||||
end
|
||||
|
||||
--- On after "Unload" event. Carrier unloads a cargo group from its cargo bay.
|
||||
@ -5726,9 +5733,6 @@ end
|
||||
-- @param #number Heading (Optional) Heading of group in degrees. Default is random heading for each unit.
|
||||
function OPSGROUP:onafterUnload(From, Event, To, OpsGroup, Coordinate, Activated, Heading)
|
||||
|
||||
-- Remove group from carrier bay.
|
||||
self:_DelCargobay(OpsGroup)
|
||||
|
||||
-- Debug info.
|
||||
OpsGroup:I(OpsGroup.lid..string.format("New cargo status %s --> %s", OpsGroup.cargoStatus, OPSGROUP.CargoStatus.NOTCARGO))
|
||||
|
||||
@ -5841,7 +5845,7 @@ end
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param #OPSGROUP.CargoTransport CargoTransport
|
||||
-- @param Ops.OpsTransport#OPSTRANSPORT CargoTransport
|
||||
function OPSGROUP:onafterDelivered(From, Event, To, CargoTransport)
|
||||
|
||||
-- Set cargo status.
|
||||
|
||||
@ -2,13 +2,13 @@
|
||||
--
|
||||
-- ## Main Features:
|
||||
--
|
||||
-- * Patrol waypoints *ad infinitum*
|
||||
-- * Transport troops from A to B.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Example Missions:
|
||||
--
|
||||
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/OPS%20-%20Armygroup).
|
||||
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/OPS%20-%20Transport).
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
@ -32,22 +32,25 @@
|
||||
-- @field #number prio Priority of this transport. Should be a number between 0 (high prio) and 100 (low prio).
|
||||
-- @field #number importance Importance of this transport. Smaller=higher.
|
||||
-- @field #number Tstart Start time in *abs.* seconds.
|
||||
-- @field #number Tstop Stop time in *abs.* seconds. Default `#nil` (never stops).
|
||||
-- @field Core.Zone#ZONE pickupzone Zone where the cargo is picked up.
|
||||
-- @field Core.Zone#ZONE deployzone Zone where the cargo is dropped off.
|
||||
-- @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 Ops.OpsGroup#OPSGROUP carrierGroup The new carrier group.
|
||||
-- @field 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.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
--- *Your soul may belong to Jesus, but your ass belongs to the marines.* -- Eugene B. Sledge
|
||||
--- *Victory is the beautiful, bright-colored flower. Transport is the stem without which it could never have blossomed.* -- Winston Churchill
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- 
|
||||
-- 
|
||||
--
|
||||
-- # The OPSTRANSPORT Concept
|
||||
--
|
||||
-- This class enhances naval groups.
|
||||
-- Transport OPSGROUPS using carriers such as APCs, helicopters or airplanes.
|
||||
--
|
||||
-- @field #OPSTRANSPORT
|
||||
OPSTRANSPORT = {
|
||||
@ -99,11 +102,13 @@ function OPSTRANSPORT:New(GroupSet, Pickupzone, Deployzone)
|
||||
-- Inherit everything from FSM class.
|
||||
local self=BASE:Inherit(self, FSM:New()) -- #OPSTRANSPORT
|
||||
|
||||
-- Increase ID counter.
|
||||
_OPSTRANSPORTID=_OPSTRANSPORTID+1
|
||||
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("OPSTRANSPORT [UID=%d] %s --> %s | ", _OPSTRANSPORTID, Pickupzone:GetName(), Deployzone:GetName())
|
||||
|
||||
-- Defaults.
|
||||
self.uid=_OPSTRANSPORTID
|
||||
self.status=OPSTRANSPORT.Status.PLANNING
|
||||
self.pickupzone=Pickupzone
|
||||
@ -112,51 +117,13 @@ function OPSTRANSPORT:New(GroupSet, Pickupzone, Deployzone)
|
||||
self.disembarkzone=Deployzone
|
||||
self.prio=50
|
||||
self.importance=nil
|
||||
self.Tstart=timer.getAbsTime()
|
||||
self.Tstart=timer.getAbsTime()+5
|
||||
self.carrierGroup=nil
|
||||
self.cargos={}
|
||||
self.carriers={}
|
||||
|
||||
|
||||
|
||||
-- Check type of GroupSet provided.
|
||||
if GroupSet:IsInstanceOf("GROUP") or GroupSet:IsInstanceOf("OPSGROUP") then
|
||||
|
||||
-- We got a single GROUP or OPSGROUP object.
|
||||
local cargo=self:_CreateCargoGroupData(GroupSet, Pickupzone, Deployzone)
|
||||
|
||||
if cargo then --and self:CanCargo(cargo.opsgroup)
|
||||
table.insert(self.cargos, cargo)
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- We got a SET_GROUP object.
|
||||
|
||||
for _,group in pairs(GroupSet.Set) do
|
||||
|
||||
local cargo=self:_CreateCargoGroupData(group, Pickupzone, Deployzone)
|
||||
|
||||
if cargo then --and self:CanCargo(cargo.opsgroup) then
|
||||
table.insert(self.cargos, cargo)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- Debug info.
|
||||
if self.verbose>=0 then
|
||||
local text=string.format("Created Cargo Transport (UID=%d) from %s(%s) --> %s(%s)",
|
||||
self.uid, self.pickupzone:GetName(), self.embarkzone:GetName(), self.deployzone:GetName(), self.disembarkzone:GetName())
|
||||
local Weight=0
|
||||
for _,_cargo in pairs(self.cargos) do
|
||||
local cargo=_cargo --#OPSGROUP.CargoGroup
|
||||
local weight=cargo.opsgroup:GetWeightTotal()
|
||||
Weight=Weight+weight
|
||||
text=text..string.format("\n- %s [%s] weight=%.1f kg", cargo.opsgroup:GetName(), cargo.opsgroup:GetState(), weight)
|
||||
end
|
||||
text=text..string.format("\nTOTAL: Ncargo=%d, Weight=%.1f kg", #self.cargos, Weight)
|
||||
self:I(self.lid..text)
|
||||
if GroupSet then
|
||||
self:AddCargoGroups(GroupSet, Pickupzone, Deployzone)
|
||||
end
|
||||
|
||||
|
||||
@ -182,6 +149,56 @@ end
|
||||
-- User Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Add cargo groups to be transported.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param Core.Set#SET_GROUP GroupSet Set of groups to be transported. Can also be passed as a single GROUP or OPSGROUP object.
|
||||
-- @return #OPSTRANSPORT self
|
||||
function OPSTRANSPORT:AddCargoGroups(GroupSet, Pickupzone, Deployzone)
|
||||
|
||||
-- Check type of GroupSet provided.
|
||||
if GroupSet:IsInstanceOf("GROUP") or GroupSet:IsInstanceOf("OPSGROUP") then
|
||||
|
||||
-- We got a single GROUP or OPSGROUP object.
|
||||
local cargo=self:_CreateCargoGroupData(GroupSet, Pickupzone, Deployzone)
|
||||
|
||||
if cargo then --and self:CanCargo(cargo.opsgroup)
|
||||
table.insert(self.cargos, cargo)
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- We got a SET_GROUP object.
|
||||
|
||||
for _,group in pairs(GroupSet.Set) do
|
||||
|
||||
local cargo=self:_CreateCargoGroupData(group, Pickupzone, Deployzone)
|
||||
|
||||
if cargo then
|
||||
table.insert(self.cargos, cargo)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- Debug info.
|
||||
if self.verbose>=0 then
|
||||
local text=string.format("Created Cargo Transport (UID=%d) from %s(%s) --> %s(%s)",
|
||||
self.uid, self.pickupzone:GetName(), self.embarkzone:GetName(), self.deployzone:GetName(), self.disembarkzone:GetName())
|
||||
local Weight=0
|
||||
for _,_cargo in pairs(self.cargos) do
|
||||
local cargo=_cargo --#OPSGROUP.CargoGroup
|
||||
local weight=cargo.opsgroup:GetWeightTotal()
|
||||
Weight=Weight+weight
|
||||
text=text..string.format("\n- %s [%s] weight=%.1f kg", cargo.opsgroup:GetName(), cargo.opsgroup:GetState(), weight)
|
||||
end
|
||||
text=text..string.format("\nTOTAL: Ncargo=%d, Weight=%.1f kg", #self.cargos, Weight)
|
||||
self:I(self.lid..text)
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set embark zone.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param Core.Zone#ZONE EmbarkZone Zone where the troops are embarked.
|
||||
@ -191,6 +208,43 @@ function OPSTRANSPORT:SetEmbarkZone(EmbarkZone)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set disembark zone.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param Core.Zone#ZONE DisembarkZone Zone where the troops are disembarked.
|
||||
-- @return #OPSTRANSPORT self
|
||||
function OPSTRANSPORT:SetDisembarkZone(DisembarkZone)
|
||||
self.disembarkzone=DisembarkZone or self.deployzone
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set activation status of group when disembarked from transport carrier.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param #boolean Active If `true` or `nil`, group is activated when disembarked. If `false`, group is late activated and needs to be activated manually.
|
||||
-- @return #OPSTRANSPORT self
|
||||
function OPSTRANSPORT:SetDisembarkActivation(Active)
|
||||
if Active==true or Active==nil then
|
||||
self.disembarkActivation=true
|
||||
else
|
||||
self.disembarkActivation=false
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set if group remains *in utero* after disembarkment from carrier. Can be used to directly load the group into another carrier. Similar to disembark in late activated state.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param #boolean InUtero If `true` or `nil`, group remains *in utero* after disembarkment.
|
||||
-- @return #OPSTRANSPORT self
|
||||
function OPSTRANSPORT:SetDisembarkInUtero(InUtero)
|
||||
if InUtero==true or InUtero==nil then
|
||||
self.disembarkInUtero=true
|
||||
else
|
||||
self.disembarkInUtero=false
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Add a carrier assigned for this transport.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param Ops.OpsGroup#OPSGROUP CarrierGroup Carrier OPSGROUP.
|
||||
@ -240,7 +294,7 @@ function OPSTRANSPORT:_CreateCargoGroupData(group, Pickupzone, Deployzone)
|
||||
|
||||
if group:IsInstanceOf("OPSGROUP") then
|
||||
opsgroup=group
|
||||
else
|
||||
elseif group:IsInstanceOf("GROUP") then
|
||||
|
||||
opsgroup=_DATABASE:GetOpsGroup(group)
|
||||
|
||||
@ -252,10 +306,11 @@ function OPSTRANSPORT:_CreateCargoGroupData(group, Pickupzone, Deployzone)
|
||||
else
|
||||
opsgroup=ARMYGROUP:New(group)
|
||||
end
|
||||
else
|
||||
--env.info("FF found opsgroup in createcargo")
|
||||
end
|
||||
|
||||
else
|
||||
self:E(self.lid.."ERROR: Cargo must be a GROUP or OPSGROUP object!")
|
||||
return nil
|
||||
end
|
||||
|
||||
local cargo={} --#OPSGROUP.CargoGroup
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user