Fixed slingload deploy problem.

Fixed messaging. Now a message is shown when cargo reports itself when in LoadRange and when near, it will allow for loading of cargo.
Fixed the perception that cargo can be boarded when loaded in an other carrier, which is totally wrong.
This commit is contained in:
FlightControl_Master
2018-04-06 21:28:43 +02:00
parent 2ebd25d677
commit 269b52fd0e
6 changed files with 305 additions and 145 deletions

View File

@@ -224,6 +224,7 @@ do -- CARGO
Slingloadable = false, Slingloadable = false,
Moveable = false, Moveable = false,
Containable = false, Containable = false,
Reported = {},
} }
--- @type CARGO.CargoObjects --- @type CARGO.CargoObjects
@@ -235,12 +236,13 @@ do -- CARGO
-- @param #string Type -- @param #string Type
-- @param #string Name -- @param #string Name
-- @param #number Weight -- @param #number Weight
-- @param #number LoadRadius (optional)
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO -- @return #CARGO
function CARGO:New( Type, Name, Weight ) --R2.1 function CARGO:New( Type, Name, Weight, LoadRadius, NearRadius ) --R2.1
local self = BASE:Inherit( self, FSM:New() ) -- #CARGO local self = BASE:Inherit( self, FSM:New() ) -- #CARGO
self:F( { Type, Name, Weight } ) self:F( { Type, Name, Weight, LoadRadius, NearRadius } )
self:SetStartState( "UnLoaded" ) self:SetStartState( "UnLoaded" )
self:AddTransition( { "UnLoaded", "Boarding" }, "Board", "Boarding" ) self:AddTransition( { "UnLoaded", "Boarding" }, "Board", "Boarding" )
@@ -267,6 +269,9 @@ do -- CARGO
self.Moveable = false self.Moveable = false
self.Containable = false self.Containable = false
self.LoadRadius = LoadRadius or 500
self.NearRadius = NearRadius or 25
self:SetDeployed( false ) self:SetDeployed( false )
self.CargoScheduler = SCHEDULER:New() self.CargoScheduler = SCHEDULER:New()
@@ -405,8 +410,9 @@ do -- CARGO
end end
end end
--- Set the cargo as deployed --- Set the cargo as deployed.
-- @param #CARGO self -- @param #CARGO self
-- @param #boolean Deployed true if the cargo is to be deployed. false or nil otherwise.
function CARGO:SetDeployed( Deployed ) function CARGO:SetDeployed( Deployed )
self.Deployed = Deployed self.Deployed = Deployed
end end
@@ -507,7 +513,86 @@ do -- CARGO
end end
--- Set the Load radius, which is the radius till when the Cargo can be loaded.
-- @param #CARGO self
-- @param #number LoadRadius The radius till Cargo can be loaded.
-- @return #CARGO
function CARGO:SetLoadRadius( LoadRadius )
self.LoadRadius = LoadRadius or 150
end
--- Get the Load radius, which is the radius till when the Cargo can be loaded.
-- @param #CARGO self
-- @return #number The radius till Cargo can be loaded.
function CARGO:GetLoadRadius()
return self.LoadRadius
end
--- Check if Cargo is in the LoadRadius for the Cargo to be Boarded or Loaded.
-- @param #CARGO self
-- @param Core.Point#Coordinate Coordinate
-- @return #boolean true if the CargoGroup is within the loading radius.
function CARGO:IsInLoadRadius( Coordinate )
self:F( { Coordinate } )
local Distance = 0
if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= self.LoadRadius then
return true
end
end
return false
end
--- Check if the Cargo can report itself to be Boarded or Loaded.
-- @param #CARGO self
-- @param Core.Point#Coordinate Coordinate
-- @return #boolean true if the Cargo can report itself.
function CARGO:IsInReportRadius( Coordinate )
self:F( { Coordinate } )
local Distance = 0
if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= self.LoadRadius then
return true
end
end
return false
end
--- Check if CargoCarrier is near the Cargo to be Loaded.
-- @param #CARGO self
-- @param Core.Point#POINT_VEC2 PointVec2
-- @param #number NearRadius The radius when the cargo will board the Carrier (to avoid collision).
-- @return #boolean
function CARGO:IsNear( PointVec2, NearRadius )
self:F( { PointVec2 = PointVec2, NearRadius = NearRadius } )
if self.CargoObject:IsAlive() then
--local Distance = PointVec2:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
self:F( { CargoObjectName = self.CargoObject:GetName() } )
self:F( { CargoObjectVec2 = self.CargoObject:GetVec2() } )
self:F( { PointVec2 = PointVec2:GetVec2() } )
local Distance = PointVec2:Get2DDistance( self.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= NearRadius then
return true
end
end
return false
end
@@ -534,30 +619,6 @@ do -- CARGO
end end
--- Check if CargoCarrier is near the Cargo to be Loaded.
-- @param #CARGO self
-- @param Core.Point#POINT_VEC2 PointVec2
-- @param #number NearRadius The radius when the cargo will board the Carrier (to avoid collision).
-- @return #boolean
function CARGO:IsNear( PointVec2, NearRadius )
self:F( { PointVec2 = PointVec2, NearRadius = NearRadius } )
if self.CargoObject:IsAlive() then
--local Distance = PointVec2:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
self:F( { CargoObjectName = self.CargoObject:GetName() } )
self:F( { CargoObjectVec2 = self.CargoObject:GetVec2() } )
self:F( { PointVec2 = PointVec2:GetVec2() } )
local Distance = PointVec2:Get2DDistance( self.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= NearRadius then
return true
end
end
return false
end
--- Get the current PointVec2 of the cargo. --- Get the current PointVec2 of the cargo.
-- @param #CARGO self -- @param #CARGO self
-- @return Core.Point#POINT_VEC2 -- @return Core.Point#POINT_VEC2
@@ -580,6 +641,85 @@ do -- CARGO
self.Weight = Weight self.Weight = Weight
return self return self
end end
--- Send a CC message to a @{Group}.
-- @param #CARGO self
-- @param #string Message
-- @param Wrapper.Group#GROUP CarrierGroup The Carrier Group.
-- @param #sring Name (optional) The name of the Group used as a prefix for the message to the Group. If not provided, there will be nothing shown.
function CARGO:MessageToGroup( Message, CarrierGroup, Name )
MESSAGE:New( Message, 20, "Cargo " .. self:GetName() ):ToGroup( CarrierGroup )
end
--- Report to a Carrier Group.
-- @param #CARGO self
-- @param #string Action The string describing the action for the cargo.
-- @param Wrapper.Group#GROUP CarrierGroup The Carrier Group to send the report to.
-- @return #CARGO
function CARGO:Report( ReportText, Action, CarrierGroup )
if not self.Reported[CarrierGroup] or not self.Reported[CarrierGroup][Action] then
self.Reported[CarrierGroup] = {}
self.Reported[CarrierGroup][Action] = true
self:MessageToGroup( ReportText, CarrierGroup )
if self.ReportFlareColor then
if not self.Reported[CarrierGroup]["Flaring"] then
self:Flare( self.ReportFlareColor )
self.Reported[CarrierGroup]["Flaring"] = true
end
end
if self.ReportSmokeColor then
if not self.Reported[CarrierGroup]["Smoking"] then
self:Smoke( self.ReportSmokeColor )
self.Reported[CarrierGroup]["Smoking"] = true
end
end
end
end
--- Report to a Carrier Group with a Flaring signal.
-- @param #CARGO self
-- @param Utils#UTILS.FlareColor FlareColor the color of the flare.
-- @return #CARGO
function CARGO:ReportFlare( FlareColor )
self.ReportFlareColor = FlareColor
end
--- Report to a Carrier Group with a Smoking signal.
-- @param #CARGO self
-- @param Utils#UTILS.SmokeColor SmokeColor the color of the smoke.
-- @return #CARGO
function CARGO:ReportSmoke( SmokeColor )
self.ReportSmokeColor = SmokeColor
end
--- Reset the reporting for a Carrier Group.
-- @param #CARGO self
-- @param #string Action The string describing the action for the cargo.
-- @param Wrapper.Group#GROUP CarrierGroup The Carrier Group to send the report to.
-- @return #CARGO
function CARGO:ReportReset( Action, CarrierGroup )
self.Reported[CarrierGroup][Action] = nil
end
--- Reset all the reporting for a Carrier Group.
-- @param #CARGO self
-- @param Wrapper.Group#GROUP CarrierGroup The Carrier Group to send the report to.
-- @return #CARGO
function CARGO:ReportResetAll( CarrierGroup )
self.Reported[CarrierGroup] = nil
end
end -- CARGO end -- CARGO
@@ -600,16 +740,13 @@ do -- CARGO_REPRESENTABLE
-- @param #string Type -- @param #string Type
-- @param #string Name -- @param #string Name
-- @param #number Weight -- @param #number Weight
-- @param #number ReportRadius (optional) -- @param #number LoadRadius (optional)
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO_REPRESENTABLE -- @return #CARGO_REPRESENTABLE
function CARGO_REPRESENTABLE:New( CargoObject, Type, Name, Weight, ReportRadius, NearRadius ) function CARGO_REPRESENTABLE:New( CargoObject, Type, Name, Weight, LoadRadius, NearRadius )
local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight ) ) -- #CARGO_REPRESENTABLE local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE
self:F( { Type, Name, Weight, ReportRadius, NearRadius } ) self:F( { Type, Name, Weight, LoadRadius, NearRadius } )
self.ReportRadius = ReportRadius or 500
self.NearRadius = NearRadius or 25
return self return self
end end
@@ -661,14 +798,12 @@ do -- CARGO_REPORTABLE
-- @param #string Type -- @param #string Type
-- @param #string Name -- @param #string Name
-- @param #number Weight -- @param #number Weight
-- @param #number ReportRadius (optional) -- @param #number LoadRadius (optional)
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO_REPORTABLE -- @return #CARGO_REPORTABLE
function CARGO_REPORTABLE:New( Type, Name, Weight, ReportRadius ) function CARGO_REPORTABLE:New( Type, Name, Weight, LoadRadius, NearRadius )
local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight ) ) -- #CARGO_REPORTABLE local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_REPORTABLE
self:F( { Type, Name, Weight, ReportRadius } ) self:F( { Type, Name, Weight, LoadRadius, NearRadius } )
self.ReportRadius = ReportRadius or 1000
return self return self
end end
@@ -680,19 +815,10 @@ do -- CARGO_REPORTABLE
-- @param #sring Name (optional) The name of the Group used as a prefix for the message to the Group. If not provided, there will be nothing shown. -- @param #sring Name (optional) The name of the Group used as a prefix for the message to the Group. If not provided, there will be nothing shown.
function CARGO_REPORTABLE:MessageToGroup( Message, TaskGroup, Name ) function CARGO_REPORTABLE:MessageToGroup( Message, TaskGroup, Name )
local Prefix = Name and "@ " .. Name .. ": " or "@ " .. TaskGroup:GetCallsign() .. ": " MESSAGE:New( Message, 20, "Cargo " .. self:GetName() ):ToGroup( TaskGroup )
Message = Prefix .. Message
MESSAGE:New( Message, 20, "Cargo: " .. self:GetName() ):ToGroup( TaskGroup )
end end
--- Get the Report radius, which is the radius when the Cargo is reporting itself.
-- @param #CARGO_REPORTABLE self
-- @return #number The range till Cargo reports itself.
function CARGO_REPORTABLE:GetBoardingRange()
return self.ReportRadius
end
end end
@@ -717,12 +843,12 @@ do -- CARGO_PACKAGE
-- @param #string Type -- @param #string Type
-- @param #string Name -- @param #string Name
-- @param #number Weight -- @param #number Weight
-- @param #number ReportRadius (optional) -- @param #number LoadRadius (optional)
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO_PACKAGE -- @return #CARGO_PACKAGE
function CARGO_PACKAGE:New( CargoCarrier, Type, Name, Weight, ReportRadius, NearRadius ) function CARGO_PACKAGE:New( CargoCarrier, Type, Name, Weight, LoadRadius, NearRadius )
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoCarrier, Type, Name, Weight, ReportRadius, NearRadius ) ) -- #CARGO_PACKAGE local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoCarrier, Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_PACKAGE
self:F( { Type, Name, Weight, ReportRadius, NearRadius } ) self:F( { Type, Name, Weight, LoadRadius, NearRadius } )
self:T( CargoCarrier ) self:T( CargoCarrier )
self.CargoCarrier = CargoCarrier self.CargoCarrier = CargoCarrier

