Got a first test mission working

This commit is contained in:
FlightControl 2016-07-01 09:16:16 +02:00
parent 6b942590bd
commit 7b66589cca
12 changed files with 48216 additions and 102 deletions

View File

@ -39,11 +39,12 @@ function MISSION:Meta()
end
--- This is the main MISSION declaration method. Each Mission is like the master or a Mission orchestration between, Clients, Tasks, Stages etc.
-- @param string MissionName is the name of the mission. This name will be used to reference the status of each mission by the players.
-- @param string MissionPriority is a string indicating the "priority" of the Mission. f.e. "Primary", "Secondary" or "First", "Second". It is free format and up to the Mission designer to choose. There are no rules behind this field.
-- @param string MissionBriefing is a string indicating the mission briefing to be shown when a player joins a @{CLIENT}.
-- @param string MissionCoalition is a string indicating the coalition or party to which this mission belongs to. It is free format and can be chosen freely by the mission designer. Note that this field is not to be confused with the coalition concept of the ME. Examples of a Mission Coalition could be "NATO", "CCCP", "Intruders", "Terrorists"...
-- @return MISSION
-- @param #MISSION self
-- @param #string MissionName is the name of the mission. This name will be used to reference the status of each mission by the players.
-- @param #string MissionPriority is a string indicating the "priority" of the Mission. f.e. "Primary", "Secondary" or "First", "Second". It is free format and up to the Mission designer to choose. There are no rules behind this field.
-- @param #string MissionBriefing is a string indicating the mission briefing to be shown when a player joins a @{CLIENT}.
-- @param #string MissionCoalition is a string indicating the coalition or party to which this mission belongs to. It is free format and can be chosen freely by the mission designer. Note that this field is not to be confused with the coalition concept of the ME. Examples of a Mission Coalition could be "NATO", "CCCP", "Intruders", "Terrorists"...
-- @return #MISSION self
-- @usage
-- -- Declare a few missions.
-- local Mission = MISSIONSCHEDULER.AddMission( 'Russia Transport Troops SA-6', 'Operational', 'Transport troops from the control center to one of the SA-6 SAM sites to activate their operation.', 'Russia' )
@ -76,6 +77,28 @@ function MISSION:New( MissionName, MissionPriority, MissionBriefing, MissionCoal
return self
end
--- Gets the mission name.
-- @param #MISSION self
-- @return #MISSION self
function MISSION:GetName()
return self.Name
end
--- Add a scoring to the mission.
-- @param #MISSION self
-- @return #MISSION self
function MISSION:AddScoring( Scoring )
self.Scoring = Scoring
return self
end
--- Get the scoring object of a mission.
-- @param #MISSION self
-- @return #SCORING Scoring
function MISSION:GetScoring()
return self.Scoring
end
--- Returns if a Mission has completed.
-- @return bool
function MISSION:IsCompleted()

View File

@ -262,10 +262,14 @@ end
--- Registers Scores the players completing a Mission Task.
-- @param #SCORING self
-- @param Unit#UNIT PlayerUnit
-- @param #string MissionName
-- @param #number Score
function SCORING:_AddMissionTaskScore( PlayerUnit, MissionName, Score )
self:F( { PlayerUnit, MissionName, Score } )
self:F( { PlayerUnit.UnitName, MissionName, Score } )
local PlayerName = PlayerUnit:getPlayerName()
local PlayerName = PlayerUnit:GetPlayerName()
if not self.Players[PlayerName].Mission[MissionName] then
self.Players[PlayerName].Mission[MissionName] = {}
@ -283,7 +287,7 @@ function SCORING:_AddMissionTaskScore( PlayerUnit, MissionName, Score )
Score .. " Score points added.",
20 ):ToAll()
self:ScoreCSV( PlayerName, "TASK_" .. MissionName:gsub( ' ', '_' ), 1, Score, PlayerUnit:getName() )
self:ScoreCSV( PlayerName, "TASK_" .. MissionName:gsub( ' ', '_' ), 1, Score, PlayerUnit:GetName() )
end

View File

@ -143,6 +143,8 @@ function STATEMACHINE_TASK:New( Task, options )
setmetatable( FsmT, Parent )
FsmT.__index = FsmT
env.info(tostring(Task.OnStateChange))
FsmT["onstatechange"] = Task.OnStateChange
FsmT.Task = Task
return FsmT

View File

