mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
OPS Cargo
This commit is contained in:
parent
c4084156ac
commit
5cc023d1fe
@ -4840,9 +4840,6 @@ end
|
||||
-- @return Ops.OpsTransport#OPSTRANSPORT The next due cargo transport or `nil`.
|
||||
function OPSGROUP:_GetNextCargoTransport()
|
||||
|
||||
-- Abs. mission time in seconds.
|
||||
local Time=timer.getAbsTime()
|
||||
|
||||
-- Current position.
|
||||
local coord=self:GetCoordinate()
|
||||
|
||||
@ -4869,7 +4866,9 @@ function OPSGROUP:_GetNextCargoTransport()
|
||||
for _,_cargotransport in pairs(self.cargoqueue) do
|
||||
local cargotransport=_cargotransport --Ops.OpsTransport#OPSTRANSPORT
|
||||
|
||||
if Time>=cargotransport.Tstart and cargotransport:GetCarrierTransportStatus(self)==OPSTRANSPORT.Status.SCHEDULED and (cargotransport.importance==nil or cargotransport.importance<=vip) and not self:_CheckDelivered(cargotransport) then
|
||||
local carrierstatusScheduled=cargotransport:GetCarrierTransportStatus(self)==OPSTRANSPORT.Status.SCHEDULED
|
||||
|
||||
if cargotransport:IsReadyToGo() and carrierstatusScheduled and (cargotransport.importance==nil or cargotransport.importance<=vip) and not self:_CheckDelivered(cargotransport) then
|
||||
cargotransport:Executing()
|
||||
cargotransport:SetCarrierTransportStatus(self, OPSTRANSPORT.Status.EXECUTING)
|
||||
return cargotransport
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
-- @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 #table conditionStart Start conditions.
|
||||
-- @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.
|
||||
@ -62,7 +63,8 @@ OPSTRANSPORT = {
|
||||
verbose = 1,
|
||||
cargos = {},
|
||||
carriers = {},
|
||||
carrierTransportStatus = {},
|
||||
carrierTransportStatus = {},
|
||||
conditionStart = {},
|
||||
}
|
||||
|
||||
--- Cargo transport status.
|
||||
@ -78,6 +80,11 @@ OPSTRANSPORT.Status={
|
||||
DELIVERED="delivered",
|
||||
}
|
||||
|
||||
--- Generic mission condition.
|
||||
-- @type OPSTRANSPORT.Condition
|
||||
-- @field #function func Callback function to check for a condition. Should return a #boolean.
|
||||
-- @field #table arg Optional arguments passed to the condition callback function.
|
||||
|
||||
--- Transport ID.
|
||||
_OPSTRANSPORTID=0
|
||||
|
||||
@ -89,7 +96,7 @@ OPSTRANSPORT.version="0.0.3"
|
||||
-- TODO list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: Add start conditions.
|
||||
-- DONE: Add start conditions.
|
||||
-- TODO: Check carrier(s) dead.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -345,6 +352,26 @@ function OPSTRANSPORT:SetPriority(Prio, Importance, Urgent)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add start condition.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param #function ConditionFunction Function that needs to be true before the transport can be started. Must return a #boolean.
|
||||
-- @param ... Condition function arguments if any.
|
||||
-- @return #OPSTRANSPORT self
|
||||
function OPSTRANSPORT:AddConditionStart(ConditionFunction, ...)
|
||||
|
||||
local condition={} --#OPSTRANSPORT.Condition
|
||||
|
||||
condition.func=ConditionFunction
|
||||
condition.arg={}
|
||||
if arg then
|
||||
condition.arg=arg
|
||||
end
|
||||
|
||||
table.insert(self.conditionStart, condition)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Add a carrier assigned for this transport.
|
||||
-- @param #OPSTRANSPORT self
|
||||
@ -367,7 +394,6 @@ function OPSTRANSPORT:GetCarrierTransportStatus(CarrierGroup)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Create a cargo group data structure.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param Wrapper.Group#GROUP group The GROUP object.
|
||||
@ -410,6 +436,38 @@ function OPSTRANSPORT:_CreateCargoGroupData(group, Pickupzone, Deployzone)
|
||||
return cargo
|
||||
end
|
||||
|
||||
--- Check if transport is ready to be started.
|
||||
-- * Start time passed.
|
||||
-- * Stop time did not pass already.
|
||||
-- * All start conditions are true.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @return #boolean If true, mission can be started.
|
||||
function OPSTRANSPORT:IsReadyToGo()
|
||||
|
||||
local Tnow=timer.getAbsTime()
|
||||
|
||||
-- Start time did not pass yet.
|
||||
if self.Tstart and Tnow<self.Tstart or false then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Stop time already passed.
|
||||
if self.Tstop and Tnow>self.Tstop or false then
|
||||
return false
|
||||
end
|
||||
|
||||
-- All start conditions true?
|
||||
local startme=self:EvalConditionsAll(self.conditionStart)
|
||||
|
||||
if not startme then
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
-- We're good to go!
|
||||
return true
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Status Update
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -552,3 +610,27 @@ function OPSTRANSPORT:_CheckDelivered()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Check if all given condition are true.
|
||||
-- @param #OPSTRANSPORT self
|
||||
-- @param #table Conditions Table of conditions.
|
||||
-- @return #boolean If true, all conditions were true. Returns false if at least one condition returned false.
|
||||
function OPSTRANSPORT:EvalConditionsAll(Conditions)
|
||||
|
||||
-- Any stop condition must be true.
|
||||
for _,_condition in pairs(Conditions or {}) do
|
||||
local condition=_condition --#OPSTRANSPORT.Condition
|
||||
|
||||
-- Call function.
|
||||
local istrue=condition.func(unpack(condition.arg))
|
||||
|
||||
-- Any false will return false.
|
||||
if not istrue then
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- All conditions were true.
|
||||
return true
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user