STATEMACHINE_TEMPLATE is added to template statemachines...

It is working now, and NOW SWITCHING SLOTS of PLAYERS ALSO WORKS IN
TASKING!!!
Jippie!!!
The next thing is to debug the DETECTION_DISPATCHER...
And make STATEMACHINE_TEMPLATE now as a parameter to create new
STATEMACHINEs, instead of that ugly table construction.
The, I need to modify the New: Methods of each STATEMACHINE_PROCESS to
be initialized with a TEMPLATE... Maybe I can commit already and just
implement this later ...
This commit is contained in:
FlightControl 2016-11-30 10:40:31 +01:00
parent 54a861cc58
commit 9ab3a2f74d
12 changed files with 215 additions and 78 deletions

View File

@ -74,6 +74,8 @@ function STATEMACHINE:SetInitialState( State )
self.current = State
end
function STATEMACHINE:AddAction( From, Event, To )
local event = {}
@ -87,6 +89,8 @@ function STATEMACHINE:AddAction( From, Event, To )
end
--- Set the default @{Process} template with key ProcessName providing the ProcessClass and the process object when it is assigned to a @{Controllable} by the task.
-- @return Process#PROCESS
function STATEMACHINE:AddProcess( From, Event, Process, ReturnEvents )
@ -164,7 +168,7 @@ function STATEMACHINE._handler( self, EventName, ... )
self:E( { EventName, ... } )
local can, to = self:can( EventName )
self:E( { EventName, can, to } )
self:E( { EventName, self.current, can, to } )
local ReturnValues = nil
@ -544,3 +548,69 @@ function STATEMACHINE_SET:_call_handler( handler, params )
end
end
--- STATEMACHINE_TEMPLATE class
-- @type STATEMACHINE_TEMPLATE
-- @extends Core.Base#BASE
STATEMACHINE_TEMPLATE = {
ClassName = "STATEMACHINE_TEMPLATE",
}
--- Creates a new STATEMACHINE_TEMPLATE object.
-- @param #STATEMACHINE_TEMPLATE self
-- @return #STATEMACHINE_TEMPLATE
function STATEMACHINE_TEMPLATE:New( options )
-- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() ) -- #STATEMACHINE_TEMPLATE
self._Transitions = self.Transitions or {}
self._Processes = self.Processes or {}
return self
end
function STATEMACHINE_TEMPLATE:AddTransition( From, Event, To )
local Transition = {}
Transition.From = From
Transition.Event = Event
Transition.To = To
self._Transitions[Transition] = Transition
end
function STATEMACHINE_TEMPLATE:GetTransitions()
return self._Transitions
end
--- Set the default @{Process} template with key ProcessName providing the ProcessClass and the process object when it is assigned to a @{Controllable} by the task.
-- @return Process#PROCESS
function STATEMACHINE_TEMPLATE:AddProcess( From, Event, ProcessTemplate, ReturnEvents )
local Process = {}
Process.From = From
Process.Event = Event
Process.Process = ProcessTemplate[1]
Process.Arguments = ProcessTemplate[2]
Process.ReturnEvents = ReturnEvents
-- Make the reference table weak.
-- setmetatable( self.options.subs, { __mode = "v" } )
self._Processes[Process] = Process
return ProcessTemplate
end
function STATEMACHINE_TEMPLATE:GetProcesses()
return self._Processes
end
function STATEMACHINE_TEMPLATE:CopyCallHandler( Fsm, OnAction, Transition )
self:E( { Fsm.ClassName, OnAction, Transition } )
if OnAction and Transition and self[OnAction .. Transition] then
Fsm[OnAction .. Transition] = self[OnAction .. Transition]
end
end

View File

@ -178,7 +178,7 @@ do -- PROCESS_ACCOUNT_DEADS
-- @param Set#SET_UNIT TargetSetUnit
-- @param #string TaskName
function PROCESS_ACCOUNT_DEADS:Template( TargetSetUnit, TaskName )
return { self, arg }
return { self, { TargetSetUnit, TaskName } }
end

