mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Got tasking working again now, with the NEW API set!!!
This is really, really great! Now document all, and optimize the code. And start video making. And re-test the test mission, all... And PUBLISH!!!
This commit is contained in:
parent
2f4eb39156
commit
4816cd2c57
@ -41,6 +41,7 @@ function STATEMACHINE:New( options )
|
|||||||
--self.__index = self
|
--self.__index = self
|
||||||
|
|
||||||
self.options = options
|
self.options = options
|
||||||
|
self.options.subs = self.options.subs or {}
|
||||||
self.current = options.initial or 'none'
|
self.current = options.initial or 'none'
|
||||||
self.events = {}
|
self.events = {}
|
||||||
self.subs = {}
|
self.subs = {}
|
||||||
@ -97,6 +98,8 @@ function STATEMACHINE:AddProcess( From, Event, Process, ReturnEvents )
|
|||||||
sub.event = "Start"
|
sub.event = "Start"
|
||||||
sub.ReturnEvents = ReturnEvents
|
sub.ReturnEvents = ReturnEvents
|
||||||
|
|
||||||
|
self.options.subs[Event] = sub
|
||||||
|
|
||||||
self:_submap( self.subs, sub, nil )
|
self:_submap( self.subs, sub, nil )
|
||||||
|
|
||||||
self:AddAction( From, Event, "*" )
|
self:AddAction( From, Event, "*" )
|
||||||
@ -145,26 +148,27 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function STATEMACHINE:_call_handler(handler, params)
|
function STATEMACHINE:_call_handler(handler, params)
|
||||||
if handler then
|
if self[handler] then
|
||||||
return handler( self, unpack(params) )
|
self:E( "Calling " .. handler )
|
||||||
|
return self[handler]( self, unpack(params) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function STATEMACHINE._handler( self, EventName, ... )
|
function STATEMACHINE._handler( self, EventName, ... )
|
||||||
|
|
||||||
self:F( { EventName, ... } )
|
self:E( { EventName, ... } )
|
||||||
|
|
||||||
local can, to = self:can( EventName )
|
local can, to = self:can( EventName )
|
||||||
self:T( { EventName, can, to } )
|
self:E( { EventName, can, to } )
|
||||||
|
|
||||||
local ReturnValues = nil
|
local ReturnValues = nil
|
||||||
|
|
||||||
if can then
|
if can then
|
||||||
local from = self.current
|
local from = self.current
|
||||||
local params = { ..., EventName, from, to }
|
local params = { EventName, from, to, ... }
|
||||||
|
|
||||||
if self:_call_handler(self["onbefore" .. EventName], params) == false
|
if self:_call_handler("onbefore" .. EventName, params) == false
|
||||||
or self:_call_handler(self["onleave" .. from], params) == false then
|
or self:_call_handler("onleave" .. from, params) == false then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -188,28 +192,28 @@ function STATEMACHINE._handler( self, EventName, ... )
|
|||||||
local fsmparent, event = self:_isendstate( to )
|
local fsmparent, event = self:_isendstate( to )
|
||||||
if fsmparent and event then
|
if fsmparent and event then
|
||||||
self:F2( { "end state: ", fsmparent, event } )
|
self:F2( { "end state: ", fsmparent, event } )
|
||||||
self:_call_handler(self["onenter" .. to] or self["on" .. to], params)
|
self:_call_handler("onenter" .. to, params)
|
||||||
self:_call_handler(self["onafter" .. EventName] or self["on" .. EventName], params)
|
self:_call_handler("onafter" .. EventName, params)
|
||||||
self:_call_handler(self["onstatechange"], params)
|
self:_call_handler("onstatechange", params)
|
||||||
fsmparent[event]( fsmparent )
|
fsmparent[event]( fsmparent )
|
||||||
execute = false
|
execute = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if execute then
|
if execute then
|
||||||
self:T3( { onenter = "onenter" .. to, callback = self["onenter" .. to] } )
|
self:T3( { onenter = "onenter" .. to, callback = self["onenter" .. to] } )
|
||||||
self:_call_handler(self["onenter" .. to] or self["on" .. to], params)
|
self:_call_handler("onenter" .. to, params)
|
||||||
|
|
||||||
self:T3( { On = "OnBefore" .. to, callback = self["OnBefore" .. to] } )
|
self:T3( { On = "OnBefore" .. to, callback = self["OnBefore" .. to] } )
|
||||||
if ( self:_call_handler(self["OnBefore" .. to], params ) ~= false ) then
|
if ( self:_call_handler("OnBefore" .. to, params ) ~= false ) then
|
||||||
|
|
||||||
self:T3( { onafter = "onafter" .. EventName, callback = self["onafter" .. EventName] } )
|
self:T3( { onafter = "onafter" .. EventName, callback = self["onafter" .. EventName] } )
|
||||||
self:_call_handler(self["onafter" .. EventName] or self["on" .. EventName], params)
|
self:_call_handler("onafter" .. EventName, params)
|
||||||
|
|
||||||
self:T3( { On = "OnAfter" .. to, callback = self["OnAfter" .. to] } )
|
self:T3( { On = "OnAfter" .. to, callback = self["OnAfter" .. to] } )
|
||||||
ReturnValues = self:_call_handler(self["OnAfter" .. to], params )
|
ReturnValues = self:_call_handler("OnAfter" .. to, params )
|
||||||
end
|
end
|
||||||
|
|
||||||
self:_call_handler(self["onstatechange"], params)
|
self:_call_handler("onstatechange", params)
|
||||||
end
|
end
|
||||||
|
|
||||||
return ReturnValues
|
return ReturnValues
|
||||||
@ -233,8 +237,8 @@ end
|
|||||||
|
|
||||||
function STATEMACHINE:_gosub( ParentFrom, ParentEvent )
|
function STATEMACHINE:_gosub( ParentFrom, ParentEvent )
|
||||||
local fsmtable = {}
|
local fsmtable = {}
|
||||||
self:E( { ParentFrom, ParentEvent, self.subs[ParentFrom] } )
|
|
||||||
if self.subs[ParentFrom] and self.subs[ParentFrom][ParentEvent] then
|
if self.subs[ParentFrom] and self.subs[ParentFrom][ParentEvent] then
|
||||||
|
self:E( { ParentFrom, ParentEvent, self.subs[ParentFrom] } )
|
||||||
return self.subs[ParentFrom][ParentEvent]
|
return self.subs[ParentFrom][ParentEvent]
|
||||||
else
|
else
|
||||||
return {}
|
return {}
|
||||||
@ -308,40 +312,6 @@ function STATEMACHINE:todot(filename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- STATEMACHINE_TASK class
|
|
||||||
-- @type STATEMACHINE_TASK
|
|
||||||
-- @field Task#TASK_BASE Task
|
|
||||||
-- @extends StateMachine#STATEMACHINE
|
|
||||||
STATEMACHINE_TASK = {
|
|
||||||
ClassName = "STATEMACHINE_TASK",
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Creates a new STATEMACHINE_TASK object.
|
|
||||||
-- @param #STATEMACHINE_TASK self
|
|
||||||
-- @param #table FSMT
|
|
||||||
-- @param Task#TASK_BASE Task
|
|
||||||
-- @param Unit#UNIT TaskUnit
|
|
||||||
-- @return #STATEMACHINE_TASK
|
|
||||||
function STATEMACHINE_TASK:New( FSMT, Task, TaskUnit )
|
|
||||||
|
|
||||||
local self = BASE:Inherit( self, STATEMACHINE:New( FSMT ) ) -- StateMachine#STATEMACHINE_PROCESS
|
|
||||||
|
|
||||||
self["onstatechange"] = Task.OnStateChange
|
|
||||||
self["onAssigned"] = Task.OnAssigned
|
|
||||||
self["onSuccess"] = Task.OnSuccess
|
|
||||||
self["onFailed"] = Task.OnFailed
|
|
||||||
|
|
||||||
self.Task = Task
|
|
||||||
self.TaskUnit = TaskUnit
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
function STATEMACHINE_TASK:_call_handler( handler, params )
|
|
||||||
if handler then
|
|
||||||
return handler( self.Task, self.TaskUnit, unpack( params ) )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- STATEMACHINE_CONTROLLABLE class
|
--- STATEMACHINE_CONTROLLABLE class
|
||||||
-- @type STATEMACHINE_CONTROLLABLE
|
-- @type STATEMACHINE_CONTROLLABLE
|
||||||
@ -385,14 +355,16 @@ function STATEMACHINE_CONTROLLABLE:GetControllable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function STATEMACHINE_CONTROLLABLE:_call_handler( handler, params )
|
function STATEMACHINE_CONTROLLABLE:_call_handler( handler, params )
|
||||||
if handler then
|
if self[handler] then
|
||||||
return handler( self, self.Controllable, unpack( params ) )
|
self:E( "Calling " .. handler )
|
||||||
|
return self[handler]( self, self.Controllable, unpack( params ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- STATEMACHINE_PROCESS class
|
--- STATEMACHINE_PROCESS class
|
||||||
-- @type STATEMACHINE_PROCESS
|
-- @type STATEMACHINE_PROCESS
|
||||||
-- @field Process#PROCESS Process
|
-- @field Process#PROCESS Process
|
||||||
|
-- @field Tasking.Task#TASK_BASE Task
|
||||||
-- @extends Core.StateMachine#STATEMACHINE_CONTROLLABLE
|
-- @extends Core.StateMachine#STATEMACHINE_CONTROLLABLE
|
||||||
STATEMACHINE_PROCESS = {
|
STATEMACHINE_PROCESS = {
|
||||||
ClassName = "STATEMACHINE_PROCESS",
|
ClassName = "STATEMACHINE_PROCESS",
|
||||||
@ -408,6 +380,92 @@ function STATEMACHINE_PROCESS:New( FSMT )
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Sets the task of the process.
|
||||||
|
-- @param #PROCESS self
|
||||||
|
-- @param Tasking.Task#TASK_BASE Task
|
||||||
|
-- @return #PROCESS
|
||||||
|
function STATEMACHINE_PROCESS:SetTask( Task )
|
||||||
|
|
||||||
|
self.Task = Task
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Gets the task of the process.
|
||||||
|
-- @param #PROCESS self
|
||||||
|
-- @return Task#TASK_BASE
|
||||||
|
function STATEMACHINE_PROCESS:GetTask()
|
||||||
|
|
||||||
|
return self.Task
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Gets the mission of the process.
|
||||||
|
-- @param #PROCESS self
|
||||||
|
-- @return Mission#MISSION
|
||||||
|
function STATEMACHINE_PROCESS:GetMission()
|
||||||
|
|
||||||
|
return self.Task.Mission
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Assign the process to a @{Unit} and activate the process.
|
||||||
|
-- @param #PROCESS self
|
||||||
|
-- @param Task.Tasking#TASK_BASE Task
|
||||||
|
-- @param Wrapper.Unit#UNIT ProcessUnit
|
||||||
|
-- @return #PROCESS self
|
||||||
|
function STATEMACHINE_PROCESS:Assign( Task, ProcessUnit )
|
||||||
|
self:E( { Task, ProcessUnit } )
|
||||||
|
|
||||||
|
self:SetControllable( ProcessUnit )
|
||||||
|
self:SetTask( Task )
|
||||||
|
|
||||||
|
self.ProcessGroup = ProcessUnit:GetGroup()
|
||||||
|
|
||||||
|
--self:Activate()
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function STATEMACHINE_PROCESS:onenterAssigned( ProcessUnit )
|
||||||
|
|
||||||
|
self.Task:Assign()
|
||||||
|
end
|
||||||
|
|
||||||
|
function STATEMACHINE_PROCESS:onenterSuccess( ProcessUnit )
|
||||||
|
|
||||||
|
self.Task:Success()
|
||||||
|
end
|
||||||
|
|
||||||
|
--- STATEMACHINE_TASK class
|
||||||
|
-- @type STATEMACHINE_TASK
|
||||||
|
-- @field Task#TASK_BASE Task
|
||||||
|
-- @extends Core.StateMachine#STATEMACHINE
|
||||||
|
STATEMACHINE_TASK = {
|
||||||
|
ClassName = "STATEMACHINE_TASK",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Creates a new STATEMACHINE_TASK object.
|
||||||
|
-- @param #STATEMACHINE_TASK self
|
||||||
|
-- @param #table FSMT
|
||||||
|
-- @param Task#TASK_BASE Task
|
||||||
|
-- @param Unit#UNIT TaskUnit
|
||||||
|
-- @return #STATEMACHINE_TASK
|
||||||
|
function STATEMACHINE_TASK:New( FSMT )
|
||||||
|
|
||||||
|
local self = BASE:Inherit( self, STATEMACHINE_CONTROLLABLE:New( FSMT ) ) -- Core.StateMachine#STATEMACHINE_TASK
|
||||||
|
|
||||||
|
self["onstatechange"] = self.OnStateChange
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function STATEMACHINE_TASK:_call_handler( handler, params )
|
||||||
|
if self[handler] then
|
||||||
|
self:E( "Calling " .. handler )
|
||||||
|
return self[handler]( self, unpack( params ) )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
do -- STATEMACHINE_SET
|
do -- STATEMACHINE_SET
|
||||||
|
|
||||||
--- STATEMACHINE_SET class
|
--- STATEMACHINE_SET class
|
||||||
@ -452,8 +510,9 @@ function STATEMACHINE_SET:Get()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function STATEMACHINE_SET:_call_handler( handler, params )
|
function STATEMACHINE_SET:_call_handler( handler, params )
|
||||||
if handler then
|
if self[handler] then
|
||||||
return handler( self, self.Set, unpack( params ) )
|
self:E( "Calling " .. handler )
|
||||||
|
return self[handler]( self, self.Set, unpack( params ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ PROCESS = {
|
|||||||
-- @param Unit#UNIT ProcessUnit (Optional) If provided, it defines the UNIT for which the process is running.
|
-- @param Unit#UNIT ProcessUnit (Optional) If provided, it defines the UNIT for which the process is running.
|
||||||
-- @return #PROCESS
|
-- @return #PROCESS
|
||||||
function PROCESS:New( FSMT, ProcessName, ProcessUnit )
|
function PROCESS:New( FSMT, ProcessName, ProcessUnit )
|
||||||
local self = BASE:Inherit( self, STATEMACHINE_CONTROLLABLE:New( FSMT, ProcessUnit ) )
|
local self = BASE:Inherit( self, STATEMACHINE_PROCESS:New( FSMT, ProcessUnit ) )
|
||||||
self:F()
|
self:F()
|
||||||
|
|
||||||
if ProcessUnit then
|
if ProcessUnit then
|
||||||
@ -41,63 +41,20 @@ function PROCESS:GetGroup()
|
|||||||
return self.ProcessGroup
|
return self.ProcessGroup
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Sets the task of the process.
|
|
||||||
-- @param #PROCESS self
|
|
||||||
-- @param Tasking.Task#TASK_BASE ProcessTask
|
|
||||||
-- @return #PROCESS
|
|
||||||
function PROCESS:SetTask( ProcessTask )
|
|
||||||
|
|
||||||
self.ProcessTask = ProcessTask
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Gets the task of the process.
|
|
||||||
-- @param #PROCESS self
|
|
||||||
-- @return Task#TASK_BASE
|
|
||||||
function PROCESS:GetTask()
|
|
||||||
|
|
||||||
return self.ProcessTask
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Gets the mission of the process.
|
|
||||||
-- @param #PROCESS self
|
|
||||||
-- @return Mission#MISSION
|
|
||||||
function PROCESS:GetMission()
|
|
||||||
|
|
||||||
return self.ProcessTask.Mission
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Assign the process to a @{Unit} and activate the process.
|
|
||||||
-- @param #PROCESS self
|
|
||||||
-- @param Unit#UNIT ProcessUnit
|
|
||||||
-- @return #PROCESS self
|
|
||||||
function PROCESS:Assign( ProcessTask, ProcessUnit )
|
|
||||||
|
|
||||||
self:SetControllable( ProcessUnit )
|
|
||||||
self:SetTask( ProcessTask )
|
|
||||||
|
|
||||||
self.ProcessGroup = ProcessUnit:GetGroup()
|
|
||||||
--self:Activate()
|
|
||||||
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Adds a score for the PROCESS to be achieved.
|
--- Adds a score for the PROCESS to be achieved.
|
||||||
-- @param #PROCESS self
|
-- @param #PROCESS self
|
||||||
-- @param Task#TASK_BASE Task The task for which the process needs to account score.
|
|
||||||
-- @param #string ProcessStatus is the state of the process when the score needs to be given. (See the relevant state descriptions of the process).
|
-- @param #string ProcessStatus is the state of the process when the score needs to be given. (See the relevant state descriptions of the process).
|
||||||
-- @param #string ScoreText is a text describing the score that is given according the status.
|
-- @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.
|
-- @param #number Score is a number providing the score of the status.
|
||||||
-- @return #PROCESS self
|
-- @return #PROCESS self
|
||||||
function PROCESS:AddScore( Task, ProcessStatus, ScoreText, Score )
|
function PROCESS:AddScore( ProcessStatus, ScoreText, Score )
|
||||||
self:F2( { ProcessStatus, ScoreText, Score } )
|
self:F2( { ProcessStatus, ScoreText, Score } )
|
||||||
|
|
||||||
self.Scores[ProcessStatus] = self.Scores[ProcessStatus] or {}
|
self.Scores[ProcessStatus] = self.Scores[ProcessStatus] or {}
|
||||||
self.Scores[ProcessStatus].ScoreText = ScoreText
|
self.Scores[ProcessStatus].ScoreText = ScoreText
|
||||||
self.Scores[ProcessStatus].Score = Score
|
self.Scores[ProcessStatus].Score = Score
|
||||||
self.Scores[ProcessStatus].Task = Task
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -108,17 +65,18 @@ end
|
|||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function PROCESS:OnStateChange( ProcessUnit, Event, From, To )
|
function PROCESS:onstatechange( ProcessUnit, Event, From, To, Dummy )
|
||||||
self:E( { self.ProcessName, Event, From, To, ProcessUnit.UnitName } )
|
self:E( { ProcessUnit, Event, From, To, Dummy } )
|
||||||
|
|
||||||
if self:IsTrace() then
|
if self:IsTrace() then
|
||||||
MESSAGE:New( "Process " .. self.ProcessName .. " : " .. Event .. " changed to state " .. To, 15 ):ToAll()
|
MESSAGE:New( "Process " .. self.ProcessName .. " : " .. Event .. " changed to state " .. To, 15 ):ToAll()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:E( self.Scores[To] )
|
||||||
-- TODO: This needs to be reworked with a callback functions allocated within Task, and set within the mission script from the Task Objects...
|
-- TODO: This needs to be reworked with a callback functions allocated within Task, and set within the mission script from the Task Objects...
|
||||||
if self.Scores[To] then
|
if self.Scores[To] then
|
||||||
|
|
||||||
local Task = self.Scores[To].Task
|
local Task = self.Task
|
||||||
local Scoring = Task:GetScoring()
|
local Scoring = Task:GetScoring()
|
||||||
if Scoring then
|
if Scoring then
|
||||||
Scoring:_AddMissionTaskScore( Task.Mission, ProcessUnit, self.Scores[To].ScoreText, self.Scores[To].Score )
|
Scoring:_AddMissionTaskScore( Task.Mission, ProcessUnit, self.Scores[To].ScoreText, self.Scores[To].Score )
|
||||||
|
|||||||
@ -276,17 +276,19 @@ function SCORING:_AddMissionTaskScore( Mission, PlayerUnit, Text, Score )
|
|||||||
|
|
||||||
self:F( { Mission:GetName(), PlayerUnit.UnitName, PlayerName, Text, Score } )
|
self:F( { Mission:GetName(), PlayerUnit.UnitName, PlayerName, Text, Score } )
|
||||||
|
|
||||||
if not self.Players[PlayerName].Mission[MissionName] then
|
local PlayerData = self.Players[PlayerName]
|
||||||
self.Players[PlayerName].Mission[MissionName] = {}
|
|
||||||
self.Players[PlayerName].Mission[MissionName].ScoreTask = 0
|
if not PlayerData.Mission[MissionName] then
|
||||||
self.Players[PlayerName].Mission[MissionName].ScoreMission = 0
|
PlayerData.Mission[MissionName] = {}
|
||||||
|
PlayerData.Mission[MissionName].ScoreTask = 0
|
||||||
|
PlayerData.Mission[MissionName].ScoreMission = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T( PlayerName )
|
self:T( PlayerName )
|
||||||
self:T( self.Players[PlayerName].Mission[MissionName] )
|
self:T( PlayerData.Mission[MissionName] )
|
||||||
|
|
||||||
self.Players[PlayerName].Score = self.Players[PlayerName].Score + Score
|
PlayerData.Score = self.Players[PlayerName].Score + Score
|
||||||
self.Players[PlayerName].Mission[MissionName].ScoreTask = self.Players[PlayerName].Mission[MissionName].ScoreTask + Score
|
PlayerData.Mission[MissionName].ScoreTask = self.Players[PlayerName].Mission[MissionName].ScoreTask + Score
|
||||||
|
|
||||||
MESSAGE:New( "Player '" .. PlayerName .. "' has " .. Text .. " in Mission '" .. MissionName .. "'. " ..
|
MESSAGE:New( "Player '" .. PlayerName .. "' has " .. Text .. " in Mission '" .. MissionName .. "'. " ..
|
||||||
Score .. " task score!",
|
Score .. " task score!",
|
||||||
@ -306,10 +308,12 @@ function SCORING:_AddMissionScore( Mission, Text, Score )
|
|||||||
|
|
||||||
local MissionName = Mission:GetName()
|
local MissionName = Mission:GetName()
|
||||||
|
|
||||||
self:F( { Mission, Text, Score } )
|
self:E( { Mission, Text, Score } )
|
||||||
|
self:E( self.Players )
|
||||||
|
|
||||||
for PlayerName, PlayerData in pairs( self.Players ) do
|
for PlayerName, PlayerData in pairs( self.Players ) do
|
||||||
|
|
||||||
|
self:E( PlayerData )
|
||||||
if PlayerData.Mission[MissionName] then
|
if PlayerData.Mission[MissionName] then
|
||||||
|
|
||||||
PlayerData.Score = PlayerData.Score + Score
|
PlayerData.Score = PlayerData.Score + Score
|
||||||
|
|||||||
@ -96,10 +96,10 @@ do -- PROCESS_ACCOUNT
|
|||||||
{ name = 'Report', from = '*', to = 'Report' },
|
{ name = 'Report', from = '*', to = 'Report' },
|
||||||
{ name = 'Event', from = '*', to = 'Account' },
|
{ name = 'Event', from = '*', to = 'Account' },
|
||||||
{ name = 'More', from = 'Account', to = 'Wait' },
|
{ name = 'More', from = 'Account', to = 'Wait' },
|
||||||
{ name = 'NoMore', from = 'Account', to = 'Success' },
|
{ name = 'NoMore', from = 'Account', to = 'Accounted' },
|
||||||
{ name = 'Fail', from = '*', to = 'Failed' },
|
{ name = 'Fail', from = '*', to = 'Failed' },
|
||||||
},
|
},
|
||||||
endstates = { 'Success', 'Failed' }
|
endstates = { 'Accounted', 'Failed' }
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Inherits from BASE
|
-- Inherits from BASE
|
||||||
@ -214,6 +214,7 @@ do -- PROCESS_ACCOUNT_DEADS
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function PROCESS_ACCOUNT_DEADS:onenterReport( ProcessUnit, Event, From, To )
|
function PROCESS_ACCOUNT_DEADS:onenterReport( ProcessUnit, Event, From, To )
|
||||||
|
self:E( { ProcessUnit, Event, From, To } )
|
||||||
|
|
||||||
local TaskGroup = ProcessUnit:GetGroup()
|
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 )
|
MESSAGE:New( "Your group with assigned " .. self.TaskName .. " task has " .. self.TargetSetUnit:GetUnitTypesText() .. " targets left to be destroyed.", 5, "HQ" ):ToGroup( TaskGroup )
|
||||||
@ -226,7 +227,7 @@ do -- PROCESS_ACCOUNT_DEADS
|
|||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
function PROCESS_ACCOUNT_DEADS:onenterAccount( ProcessUnit, EventData, Event, From, To )
|
function PROCESS_ACCOUNT_DEADS:onenterAccount( ProcessUnit, Event, From, To, EventData )
|
||||||
self:T( { ProcessUnit, EventData, Event, From, To } )
|
self:T( { ProcessUnit, EventData, Event, From, To } )
|
||||||
|
|
||||||
self:T({self.Controllable})
|
self:T({self.Controllable})
|
||||||
|
|||||||
@ -77,7 +77,14 @@ TASK_BASE = {
|
|||||||
-- @return #TASK_BASE self
|
-- @return #TASK_BASE self
|
||||||
function TASK_BASE:New( Mission, SetGroupAssign, TaskName, TaskType, TaskCategory )
|
function TASK_BASE:New( Mission, SetGroupAssign, TaskName, TaskType, TaskCategory )
|
||||||
|
|
||||||
local self = BASE:Inherit( self, BASE:New() )
|
|
||||||
|
local self = BASE:Inherit( self, STATEMACHINE_TASK:New( {} ) )
|
||||||
|
|
||||||
|
self:SetInitialState( "Planned" )
|
||||||
|
self:AddAction( "Planned", "Assign", "Assigned" )
|
||||||
|
self:AddAction( "Assigned", "Success", "Success" )
|
||||||
|
self:AddAction( "*", "Fail", "Failed" )
|
||||||
|
|
||||||
self:E( "New TASK " .. TaskName )
|
self:E( "New TASK " .. TaskName )
|
||||||
|
|
||||||
self.Processes = {}
|
self.Processes = {}
|
||||||
@ -93,7 +100,8 @@ function TASK_BASE:New( Mission, SetGroupAssign, TaskName, TaskType, TaskCategor
|
|||||||
|
|
||||||
self.TaskBriefing = "You are assigned to the task: " .. self.TaskName .. "."
|
self.TaskBriefing = "You are assigned to the task: " .. self.TaskName .. "."
|
||||||
|
|
||||||
self.FsmTemplate = self.FsmTemplate or STATEMACHINE_TASK:New( {}, self )
|
self.FsmTemplate = self.FsmTemplate or STATEMACHINE_PROCESS:New( {} )
|
||||||
|
self.FsmTemplate:SetTask( self )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -158,9 +166,10 @@ function TASK_BASE:AssignToUnit( TaskUnit )
|
|||||||
|
|
||||||
-- Assign each FsmSub in FsmUnit to the TaskUnit.
|
-- Assign each FsmSub in FsmUnit to the TaskUnit.
|
||||||
-- (This is not done during the copy).
|
-- (This is not done during the copy).
|
||||||
for FsmSubID, FsmSub in ipairs( FsmUnit:GetSubs() ) do
|
self:E(FsmUnit:GetSubs())
|
||||||
self:E( { "Sub ID", FsmSub:GetClassNameAndID() } )
|
for FsmSubID, FsmSub in pairs( FsmUnit:GetSubs() ) do
|
||||||
FsmSub:Assign( self, TaskUnit )
|
self:E( { "Sub ID", FsmSub.fsm:GetClassNameAndID(), FsmSubID } )
|
||||||
|
FsmSub.fsm:Assign( self, TaskUnit )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -590,7 +599,7 @@ end
|
|||||||
|
|
||||||
--- Gets the Scoring of the task
|
--- Gets the Scoring of the task
|
||||||
-- @param #TASK_BASE self
|
-- @param #TASK_BASE self
|
||||||
-- @return Scoring#SCORING Scoring
|
-- @return Functional.Scoring#SCORING Scoring
|
||||||
function TASK_BASE:GetScoring()
|
function TASK_BASE:GetScoring()
|
||||||
return self.Mission:GetScoring()
|
return self.Mission:GetScoring()
|
||||||
end
|
end
|
||||||
@ -766,7 +775,7 @@ end
|
|||||||
-- @param #string ScoreText is a text describing the score that is given according the status.
|
-- @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.
|
-- @param #number Score is a number providing the score of the status.
|
||||||
-- @return #TASK_BASE self
|
-- @return #TASK_BASE self
|
||||||
function TASK_BASE:AddScore( TaskStatus, ScoreText, Score )
|
function TASK_BASE:AddScoreTask( TaskStatus, ScoreText, Score )
|
||||||
self:F2( { TaskStatus, ScoreText, Score } )
|
self:F2( { TaskStatus, ScoreText, Score } )
|
||||||
|
|
||||||
self.Scores[TaskStatus] = self.Scores[TaskStatus] or {}
|
self.Scores[TaskStatus] = self.Scores[TaskStatus] or {}
|
||||||
@ -775,26 +784,35 @@ function TASK_BASE:AddScore( TaskStatus, ScoreText, Score )
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Adds a score for the TASK to be achieved.
|
||||||
|
-- @param #TASK_BASE self
|
||||||
|
-- @param #string TaskStatus is the status of the TASK 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 #TASK_BASE self
|
||||||
|
function TASK_BASE:AddScoreProcess( Event, State, ScoreText, Score )
|
||||||
|
self:F2( { State, ScoreText, Score } )
|
||||||
|
|
||||||
|
|
||||||
|
self:E( self:GetFsmTemplate():GetSubs()[Event].fsm )
|
||||||
|
local Process = self:GetFsmTemplate():GetSubs()[Event].fsm
|
||||||
|
|
||||||
|
Process:AddScore( State, ScoreText, Score )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- StateMachine callback function for a TASK
|
--- StateMachine callback function for a TASK
|
||||||
-- @param #TASK_BASE self
|
-- @param #TASK_BASE self
|
||||||
-- @param Unit#UNIT TaskUnit
|
|
||||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||||
-- @param #string Event
|
-- @param #string Event
|
||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Event#EVENTDATA Event
|
-- @param Event#EVENTDATA Event
|
||||||
function TASK_BASE:OnAssigned( TaskUnit, Fsm, Event, From, To )
|
function TASK_BASE:onenterAssigned( Fsm, Event, From, To )
|
||||||
|
|
||||||
self:E("Assigned")
|
self:E("Assigned")
|
||||||
|
|
||||||
local TaskGroup = TaskUnit:GetGroup()
|
|
||||||
|
|
||||||
TaskGroup:Message( self.TaskBriefing, 20 )
|
|
||||||
|
|
||||||
self:RemoveMenuForGroup( TaskGroup )
|
|
||||||
self:SetAssignedMenuForGroup( TaskGroup )
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -806,19 +824,9 @@ end
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Event#EVENTDATA Event
|
-- @param Event#EVENTDATA Event
|
||||||
function TASK_BASE:OnSuccess( TaskUnit, Fsm, Event, From, To )
|
function TASK_BASE:onenterSuccess( TaskUnit, Fsm, Event, From, To )
|
||||||
|
|
||||||
self:E("Success")
|
self:E("Success")
|
||||||
|
|
||||||
self:UnAssignFromGroups()
|
|
||||||
self:RemoveMenu()
|
|
||||||
|
|
||||||
local TaskGroup = TaskUnit:GetGroup()
|
|
||||||
|
|
||||||
self:StateSuccess()
|
|
||||||
|
|
||||||
-- The task has become successful, the event catchers can be cleaned.
|
|
||||||
self:EventRemoveAll()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- StateMachine callback function for a TASK
|
--- StateMachine callback function for a TASK
|
||||||
@ -850,17 +858,18 @@ end
|
|||||||
-- @param #string From
|
-- @param #string From
|
||||||
-- @param #string To
|
-- @param #string To
|
||||||
-- @param Event#EVENTDATA Event
|
-- @param Event#EVENTDATA Event
|
||||||
function TASK_BASE:OnStateChange( TaskUnit, Fsm, Event, From, To )
|
function TASK_BASE:onstatechange( Event, From, To )
|
||||||
|
|
||||||
if self:IsTrace() then
|
if self:IsTrace() then
|
||||||
MESSAGE:New( "Task " .. self.TaskName .. " : " .. Event .. " changed to state " .. To, 15 ):ToAll()
|
MESSAGE:New( "Task " .. self.TaskName .. " : " .. Event .. " changed to state " .. To, 15 ):ToAll()
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T2( { Event, From, To } )
|
self:E( { Event, From, To, self:IsTrace() } )
|
||||||
self:SetState( self, "State", To )
|
self:E( self.Scores )
|
||||||
|
|
||||||
if self.Scores[To] then
|
if self.Scores[To] then
|
||||||
local Scoring = self:GetScoring()
|
local Scoring = self:GetScoring()
|
||||||
|
self:E( Scoring )
|
||||||
if Scoring then
|
if Scoring then
|
||||||
Scoring:_AddMissionScore( self.Mission, self.Scores[To].ScoreText, self.Scores[To].Score )
|
Scoring:_AddMissionScore( self.Mission, self.Scores[To].ScoreText, self.Scores[To].Score )
|
||||||
end
|
end
|
||||||
|
|||||||
@ -20,19 +20,20 @@ FsmSEAD:AddProcess( "Planned", "Accept", PROCESS_ASSIGN_ACCEPT:New( "SEAD t
|
|||||||
FsmSEAD:AddProcess( "Assigned", "Route", PROCESS_ROUTE_ZONE:New( TargetZone, 3000 ), { Arrived = "Update" } )
|
FsmSEAD:AddProcess( "Assigned", "Route", PROCESS_ROUTE_ZONE:New( TargetZone, 3000 ), { Arrived = "Update" } )
|
||||||
FsmSEAD:AddAction ( "Rejected", "Eject", "Planned" )
|
FsmSEAD:AddAction ( "Rejected", "Eject", "Planned" )
|
||||||
FsmSEAD:AddAction ( "Arrived", "Update", "Updated" )
|
FsmSEAD:AddAction ( "Arrived", "Update", "Updated" )
|
||||||
FsmSEAD:AddProcess( "Updated", "Account", PROCESS_ACCOUNT_DEADS:New( TargetSet, "SEAD" ), { Destroyed = "Success" } )
|
FsmSEAD:AddProcess( "Updated", "Account", PROCESS_ACCOUNT_DEADS:New( TargetSet, "SEAD" ), { Accounted = "Success" } )
|
||||||
FsmSEAD:AddProcess( "Updated", "Smoke", PROCESS_SMOKE_TARGETS_ZONE:New( TargetSet, TargetZone ) )
|
FsmSEAD:AddProcess( "Updated", "Smoke", PROCESS_SMOKE_TARGETS_ZONE:New( TargetSet, TargetZone ) )
|
||||||
FsmSEAD:AddAction ( "Destroyed", "Success", "Success" )
|
FsmSEAD:AddAction ( "Accounted", "Success", "Success" )
|
||||||
FsmSEAD:AddAction ( "Failed", "Fail", "Failed" )
|
FsmSEAD:AddAction ( "Failed", "Fail", "Failed" )
|
||||||
|
|
||||||
--TaskSEAD:AddScoreTask( "Success", "Destroyed all target radars", 250 )
|
TaskSEAD:AddScoreTask( "Success", "Destroyed all target radars", 250 )
|
||||||
--TaskSEAD:AddScoreTask( "Failed", "Failed to destroy all target radars", -100 )
|
TaskSEAD:AddScoreTask( "Failed", "Failed to destroy all target radars", -100 )
|
||||||
--TaskSEAD:AddScoreProcess( "Account", "Account", "destroyed a radar", 25 )
|
TaskSEAD:AddScoreProcess( "Account", "Account", "destroyed a radar", 25 )
|
||||||
--TaskSEAD:AddScoreProcess( "Smoke", "Failed", "failed to destroy a radar", -100 )
|
TaskSEAD:AddScoreProcess( "Account", "Fail", "failed to destroy a radar", -100 )
|
||||||
|
|
||||||
function FsmSEAD:onenterUpdated( TaskUnit )
|
function FsmSEAD:onenterUpdated( TaskUnit )
|
||||||
TaskSEAD:Account()
|
self:E( { self } )
|
||||||
TaskSEAD:Smoke()
|
self:Account()
|
||||||
|
self:Smoke()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Needs to be checked, should not be necessary ...
|
-- Needs to be checked, should not be necessary ...
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user