mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Got mission dispatching working again with SEAD_Task and A2G_Task ...
Next is debugging all, and ensuring the scoring and Failed / Abort is working.
This commit is contained in:
parent
35ac87109b
commit
c27b6efe12
@ -133,7 +133,7 @@ function BASE:_SetDestructor()
|
||||
local proxyMeta = getmetatable(proxy)
|
||||
|
||||
proxyMeta.__gc = function ()
|
||||
-- env.info("In __gc for " .. Child:GetClassNameAndID() )
|
||||
env.info("In __gc for " .. self:GetClassNameAndID() )
|
||||
if self._Destructor then
|
||||
self:_Destructor()
|
||||
end
|
||||
|
||||
@ -48,22 +48,22 @@ function STATEMACHINE:New( options )
|
||||
self.endstates = {}
|
||||
|
||||
for _, event in pairs(options.events or {}) do
|
||||
self:E({ "events", event })
|
||||
self:T3({ "events", event })
|
||||
self:_eventmap( self.events, event )
|
||||
end
|
||||
|
||||
for name, callback in pairs(options.callbacks or {}) do
|
||||
self:E("callbacks")
|
||||
self:T3("callbacks")
|
||||
self[name] = callback
|
||||
end
|
||||
|
||||
for name, sub in pairs( options.subs or {} ) do
|
||||
self:E("sub")
|
||||
self:T3("sub")
|
||||
self:_submap( self.subs, sub, name )
|
||||
end
|
||||
|
||||
for name, endstate in pairs( options.endstates or {} ) do
|
||||
self:E("endstate")
|
||||
self:T3("endstate")
|
||||
self.endstates[endstate] = endstate
|
||||
end
|
||||
|
||||
@ -99,7 +99,7 @@ function STATEMACHINE:AddProcess( From, Event, Process, ReturnEvents )
|
||||
sub.ReturnEvents = ReturnEvents
|
||||
|
||||
-- Make the reference table weak.
|
||||
setmetatable( self.options.subs, { __mode = "v" } )
|
||||
-- setmetatable( self.options.subs, { __mode = "v" } )
|
||||
self.options.subs[Event] = sub
|
||||
|
||||
self:_submap( self.subs, sub, nil )
|
||||
@ -136,7 +136,7 @@ function STATEMACHINE:_eventmap( events, event )
|
||||
end
|
||||
|
||||
function STATEMACHINE:_submap( subs, sub, name )
|
||||
self:E( { sub = sub, name = name } )
|
||||
self:F( { sub = sub, name = name } )
|
||||
subs[sub.FromParent] = subs[sub.FromParent] or {}
|
||||
subs[sub.FromParent][sub.EventParent] = subs[sub.FromParent][sub.EventParent] or {}
|
||||
|
||||
@ -187,7 +187,7 @@ function STATEMACHINE._handler( self, EventName, ... )
|
||||
-- self:F2( "nextevent = " .. sub.nextevent )
|
||||
-- self[sub.nextevent]( self )
|
||||
--end
|
||||
self:F2( "calling sub: " .. sub.event )
|
||||
self:E( "calling sub event: " .. sub.event )
|
||||
sub.fsm.fsmparent = self
|
||||
sub.fsm.ReturnEvents = sub.ReturnEvents
|
||||
sub.fsm[sub.event]( sub.fsm )
|
||||
@ -243,7 +243,7 @@ end
|
||||
function STATEMACHINE:_gosub( ParentFrom, ParentEvent )
|
||||
local fsmtable = {}
|
||||
if self.subs[ParentFrom] and self.subs[ParentFrom][ParentEvent] then
|
||||
self:E( { ParentFrom, ParentEvent, self.subs[ParentFrom] } )
|
||||
self:E( { ParentFrom, ParentEvent, self.subs[ParentFrom], self.subs[ParentFrom][ParentEvent] } )
|
||||
return self.subs[ParentFrom][ParentEvent]
|
||||
else
|
||||
return {}
|
||||
@ -271,7 +271,7 @@ function STATEMACHINE:_isendstate( Current )
|
||||
end
|
||||
|
||||
function STATEMACHINE:_add_to_map(map, event)
|
||||
self:E( { map, event } )
|
||||
self:F3( { map, event } )
|
||||
if type(event.from) == 'string' then
|
||||
map[event.from] = event.to
|
||||
else
|
||||
@ -279,7 +279,16 @@ function STATEMACHINE:_add_to_map(map, event)
|
||||
map[from] = event.to
|
||||
end
|
||||
end
|
||||
self:E( { map, event } )
|
||||
self:T3( { map, event } )
|
||||
end
|
||||
|
||||
function STATEMACHINE:GetState()
|
||||
return self.current
|
||||
end
|
||||
|
||||
|
||||
function STATEMACHINE:Is( State )
|
||||
return self.current == State
|
||||
end
|
||||
|
||||
function STATEMACHINE:is(state)
|
||||
@ -288,7 +297,7 @@ end
|
||||
|
||||
function STATEMACHINE:can(e)
|
||||
local event = self.events[e]
|
||||
self:E( { self.current, event } )
|
||||
self:F3( { self.current, event } )
|
||||
local to = event and event.map[self.current] or event.map['*']
|
||||
return to ~= nil, to
|
||||
end
|
||||
@ -432,11 +441,13 @@ function STATEMACHINE_PROCESS:Assign( Task, ProcessUnit )
|
||||
end
|
||||
|
||||
function STATEMACHINE_PROCESS:onenterAssigned( ProcessUnit )
|
||||
self:E( "Assign" )
|
||||
|
||||
self.Task:Assign()
|
||||
end
|
||||
|
||||
function STATEMACHINE_PROCESS:onenterSuccess( ProcessUnit )
|
||||
self:E( "Success" )
|
||||
|
||||
self.Task:Success()
|
||||
end
|
||||
|
||||
@ -381,6 +381,7 @@ do -- DETECTION_DISPATCHER
|
||||
|
||||
if Task then
|
||||
if Task:IsStatePlanned() and DetectedArea.Changed == true then
|
||||
self:E( "Removing Tasking: " .. Task:GetTaskName() )
|
||||
Mission:RemoveTaskMenu( Task )
|
||||
Task = Mission:RemoveTask( Task )
|
||||
end
|
||||
@ -420,10 +421,11 @@ do -- DETECTION_DISPATCHER
|
||||
if not SEADTask then
|
||||
local TargetSetUnit = self:EvaluateSEAD( DetectedArea ) -- Returns a SetUnit if there are targets to be SEADed...
|
||||
if TargetSetUnit then
|
||||
SEADTask = Mission:AddTask( TASK_SEAD:New( Mission, self.SetGroup, "SEAD." .. AreaID, TargetSetUnit , DetectedZone ) ):StatePlanned()
|
||||
SEADTask = Mission:AddTask( TASK_SEAD:New( Mission, self.SetGroup, "SEAD." .. AreaID, TargetSetUnit , DetectedZone ) )
|
||||
end
|
||||
end
|
||||
if SEADTask and SEADTask:IsStatePlanned() then
|
||||
self:E( "Planned" )
|
||||
SEADTask:SetPlannedMenu()
|
||||
TaskMsg[#TaskMsg+1] = " - " .. SEADTask:GetStateString() .. " SEAD " .. AreaID .. " - " .. SEADTask.TargetSetUnit:GetUnitTypesText()
|
||||
end
|
||||
@ -434,7 +436,7 @@ do -- DETECTION_DISPATCHER
|
||||
if not CASTask then
|
||||
local TargetSetUnit = self:EvaluateCAS( DetectedArea ) -- Returns a SetUnit if there are targets to be SEADed...
|
||||
if TargetSetUnit then
|
||||
CASTask = Mission:AddTask( TASK_A2G:New( Mission, self.SetGroup, "CAS." .. AreaID, "CAS", TargetSetUnit , DetectedZone, DetectedArea.NearestFAC ) ):StatePlanned()
|
||||
CASTask = Mission:AddTask( TASK_A2G:New( Mission, self.SetGroup, "CAS." .. AreaID, "CAS", TargetSetUnit , DetectedZone, DetectedArea.NearestFAC ) )
|
||||
end
|
||||
end
|
||||
if CASTask and CASTask:IsStatePlanned() then
|
||||
@ -448,7 +450,7 @@ do -- DETECTION_DISPATCHER
|
||||
if not BAITask then
|
||||
local TargetSetUnit = self:EvaluateBAI( DetectedArea, self.CommandCenter:GetCoalition() ) -- Returns a SetUnit if there are targets to be SEADed...
|
||||
if TargetSetUnit then
|
||||
BAITask = Mission:AddTask( TASK_A2G:New( Mission, self.SetGroup, "BAI." .. AreaID, "BAI", TargetSetUnit , DetectedZone, DetectedArea.NearestFAC ) ):StatePlanned()
|
||||
BAITask = Mission:AddTask( TASK_A2G:New( Mission, self.SetGroup, "BAI." .. AreaID, "BAI", TargetSetUnit , DetectedZone, DetectedArea.NearestFAC ) )
|
||||
end
|
||||
end
|
||||
if BAITask and BAITask:IsStatePlanned() then
|
||||
|
||||
@ -13,7 +13,6 @@ MISSION = {
|
||||
Name = "",
|
||||
MissionStatus = "PENDING",
|
||||
_Clients = {},
|
||||
Tasks = {},
|
||||
TaskMenus = {},
|
||||
TaskCategoryMenus = {},
|
||||
TaskTypeMenus = {},
|
||||
@ -57,6 +56,9 @@ function MISSION:New( MissionName, MissionPriority, MissionBriefing, MissionCoal
|
||||
self.MissionPriority = MissionPriority
|
||||
self.MissionBriefing = MissionBriefing
|
||||
self.MissionCoalition = MissionCoalition
|
||||
|
||||
self.Tasks = {}
|
||||
setmetatable( self.Tasks, { __mode = "v" } )
|
||||
|
||||
return self
|
||||
end
|
||||
@ -141,8 +143,7 @@ function MISSION:ClearMissionMenu()
|
||||
end
|
||||
|
||||
--- Get the TASK identified by the TaskNumber from the Mission. This function is useful in GoalFunctions.
|
||||
-- @param #string TaskIndex is the Index of the @{Task} within the @{Mission}.
|
||||
-- @param #number TaskID is the ID of the @{Task} within the @{Mission}.
|
||||
-- @param #string TaskName The Name of the @{Task} within the @{Mission}.
|
||||
-- @return Task#TASK_BASE The Task
|
||||
-- @return #nil Returns nil if no task was found.
|
||||
function MISSION:GetTask( TaskName )
|
||||
@ -178,6 +179,7 @@ end
|
||||
function MISSION:RemoveTask( Task )
|
||||
|
||||
local TaskName = Task:GetTaskName()
|
||||
|
||||
self:F( TaskName )
|
||||
self.Tasks[TaskName] = self.Tasks[TaskName] or { n = 0 }
|
||||
|
||||
@ -187,6 +189,8 @@ function MISSION:RemoveTask( Task )
|
||||
self.Tasks[TaskName] = nil
|
||||
Task = nil
|
||||
|
||||
collectgarbage()
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
@ -406,7 +410,7 @@ end
|
||||
function MISSION:GetTasks()
|
||||
self:F()
|
||||
|
||||
return self._Tasks
|
||||
return self.Tasks
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ function TASK_BASE:New( Mission, SetGroupAssign, TaskName, TaskType, TaskCategor
|
||||
self:SetName( TaskName )
|
||||
self:SetID( Mission:GetNextTaskID( self ) ) -- The Mission orchestrates the task sequences ..
|
||||
|
||||
self.TaskBriefing = "You are assigned to the task: " .. self.TaskName .. "."
|
||||
self.TaskBriefing = "You are invited for the task: " .. self.TaskName .. "."
|
||||
|
||||
self.FsmTemplate = self.FsmTemplate or STATEMACHINE_PROCESS:New( {} )
|
||||
self.FsmTemplate:SetTask( self )
|
||||
@ -432,6 +432,8 @@ function TASK_BASE.MenuAssignToGroup( MenuParam )
|
||||
local self = MenuParam.self
|
||||
local TaskGroup = MenuParam.TaskGroup
|
||||
|
||||
self:E( "Assigned menu selected")
|
||||
|
||||
self:AssignToGroup( TaskGroup )
|
||||
end
|
||||
|
||||
@ -691,7 +693,7 @@ end
|
||||
--- Is the @{Task} status **Success**.
|
||||
-- @param #TASK_BASE self
|
||||
function TASK_BASE:IsStateSuccess()
|
||||
return self:GetStateString() == "Success"
|
||||
return self:Is( "Success" )
|
||||
end
|
||||
|
||||
--- Sets a @{Task} to status **Failed**.
|
||||
@ -704,7 +706,7 @@ end
|
||||
--- Is the @{Task} status **Failed**.
|
||||
-- @param #TASK_BASE self
|
||||
function TASK_BASE:IsStateFailed()
|
||||
return self:GetStateString() == "Failed"
|
||||
return self:Is( "Failed" )
|
||||
end
|
||||
|
||||
--- Sets a @{Task} to status **Planned**.
|
||||
@ -717,7 +719,7 @@ end
|
||||
--- Is the @{Task} status **Planned**.
|
||||
-- @param #TASK_BASE self
|
||||
function TASK_BASE:IsStatePlanned()
|
||||
return self:GetStateString() == "Planned"
|
||||
return self:Is( "Planned" )
|
||||
end
|
||||
|
||||
--- Sets a @{Task} to status **Assigned**.
|
||||
@ -730,7 +732,7 @@ end
|
||||
--- Is the @{Task} status **Assigned**.
|
||||
-- @param #TASK_BASE self
|
||||
function TASK_BASE:IsStateAssigned()
|
||||
return self:GetStateString() == "Assigned"
|
||||
return self:Is( "Assigned" )
|
||||
end
|
||||
|
||||
--- Sets a @{Task} to status **Hold**.
|
||||
@ -743,7 +745,7 @@ end
|
||||
--- Is the @{Task} status **Hold**.
|
||||
-- @param #TASK_BASE self
|
||||
function TASK_BASE:IsStateHold()
|
||||
return self:GetStateString() == "Hold"
|
||||
return self:Is( "Hold" )
|
||||
end
|
||||
|
||||
--- Sets a @{Task} to status **Replanned**.
|
||||
@ -756,7 +758,7 @@ end
|
||||
--- Is the @{Task} status **Replanned**.
|
||||
-- @param #TASK_BASE self
|
||||
function TASK_BASE:IsStateReplanned()
|
||||
return self:GetStateString() == "Replanned"
|
||||
return self:Is( "Replanned" )
|
||||
end
|
||||
|
||||
--- Gets the @{Task} status.
|
||||
@ -812,28 +814,27 @@ end
|
||||
|
||||
--- StateMachine callback function for a TASK
|
||||
-- @param #TASK_BASE self
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Event#EVENTDATA Event
|
||||
function TASK_BASE:onenterAssigned( Fsm, Event, From, To )
|
||||
function TASK_BASE:onenterAssigned( Event, From, To )
|
||||
|
||||
self:E("Assigned")
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- StateMachine callback function for a TASK
|
||||
-- @param #TASK_BASE self
|
||||
-- @param Unit#UNIT TaskUnit
|
||||
-- @param StateMachine#STATEMACHINE_TASK Fsm
|
||||
-- @param #string Event
|
||||
-- @param #string From
|
||||
-- @param #string To
|
||||
-- @param Event#EVENTDATA Event
|
||||
function TASK_BASE:onenterSuccess( TaskUnit, Fsm, Event, From, To )
|
||||
function TASK_BASE:onenterSuccess( Event, From, To )
|
||||
|
||||
self:E("Success")
|
||||
|
||||
end
|
||||
|
||||
--- StateMachine callback function for a TASK
|
||||
|
||||
@ -47,12 +47,12 @@ do -- TASK_SEAD
|
||||
|
||||
local Fsm = self:GetFsmTemplate()
|
||||
|
||||
Fsm:AddProcess( "Planned", "Accept", "Planned", PROCESS_ASSIGN_ACCEPT:New( self.TaskBriefing ), { Assigned = "Route", Rejected = "Eject" } )
|
||||
Fsm:AddProcess( "Planned", "Accept", PROCESS_ASSIGN_ACCEPT:New( self.TaskBriefing ), { Assigned = "Route", Rejected = "Eject" } )
|
||||
Fsm:AddProcess( "Assigned", "Route", PROCESS_ROUTE_ZONE:New( self.TargetZone ), { Arrived = "Update" } )
|
||||
Fsm:AddAction ( "Rejected", "Eject", "Planned" )
|
||||
Fsm:AddAction ( "Arrived", "Update", "Updated" )
|
||||
Fsm:AddProcess( "Updated", "Account", PROCESS_ACCOUNT_DEADS:New( self.TargetSetUnit, "SEAD" ), { Accounted = "Success" } )
|
||||
Fsm:AddProcess( "Updated", "Smoke", PROCESS_SMOKE_TARGETS_ZONE:New( self.TargetSetUnit, self.TargetZone ) )
|
||||
Fsm:AddProcess( "*", "Account", PROCESS_ACCOUNT_DEADS:New( self.TargetSetUnit, "SEAD" ), { Accounted = "Success" } )
|
||||
Fsm:AddProcess( "*", "Smoke", PROCESS_SMOKE_TARGETS_ZONE:New( self.TargetSetUnit, self.TargetZone ) )
|
||||
Fsm:AddAction ( "Accounted", "Success", "Success" )
|
||||
Fsm:AddAction ( "Failed", "Fail", "Failed" )
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user