Merge remote-tracking branch 'refs/remotes/origin/master' into Detection

# Conflicts:
#	Moose Test
Missions/Moose_Test_DETECTION/Moose_Test_DETECTION_Laser.miz
This commit is contained in:
FlightControl 2016-07-06 22:26:23 +02:00
commit bba6aa8fb6
15 changed files with 800 additions and 50138 deletions

View File

@ -47,10 +47,11 @@ Include.File( "AirbasePolice" )
Include.File( "Detection" )
Include.File( "FAC" )
Include.File( "StateMachine" )
Include.File( "Task2" )
Include.File( "TaskSead" )
Include.File( "TaskMenu" )
Include.File( "TaskRoute" )
Include.File( "Process" )
Include.File( "Process_SEAD" )
Include.File( "Process_Route" )
Include.File( "Task" )
Include.File( "Task_SEAD" )
-- The order of the declarations is important here. Don't touch it.

View File

@ -0,0 +1,71 @@
--- @module Process
--- The PROCESS class
-- @type PROCESS
-- @field Scheduler#SCHEDULER ProcessScheduler
-- @field Unit#UNIT ProcessUnit
-- @field Task#MISSION Task
-- @field StateMachine#STATEMACHINE_TASK Fsm
-- @extends Base#BASE
PROCESS = {
ClassName = "TASK",
ProcessScheduler = nil,
NextEvent = nil,
Scores = {},
}
--- Instantiates a new TASK Base. Should never be used. Interface Class.
-- @param #PROCESS self
-- @param Unit#UNIT ProcessUnit
-- @return #PROCESS self
function PROCESS:New( Task, ProcessUnit )
local self = BASE:Inherit( self, BASE:New() )
self:F()
self.ProcessUnit = ProcessUnit
self.Task = Task
return self
end
--- @param #PROCESS self
function PROCESS:NextEvent( NextEvent, ... )
self:E( NextEvent )
self.ProcessScheduler = SCHEDULER:New( self.Fsm, NextEvent, { self, self.ProcessUnit, unpack( arg ) }, 1 )
end
--- Adds a score for the PROCESS to be achieved.
-- @param #PROCESS self
-- @param #string ProcessStatus is the status of the PROCESS when the score needs to be given.
-- @param #string ScoreText is a text describing the score that is given according the status.
-- @param #number Score is a number providing the score of the status.
-- @return #PROCESS self
function PROCESS:AddScore( ProcessStatus, ScoreText, Score )
self:F2( { ProcessStatus, ScoreText, Score } )
self.Scores[ProcessStatus] = self.Scores[ProcessStatus] or {}
self.Scores[ProcessStatus].ScoreText = ScoreText
self.Scores[ProcessStatus].Score = Score
return self
end
--- StateMachine callback function for a PROCESS
-- @param #PROCESS self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function PROCESS:OnStateChange( Fsm, Event, From, To )
self:E( { Event, From, To, self.ProcessUnit.UnitName } )
if self.Scores[To] then
self.Unit:Message( "Score:" .. self.Scores[To].ScoreText .. " " .. To , 15 )
local Scoring = self.Task:GetScoring()
if Scoring then
Scoring:_AddTaskProcessScore( self.ProcessUnit, self.Task:GetName(), self.Scores[To].Score )
end
end
end

View File