View File

@ -84,7 +84,7 @@ do -- PROCESS_ASSIGN
--- PROCESS_ASSIGN class
-- @type PROCESS_ASSIGN
-- @field Task#TASK_BASE Task
-- @field Tasking.Task#TASK_BASE Task
-- @field Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Fsm.Process#PROCESS
@ -128,7 +128,7 @@ do -- PROCESS_ASSIGN_ACCEPT
-- @field Task#TASK_BASE Task
-- @field Unit#UNIT ProcessUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Process#PROCESS
-- @extends Fsm.Process#PROCESS
PROCESS_ASSIGN_ACCEPT = {
ClassName = "PROCESS_ASSIGN_ACCEPT",
}
@ -159,17 +159,34 @@ do -- PROCESS_ASSIGN_ACCEPT
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_ACCEPT self
-- @param Controllable#CONTROLLABLE ProcessUnit
-- @param Wrapper.Unit#UNIT 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() )
local ProcessGroup = ProcessUnit:GetGroup()
MESSAGE:New( self.TaskBriefing, 30, ProcessUnit:GetPlayerName() .. " Task Acceptance" ):ToGroup( ProcessGroup )
self:__Assign( 1 )
end
--- StateMachine callback function
-- @param #PROCESS_ASSIGN_ACCEPT self
-- @param Wrapper.Unit#UNIT ProcessUnit
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS_ASSIGN_ACCEPT:onenterAssigned( ProcessUnit, Event, From, To )
self:E( { ProcessUnit, Event, From, To } )
local ProcessGroup = ProcessUnit:GetGroup()
MESSAGE:New( "You are assigned to the task " .. self.Task:GetName(), 30, ProcessUnit:GetPlayerName() .. ": Task Assignment" ):ToGroup( ProcessGroup )
self.Task:Assign()
end
end -- PROCESS_ASSIGN_ACCEPT
@ -185,6 +202,16 @@ do -- PROCESS_ASSIGN_MENU_ACCEPT
PROCESS_ASSIGN_MENU_ACCEPT = {
ClassName = "PROCESS_ASSIGN_MENU_ACCEPT",
}
--- Init.
-- @param #PROCESS_ASSIGN_MENU_ACCEPT self
-- @param #string TaskName
-- @param #string TaskBriefing
-- @return #PROCESS_ASSIGN_MENU_ACCEPT self
function PROCESS_ASSIGN_MENU_ACCEPT:Template( TaskName, TaskBriefing )
return { self, { TaskName, TaskBriefing } }
end
--- 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.

View File

@ -200,7 +200,7 @@ do -- PROCESS_ROUTE_ZONE
-- @param #PROCESS_ROUTE_ZONE self
-- @param Zone#ZONE_BASE TargetZone
function PROCESS_ROUTE_ZONE:Template( TargetZone )
return { self, arg }
return { self, { TargetZone } }
end

View File

@ -156,7 +156,7 @@ do -- PROCESS_SMOKE_TARGETS_ZONE
-- @param Set#SET_UNIT TargetSetUnit
-- @param Zone#ZONE_BASE TargetZone
function PROCESS_SMOKE_TARGETS_ZONE:Template( TargetSetUnit, TargetZone )
return { self, arg }
return { self, { TargetSetUnit, TargetZone } }
end
--- 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.

View File

@ -69,12 +69,12 @@ function COMMANDCENTER:New( CommandCenterPositionable, CommandCenterName )
self:EventOnBirth(
--- @param Core.Event#EVENTDATA EventData
function( HQ, EventData )
function( self, EventData )
self:E( { EventData } )
local EventGroup = GROUP:Find( EventData.IniDCSGroup )
if EventGroup and HQ:HasGroup( EventGroup ) then
if EventGroup and self:HasGroup( EventGroup ) then
local MenuReporting = MENU_GROUP:New( EventGroup, "Reporting", self.CommandCenterMenu )
local MenuMissions = MENU_GROUP_COMMAND:New( EventGroup, "Missions", MenuReporting, HQ.ReportMissions, HQ, EventGroup )
local MenuMissions = MENU_GROUP_COMMAND:New( EventGroup, "Missions", MenuReporting, self.ReportMissions, self, EventGroup )
end
end
)