View File

@@ -23,7 +23,7 @@ do -- CARGO_CRATE
--- Models the behaviour of cargo crates, which can be slingloaded and boarded on helicopters. --- Models the behaviour of cargo crates, which can be slingloaded and boarded on helicopters.
-- @type CARGO_CRATE -- @type CARGO_CRATE
-- @extends #CARGO_REPRESENTABLE -- @extends Cargo.Cargo#CARGO_REPRESENTABLE
--- # CARGO\_CRATE class, extends @{#CARGO_REPRESENTABLE} --- # CARGO\_CRATE class, extends @{#CARGO_REPRESENTABLE}
-- --
@@ -42,11 +42,11 @@ do -- CARGO_CRATE
-- @param Wrapper.Static#STATIC CargoStatic -- @param Wrapper.Static#STATIC CargoStatic
-- @param #string Type -- @param #string Type
-- @param #string Name -- @param #string Name
-- @param #number ReportRadius (optional) -- @param #number LoadRadius (optional)
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO_CRATE -- @return #CARGO_CRATE
function CARGO_CRATE:New( CargoStatic, Type, Name, ReportRadius, NearRadius ) function CARGO_CRATE:New( CargoStatic, Type, Name, LoadRadius, NearRadius )
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoStatic, Type, Name, nil, ReportRadius, NearRadius ) ) -- #CARGO_CRATE local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoStatic, Type, Name, nil, LoadRadius, NearRadius ) ) -- #CARGO_CRATE
self:F( { Type, Name, NearRadius } ) self:F( { Type, Name, NearRadius } )
self.CargoObject = CargoStatic self.CargoObject = CargoStatic
@@ -134,6 +134,27 @@ do -- CARGO_CRATE
return false return false
end end
--- Check if Cargo Crate is in the radius for the Cargo to be Boarded or Loaded.
-- @param #CARGO self
-- @param Core.Point#Coordinate Coordinate
-- @return #boolean true if the Cargo Crate is within the loading radius.
function CARGO_CRATE:IsInLoadRadius( Coordinate )
self:F( { Coordinate } )
local Distance = 0
if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= self.NearRadius then
return true
end
end
return false
end
--- Get the current Coordinate of the CargoGroup. --- Get the current Coordinate of the CargoGroup.
-- @param #CARGO_CRATE self -- @param #CARGO_CRATE self
-- @return Core.Point#COORDINATE The current Coordinate of the first Cargo of the CargoGroup. -- @return Core.Point#COORDINATE The current Coordinate of the first Cargo of the CargoGroup.
@@ -188,28 +209,6 @@ do -- CARGO_CRATE
end end
--- Check if CargoGroup is in the ReportRadius for the Cargo to be Loaded.
-- @param #CARGO_CRATE self
-- @param Core.Point#Coordinate Coordinate
-- @return #boolean true if the CargoGroup is within the reporting radius.
function CARGO_CRATE:IsInRadius( Coordinate )
self:F( { Coordinate } )
local Distance = 0
if self:IsLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoCarrier:GetPointVec2() )
else
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
end
self:T( Distance )
if Distance <= self.ReportRadius then
return true
else
return false
end
end
--- Respawn the CargoGroup. --- Respawn the CargoGroup.
-- @param #CARGO_CRATE self -- @param #CARGO_CRATE self
function CARGO_CRATE:Respawn() function CARGO_CRATE:Respawn()

