This commit is contained in:
Sven Van de Velde 2016-08-05 09:26:34 +02:00
parent e1610330f4
commit 92f1f08d5f
10 changed files with 354 additions and 29712 deletions

View File

@ -49,167 +49,146 @@ do -- CARGO
Containable = false,
}
--- @type CARGO.CargoObjects
-- @map < #string, Positionable#POSITIONABLE > The alive POSITIONABLE objects representing the the cargo.
--- @type CARGO.CargoObjects
-- @map < #string, Positionable#POSITIONABLE > The alive POSITIONABLE objects representing the the cargo.
--- CARGO Constructor.
-- @param #CARGO self
-- @param Mission#MISSION Mission
-- @param #string Type
-- @param #string Name
-- @param #number Weight
-- @param #number ReportRadius (optional)
-- @param #number NearRadius (optional)
-- @return #CARGO
function CARGO:New( Mission, Type, Name, Weight, ReportRadius, NearRadius )
local self = BASE:Inherit( self, BASE:New() ) -- #CARGO
self:F( { Type, Name, Weight, ReportRadius, NearRadius } )
self.Type = Type
self.Name = Name
self.Weight = Weight
self.ReportRadius = ReportRadius
self.NearRadius = NearRadius
self.CargoObjects = nil
self.CargoCarrier = nil
self.Representable = false
self.Slingloadable = false
self.Moveable = false
self.Containable = false
self.CargoScheduler = SCHEDULER:New()
CARGOS[self.Name] = self
return self
end
--- Template method to spawn a new representation of the CARGO in the simulator.
-- @param #CARGO self
-- @return #CARGO
function CARGO:Spawn( PointVec2 )
self:F()
end
--- Board Cargo to a Carrier with a defined Speed.
-- @param #CARGO self
-- @param Unit#UNIT CargoCarrier
-- @param #number Speed
function CARGO:Board( CargoCarrier, Speed )
self:F()
self:_NextEvent( self.FsmP.Board, CargoCarrier, Speed )
end
--- UnBoard Cargo from a Carrier with a defined Speed.
-- @param #CARGO self
-- @param Unit#UNIT CargoCarrier
-- @param #number Speed
function CARGO:UnBoard( Speed )
self:F()
--- CARGO Constructor.
-- @param #CARGO self
-- @param Mission#MISSION Mission
-- @param #string Type
-- @param #string Name
-- @param #number Weight
-- @param #number ReportRadius (optional)
-- @param #number NearRadius (optional)
-- @return #CARGO
function CARGO:New( Mission, Type, Name, Weight, ReportRadius, NearRadius )
local self = BASE:Inherit( self, BASE:New() ) -- #CARGO
self:F( { Type, Name, Weight, ReportRadius, NearRadius } )
self:_NextEvent( self.FsmP.UnBoard, Speed )
end
--- Load Cargo to a Carrier.
-- @param #CARGO self
-- @param Unit#UNIT CargoCarrier
-- @param #number Speed
function CARGO:Load( CargoCarrier )
self:F()
self:_NextEvent( self.FsmP.Load, CargoCarrier )
end
--- UnLoad Cargo from a Carrier.
-- @param #CARGO self
-- @param Unit#UNIT CargoCarrier
-- @param #number Speed
function CARGO:UnLoad()
self:F()
self.Type = Type
self.Name = Name
self.Weight = Weight
self.ReportRadius = ReportRadius
self.NearRadius = NearRadius
self.CargoObjects = nil
self.CargoCarrier = nil
self.Representable = false
self.Slingloadable = false
self.Moveable = false
self.Containable = false
local Process = STATEMACHINE_PROCESS:New( self, {
initial = 'UnLoaded',
events = {
{ name = 'Board', from = 'UnLoaded', to = 'Boarding' },
{ name = 'Boarded', from = 'Boarding', to = 'Boarding' },
{ name = 'Load', from = 'Boarding', to = 'Loaded' },
{ name = 'Load', from = 'UnLoaded', to = 'Loaded' },
{ name = 'UnBoard', from = 'Loaded', to = 'UnBoarding' },
{ name = 'UnBoard', from = 'UnBoarding', to = 'UnBoarding' },
{ name = 'UnBoarded', from = 'UnBoarding', to = 'UnLoaded' },
{ name = 'UnLoad', from = 'Loaded', to = 'UnLoaded' },
},
callbacks = {
OnBoard = self.Board,
OnBoarded = self.OnBoarded,
OnLoad = self.Load,
OnUnBoard = self.UnBoard,
OnUnBoarded = self.UnBoarded,
OnUnLoad = self.UnLoad,
OnLoaded = self.Loaded,
OnUnLoaded = self.UnLoaded,
},
} )
self.CargoScheduler = SCHEDULER:New()
CARGOS[self.CargoName] = self
self:_NextEvent( self.FsmP.UnLoad )
end
--- Check if CargoCarrier is near the Cargo to be Loaded.
-- @param #CARGO self
-- @param Unit#UNIT CargoCarrier
-- @return #boolean
function CARGO:IsNear( CargoCarrier )
self:F()
local CargoCarrierPoint = CargoCarrier:GetPointVec2()
return self
end
--- @param #CARGO self
function CARGO:NextEvent( NextEvent, ... )
self:F( self.Name )
self.CargoScheduler:Schedule( self.Fsm, NextEvent, arg, 1 ) -- This schedules the next event, but only if scheduling is activated.
local Distance = CargoCarrierPoint:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= self.NearRadius then
return true
else
return false
end
end
--- Template method to spawn a new representation of the CARGO in the simulator.
-- @param #CARGO self
-- @return #CARGO
function CARGO:Spawn( PointVec2 )
self:F()
end
--- Load Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO:Load( FsmP, Event, From, To, CargoCarrier )
self:F()
end
--- Loaded State.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO:OnLoaded( FsmP, Event, From, To, CargoCarrier )
self:F()
self.CargoCarrier = CargoCarrier
self:T( "Cargo " .. self.Name .. " loaded in " .. self.CargoCarrier:GetName() )
end
--- UnLoad Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
function CARGO:UnLoad( FsmP, Event, From, To )
self:F()
end
--- UnLoaded State.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
function CARGO:OnUnLoaded( FsmP, Event, From, To )
self:F()
--- Board Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO:Board( FsmP, Event, From, To, CargoCarrier )
self:F()
self:T( "Cargo " .. self.Name .. " unloaded from " .. self.CargoCarrier:GetName() )
self.CargoCarrier = nil
end
end
--- Boarded Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO:Boarded( FsmP, Event, From, To, CargoCarrier )
self:F()
end
function CARGO:IsNear( CargoCarrier, CargoObject, Radius )
self:F()
local Near = true
return Near
end
--- Loaded State.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO:Loaded( FsmP, Event, From, To, CargoCarrier )
self:F()
self.CargoCarrier = CargoCarrier
self:T( "Cargo " .. self.Name .. " loaded in " .. self.CargoCarrier:GetName() )
end
--- UnLoaded State.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
function CARGO:StatusUnLoaded( FsmP, Event, From, To )
self:F()
self:T( "Cargo " .. self.Name .. " unloaded from " .. self.CargoCarrier:GetName() )
self.CargoCarrier = nil
end
--- @param #CARGO self
function CARGO:_NextEvent( NextEvent, ... )
self:F( self.Name )
self.CargoScheduler:Schedule( self.FsmP, NextEvent, arg, 1 ) -- This schedules the next event, but only if scheduling is activated.
end
end
@ -221,90 +200,133 @@ do -- CARGO_REPRESENTABLE
ClassName = "CARGO_REPRESENTABLE"
}
--- CARGO_REPRESENTABLE Constructor.
-- @param #CARGO_REPRESENTABLE self
-- @param Mission#MISSION Mission
-- @param Controllable#Controllable CargoObject
-- @param #string Type
-- @param #string Name
-- @param #number Weight
-- @param #number ReportRadius (optional)
-- @param #number NearRadius (optional)
-- @return #CARGO_REPRESENTABLE
function CARGO_REPRESENTABLE:New( Mission, CargoObject, Type, Name, Weight, ReportRadius, NearRadius )
local self = BASE:Inherit( self, CARGO:New( Mission, Type, Name, Weight, ReportRadius, NearRadius ) ) -- #CARGO
self:F( { Type, Name, Weight, ReportRadius, NearRadius } )
self.CargoObject = CargoObject
return self
end
--- Board Event.
-- @param #CARGO_REPRESENTABLE self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO_REPRESENTABLE:Onboard( FsmP, Event, From, To, CargoCarrier )
self:F()
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
local Points = {}
local PointStartVec2 = self.CargoObject:GetPointVec2()
local PointEndVec2 = Carrier:GetPointVec2()
Points[#Points+1] = PointStartVec2:RoutePointGround( "Cone", 10 )
Points[#Points+1] = PointEndVec2:RoutePointGround( "Cone", 10 )
local TaskRoute = self.CargoObject:TaskRoute( Points )
self.CargoObject:SetTask( TaskRoute, 4 )
end
--- CARGO_REPRESENTABLE Constructor.
-- @param #CARGO_REPRESENTABLE self
-- @param Mission#MISSION Mission
-- @param Controllable#Controllable CargoObject
-- @param #string Type
-- @param #string Name
-- @param #number Weight
-- @param #number ReportRadius (optional)
-- @param #number NearRadius (optional)
-- @return #CARGO_REPRESENTABLE
function CARGO_REPRESENTABLE:New( Mission, CargoObject, Type, Name, Weight, ReportRadius, NearRadius )
local self = BASE:Inherit( self, CARGO:New( Mission, Type, Name, Weight, ReportRadius, NearRadius ) ) -- #CARGO
self:F( { Type, Name, Weight, ReportRadius, NearRadius } )
self:NextEvent( FsmP.Boarded, CargoCarrier )
self:T( CargoObject )
self.CargoObject = CargoObject
end
self.FsmP = STATEMACHINE_PROCESS:New( self, {
initial = 'UnLoaded',
events = {
{ name = 'Board', from = 'UnLoaded', to = 'Boarding' },
{ name = 'Boarded', from = 'Boarding', to = 'Boarding' },
{ name = 'Load', from = 'Boarding', to = 'Loaded' },
{ name = 'Load', from = 'UnLoaded', to = 'Loaded' },
{ name = 'UnBoard', from = 'Loaded', to = 'UnBoarding' },
{ name = 'UnBoarded', from = 'UnBoarding', to = 'UnBoarding' },
{ name = 'UnLoad', from = 'UnBoarding', to = 'UnLoaded' },
{ name = 'UnLoad', from = 'Loaded', to = 'UnLoaded' },
},
callbacks = {
onBoard = self.OnBoard,
onBoarded = self.OnBoarded,
onLoad = self.OnLoad,
onUnBoard = self.OnUnBoard,
onUnBoarded = self.OnUnBoarded,
onUnLoad = self.OnUnLoad,
onLoaded = self.OnLoaded,
onUnLoaded = self.OnUnLoaded,
},
} )
--- Boarded Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO:Boarded( FsmP, Event, From, To, CargoCarrier )
self:F()
if self:IsNear( CargoCarrier ) then
self:NextEvent( FsmP.Boarded, CargoCarrier )
else
self:NextEvent( FsmP.Load, CargoCarrier )
end
return self
end
--- Board Event.
-- @param #CARGO_REPRESENTABLE self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO_REPRESENTABLE:OnBoard( FsmP, Event, From, To, CargoCarrier, Speed )
self:F()
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
local Points = {}
local PointStartVec2 = self.CargoObject:GetPointVec2()
local PointEndVec2 = CargoCarrier:GetPointVec2()
Points[#Points+1] = PointStartVec2:RoutePointGround( Speed )
Points[#Points+1] = PointEndVec2:RoutePointGround( Speed )
local TaskRoute = self.CargoObject:TaskRoute( Points )
self.CargoObject:SetTask( TaskRoute, 4 )
end
--- Load Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO:Load( FsmP, Event, From, To, CargoCarrier )
self:F()
self.CargoCarrier = CargoCarrier
self.CargoObject:Destroy()
self:_NextEvent( FsmP.Boarded, CargoCarrier )
end
--- Boarded Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO_REPRESENTABLE:OnBoarded( FsmP, Event, From, To, CargoCarrier )
self:F()
if self:IsNear( CargoCarrier ) then
self:_NextEvent( FsmP.Load, CargoCarrier )
else
self:_NextEvent( FsmP.Boarded, CargoCarrier )
end
end
--- UnBoarded Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO_REPRESENTABLE:OnUnBoarded( FsmP, Event, From, To )
self:F()
if self.CargoObject:GetVelocityKMH() <= 0.1 then
self:_NextEvent( FsmP.UnLoad )
else
self:_NextEvent( FsmP.Boarded, CargoCarrier )
end
end
--- Load Event.
-- @param #CARGO self
-- @param StateMachine#STATEMACHINE_PROCESS FsmP
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT CargoCarrier
function CARGO_REPRESENTABLE:OnLoad( FsmP, Event, From, To, CargoCarrier )
self:F()
self.CargoCarrier = CargoCarrier
self.CargoObject:Destroy()
end
end
@ -316,22 +338,22 @@ do -- CARGO_UNIT
ClassName = "CARGO_UNIT"
}
--- CARGO_UNIT Constructor.
-- @param #CARGO_UNIT self
-- @param Mission#MISSION Mission
-- @param Unit#UNIT CargoUnit
-- @param #string Type
-- @param #string Name
-- @param #number Weight
-- @param #number ReportRadius (optional)
-- @param #number NearRadius (optional)
-- @return #CARGO_UNIT
function CARGO_UNIT:New( Mission, CargoUnit, Type, Name, Weight, ReportRadius, NearRadius )
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( Mission, CargoUnit, Type, Name, Weight, ReportRadius, NearRadius ) ) -- #CARGO
self:F( { Type, Name, Weight, ReportRadius, NearRadius } )
return self
end
--- CARGO_UNIT Constructor.
-- @param #CARGO_UNIT self
-- @param Mission#MISSION Mission
-- @param Unit#UNIT CargoUnit
-- @param #string Type
-- @param #string Name
-- @param #number Weight
-- @param #number ReportRadius (optional)
-- @param #number NearRadius (optional)
-- @return #CARGO_UNIT
function CARGO_UNIT:New( Mission, CargoUnit, Type, Name, Weight, ReportRadius, NearRadius )
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( Mission, CargoUnit, Type, Name, Weight, ReportRadius, NearRadius ) ) -- #CARGO
self:F( { Type, Name, Weight, ReportRadius, NearRadius } )
return self
end
end
@ -591,31 +613,49 @@ function CARGO_SLINGLOAD:Spawn( Client )
-- This does not work in 1.5.2.
CargoStatic = StaticObject.getByName( self.CargoName )
if CargoStatic then
CargoStatic:destroy()
end
--]]
CargoStatic = StaticObject.getByName( self.CargoStaticName )
@ -1028,3 +1068,6 @@ end

