Got SEAD tasking working now with new Process Templates...

This commit is contained in:
FlightControl
2016-11-06 11:34:32 +01:00
parent 6239b6263c
commit 764266d552
17 changed files with 477 additions and 356 deletions

View File

@@ -0,0 +1,249 @@
--- (SP) (MP) (FSM) Account for (Detect, count and report) DCS events occuring on DCS objects (units).
--
-- ===
--
-- # @{#PROCESS_ACCOUNT} FSM class, extends @{Process#PROCESS}
--
-- ## PROCESS_ACCOUNT state machine:
--
-- This class is a state machine: it manages a process that is triggered by events causing state transitions to occur.
-- All derived classes from this class will start with the class name, followed by a \_. See the relevant derived class descriptions below.
-- Each derived class follows exactly the same process, using the same events and following the same state transitions,
-- but will have **different implementation behaviour** upon each event or state transition.
--
-- ### PROCESS_ACCOUNT **Events**:
--
-- These are the events defined in this class:
--
-- * **Start**: The process is started. The process will go into the Report state.
-- * **Event**: A relevant event has occured that needs to be accounted for. The process will go into the Account state.
-- * **Report**: The process is reporting to the player the accounting status of the DCS events.
-- * **More**: There are more DCS events that need to be accounted for. The process will go back into the Report state.
-- * **NoMore**: There are no more DCS events that need to be accounted for. The process will go into the Success state.
--
-- ### PROCESS_ACCOUNT **Event methods**:
--
-- Event methods are available (dynamically allocated by the state machine), that accomodate for state transitions occurring in the process.
-- There are two types of event methods, which you can use to influence the normal mechanisms in the state machine:
--
-- * **Immediate**: The event method has exactly the name of the event.
-- * **Delayed**: The event method starts with a __ + the name of the event. The first parameter of the event method is a number value, expressing the delay in seconds when the event will be executed.
--
-- ### PROCESS_ACCOUNT **States**:
--
-- * **Assigned**: The player is assigned to the task. This is the initialization state for the process.
-- * **Waiting**: the process is waiting for a DCS event to occur within the simulator. This state is set automatically.
-- * **Report**: The process is Reporting to the players in the group of the unit. This state is set automatically every 30 seconds.
-- * **Account**: The relevant DCS event has occurred, and is accounted for.
-- * **Success (*)**: All DCS events were accounted for.
-- * **Failed (*)**: The process has failed.
--
-- (*) End states of the process.
--
-- ### PROCESS_ACCOUNT 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:
--
-- * **Before** the state transition.
-- The state transition method needs to start with the name **OnBefore + 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!
--
-- * **After** the state transition.
-- The state transition method needs to start with the name **OnAfter + the name of the state**.
-- These state transition methods need to provide a return value, which is specified at the function description.
--
-- # 1) @{#PROCESS_ACCOUNT_DEADS} FSM class, extends @{Account#PROCESS_ACCOUNT}
--
-- The PROCESS_ACCOUNT_DEADS class accounts (detects, counts and reports) successful kills of DCS units.
-- The process is given a @{Set} of units that will be tracked upon successful destruction.
-- The process will end after each target has been successfully destroyed.
-- Each successful dead will trigger an Account state transition that can be scored, modified or administered.
--
--
-- ## PROCESS_ACCOUNT_DEADS constructor:
--
-- * @{#PROCESS_ACCOUNT_DEADS.New}(): Creates a new PROCESS_ACCOUNT_DEADS object.
--
-- ===
--
-- @module Account
do -- PROCESS_ACCOUNT
--- PROCESS_ACCOUNT class
-- @type PROCESS_ACCOUNT
-- @field Set#SET_UNIT TargetSetUnit
-- @extends Fsm.Process#PROCESS
PROCESS_ACCOUNT = {
ClassName = "PROCESS_ACCOUNT",
TargetSetUnit = nil,
}
--- Creates a new DESTROY process.
-- @param #PROCESS_ACCOUNT self
-- @return #PROCESS_ACCOUNT
function PROCESS_ACCOUNT:New()
local FSMT = {
initial = 'Assigned',
events = {
{ name = 'Start', from = 'Assigned', to = 'Waiting' },
{ name = 'Wait', from = '*', to = 'Waiting' },
{ name = 'Report', from = '*', to = 'Report' },
{ name = 'Event', from = '*', to = 'Account' },
{ name = 'More', from = 'Account', to = 'Wait' },
{ name = 'NoMore', from = 'Account', to = 'Success' },
{ name = 'Fail', from = '*', to = 'Failed' },
},
endstates = { 'Success', 'Failed' }
}
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( FSMT, "PROCESS_ACCOUNT" ) ) -- #PROCESS_ACCOUNT
self.DisplayInterval = 30
self.DisplayCount = 30
self.DisplayMessage = true
self.DisplayTime = 10 -- 10 seconds is the default
self.DisplayCategory = "HQ" -- Targets is the default display category
return self
end
--- Process Events
--- StateMachine callback function
-- @param #PROCESS_ACCOUNT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ACCOUNT:onafterStart( ProcessUnit, Event, From, To )
self:__Wait( 1 )
end
--- StateMachine callback function
-- @param #PROCESS_ACCOUNT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ACCOUNT:onenterWaiting( ProcessUnit, Event, From, To )
if self.DisplayCount >= self.DisplayInterval then
self:Report()
self.DisplayCount = 1
else
self.DisplayCount = self.DisplayCount + 1
end
return true -- Process always the event.
end
--- StateMachine callback function
-- @param #PROCESS_ACCOUNT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ACCOUNT:onafterEvent( ProcessUnit, Event, From, To, Event )
self:__NoMore( 1 )
end
end -- PROCESS_ACCOUNT
do -- PROCESS_ACCOUNT_DEADS
--- PROCESS_ACCOUNT_DEADS class
-- @type PROCESS_ACCOUNT_DEADS
-- @field Set#SET_UNIT TargetSetUnit
-- @extends Process#PROCESS
PROCESS_ACCOUNT_DEADS = {
ClassName = "PROCESS_ACCOUNT_DEADS",
TargetSetUnit = nil,
}
--- Creates a new DESTROY process.
-- @param #PROCESS_ACCOUNT_DEADS self
-- @param Set#SET_UNIT TargetSetUnit
-- @param #string TaskName
-- @return #PROCESS_ACCOUNT_DEADS self
function PROCESS_ACCOUNT_DEADS:New( TargetSetUnit, TaskName )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS_ACCOUNT:New() ) -- #PROCESS_ACCOUNT_DEADS
self.TargetSetUnit = TargetSetUnit
self.TaskName = TaskName
_EVENTDISPATCHER:OnDead( self.EventDead, self )
return self
end
--- Process Events
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ACCOUNT_DEADS:onenterReport( ProcessUnit, Event, From, To )
local TaskGroup = ProcessUnit:GetGroup()
MESSAGE:New( "Your group with assigned " .. self.TaskName .. " task has " .. self.TargetSetUnit:GetUnitTypesText() .. " targets left to be destroyed.", 5, "HQ" ):ToGroup( TaskGroup )
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ACCOUNT_DEADS:onenterAccount( ProcessUnit, Event, From, To, Event )
self.TargetSetUnit:Flush()
if self.TargetSetUnit:FindUnit( Event.IniUnitName ) then
self.TargetSetUnit:RemoveUnitsByName( Event.IniUnitName )
local TaskGroup = ProcessUnit:GetGroup()
MESSAGE:New( "You hit a target. Your group with assigned " .. self.TaskName .. " task has " .. self.TargetSetUnit:Count() .. " targets ( " .. self.TargetSetUnit:GetUnitTypesText() .. " ) left to be destroyed.", 15, "HQ" ):ToGroup( TaskGroup )
end
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ACCOUNT_DEADS:onafterEvent( ProcessUnit, Event, From, To, Event )
if self.TargetSetUnit:Count() > 0 then
self:__More( 1 )
else
self:__NoMore( 1 )
end
end
--- DCS Events
--- @param #PROCESS_ACCOUNT_DEADS self
-- @param Event#EVENTDATA Event
function PROCESS_ACCOUNT_DEADS:EventDead( Event )
if Event.IniDCSUnit then
self:__Event( 1 )
end
end
end -- PROCESS_ACCOUNT DEADS

