From 7306bf28e0521a377f61e4e52270023a119822b7 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 17 Dec 2021 13:26:27 +0100 Subject: [PATCH] OPS - CHIEF: fixed ground groups deployment - AUFTRAG: minor fixes - OPSGROUP: emission option --- Moose Development/Moose/Ops/ArmyGroup.lua | 7 +-- Moose Development/Moose/Ops/Auftrag.lua | 12 ++--- Moose Development/Moose/Ops/Chief.lua | 35 ++++++------- Moose Development/Moose/Ops/NavyGroup.lua | 1 + Moose Development/Moose/Ops/OpsGroup.lua | 64 +++++++++++++++++++++-- 5 files changed, 85 insertions(+), 34 deletions(-) diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index c8aec60ab..53780719e 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -103,7 +103,8 @@ function ARMYGROUP:New(group) -- Defaults self:SetDefaultROE() self:SetDefaultAlarmstate() - self:SetDefaultEPLRS(self.isEPLRS) + self:SetDefaultEPLRS(self.isEPLRS) + self:SetDefaultEmission() self:SetDetection() self:SetPatrolAdInfinitum(false) self:SetRetreatZones() @@ -1726,7 +1727,7 @@ function ARMYGROUP:SwitchFormation(Formation, Permanently, NoRouteUpdate) self.option.Formation=Formation if self:IsInUtero() then - self:T(self.lid..string.format("Will switch formation to %s (permanently=%s) when group is spawned", self.option.Formation, tostring(Permanently))) + self:T(self.lid..string.format("Will switch formation to %s (permanently=%s) when group is spawned", tostring(self.option.Formation), tostring(Permanently))) else -- Update route with the new formation. @@ -1736,7 +1737,7 @@ function ARMYGROUP:SwitchFormation(Formation, Permanently, NoRouteUpdate) end -- Debug info. - self:T(self.lid..string.format("Switching formation to %s (permanently=%s)", self.option.Formation, tostring(Permanently))) + self:T(self.lid..string.format("Switching formation to %s (permanently=%s)", tostring(self.option.Formation), tostring(Permanently))) end diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index d88f8f4dc..d290944dd 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -4244,13 +4244,7 @@ function AUFTRAG:_TargetFromObject(Object) self.engageTarget=TARGET:New(Object) end - - if self.type == AUFTRAG.Type.ALERT5 then - self.alert5Target = self.engageTarget - - end - else -- Target was already specified elsewhere. @@ -4378,10 +4372,10 @@ function AUFTRAG:GetTargetCoordinate() local coord=self.engageTarget:GetCoordinate() return coord - elseif self.alert5Target then + elseif self.type==AUFTRAG.Type.ALERT5 then - local coord=self.alert5Target:GetCoordinate() - return coord + -- For example, COMMANDER will not assign a coordiante. This will be done later, when the mission is assigned to an airwing. + return nil else self:E(self.lid.."ERROR: Cannot get target coordinate!") diff --git a/Moose Development/Moose/Ops/Chief.lua b/Moose Development/Moose/Ops/Chief.lua index 8a0ede2be..266107f3f 100644 --- a/Moose Development/Moose/Ops/Chief.lua +++ b/Moose Development/Moose/Ops/Chief.lua @@ -1752,12 +1752,12 @@ function CHIEF:CheckOpsZoneQueue() self:T3(self.lid..string.format("Zone is empty ==> Recruit Patrol zone infantry assets")) -- Recruit ground assets that - local recruited=self:RecruitAssetsForZone(stratzone, AUFTRAG.Type.ONGUARD, 1, 3, {Group.Category.GROUND}, {GROUP.Attribute.GROUND_INFANTRY, GROUP.Attribute.GROUND_TANK}) - local recruited1=self:RecruitAssetsForZone(stratzone, AUFTRAG.Type.ARMOREDGUARD, 1, 1, {Group.Category.GROUND}, {GROUP.Attribute.GROUND_TANK}) + local recruitedI=self:RecruitAssetsForZone(stratzone, AUFTRAG.Type.ONGUARD, 1, 3, {Group.Category.GROUND}, {GROUP.Attribute.GROUND_INFANTRY}) + local recruitedT=self:RecruitAssetsForZone(stratzone, AUFTRAG.Type.ARMOREDGUARD, 1, 1, {Group.Category.GROUND}, {GROUP.Attribute.GROUND_TANK}) -- Debug info. - self:T(self.lid..string.format("Zone is empty ==> Recruit Patrol zone infantry assets=%s", tostring(recruited))) - self:T(self.lid..string.format("Zone is empty ==> Recruit Patrol zone armored assets=%s", tostring(recruited1))) + self:T(self.lid..string.format("Zone is empty ==> Recruit Patrol zone infantry assets=%s", tostring(recruitedI))) + self:T(self.lid..string.format("Zone is empty ==> Recruit Patrol zone armored assets=%s", tostring(recruitedT))) end else @@ -2198,10 +2198,13 @@ function CHIEF:RecruitAssetsForZone(StratZone, MissionType, NassetsMin, NassetsM if recruited then + -- Debug messgage. + self:T2(self.lid..string.format("Recruited %d assets for %s mission STRATEGIC zone %s", #assets, MissionType, tostring(StratZone.opszone.zoneName))) + if MissionType==AUFTRAG.Type.PATROLZONE or MissionType==AUFTRAG.Type.ONGUARD then -- Debug messgage. - self:T2(self.lid..string.format("Recruited %d assets from for PATROL mission", #assets)) + self:T2(self.lid..string.format("Recruited %d assets for PATROL mission", #assets)) local recruitedTrans=true local transport=nil @@ -2209,8 +2212,7 @@ function CHIEF:RecruitAssetsForZone(StratZone, MissionType, NassetsMin, NassetsM -- Categories. Currently only helicopters are allowed due to problems with ground transports (might get stuck, might not be a land connection. -- TODO: Check if ground transport is possible. For example, by trying land.getPathOnRoad or something. - local Categories={self.TransportCategories} - --local Categories={Group.Category.HELICOPTER, Group.Category.GROUND} + local Categories=self.TransportCategories -- Recruit transport assets for infantry. recruitedTrans, transport=LEGION.AssignAssetsForTransport(self.commander, self.commander.legions, assets, 1, 1, StratZone.opszone.zone, nil, Categories) @@ -2242,9 +2244,7 @@ function CHIEF:RecruitAssetsForZone(StratZone, MissionType, NassetsMin, NassetsM self:MissionAssign(mission, legions) -- Attach mission to ops zone. - -- TODO: Need a better way! - --StratZone.missionPatrol=mission - StratZone.opszone:_AddMission(self.coalition,MissionType,mission) + StratZone.opszone:_AddMission(self.coalition, MissionType, mission) return true else @@ -2281,9 +2281,7 @@ function CHIEF:RecruitAssetsForZone(StratZone, MissionType, NassetsMin, NassetsM self:MissionAssign(mission, legions) -- Attach mission to ops zone. - -- TODO: Need a better way! - --StratZone.missionCAS=mission - StratZone.opszone:_AddMission(self.coalition,MissionType,mission) + StratZone.opszone:_AddMission(self.coalition, MissionType, mission) return true elseif MissionType==AUFTRAG.Type.ARTY then @@ -2303,9 +2301,7 @@ function CHIEF:RecruitAssetsForZone(StratZone, MissionType, NassetsMin, NassetsM self:MissionAssign(mission, legions) -- Attach mission to ops zone. - -- TODO: Need a better way! - --StratZone.missionARTY=mission - StratZone.opszone:_AddMission(self.coalition,MissionType,mission) + StratZone.opszone:_AddMission(self.coalition, MissionType, mission) return true elseif MissionType==AUFTRAG.Type.ARMOREDGUARD then @@ -2324,15 +2320,16 @@ function CHIEF:RecruitAssetsForZone(StratZone, MissionType, NassetsMin, NassetsM self:MissionAssign(mission, legions) -- Attach mission to ops zone. - -- TODO: Need a better way! - --StratZone.missionARTY=mission - StratZone.opszone:_AddMission(self.coalition,MissionType,mission) + StratZone.opszone:_AddMission(self.coalition, MissionType, mission) return true end end + -- Debug messgage. + self:T2(self.lid..string.format("Could NOT recruit assets for %s mission of STRATEGIC zone %s", MissionType, tostring(StratZone.opszone.zoneName))) + return false end diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index e34549feb..a46183e47 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -134,6 +134,7 @@ function NAVYGROUP:New(group) self:SetDefaultROE() self:SetDefaultAlarmstate() self:SetDefaultEPLRS(self.isEPLRS) + self:SetDefaultEmission() self:SetDetection() self:SetPatrolAdInfinitum(true) self:SetPathfinding(false) diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 666b7735f..4a44b31c3 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -334,6 +334,7 @@ OPSGROUP.TaskType={ -- @field #number Formation Formation. -- @field #boolean EPLRS data link. -- @field #boolean Disperse Disperse under fire. +-- @field #boolen Emission Emission on/off. --- Weapon range data. -- @type OPSGROUP.WeaponData @@ -9651,7 +9652,7 @@ function OPSGROUP:GetAlarmstate() return self.option.Alarm or self.optionDefault.Alarm end ---- Set the default Alarm State for the group. This is the state gets when the group is spawned or to which it defaults back after a mission. +--- Set the default EPLRS for the group. -- @param #OPSGROUP self -- @param #boolean OnOffSwitch If `true`, EPLRS is on by default. If `false` default EPLRS setting is off. If `nil`, default is on if group has EPLRS and off if it does not have a datalink. -- @return #OPSGROUP self @@ -9693,7 +9694,7 @@ function OPSGROUP:SwitchEPLRS(OnOffSwitch) end else - self:E(self.lid.."WARNING: Cannot switch Alarm State! Group is not alive") + self:E(self.lid.."WARNING: Cannot switch EPLRS! Group is not alive") end return self @@ -9706,6 +9707,61 @@ function OPSGROUP:GetEPLRS() return self.option.EPLRS or self.optionDefault.EPLRS end +--- Set the default EPLRS for the group. +-- @param #OPSGROUP self +-- @param #boolean OnOffSwitch If `true`, EPLRS is on by default. If `false` default EPLRS setting is off. If `nil`, default is on if group has EPLRS and off if it does not have a datalink. +-- @return #OPSGROUP self +function OPSGROUP:SetDefaultEmission(OnOffSwitch) + + if OnOffSwitch==nil then + self.optionDefault.Emission=true + else + self.optionDefault.EPLRS=OnOffSwitch + end + + return self +end + +--- Switch emission on or off. +-- @param #OPSGROUP self +-- @param #boolean OnOffSwitch If `true` or `nil`, switch emission on. If `false` emission switched off. +-- @return #OPSGROUP self +function OPSGROUP:SwitchEmission(OnOffSwitch) + + if self:IsAlive() or self:IsInUtero() then + + if OnOffSwitch==nil then + + self.option.Emission=self.optionDefault.Emission + + else + + self.option.Emission=OnOffSwitch + + end + + if self:IsInUtero() then + self:T2(self.lid..string.format("Setting current EMISSION=%s when GROUP is SPAWNED", tostring(self.option.Emission))) + else + + self.group:EnableEmission(self.option.Emission) + self:T(self.lid..string.format("Setting current EMISSION=%s", tostring(self.option.Emission))) + + end + else + self:E(self.lid.."WARNING: Cannot switch Emission! Group is not alive") + end + + return self +end + +--- Get current emission state. +-- @param #OPSGROUP self +-- @return #boolean If `true`, emission is on. +function OPSGROUP:GetEmission() + return self.option.Emission or self.optionDefault.Emission +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- SETTINGS FUNCTIONS ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -10134,7 +10190,7 @@ function OPSGROUP:SwitchFormation(Formation) self.option.Formation=Formation -- Debug info. - self:T(self.lid..string.format("Switching formation to %d", self.option.Formation)) + self:T(self.lid..string.format("Switching formation to %s", tostring(self.option.Formation))) end @@ -11157,6 +11213,8 @@ function OPSGROUP:_AddElementByName(unitname) element.category=unit:GetUnitCategory() element.categoryname=unit:GetCategoryName() element.typename=unit:GetTypeName() + + --self:I({desc=element.descriptors}) -- Ammo.