diff --git a/Moose Development/Moose/Tasking/CommandCenter.lua b/Moose Development/Moose/Tasking/CommandCenter.lua index bbb159668..ac1f310c8 100644 --- a/Moose Development/Moose/Tasking/CommandCenter.lua +++ b/Moose Development/Moose/Tasking/CommandCenter.lua @@ -175,6 +175,14 @@ COMMANDCENTER = { CommunicationMode = "80", } + +--- @type COMMANDCENTER.AutoAssignMethods +COMMANDCENTER.AutoAssignMethods = { + ["Random"] = 1, + ["Distance"] = 2, + ["Priority"] = 3 + } + --- The constructor takes an IDENTIFIABLE as the HQ command center. -- @param #COMMANDCENTER self -- @param Wrapper.Positionable#POSITIONABLE CommandCenterPositionable @@ -192,6 +200,7 @@ function COMMANDCENTER:New( CommandCenterPositionable, CommandCenterName ) self:SetAutoAssignTasks( false ) self:SetAutoAcceptTasks( true ) + self:SetAutoAssignMethod( COMMANDCENTER.AutoAssignMethods.Random ) self:HandleEvent( EVENTS.Birth, --- @param #COMMANDCENTER self @@ -462,7 +471,7 @@ function COMMANDCENTER:GetMenu( TaskGroup ) self.CommandCenterMenus[TaskGroup] = CommandCenterMenu if self.AutoAssignTasks == false then - local AssignTaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Assign Task", CommandCenterMenu, self.AssignRandomTask, self, TaskGroup ):SetTime(MenuTime):SetTag("AutoTask") + local AssignTaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Assign Task", CommandCenterMenu, self.AssignTask, self, TaskGroup ):SetTime(MenuTime):SetTag("AutoTask") end CommandCenterMenu:Remove( MenuTime, "AutoTask" ) @@ -473,22 +482,33 @@ end --- Assigns a random task to a TaskGroup. -- @param #COMMANDCENTER self -- @return #COMMANDCENTER -function COMMANDCENTER:AssignRandomTask( TaskGroup ) +function COMMANDCENTER:AssignTask( TaskGroup ) local Tasks = {} + local AssignPriority = 99999999 + local AutoAssignMethod = self.AutoAssignMethod for MissionID, Mission in pairs( self:GetMissions() ) do local Mission = Mission -- Tasking.Mission#MISSION local MissionTasks = Mission:GetGroupTasks( TaskGroup ) for MissionTaskName, MissionTask in pairs( MissionTasks or {} ) do - Tasks[#Tasks+1] = MissionTask + local TaskPriority = MissionTask:GetAutoAssignPriority( self.AutoAssignMethod, self, TaskGroup ) + if TaskPriority < AssignPriority then + AssignPriority = TaskPriority + Tasks = {} + end + if TaskPriority == AssignPriority then + Tasks[#Tasks+1] = MissionTask + end end end local Task = Tasks[ math.random( 1, #Tasks ) ] -- Tasking.Task#TASK + + self:I( "Assigning task " .. Task:GetName() .. " using auto assign method " .. self.AutoAssignMethod .. " to " .. TaskGroup:GetName() .. " with task priority " .. AssignPriority ) if not self.AutoAcceptTasks == true then - Task:SetAssignMethod( ACT_ASSIGN_MENU_ACCEPT:New( Task.TaskBriefing ) ) + Task:SetAutoAssignMethod( ACT_ASSIGN_MENU_ACCEPT:New( Task.TaskBriefing ) ) end Task:AssignToGroup( TaskGroup ) @@ -551,6 +571,24 @@ function COMMANDCENTER:SetAutoAcceptTasks( AutoAccept ) end + +--- Define the method to be used to assign automatically a task from the available tasks in the mission. +-- There are 3 types of methods that can be applied for the moment: +-- +-- 1. Random - assigns a random task in the mission to the player. +-- 2. Distance - assigns a task based on a distance evaluation from the player. The closest are to be assigned first. +-- 3. Priority - assigns a task based on the priority as defined by the mission designer, using the SetTaskPriority parameter. +-- +-- The different task classes implement the logic to determine the priority of automatic task assignment to a player, depending on one of the above methods. +-- The method @{Tasking.Task#TASK.GetAutoAssignPriority} calculate the priority of the tasks to be assigned. +-- @param #COMMANDCENTER self +-- @param #COMMANDCENTER.AutoAssignMethods AutoAssignMethod A selection of an assign method from the COMMANDCENTER.AutoAssignMethods enumeration. +function COMMANDCENTER:SetAutoAssignMethod( AutoAssignMethod ) + + self.AutoAssignMethod = AutoAssignMethod or COMMANDCENTER.AutoAssignMethods.Random + +end + --- Automatically assigns tasks to all TaskGroups. -- @param #COMMANDCENTER self function COMMANDCENTER:AssignTasks() @@ -568,7 +606,7 @@ function COMMANDCENTER:AssignTasks() -- Only groups with planes or helicopters will receive automatic tasks. -- TODO Workaround DCS-BUG-3 - https://github.com/FlightControl-Master/MOOSE/issues/696 if TaskGroup:IsAir() then - self:AssignRandomTask( TaskGroup ) + self:AssignTask( TaskGroup ) end end end diff --git a/Moose Development/Moose/Tasking/TaskInfo.lua b/Moose Development/Moose/Tasking/TaskInfo.lua index e5b23aa16..95c14ee58 100644 --- a/Moose Development/Moose/Tasking/TaskInfo.lua +++ b/Moose Development/Moose/Tasking/TaskInfo.lua @@ -130,6 +130,15 @@ function TASKINFO:AddCoordinate( Coordinate, Order, Detail, Keep ) end +--- Get the Coordinate. +-- @param #TASKINFO self +-- @return Core.Point#COORDINATE Coordinate +function TASKINFO:GetCoordinate() + return self:GetData( "Coordinate" ) +end + + + --- Add Coordinates. -- @param #TASKINFO self -- @param #list Coordinates diff --git a/Moose Development/Moose/Tasking/Task_A2A.lua b/Moose Development/Moose/Tasking/Task_A2A.lua index bd12b7e43..bb91c02bb 100644 --- a/Moose Development/Moose/Tasking/Task_A2A.lua +++ b/Moose Development/Moose/Tasking/Task_A2A.lua @@ -351,6 +351,26 @@ do -- TASK_A2A end end + --- This function is called from the @{Tasking.CommandCenter#COMMANDCENTER} to determine the method of automatic task selection. + -- @param #TASK_A2A self + -- @param #number AutoAssignMethod The method to be applied to the task. + -- @param Tasking.CommandCenter#COMMANDCENTER CommandCenter The command center. + -- @param Wrapper.Group#GROUP TaskGroup The player group. + function TASK_A2A:GetAutoAssignPriority( AutoAssignMethod, CommandCenter, TaskGroup ) + + if AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Random then + return math.random( 1, 9 ) + elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Distance then + local Coordinate = self.TaskInfo:GetData( "Coordinate" ) + local Distance = TaskGroup:GetCoordinate():Get2DDistance( CommandCenter:GetPositionable():GetCoordinate() ) + return math.floor( Distance ) + elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Priority then + return 1 + end + + return 0 + end + end diff --git a/Moose Development/Moose/Tasking/Task_A2G.lua b/Moose Development/Moose/Tasking/Task_A2G.lua index 634234654..af0d25160 100644 --- a/Moose Development/Moose/Tasking/Task_A2G.lua +++ b/Moose Development/Moose/Tasking/Task_A2G.lua @@ -355,6 +355,26 @@ do -- TASK_A2G end end + + --- This function is called from the @{Tasking.CommandCenter#COMMANDCENTER} to determine the method of automatic task selection. + -- @param #TASK_A2G self + -- @param #number AutoAssignMethod The method to be applied to the task. + -- @param Tasking.CommandCenter#COMMANDCENTER CommandCenter The command center. + -- @param Wrapper.Group#GROUP TaskGroup The player group. + function TASK_A2G:GetAutoAssignPriority( AutoAssignMethod, CommandCenter, TaskGroup ) + + if AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Random then + return math.random( 1, 9 ) + elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Distance then + local Coordinate = self.TaskInfo:GetData( "Coordinate" ) + local Distance = TaskGroup:GetCoordinate():Get2DDistance( CommandCenter:GetPositionable():GetCoordinate() ) + return math.floor( Distance ) + elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Priority then + return 1 + end + + return 0 + end end diff --git a/Moose Development/Moose/Tasking/Task_CARGO.lua b/Moose Development/Moose/Tasking/Task_CARGO.lua index 97a067220..b327ab6a3 100644 --- a/Moose Development/Moose/Tasking/Task_CARGO.lua +++ b/Moose Development/Moose/Tasking/Task_CARGO.lua @@ -1381,6 +1381,23 @@ do -- TASK_CARGO return 0 end + + --- This function is called from the @{Tasking.CommandCenter#COMMANDCENTER} to determine the method of automatic task selection. + -- @param #TASK_CARGO self + -- @param #number AutoAssignMethod The method to be applied to the task. + -- @param Wrapper.Group#GROUP TaskGroup The player group. + function TASK_CARGO:GetAutoAssignPriority( AutoAssignMethod, TaskGroup ) + + if AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Random then + return math.random( 1, 9 ) + elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Distance then + return 0 + elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Priority then + return 1 + end + + return 0 + end diff --git a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua index 0745ea150..8a56784ea 100644 --- a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua +++ b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua @@ -221,7 +221,6 @@ do -- TASK_CAPTURE_ZONE -- @param #TASK_CAPTURE_ZONE self function TASK_CAPTURE_ZONE:UpdateTaskInfo() - local ZoneCoordinate = self.ZoneGoal:GetZone():GetCoordinate() self.TaskInfo:AddCoordinate( ZoneCoordinate, 0, "SOD" ) self.TaskInfo:AddText( "Zone Name", self.ZoneGoal:GetZoneName(), 10, "MOD" ) @@ -230,8 +229,8 @@ do -- TASK_CAPTURE_ZONE function TASK_CAPTURE_ZONE:ReportOrder( ReportGroup ) - local Coordinate = self.TaskInfo:GetData( "Coordinate" ) - --local Coordinate = self.TaskInfo.Coordinates.TaskInfoText + + local Coordinate = self.TaskInfo:GetCoordinate() local Distance = ReportGroup:GetCoordinate():Get2DDistance( Coordinate ) return Distance @@ -262,5 +261,25 @@ do -- TASK_CAPTURE_ZONE self:__Goal( -10, PlayerUnit, PlayerName ) end + --- This function is called from the @{Tasking.CommandCenter#COMMANDCENTER} to determine the method of automatic task selection. + -- @param #TASK_CAPTURE_ZONE self + -- @param #number AutoAssignMethod The method to be applied to the task. + -- @param Tasking.CommandCenter#COMMANDCENTER CommandCenter The command center. + -- @param Wrapper.Group#GROUP TaskGroup The player group. + function TASK_CAPTURE_ZONE:GetAutoAssignPriority( AutoAssignMethod, CommandCenter, TaskGroup ) + + if AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Random then + return math.random( 1, 9 ) + elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Distance then + local Coordinate = self.TaskInfo:GetCoordinate() + local Distance = TaskGroup:GetCoordinate():Get2DDistance( CommandCenter:GetPositionable():GetCoordinate() ) + return math.floor( Distance ) + elseif AutoAssignMethod == COMMANDCENTER.AutoAssignMethods.Priority then + return 1 + end + + return 0 + end + end diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index a3462e786..a068d6a72 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -2355,7 +2355,7 @@ do -- Route methods -- Calculate the direct distance between the initial and final points. local LengthDirect=FromCoordinate:Get2DDistance(ToCoordinate) - if GotPath then + if GotPath and LengthRoad then -- Off road part of the rout: Total=OffRoad+OnRoad. LengthOffRoad=LengthOnRoad-LengthRoad @@ -2378,7 +2378,7 @@ do -- Route methods local canroad=false -- Check if a valid path on road could be found. - if GotPath and LengthDirect > 2000 then -- if the length of the movement is less than 1 km, drive directly. + if GotPath and LengthRoad and LengthDirect > 2000 then -- if the length of the movement is less than 1 km, drive directly. -- Check whether the road is very long compared to direct path. if LongRoad and Shortcut then