mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
commit
96aa49d682
@ -1011,12 +1011,12 @@ do -- FSM_PROCESS
|
||||
-- Copy Processes
|
||||
for ProcessID, Process in pairs( self:GetProcesses() ) do
|
||||
self:E( { Process} )
|
||||
Process.fsm:Remove()
|
||||
Process.fsm = nil
|
||||
if Process.fsm then
|
||||
Process.fsm:Remove()
|
||||
Process.fsm = nil
|
||||
end
|
||||
end
|
||||
|
||||
self._Processes = nil
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@ -1121,7 +1121,7 @@ end
|
||||
self:T( { ProcessUnit, From, Event, To, Dummy, self:IsTrace() } )
|
||||
|
||||
if self:IsTrace() then
|
||||
MESSAGE:New( "@ Process " .. self:GetClassNameAndID() .. " : " .. Event .. " changed to state " .. To, 2 ):ToAll()
|
||||
--MESSAGE:New( "@ Process " .. self:GetClassNameAndID() .. " : " .. Event .. " changed to state " .. To, 2 ):ToAll()
|
||||
end
|
||||
|
||||
self:T( { Scores = self._Scores, To = To } )
|
||||
|
||||
@ -82,7 +82,7 @@ do -- MENU_BASE
|
||||
-- @param #string MenuText The text of the child menu.
|
||||
-- @return #MENU_BASE
|
||||
function MENU_BASE:GetMenu( MenuText )
|
||||
self:F( { self.Menus, MenuText } )
|
||||
self:F2( { Menu = self.Menus[MenuText] } )
|
||||
return self.Menus[MenuText]
|
||||
end
|
||||
|
||||
@ -810,9 +810,9 @@ do
|
||||
-- @param MenuTime
|
||||
-- @return #MENU_GROUP self
|
||||
function MENU_GROUP:RemoveSubMenus( MenuTime )
|
||||
self:F2( { self.MenuPath, MenuTime, self.MenuTime } )
|
||||
--self:F2( { self.MenuPath, MenuTime, self.MenuTime } )
|
||||
|
||||
self:T( { "Removing Group SubMenus:", self.MenuGroup:GetName(), self.MenuPath } )
|
||||
--self:T( { "Removing Group SubMenus:", self.MenuGroup:GetName(), self.MenuPath } )
|
||||
for MenuText, Menu in pairs( self.Menus ) do
|
||||
Menu:Remove( MenuTime )
|
||||
end
|
||||
@ -825,7 +825,7 @@ do
|
||||
-- @param MenuTime
|
||||
-- @return #nil
|
||||
function MENU_GROUP:Remove( MenuTime )
|
||||
self:F( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
|
||||
--self:F2( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
|
||||
|
||||
self:RemoveSubMenus( MenuTime )
|
||||
|
||||
@ -844,7 +844,7 @@ do
|
||||
end
|
||||
end
|
||||
end
|
||||
self:T( { "Removing Group Menu:", self.MenuGroup:GetName(), self.MenuGroup._Menus[self.Path].Path } )
|
||||
self:T( { "Removing Group Menu:", MenuGroup = self.MenuGroup:GetName(), MenuPath = self.MenuGroup._Menus[self.Path].Path } )
|
||||
self.MenuGroup._Menus[self.Path] = nil
|
||||
self = nil
|
||||
end
|
||||
@ -882,7 +882,7 @@ do
|
||||
local Path = ( ParentMenu and ( table.concat( ParentMenu.MenuPath or {}, "@" ) .. "@" .. MenuText ) ) or MenuText
|
||||
if MenuGroup._Menus[Path] then
|
||||
self = MenuGroup._Menus[Path]
|
||||
self:T( { "Re-using Group Command Menu:", MenuGroup:GetName(), MenuText } )
|
||||
self:F2( { "Re-using Group Command Menu:", MenuGroup:GetName(), MenuText } )
|
||||
else
|
||||
self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) )
|
||||
|
||||
@ -896,7 +896,7 @@ do
|
||||
self.MenuText = MenuText
|
||||
self.ParentMenu = ParentMenu
|
||||
|
||||
self:T( { "Adding Group Command Menu:", MenuGroup:GetName(), MenuText, self.MenuParentPath } )
|
||||
self:F( { "Adding Group Command Menu:", MenuGroup = MenuGroup:GetName(), MenuText = MenuText, MenuPath = self.MenuParentPath } )
|
||||
self.MenuPath = missionCommands.addCommandForGroup( self.MenuGroupID, MenuText, self.MenuParentPath, self.MenuCallHandler, arg )
|
||||
|
||||
if self.ParentMenu and self.ParentMenu.Menus then
|
||||
@ -914,14 +914,14 @@ do
|
||||
-- @param MenuTime
|
||||
-- @return #nil
|
||||
function MENU_GROUP_COMMAND:Remove( MenuTime )
|
||||
self:F( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
|
||||
--self:F2( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
|
||||
|
||||
if not MenuTime or self.MenuTime ~= MenuTime then
|
||||
if self.MenuGroup._Menus[self.Path] then
|
||||
self = self.MenuGroup._Menus[self.Path]
|
||||
|
||||
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
|
||||
self:T( { "Removing Group Command Menu:", self.MenuGroup:GetName(), self.MenuText, self.Path, self.MenuGroup._Menus[self.Path].Path } )
|
||||
self:T( { "Removing Group Command Menu:", MenuGroup = self.MenuGroup:GetName(), MenuText = self.MenuText, MenuPath = self.Path } )
|
||||
|
||||
self.ParentMenu.Menus[self.MenuText] = nil
|
||||
self.ParentMenu.MenuCount = self.ParentMenu.MenuCount - 1
|
||||
|
||||
@ -165,11 +165,10 @@ end
|
||||
-- @param #SET_BASE self
|
||||
-- @param #string ObjectName
|
||||
function SET_BASE:Remove( ObjectName )
|
||||
self:F( ObjectName )
|
||||
|
||||
local t = self.Set[ObjectName]
|
||||
|
||||
self:E( { ObjectName, t } )
|
||||
self:F3( { ObjectName, t } )
|
||||
|
||||
if t then
|
||||
if t._next then
|
||||
@ -1568,7 +1567,7 @@ end
|
||||
-- @return #string The name of the UNIT
|
||||
-- @return #table The UNIT
|
||||
function SET_UNIT:FindInDatabase( Event )
|
||||
self:E( { Event.IniDCSUnitName, self.Set[Event.IniDCSUnitName], Event } )
|
||||
self:F2( { Event.IniDCSUnitName, self.Set[Event.IniDCSUnitName], Event } )
|
||||
|
||||
|
||||
return Event.IniDCSUnitName, self.Set[Event.IniDCSUnitName]
|
||||
|
||||
@ -269,7 +269,6 @@ end
|
||||
-- @param #COMMANDCENTER self
|
||||
-- @return Core.Menu#MENU_COALITION
|
||||
function COMMANDCENTER:GetMenu()
|
||||
self:F()
|
||||
return self.CommandCenterMenu
|
||||
end
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ MISSION = {
|
||||
ClassName = "MISSION",
|
||||
Name = "",
|
||||
MissionStatus = "PENDING",
|
||||
AssignedGroups = {},
|
||||
}
|
||||
|
||||
--- This is the main MISSION declaration method. Each Mission is like the master or a Mission orchestration between, Clients, Tasks, Stages etc.
|
||||
@ -288,20 +289,17 @@ end
|
||||
-- If the Unit is part of a Task in the Mission, true is returned.
|
||||
-- @param #MISSION self
|
||||
-- @param Wrapper.Unit#UNIT PlayerUnit The CLIENT or UNIT of the Player joining the Mission.
|
||||
-- @return #boolean true if Unit is part of a Task in the Mission.
|
||||
-- @return #MISSION
|
||||
function MISSION:AbortUnit( PlayerUnit )
|
||||
self:F( { PlayerUnit = PlayerUnit } )
|
||||
|
||||
local PlayerUnitRemoved = false
|
||||
|
||||
for TaskID, Task in pairs( self:GetTasks() ) do
|
||||
local Task = Task -- Tasking.Task#TASK
|
||||
if Task:AbortUnit( PlayerUnit ) then
|
||||
PlayerUnitRemoved = true
|
||||
end
|
||||
local PlayerGroup = PlayerUnit:GetGroup()
|
||||
Task:AbortGroup( PlayerGroup )
|
||||
end
|
||||
|
||||
return PlayerUnitRemoved
|
||||
return self
|
||||
end
|
||||
|
||||
--- Handles a crash of a PlayerUnit from the Mission.
|
||||
@ -366,7 +364,7 @@ end
|
||||
-- @param #MISSION self
|
||||
-- @param #number MenuTime
|
||||
function MISSION:SetMenu( MenuTime )
|
||||
self:F()
|
||||
self:F( { self:GetName(), MenuTime } )
|
||||
|
||||
for _, TaskData in pairs( self:GetTasks() ) do
|
||||
local Task = TaskData -- Tasking.Task#TASK
|
||||
@ -378,7 +376,7 @@ end
|
||||
-- @param #MISSION self
|
||||
-- @param #number MenuTime
|
||||
function MISSION:RemoveMenu( MenuTime )
|
||||
self:F()
|
||||
self:F( { self:GetName(), MenuTime } )
|
||||
|
||||
for _, Task in pairs( self:GetTasks() ) do
|
||||
local Task = Task -- Tasking.Task#TASK
|
||||
@ -387,6 +385,58 @@ function MISSION:RemoveMenu( MenuTime )
|
||||
end
|
||||
|
||||
|
||||
do -- Group Assignment
|
||||
|
||||
--- Returns if the @{Mission} is assigned to the Group.
|
||||
-- @param #MISSION self
|
||||
-- @param Wrapper.Group#GROUP MissionGroup
|
||||
-- @return #boolean
|
||||
function MISSION:IsGroupAssigned( MissionGroup )
|
||||
|
||||
local MissionGroupName = MissionGroup:GetName()
|
||||
|
||||
if self.AssignedGroups[MissionGroupName] == MissionGroup then
|
||||
self:T( { "Mission is assigned to:", MissionGroup:GetName() } )
|
||||
return true
|
||||
end
|
||||
|
||||
self:T( { "Mission is not assigned to:", MissionGroup:GetName() } )
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--- Set @{Group} assigned to the @{Mission}.
|
||||
-- @param #MISSION self
|
||||
-- @param Wrapper.Group#GROUP MissionGroup
|
||||
-- @return #MISSION
|
||||
function MISSION:SetGroupAssigned( MissionGroup )
|
||||
|
||||
local MissionName = self:GetName()
|
||||
local MissionGroupName = MissionGroup:GetName()
|
||||
|
||||
self.AssignedGroups[MissionGroupName] = MissionGroup
|
||||
self:E( string.format( "Mission %s is assigned to %s", MissionName, MissionGroupName ) )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Clear the @{Group} assignment from the @{Mission}.
|
||||
-- @param #MISSION self
|
||||
-- @param Wrapper.Group#GROUP MissionGroup
|
||||
-- @return #MISSION
|
||||
function MISSION:ClearGroupAssignment( MissionGroup )
|
||||
|
||||
local MissionName = self:GetName()
|
||||
local MissionGroupName = MissionGroup:GetName()
|
||||
|
||||
self.AssignedGroups[MissionGroupName] = nil
|
||||
self:E( string.format( "Mission %s is unassigned to %s", MissionName, MissionGroupName ) )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Gets the COMMANDCENTER.
|
||||
-- @param #MISSION self
|
||||
-- @return Tasking.CommandCenter#COMMANDCENTER
|
||||
@ -642,7 +692,6 @@ end
|
||||
-- Tasks = Mission:GetTasks()
|
||||
-- env.info( "Task 2 Completion = " .. Tasks[2]:GetGoalPercentage() .. "%" )
|
||||
function MISSION:GetTasks()
|
||||
self:F()
|
||||
|
||||
return self.Tasks
|
||||
end
|
||||
|
||||
@ -78,6 +78,7 @@ TASK = {
|
||||
Mission = nil,
|
||||
CommandCenter = nil,
|
||||
TimeOut = 0,
|
||||
AssignedGroups = {},
|
||||
}
|
||||
|
||||
--- FSM PlayerAborted event handler prototype for TASK.
|
||||
@ -164,6 +165,7 @@ function TASK:New( Mission, SetGroupAssign, TaskName, TaskType )
|
||||
self:AddTransition( "Planned", "Assign", "Assigned" )
|
||||
self:AddTransition( "Assigned", "AssignUnit", "Assigned" )
|
||||
self:AddTransition( "Assigned", "Success", "Success" )
|
||||
self:AddTransition( "Assigned", "Hold", "Hold" )
|
||||
self:AddTransition( "Assigned", "Fail", "Failed" )
|
||||
self:AddTransition( "Assigned", "Abort", "Aborted" )
|
||||
self:AddTransition( "Assigned", "Cancel", "Cancelled" )
|
||||
@ -241,9 +243,9 @@ function TASK:JoinUnit( PlayerUnit, PlayerGroup )
|
||||
--self:MessageToGroups( PlayerUnit:GetPlayerName() .. " is planning to join Task " .. self:GetName() )
|
||||
end
|
||||
if self:IsStateAssigned() then
|
||||
local IsAssignedToGroup = self:IsAssignedToGroup( PlayerGroup )
|
||||
self:E( { IsAssignedToGroup = IsAssignedToGroup } )
|
||||
if IsAssignedToGroup then
|
||||
local IsGroupAssigned = self:IsGroupAssigned( PlayerGroup )
|
||||
self:E( { IsGroupAssigned = IsGroupAssigned } )
|
||||
if IsGroupAssigned then
|
||||
self:AssignToUnit( PlayerUnit )
|
||||
self:MessageToGroups( PlayerUnit:GetPlayerName() .. " joined Task " .. self:GetName() )
|
||||
end
|
||||
@ -259,13 +261,10 @@ end
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Unit#UNIT PlayerUnit The CLIENT or UNIT of the Player aborting the Task.
|
||||
-- @return #boolean true if Unit is part of the Task.
|
||||
function TASK:AbortUnit( PlayerUnit )
|
||||
self:F( { PlayerUnit = PlayerUnit } )
|
||||
|
||||
local PlayerUnitAborted = false
|
||||
function TASK:AbortGroup( PlayerGroup )
|
||||
self:F( { PlayerGroup = PlayerGroup } )
|
||||
|
||||
local PlayerGroups = self:GetGroups()
|
||||
local PlayerGroup = PlayerUnit:GetGroup()
|
||||
|
||||
-- Is the PlayerGroup part of the PlayerGroups?
|
||||
if PlayerGroups:IsIncludeObject( PlayerGroup ) then
|
||||
@ -273,24 +272,39 @@ function TASK:AbortUnit( PlayerUnit )
|
||||
-- Check if the PlayerGroup is already assigned to the Task. If yes, the PlayerGroup is aborted from the Task.
|
||||
-- If the PlayerUnit was the last unit of the PlayerGroup, the menu needs to be removed from the Group.
|
||||
if self:IsStateAssigned() then
|
||||
local IsAssignedToGroup = self:IsAssignedToGroup( PlayerGroup )
|
||||
self:E( { IsAssignedToGroup = IsAssignedToGroup } )
|
||||
if IsAssignedToGroup then
|
||||
local PlayerName = PlayerUnit:GetPlayerName()
|
||||
self:UnAssignFromUnit( PlayerUnit )
|
||||
local IsGroupAssigned = self:IsGroupAssigned( PlayerGroup )
|
||||
self:E( { IsGroupAssigned = IsGroupAssigned } )
|
||||
if IsGroupAssigned then
|
||||
local PlayerName = PlayerGroup:GetUnit(1):GetPlayerName()
|
||||
self:MessageToGroups( PlayerName .. " aborted Task " .. self:GetName() )
|
||||
self:E( { TaskGroup = PlayerGroup:GetName(), GetUnits = PlayerGroup:GetUnits() } )
|
||||
if #PlayerGroup:GetUnits() == 1 then
|
||||
self:UnAssignFromGroup( PlayerGroup )
|
||||
PlayerGroup:SetState( PlayerGroup, "Assigned", nil )
|
||||
self:UnAssignFromGroup( PlayerGroup )
|
||||
--self:Abort()
|
||||
|
||||
-- Now check if the task needs to go to hold...
|
||||
-- It will go to hold, if there are no players in the mission...
|
||||
|
||||
PlayerGroups:Flush()
|
||||
local IsRemaining = false
|
||||
for GroupName, AssignedGroup in pairs( PlayerGroups:GetSet() or {} ) do
|
||||
if self:IsGroupAssigned( AssignedGroup ) == true then
|
||||
IsRemaining = true
|
||||
self:F( { Task = self:GetName(), IsRemaining = IsRemaining } )
|
||||
break
|
||||
end
|
||||
end
|
||||
self:Abort()
|
||||
self:PlayerAborted( PlayerUnit )
|
||||
|
||||
self:F( { Task = self:GetName(), IsRemaining = IsRemaining } )
|
||||
if IsRemaining == false then
|
||||
self:Abort()
|
||||
end
|
||||
|
||||
self:PlayerAborted( PlayerGroup:GetUnit(1) )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
return PlayerUnitAborted
|
||||
return self
|
||||
end
|
||||
|
||||
--- A PlayerUnit crashed in a Task. Abort the Player.
|
||||
@ -313,14 +327,14 @@ function TASK:CrashUnit( PlayerUnit )
|
||||
-- Check if the PlayerGroup is already assigned to the Task. If yes, the PlayerGroup is aborted from the Task.
|
||||
-- If the PlayerUnit was the last unit of the PlayerGroup, the menu needs to be removed from the Group.
|
||||
if self:IsStateAssigned() then
|
||||
local IsAssignedToGroup = self:IsAssignedToGroup( PlayerGroup )
|
||||
self:E( { IsAssignedToGroup = IsAssignedToGroup } )
|
||||
if IsAssignedToGroup then
|
||||
local IsGroupAssigned = self:IsGroupAssigned( PlayerGroup )
|
||||
self:E( { IsGroupAssigned = IsGroupAssigned } )
|
||||
if IsGroupAssigned then
|
||||
self:UnAssignFromUnit( PlayerUnit )
|
||||
self:MessageToGroups( PlayerUnit:GetPlayerName() .. " crashed in Task " .. self:GetName() )
|
||||
self:E( { TaskGroup = PlayerGroup:GetName(), GetUnits = PlayerGroup:GetUnits() } )
|
||||
if #PlayerGroup:GetUnits() == 1 then
|
||||
PlayerGroup:SetState( PlayerGroup, "Assigned", nil )
|
||||
self:ClearGroupAssignment( PlayerGroup )
|
||||
end
|
||||
self:PlayerCrashed( PlayerUnit )
|
||||
end
|
||||
@ -348,40 +362,141 @@ function TASK:GetGroups()
|
||||
return self.SetGroup
|
||||
end
|
||||
|
||||
do -- Group Assignment
|
||||
|
||||
|
||||
--- Assign the @{Task} to a @{Group}.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @return #TASK
|
||||
function TASK:AssignToGroup( TaskGroup )
|
||||
self:F( TaskGroup:GetName() )
|
||||
--- Returns if the @{Task} is assigned to the Group.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @return #boolean
|
||||
function TASK:IsGroupAssigned( TaskGroup )
|
||||
|
||||
local TaskGroupName = TaskGroup:GetName()
|
||||
|
||||
TaskGroup:SetState( TaskGroup, "Assigned", self )
|
||||
|
||||
self:E("Task is assigned to " .. TaskGroup:GetName() )
|
||||
|
||||
local Mission = self:GetMission()
|
||||
local MissionMenu = Mission:GetMenu( TaskGroup )
|
||||
MissionMenu:RemoveSubMenus()
|
||||
|
||||
self:SetAssignedMenuForGroup( TaskGroup )
|
||||
|
||||
local TaskUnits = TaskGroup:GetUnits()
|
||||
for UnitID, UnitData in pairs( TaskUnits ) do
|
||||
local TaskUnit = UnitData -- Wrapper.Unit#UNIT
|
||||
local PlayerName = TaskUnit:GetPlayerName()
|
||||
self:E(PlayerName)
|
||||
if PlayerName ~= nil or PlayerName ~= "" then
|
||||
self:AssignToUnit( TaskUnit )
|
||||
local TaskGroupName = TaskGroup:GetName()
|
||||
|
||||
if self.AssignedGroups[TaskGroupName] then
|
||||
self:T( { "Task is assigned to:", TaskGroup:GetName() } )
|
||||
return true
|
||||
end
|
||||
|
||||
self:T( { "Task is not assigned to:", TaskGroup:GetName() } )
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--- Set @{Group} assigned to the @{Task}.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @return #TASK
|
||||
function TASK:SetGroupAssigned( TaskGroup )
|
||||
|
||||
local TaskName = self:GetName()
|
||||
local TaskGroupName = TaskGroup:GetName()
|
||||
|
||||
self.AssignedGroups[TaskGroupName] = TaskGroup
|
||||
self:E( string.format( "Task %s is assigned to %s", TaskName, TaskGroupName ) )
|
||||
|
||||
-- Set the group to be assigned at mission level. This allows to decide the menu options on mission level for this group.
|
||||
self:GetMission():SetGroupAssigned( TaskGroup )
|
||||
|
||||
local SetAssignedGroups = self:GetGroups()
|
||||
|
||||
SetAssignedGroups:ForEachGroup(
|
||||
function( AssignedGroup )
|
||||
if self:IsGroupAssigned(AssignedGroup) then
|
||||
self:GetMission():GetCommandCenter():MessageToGroup( string.format( "Task %s is assigned to group %s.", TaskName, TaskGroupName ), AssignedGroup )
|
||||
else
|
||||
self:GetMission():GetCommandCenter():MessageToGroup( string.format( "Task %s is assigned to your group.", TaskName ), AssignedGroup )
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Clear the @{Group} assignment from the @{Task}.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @return #TASK
|
||||
function TASK:ClearGroupAssignment( TaskGroup )
|
||||
|
||||
local TaskName = self:GetName()
|
||||
local TaskGroupName = TaskGroup:GetName()
|
||||
|
||||
self.AssignedGroups[TaskGroupName] = nil
|
||||
self:E( string.format( "Task %s is unassigned to %s", TaskName, TaskGroupName ) )
|
||||
|
||||
-- Set the group to be assigned at mission level. This allows to decide the menu options on mission level for this group.
|
||||
self:GetMission():ClearGroupAssignment( TaskGroup )
|
||||
|
||||
local SetAssignedGroups = self:GetGroups()
|
||||
|
||||
SetAssignedGroups:ForEachGroup(
|
||||
function( AssignedGroup )
|
||||
if self:IsGroupAssigned(AssignedGroup) then
|
||||
self:GetMission():GetCommandCenter():MessageToGroup( string.format( "Task %s is unassigned from group %s.", TaskName, TaskGroupName ), AssignedGroup )
|
||||
else
|
||||
self:GetMission():GetCommandCenter():MessageToGroup( string.format( "Task %s is unassigned from your group.", TaskName ), AssignedGroup )
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
do -- Group Assignment
|
||||
|
||||
--- Assign the @{Task} to a @{Group}.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @return #TASK
|
||||
function TASK:AssignToGroup( TaskGroup )
|
||||
self:F( TaskGroup:GetName() )
|
||||
|
||||
local TaskGroupName = TaskGroup:GetName()
|
||||
|
||||
self:SetGroupAssigned( TaskGroup )
|
||||
|
||||
local TaskUnits = TaskGroup:GetUnits()
|
||||
for UnitID, UnitData in pairs( TaskUnits ) do
|
||||
local TaskUnit = UnitData -- Wrapper.Unit#UNIT
|
||||
local PlayerName = TaskUnit:GetPlayerName()
|
||||
self:E(PlayerName)
|
||||
if PlayerName ~= nil or PlayerName ~= "" then
|
||||
self:AssignToUnit( TaskUnit )
|
||||
end
|
||||
end
|
||||
|
||||
local Mission = self:GetMission()
|
||||
local CommandCenter = Mission:GetCommandCenter()
|
||||
CommandCenter:SetMenu()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- UnAssign the @{Task} from a @{Group}.
|
||||
-- @param #TASK self
|
||||
function TASK:UnAssignFromGroup( TaskGroup )
|
||||
self:F2( { TaskGroup } )
|
||||
|
||||
self:ClearGroupAssignment( TaskGroup )
|
||||
|
||||
local TaskUnits = TaskGroup:GetUnits()
|
||||
for UnitID, UnitData in pairs( TaskUnits ) do
|
||||
local TaskUnit = UnitData -- Wrapper.Unit#UNIT
|
||||
local PlayerName = TaskUnit:GetPlayerName()
|
||||
if PlayerName ~= nil or PlayerName ~= "" then
|
||||
self:UnAssignFromUnit( TaskUnit )
|
||||
end
|
||||
end
|
||||
|
||||
local Mission = self:GetMission()
|
||||
local CommandCenter = Mission:GetCommandCenter()
|
||||
CommandCenter:SetMenu()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP FindGroup
|
||||
@ -457,7 +572,7 @@ function TASK:SendBriefingToAssignedGroups()
|
||||
|
||||
for TaskGroupName, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
|
||||
if self:IsAssignedToGroup( TaskGroup ) then
|
||||
if self:IsGroupAssigned( TaskGroup ) then
|
||||
TaskGroup:Message( self.TaskBriefing, 60 )
|
||||
end
|
||||
end
|
||||
@ -474,47 +589,7 @@ function TASK:UnAssignFromGroups()
|
||||
end
|
||||
end
|
||||
|
||||
--- UnAssign the @{Task} from a @{Group}.
|
||||
-- @param #TASK self
|
||||
function TASK:UnAssignFromGroup( TaskGroup )
|
||||
self:F2( { TaskGroup } )
|
||||
|
||||
TaskGroup:SetState( TaskGroup, "Assigned", nil )
|
||||
|
||||
self:E("Task is unassigned from " .. TaskGroup:GetName() )
|
||||
|
||||
self:RemoveAssignedMenuForGroup( TaskGroup )
|
||||
|
||||
local TaskUnits = TaskGroup:GetUnits()
|
||||
for UnitID, UnitData in pairs( TaskUnits ) do
|
||||
local TaskUnit = UnitData -- Wrapper.Unit#UNIT
|
||||
local PlayerName = TaskUnit:GetPlayerName()
|
||||
if PlayerName ~= nil or PlayerName ~= "" then
|
||||
self:UnAssignFromUnit( TaskUnit )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Returns if the @{Task} is assigned to the Group.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @return #boolean
|
||||
function TASK:IsAssignedToGroup( TaskGroup )
|
||||
|
||||
local TaskGroupName = TaskGroup:GetName()
|
||||
|
||||
if self:IsStateAssigned() then
|
||||
if TaskGroup:GetState( TaskGroup, "Assigned" ) == self then
|
||||
self:T( { "Task is assigned to:", TaskGroup:GetName() } )
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
self:T( { "Task is not assigned to:", TaskGroup:GetName() } )
|
||||
return false
|
||||
end
|
||||
|
||||
--- Returns if the @{Task} has still alive and assigned Units.
|
||||
-- @param #TASK self
|
||||
@ -524,7 +599,7 @@ function TASK:HasAliveUnits()
|
||||
|
||||
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
if self:IsStateAssigned() then
|
||||
if self:IsAssignedToGroup( TaskGroup ) then
|
||||
if self:IsGroupAssigned( TaskGroup ) then
|
||||
for TaskUnitID, TaskUnit in pairs( TaskGroup:GetUnits() ) do
|
||||
if TaskUnit:IsAlive() then
|
||||
self:T( { HasAliveUnits = true } )
|
||||
@ -544,9 +619,9 @@ end
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK
|
||||
function TASK:SetMenu( MenuTime ) --R2.1 Mission Reports and Task Reports added. Fixes issue #424.
|
||||
self:F()
|
||||
self:F( { self:GetName(), MenuTime } )
|
||||
|
||||
self.SetGroup:Flush()
|
||||
--self.SetGroup:Flush()
|
||||
for TaskGroupID, TaskGroupData in pairs( self.SetGroup:GetSet() ) do
|
||||
local TaskGroup = TaskGroupData -- Wrapper.Group#GROUP
|
||||
if TaskGroup:IsAlive() and TaskGroup:GetPlayerNames() then
|
||||
@ -565,9 +640,9 @@ function TASK:SetMenu( MenuTime ) --R2.1 Mission Reports and Task Reports added.
|
||||
MENU_GROUP_COMMAND:New( TaskGroup, "Report Held Tasks", TaskGroup.MenuReports, Mission.MenuReportOverview, Mission, TaskGroup, "Hold" )
|
||||
end
|
||||
|
||||
if self:IsStatePlanned() or self:IsStateReplanned() then
|
||||
-- if self:IsStatePlanned() or self:IsStateReplanned() then
|
||||
self:SetMenuForGroup( TaskGroup, MenuTime )
|
||||
end
|
||||
-- end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -580,12 +655,9 @@ end
|
||||
-- @return #TASK
|
||||
function TASK:SetMenuForGroup( TaskGroup, MenuTime )
|
||||
|
||||
if not TaskGroup:GetState( TaskGroup, "Assigned" ) then
|
||||
self:SetPlannedMenuForGroup( TaskGroup, self:GetTaskName(), MenuTime )
|
||||
else
|
||||
if not self:IsAssignedToGroup( TaskGroup ) then
|
||||
self:SetAssignedMenuForGroup( TaskGroup, MenuTime )
|
||||
end
|
||||
self:SetPlannedMenuForGroup( TaskGroup, MenuTime )
|
||||
if self:IsGroupAssigned( TaskGroup ) then
|
||||
self:SetAssignedMenuForGroup( TaskGroup, MenuTime )
|
||||
end
|
||||
end
|
||||
|
||||
@ -596,7 +668,7 @@ end
|
||||
-- @param #string MenuText The menu text.
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK self
|
||||
function TASK:SetPlannedMenuForGroup( TaskGroup, MenuText, MenuTime )
|
||||
function TASK:SetPlannedMenuForGroup( TaskGroup, MenuTime )
|
||||
self:E( TaskGroup:GetName() )
|
||||
|
||||
local Mission = self:GetMission()
|
||||
@ -604,14 +676,21 @@ function TASK:SetPlannedMenuForGroup( TaskGroup, MenuText, MenuTime )
|
||||
local CommandCenter = Mission:GetCommandCenter()
|
||||
local CommandCenterMenu = CommandCenter:GetMenu()
|
||||
|
||||
local TaskType = self:GetType()
|
||||
local TaskText = self:GetName()
|
||||
|
||||
local MissionMenu = MENU_GROUP:New( TaskGroup, MissionName, CommandCenterMenu ):SetTime( MenuTime )
|
||||
|
||||
|
||||
local MissionMenu = Mission:GetMenu( TaskGroup )
|
||||
|
||||
local TaskType = self:GetType()
|
||||
local TaskTypeMenu = MENU_GROUP:New( TaskGroup, TaskType, MissionMenu ):SetTime( MenuTime )
|
||||
local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, MenuText, TaskTypeMenu, self.MenuAssignToGroup, { self = self, TaskGroup = TaskGroup } ):SetTime( MenuTime ):SetRemoveParent( true )
|
||||
local TaskPlannedMenu = MENU_GROUP:New( TaskGroup, "Planned Tasks", MissionMenu ):SetTime( MenuTime )
|
||||
local TaskTypeMenu = MENU_GROUP:New( TaskGroup, TaskType, TaskPlannedMenu ):SetTime( MenuTime ):SetRemoveParent( true )
|
||||
local TaskTypeMenu = MENU_GROUP:New( TaskGroup, TaskText, TaskTypeMenu ):SetTime( MenuTime ):SetRemoveParent( true )
|
||||
local ReportTaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, string.format( "Report Task %s Status", TaskText ), TaskTypeMenu, self.MenuTaskStatus, self, TaskGroup ):SetTime( MenuTime ):SetRemoveParent( true )
|
||||
|
||||
if not Mission:IsGroupAssigned( TaskGroup ) then
|
||||
local JoinTaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, string.format( "Join Task %s", TaskText ), TaskTypeMenu, self.MenuAssignToGroup, { self = self, TaskGroup = TaskGroup } ):SetTime( MenuTime ):SetRemoveParent( true )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
@ -622,15 +701,23 @@ end
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK self
|
||||
function TASK:SetAssignedMenuForGroup( TaskGroup, MenuTime )
|
||||
self:E( TaskGroup:GetName() )
|
||||
self:F( { TaskGroup:GetName(), MenuTime } )
|
||||
|
||||
local Mission = self:GetMission()
|
||||
local MissionName = Mission:GetName()
|
||||
local CommandCenter = Mission:GetCommandCenter()
|
||||
local CommandCenterMenu = CommandCenter:GetMenu()
|
||||
|
||||
local TaskType = self:GetType()
|
||||
local TaskText = self:GetName()
|
||||
|
||||
local MissionMenu = MENU_GROUP:New( TaskGroup, MissionName, CommandCenterMenu ):SetTime( MenuTime )
|
||||
local MissionMenu = Mission:GetMenu( TaskGroup )
|
||||
|
||||
self:E( { MissionMenu = MissionMenu } )
|
||||
|
||||
local TaskTypeMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Task Status", MissionMenu, self.MenuTaskStatus, self, TaskGroup ):SetTime( MenuTime )
|
||||
local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Abort Task", MissionMenu, self.MenuTaskAbort, self, TaskGroup ):SetTime( MenuTime )
|
||||
local TaskAssignedMenu = MENU_GROUP:New( TaskGroup, string.format( "Assigned Task %s", TaskText ), MissionMenu ):SetTime( MenuTime )
|
||||
local TaskTypeMenu = MENU_GROUP_COMMAND:New( TaskGroup, string.format( "Report Task %s Status", TaskText ), TaskAssignedMenu, self.MenuTaskStatus, self, TaskGroup ):SetTime( MenuTime ):SetRemoveParent( true )
|
||||
local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, string.format( "Abort Group from Task %s", TaskText ), TaskAssignedMenu, self.MenuTaskAbort, self, TaskGroup ):SetTime( MenuTime ):SetRemoveParent( true )
|
||||
|
||||
return self
|
||||
end
|
||||
@ -640,14 +727,12 @@ end
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK
|
||||
function TASK:RemoveMenu( MenuTime )
|
||||
self:F()
|
||||
self:F( { self:GetName(), MenuTime } )
|
||||
|
||||
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
local TaskGroup = TaskGroup -- Wrapper.Group#GROUP
|
||||
if TaskGroup:IsAlive() and TaskGroup:GetPlayerNames() then
|
||||
if not self:IsAssignedToGroup( TaskGroup ) then
|
||||
self:RemovePlannedMenuForGroup( TaskGroup, MenuTime )
|
||||
end
|
||||
self:RefreshMenus( TaskGroup, MenuTime )
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -658,24 +743,26 @@ end
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK self
|
||||
function TASK:RemovePlannedMenuForGroup( TaskGroup, MenuTime )
|
||||
self:F()
|
||||
function TASK:RefreshMenus( TaskGroup, MenuTime )
|
||||
self:F( { TaskGroup:GetName(), MenuTime } )
|
||||
|
||||
local Mission = self:GetMission()
|
||||
local MissionName = Mission:GetName()
|
||||
|
||||
local CommandCenter = Mission:GetCommandCenter()
|
||||
local CommandCenterMenu = CommandCenter:GetMenu()
|
||||
|
||||
local MissionMenu = Mission:GetMenu( TaskGroup )
|
||||
|
||||
local TaskText = self:GetName()
|
||||
local PlannedMenu = MissionMenu:GetMenu( "Planned Tasks" )
|
||||
local AssignedMenu = MissionMenu:GetMenu( string.format( "Assigned Task %s", TaskText ) )
|
||||
|
||||
if MissionMenu then
|
||||
local TaskType = self:GetType()
|
||||
local TypeMenu = MissionMenu:GetMenu( TaskType )
|
||||
|
||||
if TypeMenu then
|
||||
local TaskMenu = TypeMenu:GetMenu( self:GetTaskName() )
|
||||
if TaskMenu then
|
||||
TaskMenu:Remove( MenuTime )
|
||||
end
|
||||
end
|
||||
if PlannedMenu then
|
||||
PlannedMenu:Remove( MenuTime )
|
||||
end
|
||||
|
||||
if AssignedMenu then
|
||||
AssignedMenu:Remove( MenuTime )
|
||||
end
|
||||
|
||||
end
|
||||
@ -724,12 +811,7 @@ end
|
||||
-- @param #TASK self
|
||||
function TASK:MenuTaskAbort( TaskGroup )
|
||||
|
||||
for PlayerUnitName, PlayerUnit in pairs( TaskGroup:GetUnits() ) do
|
||||
self:AbortUnit( PlayerUnit )
|
||||
end
|
||||
|
||||
self:GetMission():GetCommandCenter():GetPositionable():MessageToSetGroup( "Abort", 15, self.SetGroup )
|
||||
|
||||
self:AbortGroup( TaskGroup )
|
||||
end
|
||||
|
||||
|
||||
@ -800,13 +882,14 @@ end
|
||||
function TASK:RemoveStateMachine( TaskUnit )
|
||||
self:F( { TaskUnit, self.Fsm[TaskUnit] ~= nil } )
|
||||
|
||||
self:E( self.Fsm )
|
||||
for TaskUnitT, Fsm in pairs( self.Fsm ) do
|
||||
local Fsm = Fsm -- Core.Fsm#FSM_PROCESS
|
||||
self:E( TaskUnitT )
|
||||
Fsm:Remove()
|
||||
end
|
||||
--self:E( self.Fsm )
|
||||
--for TaskUnitT, Fsm in pairs( self.Fsm ) do
|
||||
--local Fsm = Fsm -- Core.Fsm#FSM_PROCESS
|
||||
--self:E( TaskUnitT )
|
||||
--self.Fsm[TaskUnit] = nil
|
||||
--end
|
||||
|
||||
self.Fsm[TaskUnit]:Remove()
|
||||
self.Fsm[TaskUnit] = nil
|
||||
|
||||
collectgarbage()
|
||||
@ -1025,14 +1108,17 @@ function TASK:onenterAssigned( From, Event, To, PlayerUnit, PlayerName )
|
||||
|
||||
self:E( { "Task Assigned", self.Dispatcher } )
|
||||
|
||||
self:MessageToGroups( "Task " .. self:GetName() .. " has been assigned to your group." )
|
||||
|
||||
if self.Dispatcher then
|
||||
self:E( "Firing Assign event " )
|
||||
self.Dispatcher:Assign( self, PlayerUnit, PlayerName )
|
||||
if From ~= "Assigned" then
|
||||
self:GetMission():GetCommandCenter():MessageToCoalition( "Task " .. self:GetName() .. " is assigned." )
|
||||
if self.Dispatcher then
|
||||
self:E( "Firing Assign event " )
|
||||
self.Dispatcher:Assign( self, PlayerUnit, PlayerName )
|
||||
end
|
||||
|
||||
self:GetMission():__Start( 1 )
|
||||
|
||||
self:SetMenu()
|
||||
end
|
||||
|
||||
self:GetMission():__Start( 1 )
|
||||
end
|
||||
|
||||
|
||||
@ -1061,12 +1147,13 @@ end
|
||||
function TASK:onenterAborted( From, Event, To )
|
||||
|
||||
self:E( "Task Aborted" )
|
||||
|
||||
self:GetMission():GetCommandCenter():MessageToCoalition( "Task " .. self:GetName() .. " has been aborted! Task may be replanned." )
|
||||
|
||||
self:UnAssignFromGroups()
|
||||
if From ~= "Aborted" then
|
||||
self:GetMission():GetCommandCenter():MessageToCoalition( "Task " .. self:GetName() .. " has been aborted! Task may be replanned." )
|
||||
self:__Replan( 5 )
|
||||
self:SetMenu()
|
||||
end
|
||||
|
||||
self:__Replan( 5 )
|
||||
end
|
||||
|
||||
--- FSM function for a TASK
|
||||
@ -1106,7 +1193,7 @@ end
|
||||
function TASK:onstatechange( From, Event, To )
|
||||
|
||||
if self:IsTrace() then
|
||||
MESSAGE:New( "@ Task " .. self.TaskName .. " : " .. Event .. " changed to state " .. To, 2 ):ToAll()
|
||||
--MESSAGE:New( "@ Task " .. self.TaskName .. " : " .. From .. " changed to " .. To .. " by " .. Event, 2 ):ToAll()
|
||||
end
|
||||
|
||||
if self.Scores[To] then
|
||||
|
||||
@ -277,9 +277,7 @@ do -- TASK_A2G_DISPATCHER
|
||||
Mission:GetCommandCenter():SetMenu()
|
||||
|
||||
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
if not TaskGroup:GetState( TaskGroup, "Assigned" ) then
|
||||
Mission:GetCommandCenter():MessageToGroup( string.format( "Mission *%s* has tasks %s. Subscribe to a task using the Mission *Overlord* radio menu.", Mission:GetName(), TaskReport:Text(", ") ), TaskGroup )
|
||||
end
|
||||
Mission:GetCommandCenter():MessageToGroup( string.format( "Mission *%s* has tasks %s. Subscribe to a task using the Mission *Overlord* radio menu.", Mission:GetName(), TaskReport:Text(", ") ), TaskGroup )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -1141,7 +1141,7 @@ do -- Players
|
||||
end
|
||||
end
|
||||
|
||||
self:F( PlayerNames )
|
||||
self:F2( PlayerNames )
|
||||
return PlayerNames
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user