@ -1,32 +1,31 @@
--- @module TASK2
--- @module Task2
--- The TASK2 class
-- @type TASK2
-- @field Scheduler#SCHEDULER TaskScheduler
-- @field Client#CLIENT Client
-- @field Mission#MISSION Mission
-- @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
-- @return #TASK2 self
function TASK2:New( Client )
function TASK2:New( Client, Mission )
local self = BASE:Inherit( self, BASE:New() )
self:F()
self.Client = Client
self.Mission = Mission
return self
end
--- @param #TASK2 self
function TASK2:Schedule()
self.TaskScheduler = SCHEDULER:New( self.Fsm, self.Fsm.Assign, { self, self.Client }, 1)
end
--- @param #TASK2 self
function TASK2:NextEvent( NextEvent, ... )
self:E( NextEvent )
@ -34,4 +33,37 @@ function TASK2:NextEvent( NextEvent, ... )
self.TaskScheduler = SCHEDULER:New( self.Fsm, NextEvent, { self, self.Client, 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.Client.ClientName} )
if self.Scores[To] then
self.Client:Message( "Score:" .. self.Scores[To].ScoreText .. " " .. To , 15 )
local Scoring = self.Mission:GetScoring()
if Scoring then
Scoring:_AddMissionTaskScore( self.Client, self.Mission:GetName(), self.Scores[To].Score )
end
end
end

View File