View File

@@ -0,0 +1,259 @@
--- (SP) (MP) (FSM) Accept or reject process for player (task) assignments.
--
-- ===
--
-- # @{#PROCESS_ASSIGN} FSM class, extends @{Process#PROCESS}
--
-- ## PROCESS_ASSIGN state machine:
--
-- This class is a state machine: it manages a process that is triggered by events causing state transitions to occur.
-- All derived classes from this class will start with the class name, followed by a \_. See the relevant derived class descriptions below.
-- Each derived class follows exactly the same process, using the same events and following the same state transitions,
-- but will have **different implementation behaviour** upon each event or state transition.
--
-- ### PROCESS_ASSIGN **Events**:
--
-- These are the events defined in this class:
--
-- * **Start**: Start the tasking acceptance process.
-- * **Assign**: Assign the task.
-- * **Reject**: Reject the task..
--
-- ### PROCESS_ASSIGN **Event methods**:
--
-- Event methods are available (dynamically allocated by the state machine), that accomodate for state transitions occurring in the process.
-- There are two types of event methods, which you can use to influence the normal mechanisms in the state machine:
--
-- * **Immediate**: The event method has exactly the name of the event.
-- * **Delayed**: The event method starts with a __ + the name of the event. The first parameter of the event method is a number value, expressing the delay in seconds when the event will be executed.
--
-- ### PROCESS_ASSIGN **States**:
--
-- * **UnAssigned**: The player has not accepted the task.
-- * **Assigned (*)**: The player has accepted the task.
-- * **Rejected (*)**: The player has not accepted the task.
-- * **Waiting**: The process is awaiting player feedback.
-- * **Failed (*)**: The process has failed.
--
-- (*) End states of the process.
--
-- ### PROCESS_ASSIGN 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:
--
-- * **Before** the state transition.
-- The state transition method needs to start with the name **OnBefore + 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!
--
-- * **After** the state transition.
-- The state transition method needs to start with the name **OnAfter + the name of the state**.
-- These state transition methods need to provide a return value, which is specified at the function description.
--
-- ===
--
-- # 1) @{#PROCESS_ASSIGN_ACCEPT} class, extends @{Assign#PROCESS_ASSIGN}
--
-- The PROCESS_ASSIGN_ACCEPT class accepts by default a task for a player. No player intervention is allowed to reject the task.
--
-- ## 1.1) PROCESS_ASSIGN_ACCEPT constructor:
--
-- * @{#PROCESS_ASSIGN_ACCEPT.New}(): Creates a new PROCESS_ASSIGN_ACCEPT object.
--
-- ===
--
-- # 2) @{#PROCESS_ASSIGN_MENU_ACCEPT} class, extends @{Assign#PROCESS_ASSIGN}
--
-- The PROCESS_ASSIGN_MENU_ACCEPT class accepts a task when the player accepts the task through an added menu option.
-- This assignment type is useful to conditionally allow the player to choose whether or not he would accept the task.
-- The assignment type also allows to reject the task.
--
-- ## 2.1) PROCESS_ASSIGN_MENU_ACCEPT constructor:
-- -----------------------------------------
--
-- * @{#PROCESS_ASSIGN_MENU_ACCEPT.New}(): Creates a new PROCESS_ASSIGN_MENU_ACCEPT object.
--
-- ===
--
-- @module Assign
do -- PROCESS_ASSIGN
--- PROCESS_ASSIGN class
-- @type PROCESS_ASSIGN
-- @field Task#TASK_BASE Task
-- @field Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Fsm.Process#PROCESS
PROCESS_ASSIGN = {
ClassName = "PROCESS_ASSIGN",
}
--- Creates a new task assignment state machine. The process will accept the task by default, no player intervention accepted.
-- @param #PROCESS_ASSIGN self
-- @return #PROCESS_ASSIGN The task acceptance process.
function PROCESS_ASSIGN:New()
local FSMT = {
initial = 'UnAssigned',
events = {
{ name = 'Start', from = 'UnAssigned', to = 'Waiting' },
{ name = 'Assign', from = 'Waiting', to = 'Assigned' },
{ name = 'Reject', from = 'Waiting', to = 'Rejected' },
{ name = 'Fail', from = '*', to = 'Failed' },
},
endstates = {
'Assigned', 'Rejected', 'Failed'
},
}
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( FSMT, "PROCESS_ASSIGN" ) ) -- #PROCESS_ASSIGN
return self
end
end -- PROCESS_ASSIGN
do -- PROCESS_ASSIGN_ACCEPT
--- PROCESS_ASSIGN_ACCEPT class
-- @type PROCESS_ASSIGN_ACCEPT
-- @field Task#TASK_BASE Task
-- @field Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Process#PROCESS
PROCESS_ASSIGN_ACCEPT = {
ClassName = "PROCESS_ASSIGN_ACCEPT",
}
--- Creates a new task assignment state machine. The process will accept the task by default, no player intervention accepted.
-- @param #PROCESS_ASSIGN_ACCEPT self
-- @param #string TaskBriefing
-- @return #PROCESS_ASSIGN_ACCEPT The task acceptance process.
function PROCESS_ASSIGN_ACCEPT:New( TaskBriefing )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS_ASSIGN:New() ) -- #PROCESS_ASSIGN_ACCEPT
self.TaskBriefing = TaskBriefing
return self
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_ACCEPT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_ACCEPT:onafterStart( ProcessUnit, Event, From, To )
self:E( { ProcessUnit, Event, From, To } )
MESSAGE:New( self.TaskBriefing, 30, "Task Assignment" ):ToGroup( ProcessUnit:GetGroup() )
self:__Assign( 1 )
end
end -- PROCESS_ASSIGN_ACCEPT
do -- PROCESS_ASSIGN_MENU_ACCEPT
--- PROCESS_ASSIGN_MENU_ACCEPT class
-- @type PROCESS_ASSIGN_MENU_ACCEPT
-- @field Task#TASK_BASE Task
-- @field Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends #PROCESS_ASSIGN
PROCESS_ASSIGN_MENU_ACCEPT = {
ClassName = "PROCESS_ASSIGN_MENU_ACCEPT",
}
--- Creates a new task assignment state machine. The process will request from the menu if it accepts the task, if not, the unit is removed from the simulator.
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param #string TaskName
-- @param #string TaskBriefing
-- @return #PROCESS_ASSIGN_MENU_ACCEPT self
function PROCESS_ASSIGN_MENU_ACCEPT:New( TaskName, TaskBriefing )
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS_ASSIGN:New() ) -- #PROCESS_ASSIGN_MENU_ACCEPT
self.TaskBriefing = TaskBriefing
self.TaskName = TaskName
return self
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_MENU_ACCEPT:onafterStart( ProcessUnit, Event, From, To )
self:E( { ProcessUnit, Event, From, To } )
MESSAGE:New( self.TaskBriefing .. "\nAccess the radio menu to accept the task. You have 30 seconds or the assignment will be cancelled.", 30, "Task Assignment" ):ToGroup( ProcessUnit:GetGroup() )
local ProcessGroup = ProcessUnit:GetGroup()
self.Menu = MENU_GROUP:New( ProcessGroup, "Task " .. self.TaskName .. " acceptance" )
self.MenuAcceptTask = MENU_GROUP_COMMAND:New( ProcessGroup, "Accept task " .. self.TaskName, self.Menu, self.MenuAssign, self )
self.MenuRejectTask = MENU_GROUP_COMMAND:New( ProcessGroup, "Reject task " .. self.TaskName, self.Menu, self.MenuReject, self )
end
--- Menu function.
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
function PROCESS_ASSIGN_MENU_ACCEPT:MenuAssign()
self:E( )
self:__Assign( 1 )
end
--- Menu function.
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
function PROCESS_ASSIGN_MENU_ACCEPT:MenuReject()
self:E( )
self:__Reject( 1 )
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_MENU_ACCEPT:onafterAssign( ProcessUnit, Event, From, To )
self:E( { ProcessUnit.UnitNameEvent, From, To } )
self.Menu:Remove()
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_MENU_ACCEPT:onafterReject( ProcessUnit, Event, From, To )
self:E( { ProcessUnit.UnitName, Event, From, To } )
self.Menu:Remove()
--TODO: need to resolve this problem ... it has to do with the events ...
--self.Task:UnAssignFromUnit( ProcessUnit )needs to become a callback funtion call upon the event
ProcessUnit:Destroy()
end
end -- PROCESS_ASSIGN_MENU_ACCEPT

