This commit is contained in:
FlightControl 2017-03-25 11:59:20 +01:00
parent 09c05057ae
commit d1a7e5864d
4 changed files with 118 additions and 55 deletions

View File

@ -15,55 +15,7 @@
--
-- * AI_CARGO_GROUPED, represented by a Group of CARGO_UNITs.
--
-- # 1) @{#AI_CARGO} class, extends @{Fsm#FSM_PROCESS}
--
-- The @{#AI_CARGO} class defines the core functions that defines a cargo object within MOOSE.
-- A cargo is a logical object defined that is available for transport, and has a life status within a simulation.
--
-- The AI_CARGO is a state machine: it manages the different events and states of the cargo.
-- All derived classes from AI_CARGO follow the same state machine, expose the same cargo event functions, and provide the same cargo states.
--
-- ## 1.2.1) AI_CARGO Events:
--
-- * @{#AI_CARGO.Board}( ToCarrier ): Boards the cargo to a carrier.
-- * @{#AI_CARGO.Load}( ToCarrier ): Loads the cargo into a carrier, regardless of its position.
-- * @{#AI_CARGO.UnBoard}( ToPointVec2 ): UnBoard the cargo from a carrier. This will trigger a movement of the cargo to the option ToPointVec2.
-- * @{#AI_CARGO.UnLoad}( ToPointVec2 ): UnLoads the cargo from a carrier.
-- * @{#AI_CARGO.Dead}( Controllable ): The cargo is dead. The cargo process will be ended.
--
-- ## 1.2.2) AI_CARGO States:
--
-- * **UnLoaded**: The cargo is unloaded from a carrier.
-- * **Boarding**: The cargo is currently boarding (= running) into a carrier.
-- * **Loaded**: The cargo is loaded into a carrier.
-- * **UnBoarding**: The cargo is currently unboarding (=running) from a carrier.
-- * **Dead**: The cargo is dead ...
-- * **End**: The process has come to an end.
--
-- ## 1.2.3) AI_CARGO state transition methods:
--
-- State transition functions can be set **by the mission designer** customizing or improving the behaviour of the state.
-- There are 2 moments when state transition methods will be called by the state machine:
--
-- * **Leaving** the state.
-- The state transition method needs to start with the name **OnLeave + the name of the state**.
-- If the state transition method returns false, then the processing of the state transition will not be done!
-- If you want to change the behaviour of the AIControllable at this event, return false,
-- but then you'll need to specify your own logic using the AIControllable!
--
-- * **Entering** the state.
-- The state transition method needs to start with the name **OnEnter + the name of the state**.
-- These state transition methods need to provide a return value, which is specified at the function description.
--
-- # 2) #AI_CARGO_UNIT class
--
-- The AI_CARGO_UNIT class defines a cargo that is represented by a UNIT object within the simulator, and can be transported by a carrier.
-- Use the event functions as described above to Load, UnLoad, Board, UnBoard the AI_CARGO_UNIT objects to and from carriers.
--
-- # 5) #AI_CARGO_GROUPED class
--
-- The AI_CARGO_GROUPED class defines a cargo that is represented by a group of UNIT objects within the simulator, and can be transported by a carrier.
-- Use the event functions as described above to Load, UnLoad, Board, UnBoard the AI_CARGO_UNIT objects to and from carriers.
--
-- This module is still under construction, but is described above works already, and will keep working ...
--
@ -200,6 +152,49 @@ do -- AI_CARGO
-- @field #boolean Moveable This flag defines if the cargo is moveable.
-- @field #boolean Representable This flag defines if the cargo can be represented by a DCS Unit.
-- @field #boolean Containable This flag defines if the cargo can be contained within a DCS Unit.
--- # AI\_CARGO class, extends @{Fsm#FSM_PROCESS}
--
-- The AI\_CARGO class defines the core functions that defines a cargo object within MOOSE.
-- A cargo is a logical object defined that is available for transport, and has a life status within a simulation.
--
-- The AI\_CARGO is a state machine: it manages the different events and states of the cargo.
-- All derived classes from AI\_CARGO follow the same state machine, expose the same cargo event functions, and provide the same cargo states.
--
-- ## AI\_CARGO Events:
--
-- * @{#AI\_CARGO.Board}( ToCarrier ): Boards the cargo to a carrier.
-- * @{#AI\_CARGO.Load}( ToCarrier ): Loads the cargo into a carrier, regardless of its position.
-- * @{#AI\_CARGO.UnBoard}( ToPointVec2 ): UnBoard the cargo from a carrier. This will trigger a movement of the cargo to the option ToPointVec2.
-- * @{#AI\_CARGO.UnLoad}( ToPointVec2 ): UnLoads the cargo from a carrier.
-- * @{#AI\_CARGO.Dead}( Controllable ): The cargo is dead. The cargo process will be ended.
--
-- ## AI\_CARGO States:
--
-- * **UnLoaded**: The cargo is unloaded from a carrier.
-- * **Boarding**: The cargo is currently boarding (= running) into a carrier.
-- * **Loaded**: The cargo is loaded into a carrier.
-- * **UnBoarding**: The cargo is currently unboarding (=running) from a carrier.
-- * **Dead**: The cargo is dead ...
-- * **End**: The process has come to an end.
--
-- ## AI\_CARGO state transition methods:
--
-- State transition functions can be set **by the mission designer** customizing or improving the behaviour of the state.
-- There are 2 moments when state transition methods will be called by the state machine:
--
-- * **Leaving** the state.
-- The state transition method needs to start with the name **OnLeave + the name of the state**.
-- If the state transition method returns false, then the processing of the state transition will not be done!
-- If you want to change the behaviour of the AIControllable at this event, return false,
-- but then you'll need to specify your own logic using the AIControllable!
--
-- * **Entering** the state.
-- The state transition method needs to start with the name **OnEnter + the name of the state**.
-- These state transition methods need to provide a return value, which is specified at the function description.
--
-- @field #AI_CARGO AI_CARGO
--
AI_CARGO = {
ClassName = "AI_CARGO",
Type = nil,
@ -270,6 +265,23 @@ function AI_CARGO:Spawn( PointVec2 )
end
--- Check if CargoCarrier is in the radius for the Cargo to be Loaded.
-- @param #AI_CARGO self
-- @param Core.Point#POINT_VEC2 PointVec2
-- @return #boolean
function AI_CARGO:IsInRadius( PointVec2 )
self:F( { PointVec2 } )
local Distance = PointVec2:DistanceFromPointVec2( self.CargoObject:GetPointVec2() )
self:T( Distance )
if Distance <= self.ReportRadius then
return true
else
return false
end
end
--- Check if CargoCarrier is near the Cargo to be Loaded.
-- @param #AI_CARGO self
@ -299,7 +311,7 @@ end
-- @param #AI_CARGO self
-- @return #number The range till cargo will board.
function AI_CARGO:GetBoardingRange()
return self.NearRadius
return self.ReportRadius
end
end
@ -354,6 +366,16 @@ do -- AI_CARGO_UNIT
--- @type AI_CARGO_UNIT
-- @extends #AI_CARGO_REPRESENTABLE
--- # AI\_CARGO\_UNIT class, extends @{#AI_CARGO_REPRESENTABLE}
--
-- The AI\_CARGO\_UNIT class defines a cargo that is represented by a UNIT object within the simulator, and can be transported by a carrier.
-- Use the event functions as described above to Load, UnLoad, Board, UnBoard the AI\_CARGO\_UNIT objects to and from carriers.
--
-- ===
--
-- @field #AI_CARGO_UNIT AI_CARGO_UNIT
--
AI_CARGO_UNIT = {
ClassName = "AI_CARGO_UNIT"
}
@ -823,6 +845,14 @@ do -- AI_CARGO_GROUP
-- @extends AI.AI_Cargo#AI_CARGO
-- @field Set#SET_BASE CargoSet A set of cargo objects.
-- @field #string Name A string defining the name of the cargo group. The name is the unique identifier of the cargo.
--- # AI\_CARGO\_GROUP class
--
-- The AI\_CARGO\_GROUP class defines a cargo that is represented by a group of @{Unit} objects within the simulator, and can be transported by a carrier.
-- Use the event functions as described above to Load, UnLoad, Board, UnBoard the AI\_CARGO\_GROUP to and from carrier.
--
-- @field #AI_CARGO_GROUP AI_CARGO_GROUP
--
AI_CARGO_GROUP = {
ClassName = "AI_CARGO_GROUP",
}
@ -852,6 +882,14 @@ do -- AI_CARGO_GROUPED
--- @type AI_CARGO_GROUPED
-- @extends AI.AI_Cargo#AI_CARGO_GROUP
--- # AI\_CARGO\_GROUPED class
--
-- The AI\_CARGO\_GROUPED class defines a cargo that is represented by a group of UNIT objects within the simulator, and can be transported by a carrier.
-- Use the event functions as described above to Load, UnLoad, Board, UnBoard the AI\_CARGO\_UNIT objects to and from carriers.
--
-- @field #AI_CARGO_GROUPED AI_CARGO_GROUPED
--
AI_CARGO_GROUPED = {
ClassName = "AI_CARGO_GROUPED",
}

View File

@ -29,12 +29,11 @@
--
-- * **FlightControl**: Concept, Design & Programming.
--
-- @module Task_A2G
-- @module Task_CARGO
do -- TASK_CARGO
--- @type TASK_CARGO
-- @field Set#SET_UNIT TargetSetUnit
-- @extends Tasking.Task#TASK
---
@ -71,8 +70,8 @@ do -- TASK_CARGO
-- @param #string TaskType The type of Cargo task.
-- @return #TASK_CARGO self
function TASK_CARGO:New( Mission, SetGroup, TaskName, Cargo, TaskType )
local self = BASE:Inherit( self, TASK:New( Mission, SetGroup, TaskName, TaskType ) ) -- Tasking.Task#TASK_CARGO
self:F()
local self = BASE:Inherit( self, TASK:New( Mission, SetGroup, TaskName, TaskType ) ) -- #TASK_CARGO
self:F( {Mission, SetGroup, TaskName, Cargo, TaskType})
self.Cargo = Cargo
self.TaskType = TaskType
@ -92,6 +91,7 @@ do -- TASK_CARGO
Fsm:AddTransition( { "ArrivedAtCargo", "LandAtCargo" }, "Land", "Landing" )
Fsm:AddTransition( "Landing", "Landed", "Landed" )
Fsm:AddTransition( "OnGround", "PrepareBoarding", "AwaitBoarding" )
Fsm:AddTransition( "AwaitBoarding", "Board", "Boarding" )
Fsm:AddTransition( "Boarding", "Boarded", "Boarded" )
@ -120,7 +120,31 @@ do -- TASK_CARGO
function Fsm:OnAfterArriveAtCargo( TaskUnit, Task )
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
self:__Land( 0.1 )
if Task.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then
self:__Land( -0.1 )
else
self:__ArriveAtCargo( -10 )
end
end
---
-- @param #FSM_PROCESS self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @param Tasking.Task_CARGO#TASK_CARGO Task
function Fsm:OnAfterLand( TaskUnit, Task )
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
if Task.Cargo:IsInRadius( TaskUnit:GetPointVec2() ) then
if TaskUnit:InAir() then
Task:GetMission():GetCommandCenter():MessageToGroup( "Land", TaskUnit:GetGroup(), "Land" )
self:__Land( -10 )
else
Task:GetMission():GetCommandCenter():MessageToGroup( "Landed ...", TaskUnit:GetGroup(), "Land" )
self:__Landed( -0.1 )
end
else
self:__ArriveAtCargo( -0.1 )
end
end
return self
@ -138,6 +162,7 @@ do -- TASK_CARGO
-- @return #TASK_CARGO
function TASK_CARGO:SetCargoPickup( Cargo, TaskUnit )
self:F({Cargo, TaskUnit})
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteCargo = ProcessUnit:GetProcess( "RoutingToCargo", "RouteToCargoPickup" ) -- Actions.Act_Route#ACT_ROUTE_POINT

View File

@ -25,7 +25,7 @@ do
TransportHelicopters = SET_GROUP:New():FilterPrefixes( "Transport" ):FilterStart()
CargoEngineer = UNIT:FindByName( "Engineer" )
InfantryCargo = AI_CARGO_UNIT:New( CargoEngineer, "Engineer", "Engineer Sven", "81", 2000, 25 )
InfantryCargo = AI_CARGO_UNIT:New( CargoEngineer, "Engineer", "Engineer Sven", "81", 500, 25 )
Task_Cargo_Pickup = TASK_CARGO_TRANSPORT:New( Mission, TransportHelicopters, "Transport.001", InfantryCargo )