mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Fixed the boarding and unboarding process for CARGO_GROUP
This commit is contained in:
parent
469e1a3c9b
commit
f6f91a0f23
@ -238,7 +238,7 @@ function CARGO:New( Type, Name, Weight )
|
|||||||
|
|
||||||
self:SetStartState( "UnLoaded" )
|
self:SetStartState( "UnLoaded" )
|
||||||
self:AddTransition( "UnLoaded", "Board", "Boarding" )
|
self:AddTransition( "UnLoaded", "Board", "Boarding" )
|
||||||
self:AddTransition( "Boarding", "Boarding", "Boarding" )
|
self:AddTransition( "Boarding" , "Boarding", "Boarding" )
|
||||||
self:AddTransition( "Boarding", "Load", "Loaded" )
|
self:AddTransition( "Boarding", "Load", "Loaded" )
|
||||||
self:AddTransition( "UnLoaded", "Load", "Loaded" )
|
self:AddTransition( "UnLoaded", "Load", "Loaded" )
|
||||||
self:AddTransition( "Loaded", "UnBoard", "UnBoarding" )
|
self:AddTransition( "Loaded", "UnBoard", "UnBoarding" )
|
||||||
@ -575,6 +575,7 @@ function CARGO_UNIT:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius
|
|||||||
-- Respawn the group...
|
-- Respawn the group...
|
||||||
if self.CargoObject then
|
if self.CargoObject then
|
||||||
self.CargoObject:ReSpawn( CargoDeployPointVec2:GetVec3(), CargoDeployHeading )
|
self.CargoObject:ReSpawn( CargoDeployPointVec2:GetVec3(), CargoDeployHeading )
|
||||||
|
self:E( { "CargoUnits:", self.CargoObject:GetGroup():GetName() } )
|
||||||
self.CargoCarrier = nil
|
self.CargoCarrier = nil
|
||||||
|
|
||||||
local Points = {}
|
local Points = {}
|
||||||
@ -680,6 +681,87 @@ function CARGO_UNIT:onenterUnLoaded( From, Event, To, ToPointVec2 )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Board Event.
|
||||||
|
-- @param #CARGO_UNIT self
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string To
|
||||||
|
function CARGO_UNIT:onafterBoard( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
|
self:F()
|
||||||
|
|
||||||
|
NearRadius = NearRadius or 25
|
||||||
|
|
||||||
|
self.CargoInAir = self.CargoObject:InAir()
|
||||||
|
|
||||||
|
self:T( self.CargoInAir )
|
||||||
|
|
||||||
|
-- Only move the group to the carrier when the cargo is not in the air
|
||||||
|
-- (eg. cargo can be on a oil derrick, moving the cargo on the oil derrick will drop the cargo on the sea).
|
||||||
|
if not self.CargoInAir then
|
||||||
|
if self:IsNear( CargoCarrier:GetPointVec2(), NearRadius ) then
|
||||||
|
self:Load( CargoCarrier, NearRadius, ... )
|
||||||
|
else
|
||||||
|
self:__Boarding( -1, CargoCarrier, NearRadius )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Leave Boarding State.
|
||||||
|
-- @param #CARGO_UNIT self
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string To
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
function CARGO_UNIT:onleaveBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
|
self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
||||||
|
|
||||||
|
NearRadius = NearRadius or 25
|
||||||
|
|
||||||
|
if self:IsNear( CargoCarrier:GetPointVec2(), NearRadius ) then
|
||||||
|
self:__Load( 1, CargoCarrier, ... )
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Boarding Event.
|
||||||
|
-- @param #CARGO_UNIT self
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string To
|
||||||
|
-- @param Wrapper.Unit#UNIT CargoCarrier
|
||||||
|
-- @param #number NearRadius
|
||||||
|
function CARGO_UNIT:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
||||||
|
self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
||||||
|
|
||||||
|
local Speed = 90
|
||||||
|
local Angle = 180
|
||||||
|
local Distance = 5
|
||||||
|
|
||||||
|
NearRadius = NearRadius or 25
|
||||||
|
|
||||||
|
local CargoCarrierPointVec2 = CargoCarrier:GetPointVec2()
|
||||||
|
local CargoCarrierHeading = CargoCarrier:GetHeading() -- Get Heading of object in degrees.
|
||||||
|
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
||||||
|
local CargoDeployPointVec2 = CargoCarrierPointVec2:Translate( Distance, CargoDeployHeading )
|
||||||
|
|
||||||
|
local Points = {}
|
||||||
|
|
||||||
|
local PointStartVec2 = self.CargoObject:GetPointVec2()
|
||||||
|
|
||||||
|
Points[#Points+1] = PointStartVec2:RoutePointGround( Speed )
|
||||||
|
Points[#Points+1] = CargoDeployPointVec2:RoutePointGround( Speed )
|
||||||
|
|
||||||
|
local TaskRoute = self.CargoObject:TaskRoute( Points )
|
||||||
|
self.CargoObject:SetTask( TaskRoute, 2 )
|
||||||
|
|
||||||
|
self:__Boarding( -5, CargoCarrier, NearRadius, ... )
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Enter Boarding State.
|
--- Enter Boarding State.
|
||||||
@ -698,44 +780,11 @@ function CARGO_UNIT:onenterBoarding( From, Event, To, CargoCarrier, NearRadius,
|
|||||||
NearRadius = NearRadius or 25
|
NearRadius = NearRadius or 25
|
||||||
|
|
||||||
if From == "UnLoaded" or From == "Boarding" then
|
if From == "UnLoaded" or From == "Boarding" then
|
||||||
local CargoCarrierPointVec2 = CargoCarrier:GetPointVec2()
|
|
||||||
local CargoCarrierHeading = CargoCarrier:GetHeading() -- Get Heading of object in degrees.
|
|
||||||
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
|
||||||
local CargoDeployPointVec2 = CargoCarrierPointVec2:Translate( Distance, CargoDeployHeading )
|
|
||||||
|
|
||||||
local Points = {}
|
|
||||||
|
|
||||||
local PointStartVec2 = self.CargoObject:GetPointVec2()
|
|
||||||
|
|
||||||
Points[#Points+1] = PointStartVec2:RoutePointGround( Speed )
|
|
||||||
Points[#Points+1] = CargoDeployPointVec2:RoutePointGround( Speed )
|
|
||||||
|
|
||||||
local TaskRoute = self.CargoObject:TaskRoute( Points )
|
|
||||||
self.CargoObject:SetTask( TaskRoute, 2 )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Leave Boarding State.
|
|
||||||
-- @param #CARGO_UNIT self
|
|
||||||
-- @param #string Event
|
|
||||||
-- @param #string From
|
|
||||||
-- @param #string To
|
|
||||||
-- @param Wrapper.Unit#UNIT CargoCarrier
|
|
||||||
function CARGO_UNIT:onleaveBoarding( From, Event, To, CargoCarrier, NearRadius, ... )
|
|
||||||
self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } )
|
|
||||||
|
|
||||||
NearRadius = NearRadius or 25
|
|
||||||
|
|
||||||
if self:IsNear( CargoCarrier:GetPointVec2(), NearRadius ) then
|
|
||||||
self:__Load( 1, CargoCarrier, ... )
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
self:__Boarding( 1, CargoCarrier, ... )
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Loaded State.
|
--- Loaded State.
|
||||||
-- @param #CARGO_UNIT self
|
-- @param #CARGO_UNIT self
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
@ -755,27 +804,6 @@ function CARGO_UNIT:onenterLoaded( From, Event, To, CargoCarrier )
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Board Event.
|
|
||||||
-- @param #CARGO_UNIT self
|
|
||||||
-- @param #string Event
|
|
||||||
-- @param #string From
|
|
||||||
-- @param #string To
|
|
||||||
function CARGO_UNIT:onafterBoard( From, Event, To, CargoCarrier, NearRadius, ... )
|
|
||||||
self:F()
|
|
||||||
|
|
||||||
NearRadius = NearRadius or 25
|
|
||||||
|
|
||||||
self.CargoInAir = self.CargoObject:InAir()
|
|
||||||
|
|
||||||
self:T( self.CargoInAir )
|
|
||||||
|
|
||||||
-- Only move the group to the carrier when the cargo is not in the air
|
|
||||||
-- (eg. cargo can be on a oil derrick, moving the cargo on the oil derrick will drop the cargo on the sea).
|
|
||||||
if not self.CargoInAir then
|
|
||||||
self:Load( CargoCarrier, ... )
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1024,6 +1052,8 @@ function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
|
|||||||
|
|
||||||
self.CargoSet = SET_CARGO:New()
|
self.CargoSet = SET_CARGO:New()
|
||||||
|
|
||||||
|
self.CargoObject = CargoGroup
|
||||||
|
|
||||||
local WeightGroup = 0
|
local WeightGroup = 0
|
||||||
|
|
||||||
for UnitID, UnitData in pairs( CargoGroup:GetUnits() ) do
|
for UnitID, UnitData in pairs( CargoGroup:GetUnits() ) do
|
||||||
@ -1085,6 +1115,7 @@ function CARGO_GROUP:onenterLoaded( From, Event, To, CargoCarrier, ... )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.CargoObject:Destroy()
|
||||||
self.CargoCarrier = CargoCarrier
|
self.CargoCarrier = CargoCarrier
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -1220,7 +1251,7 @@ function CARGO_GROUP:onenterUnLoaded( From, Event, To, ToPointVec2, ... )
|
|||||||
)
|
)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- CARGO_GROUP
|
end -- CARGO_GROUP
|
||||||
|
|||||||
@ -531,7 +531,7 @@ do -- TASK_CARGO
|
|||||||
-- @return Core.Set#SET_CARGO The Cargo Set.
|
-- @return Core.Set#SET_CARGO The Cargo Set.
|
||||||
function TASK_CARGO:GetCargoSet()
|
function TASK_CARGO:GetCargoSet()
|
||||||
|
|
||||||
return self.CargoSet
|
return self.SetCargo
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param #TASK_CARGO self
|
--- @param #TASK_CARGO self
|
||||||
@ -773,38 +773,41 @@ do -- TASK_CARGO_TRANSPORT
|
|||||||
|
|
||||||
local Fsm = self:GetUnitProcess()
|
local Fsm = self:GetUnitProcess()
|
||||||
|
|
||||||
---
|
|
||||||
-- @param #TASK_CARGO_TRANSPORT self
|
|
||||||
-- @return #boolean
|
|
||||||
function TASK_CARGO_TRANSPORT:IsAllCargoTransported()
|
|
||||||
|
|
||||||
local CargoSet = self:GetCargoSet()
|
|
||||||
local Set = CargoSet:GetSet()
|
|
||||||
|
|
||||||
local DeployZones = self:GetDeployZones()
|
|
||||||
|
|
||||||
local CargoDeployed = true
|
|
||||||
|
|
||||||
-- Loop the CargoSet (so evaluate each Cargo in the SET_CARGO ).
|
|
||||||
for CargoID, CargoData in pairs( Set ) do
|
|
||||||
local Cargo = CargoData -- Core.Cargo#CARGO
|
|
||||||
|
|
||||||
-- Loop the DeployZones set for the TASK_CARGO_TRANSPORT.
|
|
||||||
for DeployZoneID, DeployZone in pairs( DeployZones ) do
|
|
||||||
|
|
||||||
-- If there is a Cargo not in one of DeployZones, then not all Cargo is deployed.
|
|
||||||
if Cargo:IsInZone( DeployZone ) then
|
|
||||||
else
|
|
||||||
CargoDeployed = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return CargoDeployed
|
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- @param #TASK_CARGO_TRANSPORT self
|
||||||
|
-- @return #boolean
|
||||||
|
function TASK_CARGO_TRANSPORT:IsAllCargoTransported()
|
||||||
|
|
||||||
|
local CargoSet = self:GetCargoSet()
|
||||||
|
local Set = CargoSet:GetSet()
|
||||||
|
|
||||||
|
local DeployZones = self:GetDeployZones()
|
||||||
|
|
||||||
|
local CargoDeployed = true
|
||||||
|
|
||||||
|
-- Loop the CargoSet (so evaluate each Cargo in the SET_CARGO ).
|
||||||
|
for CargoID, CargoData in pairs( Set ) do
|
||||||
|
local Cargo = CargoData -- Core.Cargo#CARGO
|
||||||
|
|
||||||
|
-- Loop the DeployZones set for the TASK_CARGO_TRANSPORT.
|
||||||
|
for DeployZoneID, DeployZone in pairs( DeployZones ) do
|
||||||
|
|
||||||
|
-- If there is a Cargo not in one of DeployZones, then not all Cargo is deployed.
|
||||||
|
self:T( { Cargo.CargoObject } )
|
||||||
|
if Cargo:IsInZone( DeployZone ) then
|
||||||
|
else
|
||||||
|
CargoDeployed = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return CargoDeployed
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -156,6 +156,7 @@ end
|
|||||||
-- @param #GROUP self
|
-- @param #GROUP self
|
||||||
-- @return Dcs.DCSWrapper.Group#Group The DCS Group.
|
-- @return Dcs.DCSWrapper.Group#Group The DCS Group.
|
||||||
function GROUP:GetDCSObject()
|
function GROUP:GetDCSObject()
|
||||||
|
self:F(self.GroupName)
|
||||||
local DCSGroup = Group.getByName( self.GroupName )
|
local DCSGroup = Group.getByName( self.GroupName )
|
||||||
|
|
||||||
if DCSGroup then
|
if DCSGroup then
|
||||||
@ -319,6 +320,7 @@ function GROUP:GetUnit( UnitNumber )
|
|||||||
local DCSGroup = self:GetDCSObject()
|
local DCSGroup = self:GetDCSObject()
|
||||||
|
|
||||||
if DCSGroup then
|
if DCSGroup then
|
||||||
|
local DCSUnit = DCSGroup:getUnit( UnitNumber )
|
||||||
local UnitFound = UNIT:Find( DCSGroup:getUnit( UnitNumber ) )
|
local UnitFound = UNIT:Find( DCSGroup:getUnit( UnitNumber ) )
|
||||||
self:T2( UnitFound )
|
self:T2( UnitFound )
|
||||||
return UnitFound
|
return UnitFound
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user