View File

@@ -0,0 +1,233 @@
--- (SP) (MP) (FSM) Route AI or players through waypoints or to zones.
--
-- ===
--
-- # @{#PROCESS_ROUTE} FSM class, extends @{Process#PROCESS}
--
-- ## PROCESS_ROUTE state machine:
--
-- This class is a state machine: it manages a process that is triggered by events causing state transitions to occur.
-- All derived classes from this class will start with the class name, followed by a \_. See the relevant derived class descriptions below.
-- Each derived class follows exactly the same process, using the same events and following the same state transitions,
-- but will have **different implementation behaviour** upon each event or state transition.
--
-- ### PROCESS_ROUTE **Events**:
--
-- These are the events defined in this class:
--
-- * **Start**: The process is started. The process will go into the Report state.
-- * **Report**: The process is reporting to the player the route to be followed.
-- * **Route**: The process is routing the controllable.
-- * **Pause**: The process is pausing the route of the controllable.
-- * **Arrive**: The controllable has arrived at a route point.
-- * **More**: There are more route points that need to be followed. The process will go back into the Report state.
-- * **NoMore**: There are no more route points that need to be followed. The process will go into the Success state.
--
-- ### PROCESS_ROUTE **Event methods**:
--
-- Event methods are available (dynamically allocated by the state machine), that accomodate for state transitions occurring in the process.
-- There are two types of event methods, which you can use to influence the normal mechanisms in the state machine:
--
-- * **Immediate**: The event method has exactly the name of the event.
-- * **Delayed**: The event method starts with a __ + the name of the event. The first parameter of the event method is a number value, expressing the delay in seconds when the event will be executed.
--
-- ### PROCESS_ROUTE **States**:
--
-- * **None**: The controllable did not receive route commands.
-- * **Arrived (*)**: The controllable has arrived at a route point.
-- * **Aborted (*)**: The controllable has aborted the route path.
-- * **Routing**: The controllable is understay to the route point.
-- * **Pausing**: The process is pausing the routing. AI air will go into hover, AI ground will stop moving. Players can fly around.
-- * **Success (*)**: All route points were reached.
-- * **Failed (*)**: The process has failed.
--
-- (*) End states of the process.
--
-- ### PROCESS_ROUTE 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:
--
-- * **Before** the state transition.
-- The state transition method needs to start with the name **OnBefore + 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!
--
-- * **After** the state transition.
-- The state transition method needs to start with the name **OnAfter + the name of the state**.
-- These state transition methods need to provide a return value, which is specified at the function description.
--
-- ===
--
-- # 1) @{#PROCESS_ROUTE_ZONE} class, extends @{Route#PROCESS_ROUTE}
--
-- The PROCESS_ROUTE_ZONE class implements the core functions to route an AIR @{Controllable} player @{Unit} to a @{Zone}.
-- The player receives on perioding times messages with the coordinates of the route to follow.
-- Upon arrival at the zone, a confirmation of arrival is sent, and the process will be ended.
--
-- # 1.1) PROCESS_ROUTE_ZONE constructor:
--
-- * @{#PROCESS_ROUTE_ZONE.New}(): Creates a new PROCESS_ROUTE_ZONE object.
--
-- ===
--
-- @module Route
do -- PROCESS_ROUTE
--- PROCESS_ROUTE class
-- @type PROCESS_ROUTE
-- @field Task#TASK TASK
-- @field Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Fsm.Process#PROCESS
PROCESS_ROUTE = {
ClassName = "PROCESS_ROUTE",
}
--- Creates a new routing state machine. The process will route a CLIENT to a ZONE until the CLIENT is within that ZONE.
-- @param #PROCESS_ROUTE self
-- @return #PROCESS_ROUTE self
function PROCESS_ROUTE:New()
local FSMT = {
initial = 'None',
events = {
{ name = 'Start', from = 'None', to = 'Routing' },
{ name = 'Report', from = '*', to = 'Reporting' },
{ name = 'Route', from = '*', to = 'Routing' },
{ name = 'Pause', from = 'Routing', to = 'Pausing' },
{ name = 'Abort', from = '*', to = 'Aborted' },
{ name = 'Arrive', from = 'Routing', to = 'Arrived' },
{ name = 'Success', from = 'Arrived', to = 'Success' },
{ name = 'Fail', from = '*', to = 'Failed' },
},
endstates = {
'Arrived', 'Failed', 'Success'
},
}
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( FSMT, "PROCESS_ROUTE" ) ) -- #PROCESS_ROUTE
self.DisplayInterval = 30
self.DisplayCount = 30
self.DisplayMessage = true
self.DisplayTime = 10 -- 10 seconds is the default
self.DisplayCategory = "HQ" -- Route is the default display category
return self
end
--- Task Events
--- StateMachine callback function
-- @param #PROCESS_ROUTE self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ROUTE:onafterStart( ProcessUnit, Event, From, To )
self:__Route( 1 )
end
--- Check if the controllable has arrived.
-- @param #PROCESS_ROUTE self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @return #boolean
function PROCESS_ROUTE:HasArrived( ProcessUnit )
return false
end
--- StateMachine callback function
-- @param #PROCESS_ROUTE self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ROUTE:onafterRoute( ProcessUnit, Event, From, To )
if ProcessUnit:IsAlive() then
local HasArrived = self:HasArrived( ProcessUnit )
if self.DisplayCount >= self.DisplayInterval then
self:T( { HasArrived = HasArrived } )
if not HasArrived then
self:__Report( 1 )
end
self.DisplayCount = 1
else
self.DisplayCount = self.DisplayCount + 1
end
self:T( { DisplayCount = self.DisplayCount } )
self:__Route( 1 )
return HasArrived -- if false, then the event will not be executed...
end
return false
end
end -- PROCESS_ROUTE
do -- PROCESS_ROUTE_ZONE
--- PROCESS_ROUTE_ZONE class
-- @type PROCESS_ROUTE_ZONE
-- @field Task#TASK TASK
-- @field Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Process.Route#PROCESS_ROUTE
PROCESS_ROUTE_ZONE = {
ClassName = "PROCESS_ROUTE_ZONE",
}
--- Creates a new routing state machine. The task will route a controllable to a ZONE until the controllable is within that ZONE.
-- @param #PROCESS_ROUTE_ZONE self
-- @param Zone#ZONE_BASE TargetZone
-- @return #PROCESS_ROUTE_ZONE self
function PROCESS_ROUTE_ZONE:New( TargetZone )
local self = BASE:Inherit( self, PROCESS_ROUTE:New() ) -- #PROCESS_ROUTE_ZONE
self.TargetZone = TargetZone
return self
end
--- Method override to check if the controllable has arrived.
-- @param #PROCESS_ROUTE self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @return #boolean
function PROCESS_ROUTE_ZONE:HasArrived( ProcessUnit )
return ProcessUnit:IsInZone( self.TargetZone )
end
--- Task Events
--- StateMachine callback function
-- @param #PROCESS_ROUTE_ZONE self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ROUTE_ZONE:onenterReporting( ProcessUnit, Event, From, To )
local ZoneVec2 = self.TargetZone:GetVec2()
local ZonePointVec2 = POINT_VEC2:New( ZoneVec2.x, ZoneVec2.y )
local TaskUnitVec2 = ProcessUnit:GetVec2()
local TaskUnitPointVec2 = POINT_VEC2:New( TaskUnitVec2.x, TaskUnitVec2.y )
local RouteText = ProcessUnit:GetCallsign() .. ": Route to " .. TaskUnitPointVec2:GetBRText( ZonePointVec2 ) .. " km to target."
MESSAGE:New( RouteText, self.DisplayTime, self.DisplayCategory ):ToGroup( ProcessUnit:GetGroup() )
end
end -- PROCESS_ROUTE_ZONE