@ -1,11 +1,10 @@
--- @module Task2
--- @module Task_SEAD
--- TASK2_SEAD class
-- @type TASK2_SEAD
-- @field Client#CLIENT Client
-- @field Set#SET_UNIT TargetSet
-- @field Menu#MENU_CLIENT_COMMAND MenuSEAD
-- @extends Task2#TASK2
TASK2_SEAD = {
ClassName = "TASK2_SEAD",
@ -13,6 +12,84 @@ TASK2_SEAD = {
TargetSet = nil,
}
--- Creates a new SEAD task.
-- @param #TASK2_SEAD self
-- @param Client#CLIENT Client
-- @param Mission#MISSION Mission
-- @param Set#SET_UNIT TargetSet
-- @return #TASK2_SEAD self
function TASK2_SEAD:New( Client, Mission, TargetSet )
-- Inherits from BASE
local self = BASE:Inherit( self, TASK2:New( Client, Mission ) ) -- #TASK2_SEAD
self.TargetSet = TargetSet
self.Fsm = STATEMACHINE_TASK:New( self, {
initial = 'Start',
events = {
{ name = 'Menu', from = 'Start', to = 'Unassigned' },
{ name = 'Assign', from = 'Unassigned', to = 'Assigned' },
{ name = 'Await', from = 'Assigned', to = 'Waiting' },
{ name = 'HitTarget', from = 'Waiting', to = 'Destroy' },
{ name = 'MoreTargets', from = 'Destroy', to = 'Waiting' },
{ name = 'Destroyed', from = 'Destroy', to = 'Success' },
{ name = 'Killed', from = 'Assigned', to = 'Failed' },
{ name = 'Killed', from = 'Waiting', to = 'Failed' },
{ name = 'Killed', from = 'Destroy', to = 'Failed' },
{ name = 'Restart', from = 'Failed', to = 'Unassigned' }
},
callbacks = {
onMenu = self.OnMenu,
onAssign = self.OnAssign,
onAwait = self.OnAwait,
onHitTarget = self.OnHitTarget,
onMoreTargets = self.OnMoreTargets,
onDestroyed = self.OnDestroyed,
onKilled = self.OnKilled,
onRestart = self.OnRestart,
}
} )
_EVENTDISPATCHER:OnHit( self.EventHit, self )
_EVENTDISPATCHER:OnDead( self.EventKilled, self )
_EVENTDISPATCHER:OnCrash( self.EventKilled, self )
self:NextEvent( self.Fsm.Menu )
return self
end
--- Task Events
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self
-- @param StateMachine#STATEMACHINE_TASK Fsm
-- @param #string Event
-- @param #string From
-- @param #string To
function TASK2_SEAD:OnMenu( Fsm, Event, From, To )
self:E( { Event, From, To, self.Client.ClientName} )
self.Client:Message( "Menu", 15 )
self.Menu = MENU_CLIENT:New( self.Client, self.Mission:GetName(), nil )
self.MenuSEAD = MENU_CLIENT_COMMAND:New( self.Client, "SEAD", self.Menu, self.SEADAssign, self )
end
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self
function TASK2_SEAD:SEADAssign()
self:E( )
self.Client:Message( "SEAD Menu Assign", 15 )
self:NextEvent( self.Fsm.Assign )
end
--- StateMachine callback function for a TASK2
-- @param #TASK2_SEAD self
-- @param StateMachine#STATEMACHINE_TASK Fsm
@ -23,6 +100,7 @@ function TASK2_SEAD:OnAssign( Fsm, Event, From, To )
self:E( { Event, From, To, self.Client.ClientName} )
self.Client:Message( "Assigned", 15 )
self.MenuSEAD:Remove()
self:NextEvent( Fsm.Await )
end
@ -45,7 +123,8 @@ end
-- @param #string Event
-- @param #string From
-- @param #string To
function TASK2_SEAD:OnHitTarget( Fsm, Event, From, To, TargetUnit )
-- @param Event#EVENTDATA Event
function TASK2_SEAD:OnHitTarget( Fsm, Event, From, To, Event )
self.Client:Message( "Hit Target", 15 )
if self.TargetSet:Count() > 0 then
@ -73,13 +152,11 @@ end
-- @param #string Event
-- @param #string From
-- @param #string To
-- @param Unit#UNIT KilledUnit
function TASK2_SEAD:OnKilled( Fsm, Event, From, To, KilledUnit )
-- @param Event#EVENTDATA DCSEvent
function TASK2_SEAD:OnKilled( Fsm, Event, From, To )
if KilledUnit:GetName() == self.Client:GetName() then
self.Client:Message( "Player got killed", 15 )
self:NextEvent( Fsm.Restart )
end
self.Client:Message( "Player got killed", 15 )
self:NextEvent( Fsm.Restart )
end
@ -92,6 +169,7 @@ end
function TASK2_SEAD:OnRestart( Fsm, Event, From, To )
self.Client:Message( "Restart SEAD Task", 15 )
self:NextEvent( Fsm.Menu )
end
@ -107,54 +185,14 @@ function TASK2_SEAD:OnDestroyed( Fsm, Event, From, To )
end
function TASK2_SEAD:New( Client, TargetSet )
-- Inherits from BASE
local self = BASE:Inherit( self, TASK2:New( Client ) ) -- #TASK2_SEAD
self.TargetSet = TargetSet
self.Fsm = STATEMACHINE_TASK:New( self, {
initial = 'Unassigned',
events = {
{ name = 'Assign', from = 'Unassigned', to = 'Assigned' },
{ name = 'Await', from = 'Assigned', to = 'Waiting' },
{ name = 'HitTarget', from = 'Waiting', to = 'Destroy' },
{ name = 'MoreTargets', from = 'Destroy', to = 'Waiting' },
{ name = 'Destroyed', from = 'Destroy', to = 'Success' },
{ name = 'Killed', from = 'Assigned', to = 'Failed' },
{ name = 'Killed', from = 'Waiting', to = 'Failed' },
{ name = 'Killed', from = 'Destroy', to = 'Failed' },
{ name = 'Restart', from = 'Failed', to = 'Unassigned' }
},
callbacks = {
onAssign = self.OnAssign,
onAwait = self.OnAwait,
onHitTarget = self.OnHitTarget,
onMoreTargets = self.OnMoreTargets,
onDestroyed = self.OnDestroyed,
onKilled = self.OnKilled,
onRestart = self.OnRestart,
}
} )
_EVENTDISPATCHER:OnHit( self.EventHit, self )
_EVENTDISPATCHER:OnDead( self.EventKilled, self )
_EVENTDISPATCHER:OnCrash( self.EventKilled, self )
self:Schedule()
end
--- DCS Events
--- @param #TASK2_SEAD self
-- @param Event#EVENTDATA Event
function TASK2_SEAD:EventHit( Event )
if Event.IniUnit then
self:NextEvent( self.Fsm.HitTarget, Event.IniUnit )
self:NextEvent( self.Fsm.HitTarget, Event )
end
end
@ -163,7 +201,9 @@ end
function TASK2_SEAD:EventKilled( Event )
if Event.IniUnit then
self:NextEvent( self.Fsm.Killed, Event.IniUnit )
if Event.IniUnitName == self.Client.ClientName then
self:NextEvent( self.Fsm.Killed, Event )
end
end
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -83,6 +83,9 @@ COPY /b Moose.lua + %1\AIBalancer.lua Moose.lua
COPY /b Moose.lua + %1\AirbasePolice.lua Moose.lua
COPY /b Moose.lua + %1\Detection.lua Moose.lua
COPY /b Moose.lua + %1\FAC.lua Moose.lua
COPY /b Moose.lua + %1\Task2.lua Moose.lua
COPY /b Moose.lua + %1\TaskSead.lua Moose.lua
COPY /b Moose.lua + %1\StateMachine.lua Moose.lua
COPY /b Moose.lua + "Moose Create Static\Moose_Trace_Off.lua" Moose.lua

View File

@ -1,5 +1,15 @@
local Mission = MISSION:New( 'SEAD Targets', "Strategic", "SEAD the enemy", "RUSSIA" )
local Scoring = SCORING:New( "SEAD" )
Mission:AddScoring( Scoring )
local Client = CLIENT:FindByName( "Test SEAD" )
local TargetSet = SET_UNIT:New():FilterPrefixes( "US Hawk SR" ):FilterStart()
local Task_SEAD = TASK2_SEAD:New( Client, TargetSet )
local Task_SEAD = TASK2_SEAD:New( Client, Mission, TargetSet )
Task_SEAD:AddScore( "Destroy", "Destroyed RADAR", 25 )
Task_SEAD:AddScore( "Success", "Destroyed all radars!!!", 100 )