From ec973fcc76944a5c012aee5a98349f8edb02b757 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Tue, 3 Apr 2018 07:43:55 +0200 Subject: [PATCH] Working CSAR ... huray --- .../Moose/Dcs/DCSCoalitionObject.lua | 2 +- Moose Development/Moose/Dcs/DCScoalition.lua | 2 + .../Moose/Tasking/CommandCenter.lua | 8 ++ Moose Development/Moose/Tasking/Mission.lua | 4 +- .../Moose/Tasking/Task_Cargo_Dispatcher.lua | 74 +++++++++++-------- Moose Development/Moose/Wrapper/Group.lua | 2 +- 6 files changed, 58 insertions(+), 34 deletions(-) diff --git a/Moose Development/Moose/Dcs/DCSCoalitionObject.lua b/Moose Development/Moose/Dcs/DCSCoalitionObject.lua index be7dc106b..119c9a807 100644 --- a/Moose Development/Moose/Dcs/DCSCoalitionObject.lua +++ b/Moose Development/Moose/Dcs/DCSCoalitionObject.lua @@ -4,7 +4,7 @@ --- @type CoalitionObject -- @extends Dcs.DCSWrapper.Object#Object -coalition = {} --#coalition + --- Returns coalition of the object. -- @function [parent=#CoalitionObject] getCoalition diff --git a/Moose Development/Moose/Dcs/DCScoalition.lua b/Moose Development/Moose/Dcs/DCScoalition.lua index 4ec5f6f10..e51508a3e 100644 --- a/Moose Development/Moose/Dcs/DCScoalition.lua +++ b/Moose Development/Moose/Dcs/DCScoalition.lua @@ -12,3 +12,5 @@ --- @function [parent=#coalition] getCountryCoalition -- @param #number countryId -- @return #number coalitionId + +coalition = coalition -- #coalition diff --git a/Moose Development/Moose/Tasking/CommandCenter.lua b/Moose Development/Moose/Tasking/CommandCenter.lua index e8e4f1d32..e521f63df 100644 --- a/Moose Development/Moose/Tasking/CommandCenter.lua +++ b/Moose Development/Moose/Tasking/CommandCenter.lua @@ -220,6 +220,14 @@ function COMMANDCENTER:GetShortText() end +--- Gets the coalition of the command center. +-- @param #COMMANDCENTER self +-- @return DCScoalition#coalition +function COMMANDCENTER:GetCoalition() + + return self.CommandCenterCoalition +end + --- Gets the POSITIONABLE of the HQ command center. -- @param #COMMANDCENTER self diff --git a/Moose Development/Moose/Tasking/Mission.lua b/Moose Development/Moose/Tasking/Mission.lua index 06a7e7d9b..441b463aa 100644 --- a/Moose Development/Moose/Tasking/Mission.lua +++ b/Moose Development/Moose/Tasking/Mission.lua @@ -29,7 +29,7 @@ MISSION = { -- @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 Dcs.DCSCoalitionWrapper.Object#coalition 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"... +-- @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 function MISSION:New( CommandCenter, MissionName, MissionPriority, MissionBriefing, MissionCoalition ) @@ -265,6 +265,8 @@ function MISSION:New( CommandCenter, MissionName, MissionPriority, MissionBriefi end + + --- FSM function for a MISSION -- @param #MISSION self -- @param #string From diff --git a/Moose Development/Moose/Tasking/Task_Cargo_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_Cargo_Dispatcher.lua index 5795b947b..df9c36dec 100644 --- a/Moose Development/Moose/Tasking/Task_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_Cargo_Dispatcher.lua @@ -177,6 +177,7 @@ do -- TASK_CARGO_DISPATCHER Mission = nil, Tasks = {}, CSAR = {}, + CSARSpawned = 0, } @@ -210,26 +211,6 @@ do -- TASK_CARGO_DISPATCHER -- For CSAR missions, we process the event when a pilot ejects. self:HandleEvent( EVENTS.Ejection ) - - -- Create the CSAR Pilot SPAWN object. - -- Let us create the Template for the replacement Pilot :-) - local Template = { - ["visible"] = false, - ["taskSelected"] = true, - ["hidden"] = false, - ["units"] = - { - [1] = - { - ["type"] = "Soldier M4", - ["skill"] = "Excellent", - ["playerCanDrive"] = false, - }, -- end of [1] - }, -- end of ["units"] - ["task"] = "Ground Nothing", - } - - self.PilotSpawn = SPAWN:NewFromTemplate( Template, "CSAR Pilot" ) return self end @@ -242,19 +223,50 @@ do -- TASK_CARGO_DISPATCHER self:E( { EventData = EventData } ) + self.CSARSpawned = self.CSARSpawned + 1 + local PlaneUnit = EventData.IniUnit local CSARName = EventData.IniUnitName - local PointVec2Spawn = EventData.IniUnit:GetPointVec2() + local CargoPointVec2 = EventData.IniUnit:GetPointVec2() + local CargoCoalition = EventData.IniUnit:GetCoalition() + local CargoCountry = EventData.IniUnit:GetCountry() + + -- Only add a CSAR task if the coalition of the mission is equal to the coalition of the ejected unit. - self.PilotSpawn:InitHeading( EventData.IniUnit:GetHeading() ) -- This will ensure that the new pilot will point towards the same heading as the plane. - self.PilotSpawn:InitCategory( Group.Category.GROUND ) - self.PilotSpawn:InitCountry( EventData.IniUnit:GetCountry() ) - self.PilotSpawn:InitCoalition( EventData.IniUnit:GetCoalition() ) - - self.CSAR[#self.CSAR+1] = {} - self.CSAR[#self.CSAR].PilotGroup = self.PilotSpawn:SpawnFromPointVec2( PointVec2Spawn ) - self.CSAR[#self.CSAR].Task = nil + if CargoCoalition == self.Mission:GetCommandCenter():GetCoalition() then + + -- Create the CSAR Pilot SPAWN object. + -- Let us create the Template for the replacement Pilot :-) + local Template = { + ["visible"] = false, + ["hidden"] = false, + ["task"] = "Ground Nothing", + ["name"] = string.format( "CSAR Pilot#%03d", self.CSARSpawned ), + ["x"] = CargoPointVec2:GetLat(), + ["y"] = CargoPointVec2:GetLon(), + ["units"] = + { + [1] = + { + ["type"] = ( CargoCoalition == coalition.side.BLUE ) and "Soldier M4" or "Infantry AK", + ["name"] = string.format( "CSAR Pilot#%03d-01", self.CSARSpawned ), + ["skill"] = "Excellent", + ["playerCanDrive"] = false, + ["x"] = CargoPointVec2:GetLat(), + ["y"] = CargoPointVec2:GetLon(), + ["heading"] = EventData.IniUnit:GetHeading(), + }, -- end of [1] + }, -- end of ["units"] + } + + local CargoGroup = GROUP:NewTemplate( Template, CargoCoalition, Group.Category.GROUND, CargoCountry ) + + self.CSAR[#self.CSAR+1] = {} + self.CSAR[#self.CSAR].PilotGroup = CargoGroup + self.CSAR[#self.CSAR].Task = nil + + end return self end @@ -294,7 +306,7 @@ do -- TASK_CARGO_DISPATCHER --- Define the deploy zones for the CSAR tasks. -- @param #TASK_CARGO_DISPATCHER self - -- @param DeployZones A list of the deploy zones. + -- @param CSARDeployZones A list of the deploy zones. -- @return #TASK_CARGO_DISPATCHER function TASK_CARGO_DISPATCHER:SetCSARDeployZones( CSARDeployZones ) @@ -361,12 +373,12 @@ do -- TASK_CARGO_DISPATCHER if CSARData.Task then else -- New CSAR Task - self:F( { PilotGroup = CSARData.PilotGroup } ) local SetCargo = self:EvaluateCSAR( CSARData.PilotGroup ) local CSARTask = TASK_CARGO_CSAR:New( Mission, self.SetGroup, string.format( "CSAR.%03d", CSARID ), SetCargo ) CSARTask:SetDeployZones( self.CSARDeployZones or {} ) Mission:AddTask( CSARTask ) TaskReport:Add( CSARTask:GetName() ) + CSARData.Task = CSARTask end end diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 66d9068a3..26062ea09 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -121,7 +121,7 @@ GROUPTEMPLATE.Takeoff = { -- @return #GROUP self function GROUP:NewTemplate( GroupTemplate, CoalitionSide, CategoryID, CountryID ) local GroupName = GroupTemplate.name - _DATABASE:_RegisterGroupTemplate( GroupTemplate, CategoryID, CountryID, CoalitionSide, GroupName ) + _DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, CategoryID, CountryID, GroupName ) self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) self:F2( GroupName ) self.GroupName = GroupName