View File

@ -53,8 +53,8 @@
-- @type TASK_BASE
-- @field Scheduler#SCHEDULER TaskScheduler
-- @field Mission#MISSION Mission
-- @field Core.StateMachine#STATEMACHINE_PROCESS FsmTemplate
-- @field Set#SET_GROUP SetGroup The Set of Groups assigned to the Task
-- @field Core.Set#SET_GROUP SetGroup The Set of Groups assigned to the Task
-- @field Core.StateMachine#STATEMACHINE_TEMPLATE FsmTemplate
-- @extends Core.StateMachine#STATEMACHINE_TASK
TASK_BASE = {
ClassName = "TASK_BASE",
@ -98,13 +98,35 @@ function TASK_BASE:New( Mission, SetGroupAssign, TaskName, TaskType )
self:SetID( Mission:GetNextTaskID( self ) ) -- The Mission orchestrates the task sequences ..
self.TaskBriefing = "You are invited for the task: " .. self.TaskName .. "."
self.FsmTemplate = self.FsmTemplate or STATEMACHINE_TEMPLATE:New( {} )
self.FsmTemplate = self.FsmTemplate or STATEMACHINE_PROCESS:New( {} )
self.FsmTemplate:SetTask( self )
-- Handle the birth of new planes within the assigned set.
self:EventOnPlayerEnterUnit(
--- @param #TASK_BASE self
-- @param Core.Event#EVENTDATA EventData
function( self, EventData )
self:E( "In EnterUnit" )
self:E( { "State", self:GetState() } )
if self:IsStateAssigned() then
local TaskUnit = EventData.IniUnit
local TaskGroup = EventData.IniUnit:GetGroup()
self:E( self.SetGroup:IsIncludeObject( TaskGroup ) )
if self.SetGroup:IsIncludeObject( TaskGroup ) then
self:AssignToUnit( TaskUnit )
end
end
end
)
return self
end
function TASK_BASE:GetFsmTemplate()
return self.FsmTemplate
end
function TASK_BASE:GetMission()
return self.Mission
@ -117,10 +139,7 @@ function TASK_BASE:GetGroups()
return self.SetGroup
end
function TASK_BASE:GetFsmTemplate()
return self.FsmTemplate
end
--- Assign the @{Task}to a @{Group}.
-- @param #TASK_BASE self
@ -166,18 +185,30 @@ end
function TASK_BASE:AssignToUnit( TaskUnit )
self:F( TaskUnit:GetName() )
-- Copy the FsmTemplate, which is not assigned to a Unit.
-- Assign the FsmTemplate to the TaskUnit.
local FsmTemplate = self:GetFsmTemplate()
local FsmUnit = UTILS.DeepCopy( FsmTemplate ) -- Core.StateMachine#STATEMACHINE_PROCESS
-- Assign a new FsmUnit to TaskUnit.
local FsmUnit = self:SetStateMachine( TaskUnit, STATEMACHINE_PROCESS:New() ) -- Core.StateMachine#STATEMACHINE_PROCESS
self:E({"Address FsmUnit", tostring( FsmUnit ) } )
FsmUnit:Assign( self, TaskUnit )
-- Assign each FsmSub in FsmUnit to the TaskUnit.
-- (This is not done during the copy).
self:E(FsmUnit:GetSubs())
for FsmSubID, FsmSub in pairs( FsmUnit:GetSubs() ) do
self:E( { "Sub ID", FsmSub.fsm:GetClassNameAndID(), FsmSubID } )
FsmSub.fsm:Assign( self, TaskUnit )
for TransitionID, Transition in pairs( self.FsmTemplate:GetTransitions() ) do
FsmUnit:AddAction( Transition.From, Transition.Event, Transition.To )
self.FsmTemplate:CopyCallHandler( FsmUnit, "onenter", Transition.From )
self.FsmTemplate:CopyCallHandler( FsmUnit, "onleave", Transition.From )
self.FsmTemplate:CopyCallHandler( FsmUnit, "onenter", Transition.To )
self.FsmTemplate:CopyCallHandler( FsmUnit, "onleave", Transition.To )
self.FsmTemplate:CopyCallHandler( FsmUnit, "onbefore", Transition.Event )
self.FsmTemplate:CopyCallHandler( FsmUnit, "onafter", Transition.Event )
end
for ProcessID, Process in pairs( self.FsmTemplate:GetProcesses() ) do
self:E( Process )
local FsmProcess = FsmUnit:AddProcess(Process.From, Process.Event, Process.Process:New( unpack( Process.Arguments ) ), Process.ReturnEvents )
self.FsmTemplate:CopyCallHandler( FsmProcess, "onenter", Process.From )
self.FsmTemplate:CopyCallHandler( FsmProcess, "onleave", Process.From )
self.FsmTemplate:CopyCallHandler( FsmProcess, "onbefore", Process.Event )
self.FsmTemplate:CopyCallHandler( FsmProcess, "onafter", Process.Event )
FsmProcess:Assign( self, TaskUnit )
end
-- Set the events
@ -190,8 +221,6 @@ function TASK_BASE:AssignToUnit( TaskUnit )
FsmUnit:SetInitialState( "Planned" )
FsmUnit:Accept() -- Each Task needs to start with an Accept event to start the flow.
return self
end
@ -265,18 +294,14 @@ end
--- Set the menu options of the @{Task} to all the groups in the SetGroup.
-- @param #TASK_BASE self
-- @return #TASK_BASE self
function TASK_BASE:SetMenu()
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
if not self:IsAssignedToGroup( TaskGroup ) then
self:SetPlannedMenuForGroup( TaskGroup, self:GetTaskName() )
else
self:SetAssignedMenuForGroup( TaskGroup )
end
self:SetMenuForGroup( TaskGroup )
end
end
--- Remove the menu options of the @{Task} to all the groups in the SetGroup.
-- @param #TASK_BASE self
-- @return #TASK_BASE self
@ -288,6 +313,17 @@ function TASK_BASE:RemoveMenu()
end
--- Set the Menu for a Group
-- @param #TASK_BASE self
function TASK_BASE:SetMenuForGroup( TaskGroup )
if not self:IsAssignedToGroup( TaskGroup ) then
self:SetPlannedMenuForGroup( TaskGroup, self:GetTaskName() )
else
self:SetAssignedMenuForGroup( TaskGroup )
end
end
--- Set the planned menu option of the @{Task}.
-- @param #TASK_BASE self
@ -718,6 +754,7 @@ function TASK_BASE:onenterAssigned( Event, From, To )
self:E("Assigned")
end

View File

@ -113,11 +113,11 @@ UTILS.OneLineSerialize = function( tbl ) -- serialization of a table all on a s
tbl_str[#tbl_str + 1] = table.concat(val_str)
end
elseif type(val) == 'function' then
-- tbl_str[#tbl_str + 1] = "function " .. tostring(ind)
-- tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
tbl_str[#tbl_str + 1] = "f() " .. tostring(ind)
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
else
-- env.info('unable to serialize value type ' .. routines.utils.basicSerialize(type(val)) .. ' at index ' .. tostring(ind))
-- env.info( debug.traceback() )
env.info('unable to serialize value type ' .. routines.utils.basicSerialize(type(val)) .. ' at index ' .. tostring(ind))
env.info( debug.traceback() )
end
end

View File

@ -1,8 +1,8 @@
--- This module contains the UNIT class.
--
-- 1) @{Unit#UNIT} class, extends @{Controllable#CONTROLLABLE}
-- 1) @{#UNIT} class, extends @{Controllable#CONTROLLABLE}
-- ===========================================================
-- The @{Unit#UNIT} class is a wrapper class to handle the DCS Unit objects:
-- The @{#UNIT} class is a wrapper class to handle the DCS Unit objects:
--
-- * Support all DCS Unit APIs.
-- * Enhance with Unit specific APIs not in the DCS Unit API set.
@ -122,7 +122,7 @@ UNIT = {
--- Create a new UNIT from DCSUnit.
-- @param #UNIT self
-- @param #string UnitName The name of the DCS unit.
-- @return Unit#UNIT
-- @return #UNIT
function UNIT:Register( UnitName )
local self = BASE:Inherit( self, CONTROLLABLE:New( UnitName ) )
self.UnitName = UnitName
@ -134,7 +134,7 @@ end
--- Finds a UNIT from the _DATABASE using a DCSUnit object.
-- @param #UNIT self
-- @param DCSUnit#Unit DCSUnit An existing DCS Unit object reference.
-- @return Unit#UNIT self
-- @return #UNIT self
function UNIT:Find( DCSUnit )
local UnitName = DCSUnit:getName()
@ -145,7 +145,7 @@ end
--- Find a UNIT in the _DATABASE using the name of an existing DCS Unit.
-- @param #UNIT self
-- @param #string UnitName The Unit Name.
-- @return Unit#UNIT self
-- @return #UNIT self
function UNIT:FindByName( UnitName )
local UnitFound = _DATABASE:FindUnit( UnitName )
@ -182,7 +182,7 @@ end
-- * When the unit is alive, it will tweak the template x, y and heading coordinates of the group and the embedded units to the current units positions.
-- * Then it will respawn the re-modelled group.
--
-- @param Unit#UNIT self
-- @param #UNIT self
-- @param DCSTypes#Vec3 SpawnVec3 The position where to Spawn the new Unit at.
-- @param #number Heading The heading of the unit respawn.
function UNIT:ReSpawn( SpawnVec3, Heading )
@ -200,7 +200,7 @@ function UNIT:ReSpawn( SpawnVec3, Heading )
self:E( #SpawnGroupTemplate.units )
for UnitID, UnitData in pairs( SpawnGroup:GetUnits() ) do
local GroupUnit = UnitData -- Unit#UNIT
local GroupUnit = UnitData -- #UNIT
self:E( GroupUnit:GetName() )
if GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3()
@ -225,7 +225,7 @@ function UNIT:ReSpawn( SpawnVec3, Heading )
self:E( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } )
else
self:E( SpawnGroupTemplate.units[UnitTemplateID].name )
local GroupUnit = UNIT:FindByName( SpawnGroupTemplate.units[UnitTemplateID].name ) -- Unit#UNIT
local GroupUnit = UNIT:FindByName( SpawnGroupTemplate.units[UnitTemplateID].name ) -- #UNIT
if GroupUnit and GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3()
local GroupUnitHeading = GroupUnit:GetHeading()
@ -262,7 +262,7 @@ end
--- Returns if the unit is activated.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #boolean true if Unit is activated.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:IsActive()
@ -282,7 +282,7 @@ end
--- Returns the Unit's callsign - the localized string.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #string The Callsign of the Unit.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetCallsign()
@ -301,7 +301,7 @@ end
--- Returns name of the player that control the unit or nil if the unit is controlled by A.I.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #string Player Name
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetPlayerName()
@ -325,7 +325,7 @@ end
-- The number is the same number the unit has in ME.
-- It may not be changed during the mission.
-- If any unit in the group is destroyed, the numbers of another units will not be changed.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #number The Unit number.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetNumber()
@ -343,7 +343,7 @@ end
--- Returns the unit's group if it exist and nil otherwise.
-- @param Wrapper.Unit#UNIT self
-- @return Group#GROUP The Group of the Unit.
-- @return Wrapper.Group#GROUP The Group of the Unit.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetGroup()
self:F2( self.UnitName )
@ -364,7 +364,7 @@ end
--- Returns the prefix name of the DCS Unit. A prefix name is a part of the name before a '#'-sign.
-- DCS Units spawned with the @{SPAWN} class contain a '#'-sign to indicate the end of the (base) DCS Unit name.
-- The spawn sequence number and unit number are contained within the name after the '#' sign.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #string The name of the DCS Unit.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetPrefix()
@ -382,7 +382,7 @@ function UNIT:GetPrefix()
end
--- Returns the Unit's ammunition.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return DCSUnit#Unit.Ammo
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetAmmo()
@ -399,7 +399,7 @@ function UNIT:GetAmmo()
end
--- Returns the unit sensors.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return DCSUnit#Unit.Sensors
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetSensors()
@ -419,7 +419,7 @@ end
-- unit:hasSensors(Unit.SensorType.RADAR, Unit.RadarType.AS)
--- Returns if the unit has sensors of a certain type.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #boolean returns true if the unit has specified types of sensors. This function is more preferable than Unit.getSensors() if you don't want to get information about all the unit's sensors, and just want to check if the unit has specified types of sensors.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:HasSensors( ... )
@ -436,7 +436,7 @@ function UNIT:HasSensors( ... )
end
--- Returns if the unit is SEADable.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #boolean returns true if the unit is SEADable.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:HasSEAD()
@ -462,7 +462,7 @@ end
--
-- * First value indicates if at least one of the unit's radar(s) is on.
-- * Second value is the object of the radar's interest. Not nil only if at least one radar of the unit is tracking a target.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #boolean Indicates if at least one of the unit's radar(s) is on.
-- @return DCSObject#Object The object of the radar's interest. Not nil only if at least one radar of the unit is tracking a target.
-- @return #nil The DCS Unit is not existing or alive.
@ -480,7 +480,7 @@ function UNIT:GetRadar()
end
--- Returns relative amount of fuel (from 0.0 to 1.0) the unit has in its internal tanks. If there are additional fuel tanks the value may be greater than 1.0.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #number The relative amount of fuel (from 0.0 to 1.0).
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetFuel()
@ -497,7 +497,7 @@ function UNIT:GetFuel()
end
--- Returns the unit's health. Dead units has health <= 1.0.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #number The Unit's health value.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetLife()
@ -514,7 +514,7 @@ function UNIT:GetLife()
end
--- Returns the Unit's initial health.
-- @param Unit#UNIT self
-- @param #UNIT self
-- @return #number The Unit's initial health value.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetLife0()
@ -625,8 +625,8 @@ end
--- Returns true if there is an **other** DCS Unit within a radius of the current 2D point of the DCS Unit.
-- @param Unit#UNIT self
-- @param Unit#UNIT AwaitUnit The other UNIT wrapper object.
-- @param #UNIT self
-- @param #UNIT AwaitUnit The other UNIT wrapper object.
-- @param Radius The radius in meters with the DCS Unit in the centre.
-- @return true If the other DCS Unit is within the radius of the 2D point of the DCS Unit.
-- @return #nil The DCS Unit is not existing or alive.

View File

@ -61,7 +61,8 @@ local TaskSEAD = TASK_BASE:New( Mission, SEADSet, "SEAD Radars", "SEAD" ) -- Tas
-- There can be many copied FsmSEAD objects internally active within TaskSEAD, for each pilot that joined the Task one is instantiated.
-- The reason why this is done, is that each unit as a role within the Task, and can have different status.
-- Therefore, the FsmSEAD is a TEMPLATE PROCESS of the TASK, and must be designed as a UNIT with a player is executing that PROCESS.
local FsmSEAD = TaskSEAD:GetFsmTemplate()
local FsmSEADTemplate = TaskSEAD:GetFsmTemplate()
-- Adding a new sub-process to the Task Template.
-- At first, the task needs to be accepted by a pilot.
@ -74,10 +75,10 @@ local FsmSEAD = TaskSEAD:GetFsmTemplate()
-- 4.1 When the return state is Assigned, fire the event in the Task FsmSEAD:Route()
-- 4.2 When the return state is Rejected, fire the event in the Task FsmSEAD:Eject()
-- All other AddProcess calls are working in a similar manner.
FsmSEAD:AddProcess( "Planned", "Accept", PROCESS_ASSIGN_ACCEPT:New( "SEAD the Area" ), { Assigned = "Route", Rejected = "Eject" } )
FsmSEADTemplate:AddProcess ( "Planned", "Accept", PROCESS_ASSIGN_ACCEPT:Template( "SEAD the Area" ), { Assigned = "Route", Rejected = "Eject" } )
-- Same, adding a process.
FsmSEAD:AddProcess( "Assigned", "Route", PROCESS_ROUTE_ZONE:New( TargetZone, 3000 ), { Arrived = "Update" } )
FsmSEADTemplate:AddProcess ( "Assigned", "Route", PROCESS_ROUTE_ZONE:Template( TargetZone, 3000 ), { Arrived = "Update" } )
-- Adding a new Action...
-- Actions define also the flow of the Task, but the actions will need to be programmed within your script.
@ -86,22 +87,24 @@ FsmSEAD:AddProcess( "Assigned", "Route", PROCESS_ROUTE_ZONE:New( TargetZone
-- 1. State From "Rejected". When the FsmSEAD is in state "Rejected", the event "Eject" can be fired.
-- 2. Event "Eject". This event can be triggered synchronously through FsmSEAD:Eject() or asynchronously through FsmSEAD:__Eject(secs).
-- 3. State To "Planned". After the event has been fired, the FsmSEAD will transition to Planned.
FsmSEAD:AddAction ( "Rejected", "Eject", "Planned" )
FsmSEAD:AddAction ( "Arrived", "Update", "Updated" )
FsmSEAD:AddProcess( "Updated", "Account", PROCESS_ACCOUNT_DEADS:New( TargetSet, "SEAD" ), { Accounted = "Success" } )
FsmSEAD:AddProcess( "Updated", "Smoke", PROCESS_SMOKE_TARGETS_ZONE:New( TargetSet, TargetZone ) )
FsmSEAD:AddAction ( "Accounted", "Success", "Success" )
FsmSEAD:AddAction ( "*", "Fail", "Failed" )
FsmSEADTemplate:AddTransition ( "Rejected", "Eject", "Planned" )
FsmSEADTemplate:AddTransition ( "Arrived", "Update", "Updated" )
FsmSEADTemplate:AddProcess ( "Updated", "Account", PROCESS_ACCOUNT_DEADS:Template( TargetSet, "SEAD" ), { Accounted = "Success" } )
FsmSEADTemplate:AddProcess ( "Updated", "Smoke", PROCESS_SMOKE_TARGETS_ZONE:Template( TargetSet, TargetZone ) )
FsmSEADTemplate:AddTransition ( "Accounted", "Success", "Success" )
FsmSEADTemplate:AddTransition ( "*", "Fail", "Failed" )
-- Now we will set the SCORING. Scoring is set using the TaskSEAD object.
-- Scores can be set on the status of the Task, and on Process level.
TaskSEAD:AddScoreTask( "Success", "Destroyed all target radars", 250 )
TaskSEAD:AddScoreTask( "Failed", "Failed to destroy all target radars", -100 )
--FsmSEADTemplate:AddScoreTask( "Success", "Destroyed all target radars", 250 )
--FsmSEADTemplate:AddScoreTask( "Failed", "Failed to destroy all target radars", -100 )
TaskSEAD:AddScoreProcess( "Account", "Account", "destroyed a radar", 25 )
TaskSEAD:AddScoreProcess( "Account", "Failed", "failed to destroy a radar", -10 )
--TaskSEAD:AddScoreProcess( "Account", "Account", "destroyed a radar", 25 )
--TaskSEAD:AddScoreProcess( "Account", "Failed", "failed to destroy a radar", -10 )
function FsmSEAD:onenterUpdated( TaskUnit )
function FsmSEADTemplate:onenterUpdated( TaskUnit )
self:E( { self } )
self:Account()
self:Smoke()