View File

@@ -23,7 +23,7 @@
do -- CARGO_GROUP do -- CARGO_GROUP
--- @type CARGO_GROUP --- @type CARGO_GROUP
-- @extends #CARGO_REPORTABLE -- @extends Cargo.Cargo#CARGO_REPORTABLE
-- @field Core.Set#SET_CARGO CargoSet The collection of derived CARGO objects. -- @field Core.Set#SET_CARGO CargoSet The collection of derived CARGO objects.
-- @field #string GroupName The name of the CargoGroup. -- @field #string GroupName The name of the CargoGroup.
@@ -45,12 +45,12 @@ do -- CARGO_GROUP
-- @param Wrapper.Group#GROUP CargoGroup -- @param Wrapper.Group#GROUP CargoGroup
-- @param #string Type -- @param #string Type
-- @param #string Name -- @param #string Name
-- @param #number ReportRadius (optional) -- @param #number LoadRadius (optional)
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO_GROUP -- @return #CARGO_GROUP
function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius ) function CARGO_GROUP:New( CargoGroup, Type, Name, LoadRadius )
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( Type, Name, 0, ReportRadius ) ) -- #CARGO_GROUP local self = BASE:Inherit( self, CARGO_REPORTABLE:New( Type, Name, 0, LoadRadius ) ) -- #CARGO_GROUP
self:F( { Type, Name, ReportRadius } ) self:F( { Type, Name, LoadRadius } )
self.CargoSet = SET_CARGO:New() self.CargoSet = SET_CARGO:New()
@@ -455,11 +455,11 @@ function CARGO_GROUP:OnEventCargoDead( EventData )
return nil return nil
end end
--- Check if CargoGroup is in the ReportRadius for the Cargo to be Loaded. --- Check if Cargo Group is in the radius for the Cargo to be Boarded.
-- @param #CARGO_GROUP self -- @param #CARGO_GROUP self
-- @param Core.Point#Coordinate Coordinate -- @param Core.Point#Coordinate Coordinate
-- @return #boolean true if the CargoGroup is within the reporting radius. -- @return #boolean true if the Cargo Group is within the load radius.
function CARGO_GROUP:IsInRadius( Coordinate ) function CARGO_GROUP:IsInLoadRadius( Coordinate )
self:F( { Coordinate } ) self:F( { Coordinate } )
local Cargo = self.CargoSet:GetFirst() -- #CARGO local Cargo = self.CargoSet:GetFirst() -- #CARGO
@@ -473,7 +473,7 @@ function CARGO_GROUP:OnEventCargoDead( EventData )
end end
self:T( Distance ) self:T( Distance )
if Distance <= self.ReportRadius then if Distance <= self.LoadRadius then
return true return true
else else
return false return false
@@ -484,6 +484,31 @@ function CARGO_GROUP:OnEventCargoDead( EventData )
end end
--- Check if Cargo Group is in the report radius.
-- @param #CARGO_GROUP self
-- @param Core.Point#Coordinate Coordinate
-- @return #boolean true if the Cargo Group is within the report radius.
function CARGO_GROUP:IsInReportRadius( Coordinate )
self:F( { Coordinate } )
local Cargo = self.CargoSet:GetFirst() -- #CARGO
if Cargo then
local Distance = 0
if Cargo:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( Cargo.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= self.LoadRadius then
return true
end
end
end
return nil
end
--- Respawn the CargoGroup. --- Respawn the CargoGroup.
-- @param #CARGO_GROUP self -- @param #CARGO_GROUP self
function CARGO_GROUP:Respawn() function CARGO_GROUP:Respawn()

View File

@@ -24,7 +24,7 @@ do -- CARGO_SLINGLOAD
--- Models the behaviour of cargo crates, which can only be slingloaded. --- Models the behaviour of cargo crates, which can only be slingloaded.
-- @type CARGO_SLINGLOAD -- @type CARGO_SLINGLOAD
-- @extends #CARGO_REPRESENTABLE -- @extends Cargo.Cargo#CARGO_REPRESENTABLE
--- # CARGO\_CRATE class, extends @{#CARGO_REPRESENTABLE} --- # CARGO\_CRATE class, extends @{#CARGO_REPRESENTABLE}
-- --
@@ -42,11 +42,11 @@ do -- CARGO_SLINGLOAD
-- @param Wrapper.Static#STATIC CargoStatic -- @param Wrapper.Static#STATIC CargoStatic
-- @param #string Type -- @param #string Type
-- @param #string Name -- @param #string Name
-- @param #number ReportRadius (optional) -- @param #number LoadRadius (optional)
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO_SLINGLOAD -- @return #CARGO_SLINGLOAD
function CARGO_SLINGLOAD:New( CargoStatic, Type, Name, ReportRadius, NearRadius ) function CARGO_SLINGLOAD:New( CargoStatic, Type, Name, LoadRadius, NearRadius )
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoStatic, Type, Name, nil, ReportRadius, NearRadius ) ) -- #CARGO_SLINGLOAD local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoStatic, Type, Name, nil, LoadRadius, NearRadius ) ) -- #CARGO_SLINGLOAD
self:F( { Type, Name, NearRadius } ) self:F( { Type, Name, NearRadius } )
self.CargoObject = CargoStatic self.CargoObject = CargoStatic
@@ -90,6 +90,28 @@ do -- CARGO_SLINGLOAD
return false return false
end end
--- Check if Cargo Slingload is in the radius for the Cargo to be Boarded or Loaded.
-- @param #CARGO_SLINGLOAD self
-- @param Core.Point#Coordinate Coordinate
-- @return #boolean true if the Cargo Slingload is within the loading radius.
function CARGO_SLINGLOAD:IsInLoadRadius( Coordinate )
self:F( { Coordinate } )
local Distance = 0
if self:IsUnLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= self.NearRadius then
return true
end
end
return false
end
--- Get the current Coordinate of the CargoGroup. --- Get the current Coordinate of the CargoGroup.
-- @param #CARGO_SLINGLOAD self -- @param #CARGO_SLINGLOAD self
-- @return Core.Point#COORDINATE The current Coordinate of the first Cargo of the CargoGroup. -- @return Core.Point#COORDINATE The current Coordinate of the first Cargo of the CargoGroup.
@@ -144,28 +166,6 @@ do -- CARGO_SLINGLOAD
end end
--- Check if CargoGroup is in the ReportRadius for the Cargo to be Loaded.
-- @param #CARGO_SLINGLOAD self
-- @param Core.Point#Coordinate Coordinate
-- @return #boolean true if the CargoGroup is within the reporting radius.
function CARGO_SLINGLOAD:IsInRadius( Coordinate )
self:F( { Coordinate } )
local Distance = 0
if self:IsLoaded() then
Distance = Coordinate:DistanceFromPointVec2( self.CargoCarrier:GetPointVec2() )
else
Distance = Coordinate:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
end
self:T( Distance )
if Distance <= self.ReportRadius then
return true
else
return false
end
end
--- Respawn the CargoGroup. --- Respawn the CargoGroup.
-- @param #CARGO_SLINGLOAD self -- @param #CARGO_SLINGLOAD self
function CARGO_SLINGLOAD:Respawn() function CARGO_SLINGLOAD:Respawn()