View File

@@ -0,0 +1,188 @@
--- (SP) (MP) (FSM) Route AI or players through waypoints or to zones.
--
-- ===
--
-- # @{#PROCESS_SMOKE} FSM class, extends @{Process#PROCESS}
--
-- ## PROCESS_SMOKE state machine:
--
-- This class is a state machine: it manages a process that is triggered by events causing state transitions to occur.
-- All derived classes from this class will start with the class name, followed by a \_. See the relevant derived class descriptions below.
-- Each derived class follows exactly the same process, using the same events and following the same state transitions,
-- but will have **different implementation behaviour** upon each event or state transition.
--
-- ### PROCESS_SMOKE **Events**:
--
-- These are the events defined in this class:
--
-- * **Start**: The process is started.
-- * **Next**: The process is smoking the targets in the given zone.
--
-- ### PROCESS_SMOKE **Event methods**:
--
-- Event methods are available (dynamically allocated by the state machine), that accomodate for state transitions occurring in the process.
-- There are two types of event methods, which you can use to influence the normal mechanisms in the state machine:
--
-- * **Immediate**: The event method has exactly the name of the event.
-- * **Delayed**: The event method starts with a __ + the name of the event. The first parameter of the event method is a number value, expressing the delay in seconds when the event will be executed.
--
-- ### PROCESS_SMOKE **States**:
--
-- * **None**: The controllable did not receive route commands.
-- * **AwaitSmoke (*)**: The process is awaiting to smoke the targets in the zone.
-- * **Smoking (*)**: The process is smoking the targets in the zone.
-- * **Failed (*)**: The process has failed.
--
-- (*) End states of the process.
--
-- ### PROCESS_SMOKE 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:
--
-- * **Before** the state transition.
-- The state transition method needs to start with the name **OnBefore + 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!
--
-- * **After** the state transition.
-- The state transition method needs to start with the name **OnAfter + the name of the state**.
-- These state transition methods need to provide a return value, which is specified at the function description.
--
-- ===
--
-- # 1) @{#PROCESS_SMOKE_TARGETS_ZONE} class, extends @{Route#PROCESS_SMOKE}
--
-- The PROCESS_SMOKE_TARGETS_ZONE class implements the core functions to smoke targets in a @{Zone}.
-- The targets are smoked within a certain range around each target, simulating a realistic smoking behaviour.
-- At random intervals, a new target is smoked.
--
-- # 1.1) PROCESS_SMOKE_TARGETS_ZONE constructor:
--
-- * @{#PROCESS_SMOKE_TARGETS_ZONE.New}(): Creates a new PROCESS_SMOKE_TARGETS_ZONE object.
--
-- ===
--
-- @module Smoke
do -- PROCESS_SMOKE
--- PROCESS_SMOKE class
-- @type PROCESS_SMOKE
-- @extends Fsm.Process#PROCESS
PROCESS_SMOKE = {
ClassName = "PROCESS_SMOKE",
}
--- Creates a new target smoking state machine. The process will request from the menu if it accepts the task, if not, the unit is removed from the simulator.
-- @param #PROCESS_SMOKE self
-- @return #PROCESS_SMOKE
function PROCESS_SMOKE:New()
local FSMT = {
initial = 'None',
events = {
{ name = 'Start', from = 'None', to = 'AwaitSmoke' },
{ name = 'Next', from = 'AwaitSmoke', to = 'Smoking' },
{ name = 'Next', from = 'Smoking', to = 'AwaitSmoke' },
{ name = 'Stop', from = '*', to = 'Success' },
{ name = 'Fail', from = 'Smoking', to = 'Failed' },
{ name = 'Fail', from = 'AwaitSmoke', to = 'Failed' },
{ name = 'Fail', from = 'None', to = 'Failed' },
},
endstates = {
'Failed', 'Success'
},
}
-- Inherits from BASE
local self = BASE:Inherit( self, PROCESS:New( FSMT, "PROCESS_SMOKE" ) ) -- #PROCESS_SMOKE
return self
end
--- Task Events
--- StateMachine callback function
-- @param #PROCESS_SMOKE self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_SMOKE:onafterStart( ProcessUnit, Event, From, To )
local ProcessGroup = self:GetGroup()
local MissionMenu = self:GetMission():GetMissionMenu( ProcessGroup )
local function MenuSmoke( MenuParam )
self:E( MenuParam )
local self = MenuParam.self
local SmokeColor = MenuParam.SmokeColor
self.SmokeColor = SmokeColor
self:__Next( 1 )
end
self.Menu = MENU_GROUP:New( ProcessGroup, "Target acquisition", MissionMenu )
self.MenuSmokeBlue = MENU_GROUP_COMMAND:New( ProcessGroup, "Drop blue smoke on targets", self.Menu, MenuSmoke, { self = self, SmokeColor = SMOKECOLOR.Blue } )
self.MenuSmokeGreen = MENU_GROUP_COMMAND:New( ProcessGroup, "Drop green smoke on targets", self.Menu, MenuSmoke, { self = self, SmokeColor = SMOKECOLOR.Green } )
self.MenuSmokeOrange = MENU_GROUP_COMMAND:New( ProcessGroup, "Drop Orange smoke on targets", self.Menu, MenuSmoke, { self = self, SmokeColor = SMOKECOLOR.Orange } )
self.MenuSmokeRed = MENU_GROUP_COMMAND:New( ProcessGroup, "Drop Red smoke on targets", self.Menu, MenuSmoke, { self = self, SmokeColor = SMOKECOLOR.Red } )
self.MenuSmokeWhite = MENU_GROUP_COMMAND:New( ProcessGroup, "Drop White smoke on targets", self.Menu, MenuSmoke, { self = self, SmokeColor = SMOKECOLOR.White } )
end
end
do -- PROCESS_SMOKE_TARGETS_ZONE
--- PROCESS_SMOKE_TARGETS_ZONE class
-- @type PROCESS_SMOKE_TARGETS_ZONE
-- @field Set#SET_UNIT TargetSetUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends #PROCESS_SMOKE
PROCESS_SMOKE_TARGETS_ZONE = {
ClassName = "PROCESS_SMOKE_TARGETS_ZONE",
}
--- Creates a new target smoking state machine. The process will request from the menu if it accepts the task, if not, the unit is removed from the simulator.
-- @param #PROCESS_SMOKE_TARGETS_ZONE self
-- @param Set#SET_UNIT TargetSetUnit
-- @param Zone#ZONE_BASE TargetZone
-- @return #PROCESS_SMOKE_TARGETS_ZONE self
function PROCESS_SMOKE_TARGETS_ZONE:New( TargetSetUnit, TargetZone )
local self = BASE:Inherit( self, PROCESS_SMOKE:New() ) -- #PROCESS_SMOKE
self.TargetSetUnit = TargetSetUnit
self.TargetZone = TargetZone
return self
end
--- StateMachine callback function
-- @param #PROCESS_SMOKE_TARGETS_ZONE self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_SMOKE_TARGETS_ZONE:onenterSmoking( ProcessUnit, Event, From, To )
self.TargetSetUnit:ForEachUnit(
--- @param Unit#UNIT SmokeUnit
function( SmokeUnit )
if math.random( 1, ( 100 * self.TargetSetUnit:Count() ) / 4 ) <= 100 then
SCHEDULER:New( self,
function()
if SmokeUnit:IsAlive() then
SmokeUnit:Smoke( self.SmokeColor, 150 )
end
end, {}, math.random( 10, 60 )
)
end
end
)
end
end