When cargo is destroyed, it will stop working...

This commit is contained in:
FlightControl
2017-05-09 09:29:08 +02:00
parent ce1f85e09a
commit d8ba37af8d
2 changed files with 170 additions and 98 deletions
+47
View File
@@ -246,6 +246,8 @@ function CARGO:New( Type, Name, Weight ) --R2.1
self:AddTransition( "UnBoarding", "UnBoarding", "UnBoarding" ) self:AddTransition( "UnBoarding", "UnBoarding", "UnBoarding" )
self:AddTransition( "UnBoarding", "UnLoad", "UnLoaded" ) self:AddTransition( "UnBoarding", "UnLoad", "UnLoaded" )
self:AddTransition( "Loaded", "UnLoad", "UnLoaded" ) self:AddTransition( "Loaded", "UnLoad", "UnLoaded" )
self:AddTransition( "*", "Destroyed", "Destroyed" )
self:AddTransition( "*", "Respawn", "UnLoaded" )
self.Type = Type self.Type = Type
@@ -264,6 +266,7 @@ function CARGO:New( Type, Name, Weight ) --R2.1
self:SetEventPriority( 5 ) self:SetEventPriority( 5 )
return self return self
end end
@@ -274,6 +277,17 @@ function CARGO:GetName() --R2.1
return self.Name return self.Name
end end
--- Get the object name of the Cargo.
-- @param #CARGO self
-- @return #string The object name of the Cargo.
function CARGO:GetObjectName() --R2.1
if self:IsLoaded() then
return self.CargoCarrier:GetName()
else
return self.CargoObject:GetName()
end
end
--- Get the type of the Cargo. --- Get the type of the Cargo.
-- @param #CARGO self -- @param #CARGO self
-- @return #string The type of the Cargo. -- @return #string The type of the Cargo.
@@ -303,6 +317,20 @@ function CARGO:IsUnLoaded()
return self:Is( "UnLoaded" ) return self:Is( "UnLoaded" )
end end
--- Check if cargo is alive.
-- @param #CARGO self
-- @return #boolean true if unloaded
function CARGO:IsAlive()
if self:IsLoaded() then
return self.CargoCarrier:IsAlive()
else
return self.CargoObject:IsAlive()
end
end
--- Template method to spawn a new representation of the CARGO in the simulator. --- Template method to spawn a new representation of the CARGO in the simulator.
-- @param #CARGO self -- @param #CARGO self
@@ -529,6 +557,16 @@ function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius )
self:T( self.ClassName ) self:T( self.ClassName )
self:HandleEvent( EVENTS.Dead,
--- @param #CARGO Cargo
-- @param Core.Event#EVENTDATA EventData
function( Cargo, EventData )
if Cargo:GetObjectName() == EventData.IniUnit:GetName() then
self:E( { "Cargo destroyed", Cargo } )
Cargo:Destroyed()
end
end
)
return self return self
end end
@@ -949,6 +987,7 @@ function CARGO_GROUP:onafterBoarding( From, Event, To, CargoCarrier, NearRadius,
local Boarded = true local Boarded = true
local Cancelled = false local Cancelled = false
local Dead = true
self.CargoSet:Flush() self.CargoSet:Flush()
@@ -963,9 +1002,14 @@ function CARGO_GROUP:onafterBoarding( From, Event, To, CargoCarrier, NearRadius,
Cancelled = true Cancelled = true
end end
if not Cargo:is( "Destroyed" ) then
Dead = false
end
end end
if not Dead then
if not Cancelled then if not Cancelled then
if not Boarded then if not Boarded then
self:__Boarding( 1, CargoCarrier, NearRadius, ... ) self:__Boarding( 1, CargoCarrier, NearRadius, ... )
@@ -975,6 +1019,9 @@ function CARGO_GROUP:onafterBoarding( From, Event, To, CargoCarrier, NearRadius,
else else
self:__CancelBoarding( 1, CargoCarrier, NearRadius, ... ) self:__CancelBoarding( 1, CargoCarrier, NearRadius, ... )
end end
else
self:__Destroyed( 1, CargoCarrier, NearRadius, ... )
end
end end
+29 -4
View File
@@ -224,6 +224,9 @@ do -- TASK_CARGO
--- @param Core.Cargo#CARGO Cargo --- @param Core.Cargo#CARGO Cargo
function( Cargo ) function( Cargo )
if Cargo:IsAlive() then
if Cargo:IsUnLoaded() then if Cargo:IsUnLoaded() then
if Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then if Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then
MENU_GROUP_COMMAND:New( MENU_GROUP_COMMAND:New(
@@ -271,6 +274,7 @@ do -- TASK_CARGO
end end
end end
end end
end
end end
) )
@@ -313,15 +317,21 @@ do -- TASK_CARGO
-- @param #FSM_PROCESS self -- @param #FSM_PROCESS self
-- @param Wrapper.Unit#UNIT TaskUnit -- @param Wrapper.Unit#UNIT TaskUnit
-- @param Tasking.Task_Cargo#TASK_CARGO Task -- @param Tasking.Task_Cargo#TASK_CARGO Task
-- @param From
-- @param Event
-- @param To
-- @param Core.Cargo#CARGO Cargo
function Fsm:onafterRouteToPickup( TaskUnit, Task, From, Event, To, Cargo ) function Fsm:onafterRouteToPickup( TaskUnit, Task, From, Event, To, Cargo )
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } ) self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
if Cargo:IsAlive() then
self.Cargo = Cargo -- Core.Cargo#CARGO self.Cargo = Cargo -- Core.Cargo#CARGO
Task:SetCargoPickup( self.Cargo, TaskUnit ) Task:SetCargoPickup( self.Cargo, TaskUnit )
self:__RouteToPickupPoint( -0.1 ) self:__RouteToPickupPoint( -0.1 )
end end
end
--- ---
-- @param #FSM_PROCESS self -- @param #FSM_PROCESS self
@@ -330,6 +340,7 @@ do -- TASK_CARGO
function Fsm:onafterArriveAtPickup( TaskUnit, Task ) function Fsm:onafterArriveAtPickup( TaskUnit, Task )
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } ) self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
if self.Cargo:IsAlive() then
if TaskUnit:IsAir() then if TaskUnit:IsAir() then
self.Cargo.CargoObject:GetUnit(1):SmokeRed() self.Cargo.CargoObject:GetUnit(1):SmokeRed()
self:__Land( -0.1, "Pickup" ) self:__Land( -0.1, "Pickup" )
@@ -337,6 +348,7 @@ do -- TASK_CARGO
self:__SelectAction( -0.1 ) self:__SelectAction( -0.1 )
end end
end end
end
--- Route to DeployZone --- Route to DeployZone
@@ -375,6 +387,7 @@ do -- TASK_CARGO
function Fsm:onafterLand( TaskUnit, Task, From, Event, To, Action ) function Fsm:onafterLand( TaskUnit, Task, From, Event, To, Action )
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } ) self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
if self.Cargo:IsAlive() then
if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then
if TaskUnit:InAir() then if TaskUnit:InAir() then
Task:GetMission():GetCommandCenter():MessageToGroup( "Land", TaskUnit:GetGroup() ) Task:GetMission():GetCommandCenter():MessageToGroup( "Land", TaskUnit:GetGroup() )
@@ -391,6 +404,7 @@ do -- TASK_CARGO
end end
end end
end end
end
--- ---
-- @param #FSM_PROCESS self -- @param #FSM_PROCESS self
@@ -399,6 +413,7 @@ do -- TASK_CARGO
function Fsm:onafterLanded( TaskUnit, Task, From, Event, To, Action ) function Fsm:onafterLanded( TaskUnit, Task, From, Event, To, Action )
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } ) self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
if self.Cargo:IsAlive() then
if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then
if TaskUnit:InAir() then if TaskUnit:InAir() then
self:__Land( -0.1, Action ) self:__Land( -0.1, Action )
@@ -413,6 +428,7 @@ do -- TASK_CARGO
end end
end end
end end
end
--- ---
-- @param #FSM_PROCESS self -- @param #FSM_PROCESS self
@@ -421,9 +437,11 @@ do -- TASK_CARGO
function Fsm:onafterPrepareBoarding( TaskUnit, Task, From, Event, To, Cargo ) function Fsm:onafterPrepareBoarding( TaskUnit, Task, From, Event, To, Cargo )
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } ) self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
if Cargo and Cargo:IsAlive() then
self.Cargo = Cargo -- Core.Cargo#CARGO_GROUP self.Cargo = Cargo -- Core.Cargo#CARGO_GROUP
self:__Board( -0.1 ) self:__Board( -0.1 )
end end
end
--- ---
-- @param #FSM_PROCESS self -- @param #FSM_PROCESS self
@@ -437,6 +455,7 @@ do -- TASK_CARGO
TaskProcess:__Boarded( 0.1 ) TaskProcess:__Boarded( 0.1 )
end end
if self.Cargo:IsAlive() then
if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then
if TaskUnit:InAir() then if TaskUnit:InAir() then
--- ABORT the boarding. Split group if any and go back to select action. --- ABORT the boarding. Split group if any and go back to select action.
@@ -448,6 +467,7 @@ do -- TASK_CARGO
--self:__ArriveAtCargo( -0.1 ) --self:__ArriveAtCargo( -0.1 )
end end
end end
end
--- ---
@@ -462,9 +482,11 @@ do -- TASK_CARGO
-- TODO:I need to find a more decent solution for this. -- TODO:I need to find a more decent solution for this.
Task:E( { CargoPickedUp = Task.CargoPickedUp } ) Task:E( { CargoPickedUp = Task.CargoPickedUp } )
if self.Cargo:IsAlive() then
if Task.CargoPickedUp then if Task.CargoPickedUp then
Task:CargoPickedUp( TaskUnit, self.Cargo ) Task:CargoPickedUp( TaskUnit, self.Cargo )
end end
end
end end
@@ -485,6 +507,7 @@ do -- TASK_CARGO
self.DeployZone = nil self.DeployZone = nil
-- Check if the Cargo is at a deployzone... If it is, provide it as a parameter! -- Check if the Cargo is at a deployzone... If it is, provide it as a parameter!
if Cargo:IsAlive() then
for DeployZoneName, DeployZone in pairs( Task.DeployZones ) do for DeployZoneName, DeployZone in pairs( Task.DeployZones ) do
if Cargo:IsInZone( DeployZone ) then if Cargo:IsInZone( DeployZone ) then
self.DeployZone = DeployZone -- Core.Zone#ZONE_BASE self.DeployZone = DeployZone -- Core.Zone#ZONE_BASE
@@ -493,6 +516,7 @@ do -- TASK_CARGO
end end
self:__UnBoard( -0.1, Cargo, self.DeployZone ) self:__UnBoard( -0.1, Cargo, self.DeployZone )
end end
end
--- ---
-- @param #FSM_PROCESS self -- @param #FSM_PROCESS self
@@ -507,16 +531,15 @@ do -- TASK_CARGO
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID(), From, Event, To, Cargo, DeployZone } ) self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID(), From, Event, To, Cargo, DeployZone } )
function self.Cargo:OnEnterUnLoaded( From, Event, To, DeployZone, TaskProcess ) function self.Cargo:OnEnterUnLoaded( From, Event, To, DeployZone, TaskProcess )
self:E({From, Event, To, DeployZone, TaskProcess }) self:E({From, Event, To, DeployZone, TaskProcess })
TaskProcess:__UnBoarded( -0.1 ) TaskProcess:__UnBoarded( -0.1 )
end end
if self.Cargo:IsAlive() then
self.Cargo:MessageToGroup( "UnBoarding ...", TaskUnit:GetGroup() ) self.Cargo:MessageToGroup( "UnBoarding ...", TaskUnit:GetGroup() )
self.Cargo:UnBoard( DeployZone:GetPointVec2(), 400, self ) self.Cargo:UnBoard( DeployZone:GetPointVec2(), 400, self )
end end
end
--- ---
@@ -530,9 +553,11 @@ do -- TASK_CARGO
-- TODO:I need to find a more decent solution for this. -- TODO:I need to find a more decent solution for this.
Task:E( { CargoDeployed = Task.CargoDeployed } ) Task:E( { CargoDeployed = Task.CargoDeployed } )
if self.Cargo:IsAlive() then
if Task.CargoDeployed then if Task.CargoDeployed then
Task:CargoDeployed( TaskUnit, self.Cargo, self.DeployZone ) Task:CargoDeployed( TaskUnit, self.Cargo, self.DeployZone )
end end
end
self:__SelectAction( 1 ) self:__SelectAction( 1 )
end end