View File

@@ -44,7 +44,7 @@ do -- CARGO_UNIT
-- @param #string Type -- @param #string Type
-- @param #string Name -- @param #string Name
-- @param #number Weight -- @param #number Weight
-- @param #number ReportRadius (optional) -- @param #number LoadRadius (optional)
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO_UNIT -- @return #CARGO_UNIT
function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius ) function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius )

View File

@@ -230,7 +230,7 @@ do -- TASK_CARGO
Task.SetCargo:ForEachCargo( Task.SetCargo:ForEachCargo(
--- @param Core.Cargo#CARGO Cargo --- @param Cargo.Cargo#CARGO Cargo
function( Cargo ) function( Cargo )
if Cargo:IsAlive() then if Cargo:IsAlive() then
@@ -250,7 +250,7 @@ do -- TASK_CARGO
if Cargo:IsUnLoaded() then if Cargo:IsUnLoaded() then
if CargoItemCount <= Task.CargoLimit then if CargoItemCount <= Task.CargoLimit then
if Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then if Cargo:IsInReportRadius( TaskUnit:GetPointVec2() ) then
local NotInDeployZones = true local NotInDeployZones = true
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
@@ -260,20 +260,50 @@ do -- TASK_CARGO
if NotInDeployZones then if NotInDeployZones then
if not TaskUnit:InAir() then if not TaskUnit:InAir() then
if Cargo:CanBoard() == true then if Cargo:CanBoard() == true then
MENU_GROUP_COMMAND:New( TaskUnit:GetGroup(), "Board cargo " .. Cargo.Name, TaskUnit.Menu, self.MenuBoardCargo, self, Cargo ):SetTime(MenuTime) if Cargo:IsInLoadRadius( TaskUnit:GetPointVec2() ) then
Cargo:Report( "Reporting for boarding at " .. Cargo:GetCoordinate():ToString( TaskUnit:GetGroup() ), "board", TaskUnit:GetGroup() )
MENU_GROUP_COMMAND:New( TaskUnit:GetGroup(), "Board cargo " .. Cargo.Name, TaskUnit.Menu, self.MenuBoardCargo, self, Cargo ):SetTime(MenuTime)
else
Cargo:Report( "Reporting at " .. Cargo:GetCoordinate():ToString( TaskUnit:GetGroup() ), "reporting", TaskUnit:GetGroup() )
end
else else
if Cargo:CanLoad() == true then if Cargo:CanLoad() == true then
MENU_GROUP_COMMAND:New( TaskUnit:GetGroup(), "Load cargo " .. Cargo.Name, TaskUnit.Menu, self.MenuLoadCargo, self, Cargo ):SetTime(MenuTime) if Cargo:IsInLoadRadius( TaskUnit:GetPointVec2() ) then
Cargo:Report( "Reporting for loading at " .. Cargo:GetCoordinate():ToString( TaskUnit:GetGroup() ), "load", TaskUnit:GetGroup() )
MENU_GROUP_COMMAND:New( TaskUnit:GetGroup(), "Load cargo " .. Cargo.Name, TaskUnit.Menu, self.MenuLoadCargo, self, Cargo ):SetTime(MenuTime)
else
Cargo:Report( "Reporting at " .. Cargo:GetCoordinate():ToString( TaskUnit:GetGroup() ), "reporting", TaskUnit:GetGroup() )
end
end end
end end
TaskUnit.Menu:SetTime( MenuTime ) TaskUnit.Menu:SetTime( MenuTime )
else
Cargo:ReportResetAll( TaskUnit:GetGroup() )
end end
end end
else else
MENU_GROUP_COMMAND:New( TaskUnit:GetGroup(), "Route to Pickup cargo " .. Cargo.Name, TaskUnit.Menu, self.MenuRouteToPickup, self, Cargo ):SetTime(MenuTime) MENU_GROUP_COMMAND:New( TaskUnit:GetGroup(), "Route to Pickup cargo " .. Cargo.Name, TaskUnit.Menu, self.MenuRouteToPickup, self, Cargo ):SetTime(MenuTime)
TaskUnit.Menu:SetTime( MenuTime ) TaskUnit.Menu:SetTime( MenuTime )
Cargo:ReportResetAll( TaskUnit:GetGroup() )
end end
end end
-- Cargo in deployzones are flagged as deployed.
for DeployZoneName, DeployZone in pairs( Task.DeployZones ) do
if Cargo:IsInZone( DeployZone ) then
if not Cargo:IsDeployed() then
Cargo:SetDeployed( true )
-- TODO:I need to find a more decent solution for this.
Task:E( { CargoDeployed = Task.CargoDeployed and "true" or "false" } )
Task:E( { CargoIsAlive = Cargo:IsAlive() and "true" or "false" } )
if Cargo:IsAlive() then
if Task.CargoDeployed then
Task:CargoDeployed( TaskUnit, Cargo, DeployZone )
end
end
end
end
end
end end
if Cargo:IsLoaded() then if Cargo:IsLoaded() then
@@ -303,7 +333,7 @@ do -- TASK_CARGO
TaskUnit.Menu:Remove( MenuTime ) TaskUnit.Menu:Remove( MenuTime )
self:__SelectAction( -15 ) self:__SelectAction( -5 )
end end
@@ -441,7 +471,7 @@ do -- TASK_CARGO
self:F( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } ) self:F( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
if self.Cargo:IsAlive() then if self.Cargo:IsAlive() then
if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then if self.Cargo:IsInLoadRadius( TaskUnit:GetPointVec2() ) then
if TaskUnit:InAir() then if TaskUnit:InAir() then
self:__Land( -10, Action ) self:__Land( -10, Action )
else else
@@ -465,7 +495,7 @@ do -- TASK_CARGO
self:F( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } ) self:F( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
if self.Cargo:IsAlive() then if self.Cargo:IsAlive() then
if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then if self.Cargo:IsInLoadRadius( TaskUnit:GetPointVec2() ) then
if TaskUnit:InAir() then if TaskUnit:InAir() then
self:__Land( -0.1, Action ) self:__Land( -0.1, Action )
else else
@@ -506,7 +536,7 @@ do -- TASK_CARGO
end end
if self.Cargo:IsAlive() then if self.Cargo:IsAlive() then
if self.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then if self.Cargo:IsInLoadRadius( 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.
else else
@@ -649,26 +679,6 @@ do -- TASK_CARGO
end end
end end
TaskUnit:RemoveCargo( Cargo ) TaskUnit:RemoveCargo( Cargo )
local NotInDeployZones = true
for DeployZoneName, DeployZone in pairs( Task.DeployZones ) do
if Cargo:IsInZone( DeployZone ) then
NotInDeployZones = false
end
end
if NotInDeployZones == false then
Cargo:SetDeployed( true )
end
-- TODO:I need to find a more decent solution for this.
Task:E( { CargoDeployed = Task.CargoDeployed and "true" or "false" } )
Task:E( { CargoIsAlive = Cargo:IsAlive() and "true" or "false" } )
if Cargo:IsAlive() then
if Task.CargoDeployed then
Task:CargoDeployed( TaskUnit, Cargo, self.DeployZone )
end
end
self:Planned() self:Planned()
self:__SelectAction( 1 ) self:__SelectAction( 1 )
@@ -739,7 +749,7 @@ do -- TASK_CARGO
local ActRouteCargo = ProcessUnit:GetProcess( "RoutingToPickup", "RouteToPickupPoint" ) -- Actions.Act_Route#ACT_ROUTE_POINT local ActRouteCargo = ProcessUnit:GetProcess( "RoutingToPickup", "RouteToPickupPoint" ) -- Actions.Act_Route#ACT_ROUTE_POINT
ActRouteCargo:Reset() ActRouteCargo:Reset()
ActRouteCargo:SetCoordinate( Cargo:GetCoordinate() ) ActRouteCargo:SetCoordinate( Cargo:GetCoordinate() )
ActRouteCargo:SetRange( Cargo:GetBoardingRange() ) ActRouteCargo:SetRange( Cargo:GetLoadRadius() )
ActRouteCargo:SetMenuCancel( TaskUnit:GetGroup(), "Cancel Routing to Cargo " .. Cargo:GetName(), TaskUnit.Menu ) ActRouteCargo:SetMenuCancel( TaskUnit:GetGroup(), "Cancel Routing to Cargo " .. Cargo:GetName(), TaskUnit.Menu )
ActRouteCargo:Start() ActRouteCargo:Start()
return self return self