View File

@ -71,7 +71,7 @@ end
--- Destroys the OBJECT.
-- @param #OBJECT self
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:Destroy()
function OBJECT:Destroy()
self:F2( self.ObjectName )
local DCSObject = self:GetDCSObject()

View File

@ -383,17 +383,18 @@ end
--- Build an ground type route point.
-- @param #POINT_VEC3 self
-- @param #POINT_VEC3.RoutePointAction Formation The route point Formation.
-- @param DCSTypes#Speed Speed Speed in km/h.
-- @param #POINT_VEC3.RoutePointAction Formation The route point Formation.
-- @return #table The route point.
function POINT_VEC3:RoutePointGround( Formation, Speed )
function POINT_VEC3:RoutePointGround( Speed, Formation )
self:F2( { Formation, Speed } )
local RoutePoint = {}
RoutePoint.x = self.PointVec3.x
RoutePoint.y = self.PointVec3.z
RoutePoint.action = Formation
RoutePoint.action = Formation or ""
RoutePoint.speed = Speed / 3.6
RoutePoint.speed_locked = true
@ -555,6 +556,26 @@ function POINT_VEC2:NewFromVec2( Vec2, LandHeightAdd )
return self
end
--- Create a new POINT_VEC2 object from Vec3 coordinates.
-- @param #POINT_VEC2 self
-- @param DCSTypes#Vec3 Vec3 The Vec3 point.
-- @return Point#POINT_VEC2 self
function POINT_VEC2:NewFromVec3( Vec3 )
local self = BASE:Inherit( self, BASE:New() )
local Vec2 = { x = Vec3.x, y = Vec3.z }
local LandHeight = land.getHeight( Vec2 )
local self = BASE:Inherit( self, POINT_VEC3:New( Vec2.x, LandHeight, Vec2.y ) )
self:F2( { Vec2.x, LandHeight, Vec2.y } )
self.PointVec2 = Vec2
self:F2( self.PointVec3 )
return self
end
--- Calculate the distance from a reference @{Point#POINT_VEC2}.
-- @param #POINT_VEC2 self
-- @param #POINT_VEC2 PointVec2Reference The reference @{Point#POINT_VEC2}.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
local Mission = MISSION:New( "Pickup Cargo", "High", "Test for Cargo Pickup", coalition.side.RED )
local CargoEngineer = UNIT:FindByName( "Engineer" )
local InfantryCargo = CARGO_UNIT:New( Mission, CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 25 )
local CargoCarrier = UNIT:FindByName( "Carrier" )
-- This call will make the Cargo run to the CargoCarrier.
-- Upon arrival at the CargoCarrier, the Cargo will be Loaded into the Carrier.
-- This process is now fully automated.
InfantryCargo:Board( CargoCarrier, 10 )

View File

@ -1,8 +0,0 @@
local Mission = MISSION:New( "Pickup Cargo", "High", "Test for Cargo Pickup", coalition.side.RED )
local CargoEngineer = UNIT:FindByName( "Engineer" )
local InfantryCargo = CARGO_UNIT:New( Mission, CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 300 )
local CargoCarrier = UNIT:FindByName( "CargoCarrier" )
InfantryCargo:OnBoard( CargoCarrier )

View File

@ -0,0 +1,14 @@
local Mission = MISSION:New( "Pickup Cargo", "High", "Test for Cargo Pickup", coalition.side.RED )
local CargoEngineer = UNIT:FindByName( "Engineer" )
local InfantryCargo = CARGO_UNIT:New( Mission, CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 25 )
local CargoCarrier = UNIT:FindByName( "Carrier" )
-- This will Load the Cargo into the Carrier, regardless where the Cargo is.
InfantryCargo:Load( CargoCarrier )
-- This will Unboard the Cargo from the Carrier.
-- The Cargo will run from the Carrier to a point in the NearRadius around the Carrier.
InfantryCargo:UnBoard( CargoCarrier, 10 )