@ -6,8 +6,8 @@
-- @field Unit#UNIT TaskUnit
-- @field Zone#ZONE_BASE TargetZone
-- @extends Task2#TASK2
TASK2_ROUTE_CLIENT = {
ClassName = "TASK2_ROUTE_CLIENT",
PROCESS_ROUTE = {
ClassName = "PROCESS_ROUTE",
}
@ -16,7 +16,7 @@ TASK2_ROUTE_CLIENT = {
-- @param Mission#MISSION Mission
-- @param Unit#UNIT Unit
-- @return #TASK2_ROUTE_CLIENT self
function TASK2_ROUTE_CLIENT:New( Mission, TaskUnit, TargetZone )
function PROCESS_ROUTE:New( Mission, TaskUnit, TargetZone )
-- Inherits from BASE
local self = BASE:Inherit( self, TASK2:New( Mission, TaskUnit ) ) -- #TASK2_ROUTE_CLIENT
@ -54,7 +54,7 @@ end
-- @param #string Event
-- @param #string From
-- @param #string To
function TASK2_ROUTE_CLIENT:OnLeaveUnArrived( Fsm, Event, From, To )
function PROCESS_ROUTE:OnLeaveUnArrived( Fsm, Event, From, To )
self:E( { Event, From, To, self.TaskUnit.UnitName } )
local IsInZone = self.TaskUnit:IsInZone( self.TargetZone )

View File

@ -1,28 +1,27 @@
--- @module Task_SEAD
--- @module Process_SEAD
--- TASK2_SEAD_CLIENT class
-- @type TASK2_SEAD_CLIENT
-- @field Unit#UNIT TaskUnit
--- PROCESS_SEAD class
-- @type PROCESS_SEAD
-- @field Unit#UNIT ProcessUnit
-- @field Set#SET_UNIT TargetSet
-- @field Menu#MENU_CLIENT_COMMAND MenuSEAD
-- @extends Task2#TASK2
TASK2_SEAD_CLIENT = {
ClassName = "TASK2_SEAD_CLIENT",
-- @extends Process#PROCESS
PROCESS_SEAD = {
ClassName = "PROCESS_SEAD",
Fsm = {},
TargetSet = nil,
}
--- Creates a new SEAD task.
-- @param #TASK2_SEAD_CLIENT self
-- @param Mission#MISSION Mission
-- @param Unit#UNIT TaskUnit
-- @param #PROCESS_SEAD self
-- @param Task#MISSION Task
-- @param Unit#UNIT ProcessUnit
-- @param Set#SET_UNIT TargetSet
-- @return #TASK2_SEAD_CLIENT self
function TASK2_SEAD_CLIENT:New( Mission, TaskUnit, TargetSet )
-- @return #PROCESS_SEAD self
function PROCESS_SEAD:New( Task, ProcessUnit, TargetSet )
-- Inherits from BASE
local self = BASE:Inherit( self, TASK2:New( Mission, TaskUnit ) ) -- #TASK2_SEAD_CLIENT
local self = BASE:Inherit( self, PROCESS:New( Task, ProcessUnit ) ) -- #PROCESS_SEAD
self.TargetSet = TargetSet
@ -55,31 +54,31 @@ function TASK2_SEAD_CLIENT:New( Mission, TaskUnit, TargetSet )
return self
end
--- Task Events
--- Process Events
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD_CLIENT self
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_SEAD self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function TASK2_SEAD_CLIENT:OnAwait( Fsm, Event, From, To )
self:E( { Event, From, To, self.TaskUnit.UnitName} )
function PROCESS_SEAD:OnAwait( Fsm, Event, From, To )
self:E( { Event, From, To, self.ProcessUnit.UnitName} )
self.TaskUnit:Message( "Waiting", 15 )
self.ProcessUnit:Message( "Waiting", 15 )
self:NextEvent( Fsm.Await )
end
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD_CLIENT self
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_SEAD self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Event#EVENTDATA Event
function TASK2_SEAD_CLIENT:OnHitTarget( Fsm, Event, From, To, Event )
function PROCESS_SEAD:OnHitTarget( Fsm, Event, From, To, Event )
self.TaskUnit:Message( "Hit Target", 15 )
self.ProcessUnit:Message( "Hit Target", 15 )
if self.TargetSet:Count() > 0 then
self:NextEvent( Fsm.MoreTargets )
else
@ -87,74 +86,74 @@ function TASK2_SEAD_CLIENT:OnHitTarget( Fsm, Event, From, To, Event )
end
end
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD_CLIENT self
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_SEAD self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function TASK2_SEAD_CLIENT:OnMoreTargets( Fsm, Event, From, To )
function PROCESS_SEAD:OnMoreTargets( Fsm, Event, From, To )
self.TaskUnit:Message( "More Targets", 15 )
self.ProcessUnit:Message( "More Targets", 15 )
end
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD_CLIENT self
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_SEAD self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Event#EVENTDATA DCSEvent
function TASK2_SEAD_CLIENT:OnKilled( Fsm, Event, From, To )
function PROCESS_SEAD:OnKilled( Fsm, Event, From, To )
self.TaskUnit:Message( "Player got killed", 15 )
self.ProcessUnit:Message( "Player got killed", 15 )
self:NextEvent( Fsm.Restart )
end
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD_CLIENT self
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_SEAD self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function TASK2_SEAD_CLIENT:OnRestart( Fsm, Event, From, To )
function PROCESS_SEAD:OnRestart( Fsm, Event, From, To )
self.TaskUnit:Message( "Restart SEAD Task", 15 )
self.ProcessUnit:Message( "Restart SEAD Process", 15 )
self:NextEvent( Fsm.Menu )
end
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD_CLIENT self
--- StateMachine callback function for a PROCESS
-- @param #PROCESS_SEAD self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function TASK2_SEAD_CLIENT:OnDestroyed( Fsm, Event, From, To )
function PROCESS_SEAD:OnDestroyed( Fsm, Event, From, To )
self.TaskUnit:Message( "Destroyed", 15 )
self.ProcessUnit:Message( "Destroyed", 15 )
end
--- DCS Events
--- @param #TASK2_SEAD_CLIENT self
--- @param #PROCESS_SEAD self
-- @param Event#EVENTDATA Event
function TASK2_SEAD_CLIENT:EventHit( Event )
function PROCESS_SEAD:EventHit( Event )
if Event.IniUnit then
self:NextEvent( self.Fsm.HitTarget, Event )
end
end
--- @param #TASK2_SEAD_CLIENT self
--- @param #PROCESS_SEAD self
-- @param Event#EVENTDATA Event
function TASK2_SEAD_CLIENT:EventKilled( Event )
function PROCESS_SEAD:EventKilled( Event )
if Event.IniUnit then
if Event.IniUnitName == self.TaskUnit.UnitName then
if Event.IniUnitName == self.ProcessUnit.UnitName then
self:NextEvent( self.Fsm.Killed, Event )
end
end

View File

@ -202,34 +202,33 @@ function STATEMACHINE:todot(filename)
dotfile:close()
end
--- STATEMACHINE_TASK class
-- @type STATEMACHINE_TASK
-- @field Task2#TASK2 Task
--- STATEMACHINE_PROCESS class
-- @type STATEMACHINE_PROCESS
-- @field Process#PROCESS Process
-- @extends StateMachine#STATEMACHINE
STATEMACHINE_TASK = {
ClassName = "STATEMACHINE_TASK",
STATEMACHINE_PROCESS = {
ClassName = "STATEMACHINE_PROCESS",
}
--- Creates a new STATEMACHINE_TASK object.
-- @param #STATEMACHINE_TASK self
-- @return #STATEMACHINE_TASK
function STATEMACHINE_TASK:New( Task, options )
--- Creates a new STATEMACHINE_PROCESS object.
-- @param #STATEMACHINE_PROCESS self
-- @return #STATEMACHINE_PROCESS
function STATEMACHINE_PROCESS:New( Process, options )
local FsmT = routines.utils.deepCopy( self ) -- Create a new self instance
local FsmProcess = routines.utils.deepCopy( self ) -- Create a new self instance
local Parent = STATEMACHINE:New(options)
setmetatable( FsmT, Parent )
FsmT.__index = FsmT
setmetatable( FsmProcess, Parent )
FsmProcess.__index = FsmProcess
env.info(tostring(Task.OnStateChange))
FsmT["onstatechange"] = Task.OnStateChange
FsmT.Task = Task
FsmProcess["onstatechange"] = Process.OnStateChange
FsmProcess.Process = Process
return FsmT
return FsmProcess
end
function STATEMACHINE_TASK:_call_handler( handler, params )
function STATEMACHINE_PROCESS:_call_handler( handler, params )
if handler then
return handler( self.Task, unpack( params ) )
return handler( self.Process, unpack( params ) )
end
end

View File

@ -1,459 +1,120 @@
--- The TASK Classes define major end-to-end activities within a MISSION. The TASK Class is the Master Class to orchestrate these activities. From this class, many concrete TASK classes are inherited.
-- @module TASK
--- @module Task
--- The TASK class
-- @type TASK
--- The TASK_BASE class
-- @type TASK_BASE
-- @field Scheduler#SCHEDULER TaskScheduler
-- @field Mission#MISSION Mission
-- @field StateMachine#STATEMACHINE Fsm
-- @extends Base#BASE
TASK = {
-- Defines the different signal types with a Task.
SIGNAL = {
COLOR = {
RED = { ID = 1, COLOR = trigger.smokeColor.Red, TEXT = "A red" },
GREEN = { ID = 2, COLOR = trigger.smokeColor.Green, TEXT = "A green" },
BLUE = { ID = 3, COLOR = trigger.smokeColor.Blue, TEXT = "A blue" },
WHITE = { ID = 4, COLOR = trigger.smokeColor.White, TEXT = "A white" },
ORANGE = { ID = 5, COLOR = trigger.smokeColor.Orange, TEXT = "An orange" }
},
TYPE = {
SMOKE = { ID = 1, TEXT = "smoke" },
FLARE = { ID = 2, TEXT = "flare" }
}
},
ClassName = "TASK",
Mission = {}, -- Owning mission of the Task
Name = '',
Stages = {},
Stage = {},
Cargos = {
InitCargos = {},
LoadCargos = {}
},
LandingZones = {
LandingZoneNames = {},
LandingZones = {}
},
ActiveStage = 0,
TaskDone = false,
TaskFailed = false,
GoalTasks = {}
TASK_BASE = {
ClassName = "TASK_BASE",
TaskScheduler = nil,
Processes = {},
Scores = {},
}
--- Instantiates a new TASK Base. Should never be used. Interface Class.
-- @return TASK
function TASK:New()
--- Instantiates a new TASK_BASE. Should never be used. Interface Class.
-- @param #TASK_BASE self
-- @return #TASK_BASE self
function TASK_BASE:New()
local self = BASE:Inherit( self, BASE:New() )
self:F()
-- assign Task default values during construction
self.TaskBriefing = "Task: No Task."
self.Time = timer.getTime()
self.ExecuteStage = _TransportExecuteStage.NONE
self:F()
self.Processes = {}
self.Fsm = {}
return self
end
function TASK:SetStage( StageSequenceIncrement )
self:F( { StageSequenceIncrement } )
local Valid = false
if StageSequenceIncrement ~= 0 then
self.ActiveStage = self.ActiveStage + StageSequenceIncrement
if 1 <= self.ActiveStage and self.ActiveStage <= #self.Stages then
self.Stage = self.Stages[self.ActiveStage]
self:T( { self.Stage.Name } )
self.Frequency = self.Stage.Frequency
Valid = true
else
Valid = false
env.info( "TASK:SetStage() self.ActiveStage is smaller or larger than self.Stages array. self.ActiveStage = " .. self.ActiveStage )
end
end
self.Time = timer.getTime()
return Valid
--- Assign the @{Task}to a @{Group}.
-- @param #TASK_BASE self
-- @param Group#GROUP TaskGroup
-- @return #TASK_BASE self
function TASK_BASE:AssignToGroup( TaskGroup )
self:FZ( TaskGroup:GetName() )
local TaskUnits = TaskGroup:GetUnits()
for UnitID, UnitData in pairs( TaskUnits ) do
local TaskUnit = UnitData -- Unit#UNIT
local PlayerName = TaskUnit:GetPlayerName()
if PlayerName ~= nil or PlayerName ~= "" then
self:AssignToUnit( TaskUnit )
end
end
return self
end
function TASK:Init()
self:F()
self.ActiveStage = 0
self:SetStage(1)
self.TaskDone = false
self.TaskFailed = false
--- Add Process to @{Task} with key @{Unit}
-- @param #TASK_BASE self
-- @param Unit#UNIT TaskUnit
-- @return #TASK_BASE self
function TASK_BASE:AddProcess( TaskUnit, Process )
local TaskUnitName = TaskUnit:GetName()
self.Processes[TaskUnitName] = self.Processes[TaskUnitName] or {}
self.Processes[TaskUnitName][#self.Processes[TaskUnitName]+1] = Process
return Process
end
--- Remove Processes from @{Task} with key @{Unit}
-- @param #TASK_BASE self
-- @return #TASK_BASE self
function TASK_BASE:RemoveProcesses( TaskUnit )
local TaskUnitName = TaskUnit:GetName()
for _, Process in pairs( self.Processes[TaskUnitName] ) do
Process = nil
end
end
--- Add a FiniteStateMachine to @{Task} with key @{Unit}
-- @param #TASK_BASE self
-- @param Unit#UNIT TaskUnit
-- @return #TASK_BASE self
function TASK_BASE:AddStateMachine( TaskUnit, Fsm )
local TaskUnitName = TaskUnit:GetName()
self.Fsm[TaskUnitName] = self.Fsm[TaskUnitName] or {}
self.Fsm[TaskUnitName][#self.Fsm[TaskUnitName]+1] = Fsm
return Fsm
end
--- Remove FiniteStateMachines from @{Task} with key @{Unit}
-- @param #TASK_BASE self
-- @return #TASK_BASE self
function TASK_BASE:RemoveStateMachines( TaskUnit )
local TaskUnitName = TaskUnit:GetName()
for _, Fsm in pairs( self.Fsm[TaskUnitName] ) do
Fsm = nil
end
end
--- Get progress of a TASK.
-- @return string GoalsText
function TASK:GetGoalProgress()
self:F2()
local GoalsText = ""
for GoalVerb, GoalVerbData in pairs( self.GoalTasks ) do
local Goals = self:GetGoalCompletion( GoalVerb )
if Goals and Goals ~= "" then
Goals = '(' .. Goals .. ')'
else
Goals = '( - )'
end
GoalsText = GoalsText .. GoalVerb .. ': ' .. self:GetGoalCount(GoalVerb) .. ' goals ' .. Goals .. ' of ' .. self:GetGoalTotal(GoalVerb) .. ' goals completed (' .. self:GetGoalPercentage(GoalVerb) .. '%); '
end
if GoalsText == "" then
GoalsText = "( - )"
end
return GoalsText
--- Assign the @{Task}to an alive @{Unit}.
-- @param #TASK_BASE self
-- @param Unit#UNIT TaskUnit
-- @return #TASK_BASE self
function TASK_BASE:AssignToUnit( TaskUnit )
return nil
end
--- Show progress of a TASK.
-- @param MISSION Mission Group structure describing the Mission.
-- @param CLIENT Client Group structure describing the Client.
function TASK:ShowGoalProgress( Mission, Client )
self:F2()
local GoalsText = ""
for GoalVerb, GoalVerbData in pairs( self.GoalTasks ) do
if Mission:IsCompleted() then
else
local Goals = self:GetGoalCompletion( GoalVerb )
if Goals and Goals ~= "" then
else
Goals = "-"
end
GoalsText = GoalsText .. self:GetGoalProgress()
end
end
if Mission.MissionReportFlash or Mission.MissionReportShow then
Client:Message( GoalsText, 10, "Mission Command: Task Status", 30, "Task status" )
end
end
--- Sets a TASK to status Done.
function TASK:Done()
self:F2()
self.TaskDone = true
end
--- Returns if a TASK is done.
-- @return bool
function TASK:IsDone()
self:F2( self.TaskDone )
return self.TaskDone
end
--- Sets a TASK to status failed.
function TASK:Failed()
self:F()
self.TaskFailed = true
end
--- Returns if a TASk has failed.
-- @return bool
function TASK:IsFailed()
self:F2( self.TaskFailed )
return self.TaskFailed
end
function TASK:Reset( Mission, Client )
self:F2()
self.ExecuteStage = _TransportExecuteStage.NONE
end
--- Returns the Goals of a TASK
-- @return @table Goals
function TASK:GetGoals()
return self.GoalTasks
end
--- Returns if a TASK has Goal(s).
-- @param #TASK self
-- @param #string GoalVerb is the name of the Goal of the TASK.
-- @return bool
function TASK:Goal( GoalVerb )
self:F2( { GoalVerb } )
if not GoalVerb then
GoalVerb = self.GoalVerb
end
self:T2( {self.GoalTasks[GoalVerb] } )
if self.GoalTasks[GoalVerb] and self.GoalTasks[GoalVerb].GoalTotal > 0 then
return true
else
return false
end
end
--- Sets the total Goals to be achieved of the Goal Name
-- @param number GoalTotal is the number of times the GoalVerb needs to be achieved.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
function TASK:SetGoalTotal( GoalTotal, GoalVerb )
self:F2( { GoalTotal, GoalVerb } )
if not GoalVerb then
GoalVerb = self.GoalVerb
end
self.GoalTasks[GoalVerb] = {}
self.GoalTasks[GoalVerb].Goals = {}
self.GoalTasks[GoalVerb].GoalTotal = GoalTotal
self.GoalTasks[GoalVerb].GoalCount = 0
return self
end
--- Gets the total of Goals to be achieved within the TASK of the GoalVerb.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
function TASK:GetGoalTotal( GoalVerb )
self:F2( { GoalVerb } )
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb ) then
return self.GoalTasks[GoalVerb].GoalTotal
else
return 0
end
end
--- Sets the total of Goals currently achieved within the TASK of the GoalVerb.
-- @param number GoalCount is the total number of Goals achieved within the TASK.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return TASK
function TASK:SetGoalCount( GoalCount, GoalVerb )
self:F2()
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb) then
self.GoalTasks[GoalVerb].GoalCount = GoalCount
end
return self
end
--- Increments the total of Goals currently achieved within the TASK of the GoalVerb, with the given GoalCountIncrease.
-- @param number GoalCountIncrease is the number of new Goals achieved within the TASK.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return TASK
function TASK:IncreaseGoalCount( GoalCountIncrease, GoalVerb )
self:F2( { GoalCountIncrease, GoalVerb } )
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb) then
self.GoalTasks[GoalVerb].GoalCount = self.GoalTasks[GoalVerb].GoalCount + GoalCountIncrease
end
return self
end
--- Gets the total of Goals currently achieved within the TASK of the GoalVerb.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return TASK
function TASK:GetGoalCount( GoalVerb )
self:F2()
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb ) then
return self.GoalTasks[GoalVerb].GoalCount
else
return 0
end
end
--- Gets the percentage of Goals currently achieved within the TASK of the GoalVerb.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return TASK
function TASK:GetGoalPercentage( GoalVerb )
self:F2()
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb ) then
return math.floor( self:GetGoalCount( GoalVerb ) / self:GetGoalTotal( GoalVerb ) * 100 + .5 )
else
return 100
end
end
--- Returns if all the Goals of the TASK were achieved.
-- @return bool
function TASK:IsGoalReached()
--- @param #TASK_BASE self
function TASK_BASE:_Schedule()
self:F2()
local GoalReached = true
for GoalVerb, Goals in pairs( self.GoalTasks ) do
self:T2( { "GoalVerb", GoalVerb } )
if self:Goal( GoalVerb ) then
local GoalToDo = self:GetGoalTotal( GoalVerb ) - self:GetGoalCount( GoalVerb )
self:T2( "GoalToDo = " .. GoalToDo )
if GoalToDo <= 0 then
else
GoalReached = false
break
end
else
break
end
end
self:T( { GoalReached, self.GoalTasks } )
return GoalReached
self.TaskScheduler = SCHEDULER:New( self, _Scheduler, {}, 15, 15 )
return self
end
--- Adds an Additional Goal for the TASK to be achieved.
-- @param string GoalVerb is the name of the Goal of the TASK.
-- @param string GoalTask is a text describing the Goal of the TASK to be achieved.
-- @param number GoalIncrease is a number by which the Goal achievement is increasing.
function TASK:AddGoalCompletion( GoalVerb, GoalTask, GoalIncrease )
self:F2( { GoalVerb, GoalTask, GoalIncrease } )
if self:Goal( GoalVerb ) then
self.GoalTasks[GoalVerb].Goals[#self.GoalTasks[GoalVerb].Goals+1] = GoalTask
self.GoalTasks[GoalVerb].GoalCount = self.GoalTasks[GoalVerb].GoalCount + GoalIncrease
end
return self
--- @param #TASK_BASE self
function TASK_BASE._Scheduler()
self:F2()
return true
end
--- Returns if the additional Goal for the TASK was completed.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return string Goals
function TASK:GetGoalCompletion( GoalVerb )
self:F2( { GoalVerb } )
if self:Goal( GoalVerb ) then
local Goals = ""
for GoalID, GoalName in pairs( self.GoalTasks[GoalVerb].Goals ) do Goals = Goals .. GoalName .. " + " end
return Goals:gsub(" + $", ""), self.GoalTasks[GoalVerb].GoalCount
end
end
function TASK.MenuAction( Parameter )
Parameter.ReferenceTask.ExecuteStage = _TransportExecuteStage.EXECUTING
Parameter.ReferenceTask.Cargo = Parameter.CargoTask
end
function TASK:StageExecute()
self:F()
local Execute = false
if self.Frequency == STAGE.FREQUENCY.REPEAT then
Execute = true
elseif self.Frequency == STAGE.FREQUENCY.NONE then
Execute = false
elseif self.Frequency >= 0 then
Execute = true
self.Frequency = self.Frequency - 1
end
return Execute
end
--- Work function to set signal events within a TASK.
function TASK:AddSignal( SignalUnitNames, SignalType, SignalColor, SignalHeight )
self:F()
local Valid = true
if Valid then
if type( SignalUnitNames ) == "table" then
self.LandingZoneSignalUnitNames = SignalUnitNames
else
self.LandingZoneSignalUnitNames = { SignalUnitNames }
end
self.LandingZoneSignalType = SignalType
self.LandingZoneSignalColor = SignalColor
self.Signalled = false
if SignalHeight ~= nil then
self.LandingZoneSignalHeight = SignalHeight
else
self.LandingZoneSignalHeight = 0
end
if self.TaskBriefing then
self.TaskBriefing = self.TaskBriefing .. " " .. SignalColor.TEXT .. " " .. SignalType.TEXT .. " will be fired when entering the landing zone."
end
end
return Valid
end
--- When the CLIENT is approaching the landing zone, a RED SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeRed( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.RED, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a GREEN SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeGreen( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.GREEN, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a BLUE SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeBlue( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.BLUE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a WHITE SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeWhite( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.WHITE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, an ORANGE SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeOrange( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.ORANGE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a RED FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareRed( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.RED, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a GREEN FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareGreen( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.GREEN, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a BLUE FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareBlue( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.BLUE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a WHITE FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareWhite( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.WHITE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, an ORANGE FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareOrange( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.ORANGE, SignalHeight )
end

View File

@ -1,71 +0,0 @@
--- @module Task2
--- The TASK2 class
-- @type TASK2
-- @field Scheduler#SCHEDULER TaskScheduler
-- @field Unit#UNIT TaskUnit
-- @field Mission#MISSION Mission
-- @field StateMachine#STATEMACHINE_TASK Fsm
-- @extends Base#BASE
TASK2 = {
ClassName = "TASK",
TaskScheduler = nil,
NextEvent = nil,
Scores = {},
}
--- Instantiates a new TASK Base. Should never be used. Interface Class.
-- @param #TASK2 self
-- @param Unit#UNIT TaskUnit
-- @return #TASK2 self
function TASK2:New( Mission, TaskUnit )
local self = BASE:Inherit( self, BASE:New() )
self:F()
self.TaskUnit = TaskUnit
self.Mission = Mission
return self
end
--- @param #TASK2 self
function TASK2:NextEvent( NextEvent, ... )
self:E( NextEvent )
self.TaskScheduler = SCHEDULER:New( self.Fsm, NextEvent, { self, self.TaskUnit, unpack( arg ) }, 1 )
end
--- Adds a score for the TASK2 to be achieved.
-- @param #TASK2 self
-- @param #string TaskStatus is the status of the TASK2 when the score needs to be given.
-- @param #string ScoreText is a text describing the score that is given according the status.
-- @param #number Score is a number providing the score of the status.
-- @return #TASK2 self
function TASK2:AddScore( TaskStatus, ScoreText, Score )
self:F2( { TaskStatus, ScoreText, Score } )
self.Scores[TaskStatus] = self.Scores[TaskStatus] or {}
self.Scores[TaskStatus].ScoreText = ScoreText
self.Scores[TaskStatus].Score = Score
return self
end
--- StateMachine callback function for a TASK2
-- @param #TASK2 self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function TASK2:OnStateChange( Fsm, Event, From, To )
self:E( { Event, From, To, self.TaskUnit.UnitName } )
if self.Scores[To] then
self.Unit:Message( "Score:" .. self.Scores[To].ScoreText .. " " .. To , 15 )
local Scoring = self.Mission:GetScoring()
if Scoring then
Scoring:_AddMissionTaskScore( self.TaskUnit, self.Mission:GetName(), self.Scores[To].Score )
end
end
end

View File

@ -0,0 +1,74 @@
--- @module Task_SEAD
--- The TASK_SEAD class
-- @type TASK_SEAD
-- @extends Task#TASK_BASE
TASK_SEAD = {
ClassName = "TASK_SEAD",
}
--- Instantiates a new TASK_SEAD. Should never be used. Interface Class.
-- @param #TASK_SEAD self
-- @param Set#SET_UNIT UnitSetTargets
-- @return #TASK_SEAD self
function TASK_SEAD:New( TargetSetUnit, TargetZone )
local self = BASE:Inherit( self, BASE:New() )
self:F()
self.TargetSetUnit= TargetSetUnit
self.TargetZone = TargetZone
return self
end
--- Assign the @{Task} to a @{Unit}.
-- @param #TASK_SEAD self
-- @param Unit#UNIT TaskUnit
-- @return #TASK_SEAD self
function TASK_SEAD:AssignToUnit( TaskUnit )
local ProcessRoute = self:AddProcess( TaskUnit, PROCESS_ROUTE:New( self, TaskUnit, self.TargetZone ) )
local ProcessSEAD = self:AddProcess( TaskUnit, PROCESS_SEAD:New( self, TaskUnit, self.TargetUnitSet ) )
local Process = self:AddStateMachine( TaskUnit, STATEMACHINE:New( {
initial = 'None',
events = {
{ name = 'Start', from = 'None', to = 'Assigned' },
{ name = 'Next', from = 'Unassigned', to = 'Assigned' },
{ name = 'Next', from = 'Assigned', to = 'Success' },
{ name = 'Fail', from = 'Assigned', to = 'Failed' },
{ name = 'Fail', from = 'Arrived', to = 'Failed' }
},
subs = {
Route = { onstateparent = 'Assigned', oneventparent = 'Start', fsm = ProcessRoute.Fsm, event = 'Route' },
Sead = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = ProcessSEAD.Fsm, event = 'Await', returnevents = { 'Next' } }
}
} ) )
---Task_Client_Sead:AddScore( "Destroy", "Destroyed RADAR", 25 )
---Task_Client_Sead:AddScore( "Success", "Destroyed all radars!!!", 100 )
Process:Start()
return self
end
--- @param #TASK_SEAD self
function TASK_SEAD:_Schedule()
self:F2()
self.TaskScheduler = SCHEDULER:New( self, _Scheduler, {}, 15, 15 )
return self
end
--- @param #TASK_SEAD self
function TASK_SEAD._Scheduler()
self:F2()
return true
end

View File

@ -0,0 +1,459 @@
--- The TASK Classes define major end-to-end activities within a MISSION. The TASK Class is the Master Class to orchestrate these activities. From this class, many concrete TASK classes are inherited.
-- @module TASK
--- The TASK class
-- @type TASK
-- @extends Base#BASE
TASK = {
-- Defines the different signal types with a Task.
SIGNAL = {
COLOR = {
RED = { ID = 1, COLOR = trigger.smokeColor.Red, TEXT = "A red" },
GREEN = { ID = 2, COLOR = trigger.smokeColor.Green, TEXT = "A green" },
BLUE = { ID = 3, COLOR = trigger.smokeColor.Blue, TEXT = "A blue" },
WHITE = { ID = 4, COLOR = trigger.smokeColor.White, TEXT = "A white" },
ORANGE = { ID = 5, COLOR = trigger.smokeColor.Orange, TEXT = "An orange" }
},
TYPE = {
SMOKE = { ID = 1, TEXT = "smoke" },
FLARE = { ID = 2, TEXT = "flare" }
}
},
ClassName = "TASK",
Mission = {}, -- Owning mission of the Task
Name = '',
Stages = {},
Stage = {},
Cargos = {
InitCargos = {},
LoadCargos = {}
},
LandingZones = {
LandingZoneNames = {},
LandingZones = {}
},
ActiveStage = 0,
TaskDone = false,
TaskFailed = false,
GoalTasks = {}
}
--- Instantiates a new TASK Base. Should never be used. Interface Class.
-- @return TASK
function TASK:New()
local self = BASE:Inherit( self, BASE:New() )
self:F()
-- assign Task default values during construction
self.TaskBriefing = "Task: No Task."
self.Time = timer.getTime()
self.ExecuteStage = _TransportExecuteStage.NONE
return self
end
function TASK:SetStage( StageSequenceIncrement )
self:F( { StageSequenceIncrement } )
local Valid = false
if StageSequenceIncrement ~= 0 then
self.ActiveStage = self.ActiveStage + StageSequenceIncrement
if 1 <= self.ActiveStage and self.ActiveStage <= #self.Stages then
self.Stage = self.Stages[self.ActiveStage]
self:T( { self.Stage.Name } )
self.Frequency = self.Stage.Frequency
Valid = true
else
Valid = false
env.info( "TASK:SetStage() self.ActiveStage is smaller or larger than self.Stages array. self.ActiveStage = " .. self.ActiveStage )
end
end
self.Time = timer.getTime()
return Valid
end
function TASK:Init()
self:F()
self.ActiveStage = 0
self:SetStage(1)
self.TaskDone = false
self.TaskFailed = false
end
--- Get progress of a TASK.
-- @return string GoalsText
function TASK:GetGoalProgress()
self:F2()
local GoalsText = ""
for GoalVerb, GoalVerbData in pairs( self.GoalTasks ) do
local Goals = self:GetGoalCompletion( GoalVerb )
if Goals and Goals ~= "" then
Goals = '(' .. Goals .. ')'
else
Goals = '( - )'
end
GoalsText = GoalsText .. GoalVerb .. ': ' .. self:GetGoalCount(GoalVerb) .. ' goals ' .. Goals .. ' of ' .. self:GetGoalTotal(GoalVerb) .. ' goals completed (' .. self:GetGoalPercentage(GoalVerb) .. '%); '
end
if GoalsText == "" then
GoalsText = "( - )"
end
return GoalsText
end
--- Show progress of a TASK.
-- @param MISSION Mission Group structure describing the Mission.
-- @param CLIENT Client Group structure describing the Client.
function TASK:ShowGoalProgress( Mission, Client )
self:F2()
local GoalsText = ""
for GoalVerb, GoalVerbData in pairs( self.GoalTasks ) do
if Mission:IsCompleted() then
else
local Goals = self:GetGoalCompletion( GoalVerb )
if Goals and Goals ~= "" then
else
Goals = "-"
end
GoalsText = GoalsText .. self:GetGoalProgress()
end
end
if Mission.MissionReportFlash or Mission.MissionReportShow then
Client:Message( GoalsText, 10, "Mission Command: Task Status", 30, "Task status" )
end
end
--- Sets a TASK to status Done.
function TASK:Done()
self:F2()
self.TaskDone = true
end
--- Returns if a TASK is done.
-- @return bool
function TASK:IsDone()
self:F2( self.TaskDone )
return self.TaskDone
end
--- Sets a TASK to status failed.
function TASK:Failed()
self:F()
self.TaskFailed = true
end
--- Returns if a TASk has failed.
-- @return bool
function TASK:IsFailed()
self:F2( self.TaskFailed )
return self.TaskFailed
end
function TASK:Reset( Mission, Client )
self:F2()
self.ExecuteStage = _TransportExecuteStage.NONE
end
--- Returns the Goals of a TASK
-- @return @table Goals
function TASK:GetGoals()
return self.GoalTasks
end
--- Returns if a TASK has Goal(s).
-- @param #TASK self
-- @param #string GoalVerb is the name of the Goal of the TASK.
-- @return bool
function TASK:Goal( GoalVerb )
self:F2( { GoalVerb } )
if not GoalVerb then
GoalVerb = self.GoalVerb
end
self:T2( {self.GoalTasks[GoalVerb] } )
if self.GoalTasks[GoalVerb] and self.GoalTasks[GoalVerb].GoalTotal > 0 then
return true
else
return false
end
end
--- Sets the total Goals to be achieved of the Goal Name
-- @param number GoalTotal is the number of times the GoalVerb needs to be achieved.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
function TASK:SetGoalTotal( GoalTotal, GoalVerb )
self:F2( { GoalTotal, GoalVerb } )
if not GoalVerb then
GoalVerb = self.GoalVerb
end
self.GoalTasks[GoalVerb] = {}
self.GoalTasks[GoalVerb].Goals = {}
self.GoalTasks[GoalVerb].GoalTotal = GoalTotal
self.GoalTasks[GoalVerb].GoalCount = 0
return self
end
--- Gets the total of Goals to be achieved within the TASK of the GoalVerb.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
function TASK:GetGoalTotal( GoalVerb )
self:F2( { GoalVerb } )
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb ) then
return self.GoalTasks[GoalVerb].GoalTotal
else
return 0
end
end
--- Sets the total of Goals currently achieved within the TASK of the GoalVerb.
-- @param number GoalCount is the total number of Goals achieved within the TASK.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return TASK
function TASK:SetGoalCount( GoalCount, GoalVerb )
self:F2()
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb) then
self.GoalTasks[GoalVerb].GoalCount = GoalCount
end
return self
end
--- Increments the total of Goals currently achieved within the TASK of the GoalVerb, with the given GoalCountIncrease.
-- @param number GoalCountIncrease is the number of new Goals achieved within the TASK.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return TASK
function TASK:IncreaseGoalCount( GoalCountIncrease, GoalVerb )
self:F2( { GoalCountIncrease, GoalVerb } )
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb) then
self.GoalTasks[GoalVerb].GoalCount = self.GoalTasks[GoalVerb].GoalCount + GoalCountIncrease
end
return self
end
--- Gets the total of Goals currently achieved within the TASK of the GoalVerb.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return TASK
function TASK:GetGoalCount( GoalVerb )
self:F2()
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb ) then
return self.GoalTasks[GoalVerb].GoalCount
else
return 0
end
end
--- Gets the percentage of Goals currently achieved within the TASK of the GoalVerb.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return TASK
function TASK:GetGoalPercentage( GoalVerb )
self:F2()
if not GoalVerb then
GoalVerb = self.GoalVerb
end
if self:Goal( GoalVerb ) then
return math.floor( self:GetGoalCount( GoalVerb ) / self:GetGoalTotal( GoalVerb ) * 100 + .5 )
else
return 100
end
end
--- Returns if all the Goals of the TASK were achieved.
-- @return bool
function TASK:IsGoalReached()
self:F2()
local GoalReached = true
for GoalVerb, Goals in pairs( self.GoalTasks ) do
self:T2( { "GoalVerb", GoalVerb } )
if self:Goal( GoalVerb ) then
local GoalToDo = self:GetGoalTotal( GoalVerb ) - self:GetGoalCount( GoalVerb )
self:T2( "GoalToDo = " .. GoalToDo )
if GoalToDo <= 0 then
else
GoalReached = false
break
end
else
break
end
end
self:T( { GoalReached, self.GoalTasks } )
return GoalReached
end
--- Adds an Additional Goal for the TASK to be achieved.
-- @param string GoalVerb is the name of the Goal of the TASK.
-- @param string GoalTask is a text describing the Goal of the TASK to be achieved.
-- @param number GoalIncrease is a number by which the Goal achievement is increasing.
function TASK:AddGoalCompletion( GoalVerb, GoalTask, GoalIncrease )
self:F2( { GoalVerb, GoalTask, GoalIncrease } )
if self:Goal( GoalVerb ) then
self.GoalTasks[GoalVerb].Goals[#self.GoalTasks[GoalVerb].Goals+1] = GoalTask
self.GoalTasks[GoalVerb].GoalCount = self.GoalTasks[GoalVerb].GoalCount + GoalIncrease
end
return self
end
--- Returns if the additional Goal for the TASK was completed.
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
-- @return string Goals
function TASK:GetGoalCompletion( GoalVerb )
self:F2( { GoalVerb } )
if self:Goal( GoalVerb ) then
local Goals = ""
for GoalID, GoalName in pairs( self.GoalTasks[GoalVerb].Goals ) do Goals = Goals .. GoalName .. " + " end
return Goals:gsub(" + $", ""), self.GoalTasks[GoalVerb].GoalCount
end
end
function TASK.MenuAction( Parameter )
Parameter.ReferenceTask.ExecuteStage = _TransportExecuteStage.EXECUTING
Parameter.ReferenceTask.Cargo = Parameter.CargoTask
end
function TASK:StageExecute()
self:F()
local Execute = false
if self.Frequency == STAGE.FREQUENCY.REPEAT then
Execute = true
elseif self.Frequency == STAGE.FREQUENCY.NONE then
Execute = false
elseif self.Frequency >= 0 then
Execute = true
self.Frequency = self.Frequency - 1
end
return Execute
end
--- Work function to set signal events within a TASK.
function TASK:AddSignal( SignalUnitNames, SignalType, SignalColor, SignalHeight )
self:F()
local Valid = true
if Valid then
if type( SignalUnitNames ) == "table" then
self.LandingZoneSignalUnitNames = SignalUnitNames
else
self.LandingZoneSignalUnitNames = { SignalUnitNames }
end
self.LandingZoneSignalType = SignalType
self.LandingZoneSignalColor = SignalColor
self.Signalled = false
if SignalHeight ~= nil then
self.LandingZoneSignalHeight = SignalHeight
else
self.LandingZoneSignalHeight = 0
end
if self.TaskBriefing then
self.TaskBriefing = self.TaskBriefing .. " " .. SignalColor.TEXT .. " " .. SignalType.TEXT .. " will be fired when entering the landing zone."
end
end
return Valid
end
--- When the CLIENT is approaching the landing zone, a RED SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeRed( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.RED, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a GREEN SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeGreen( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.GREEN, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a BLUE SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeBlue( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.BLUE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a WHITE SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeWhite( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.WHITE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, an ORANGE SMOKE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddSmokeOrange( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.SMOKE, TASK.SIGNAL.COLOR.ORANGE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a RED FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareRed( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.RED, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a GREEN FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareGreen( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.GREEN, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a BLUE FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareBlue( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.BLUE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, a WHITE FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareWhite( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.WHITE, SignalHeight )
end
--- When the CLIENT is approaching the landing zone, an ORANGE FLARE will be fired by an optional SignalUnitNames.
-- @param table|string SignalUnitNames Name of the Group that will fire the signal. If this parameter is NIL, the signal will be fired from the center of the landing zone.
-- @param number SignalHeight Altitude that the Signal should be fired...
function TASK:AddFlareOrange( SignalUnitNames, SignalHeight )
self:F()
self:AddSignal( SignalUnitNames, TASK.SIGNAL.TYPE.FLARE, TASK.SIGNAL.COLOR.ORANGE, SignalHeight )
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,63 +0,0 @@
local FACGroup = GROUP:FindByName( "FAC Group Lase" )
local FACDetection = DETECTION_BASE:New( FACGroup, 1000, 250 )
local LaseScheduler = SCHEDULER:New(nil,
--- @param Group#GROUP FACGroup
-- @param Detection#DETECTION_BASE FACDetection
function( FACGroup, FACDetection )
if FACDetection:GetDetectionUnitSetCount() > 0 then
local DetectedUnitSet = FACDetection:GetDetectionUnitSet(1)
if DetectedUnitSet then
FACDetection:E( { "I have a unit set ", DetectedUnitSet } )
local FACUnit = FACGroup:GetUnit(1)
if FACUnit then
FACDetection:E( FACUnit )
local FACDCSUnit = FACUnit:GetDCSUnit()
local FACUnitController = FACDCSUnit:getController()
DetectedUnitSet:ForEachUnit(
--- @param Unit#UNIT DetectedUnit
function( DetectedUnit, FACDCSUnit )
FACDetection:E( DetectedUnit:GetDCSUnit() )
FACDetection:E( FACDCSUnit )
local JTAC = Spot.createInfraRed( FACDCSUnit, {x = 0, y = 2.0, z = 0}, DetectedUnit:GetPointVec3(), 1337)
end, FACDCSUnit
)
end
end
end
end, { FACGroup, FACDetection },
30
)
local LaseScheduler2 = SCHEDULER:New(nil,
--- @param Group#GROUP FACGroup
-- @param Detection#DETECTION_BASE FACDetection
function( FACGroup, FACDetection )
if FACDetection:GetDetectionUnitSetCount() > 0 then
local DetectedUnitSet = FACDetection:GetDetectionUnitSet(1)
if DetectedUnitSet then
FACDetection:E( { "I have a unit set ", DetectedUnitSet } )
local FACUnit = FACGroup:GetUnit(1)
if FACUnit then
FACDetection:E( FACUnit )
local FACDCSUnit = FACUnit:GetDCSUnit()
local FACUnitController = FACDCSUnit:getController()
DetectedUnitSet:ForEachUnit(
--- @param Unit#UNIT DetectedUnit
function( DetectedUnit, FACDCSUnit )
FACDetection:E( DetectedUnit:GetDCSUnit() )
FACDetection:E( FACDCSUnit )
local TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity
= FACUnitController:isTargetDetected( DetectedUnit:GetDCSUnit(), Controller.Detection.IRST )
FACDetection:E( { TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity } )
end, FACDCSUnit
)
end
end
end
end, { FACGroup, FACDetection },
40
)

View File

@ -9,29 +9,7 @@ local TargetSet = SET_UNIT:New():FilterPrefixes( "US Hawk SR" ):FilterStart()
local TargetZone = ZONE:New( "Target Zone" )
local Task_Menu = TASK2_MENU_CLIENT:New( Mission, Client, "SEAD" )
local Task_Route = TASK2_ROUTE_CLIENT:New( Mission, Client, TargetZone ) -- The target location is dynamically defined in state machine
local Task_Client_Sead = TASK2_SEAD_CLIENT:New( Mission, Client, TargetSet )
Task_Client_Sead:AddScore( "Destroy", "Destroyed RADAR", 25 )
Task_Client_Sead:AddScore( "Success", "Destroyed all radars!!!", 100 )
local Task_Sead = STATEMACHINE:New( {
initial = 'None',
events = {
{ name = 'Start', from = 'None', to = 'Unassigned' },
{ name = 'Next', from = 'Unassigned', to = 'Assigned' },
{ name = 'Next', from = 'Assigned', to = 'Success' },
{ name = 'Fail', from = 'Assigned', to = 'Failed' },
{ name = 'Fail', from = 'Arrived', to = 'Failed' }
},
subs = {
Menu = { onstateparent = 'Unassigned', oneventparent = 'Start', fsm = Task_Menu.Fsm, event = 'Menu', returnevents = { 'Next' } },
Route = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = Task_Route.Fsm, event = 'Route' },
Sead = { onstateparent = 'Assigned', oneventparent = 'Next', fsm = Task_Client_Sead.Fsm, event = 'Await', returnevents = { 'Next' } }
}
} )
Task_Sead:Start()
local Task_SEAD = TASK_SEAD:New( TargetSet, TargetZone )