From a33e542df5fca1273f7f6b2b4258d47bd5ff550b Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 8 Jan 2025 13:04:54 +0100 Subject: [PATCH] xx --- Moose Development/Moose/Core/Set.lua | 7 ++ .../Moose/Functional/Tiresias.lua | 98 +++++++++++++++---- Moose Development/Moose/Ops/EasyGCICAP.lua | 27 ++++- 3 files changed, 107 insertions(+), 25 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 96b629660..5cd4d8681 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -1538,6 +1538,13 @@ do local size = 1 if Event.IniDCSGroup then size = Event.IniDCSGroup:getSize() + elseif Event.IniDCSGroupName then + local grp = Group.getByName(Event.IniDCSGroupName) + if grp then + size = grp:getSize() + end + elseif Object:IsAlive() then + size = Object:CountAliveUnits() end if size == 1 then -- Only remove if the last unit of the group was destroyed. self:Remove( ObjectName ) diff --git a/Moose Development/Moose/Functional/Tiresias.lua b/Moose Development/Moose/Functional/Tiresias.lua index 83cc02bba..a459bacf0 100644 --- a/Moose Development/Moose/Functional/Tiresias.lua +++ b/Moose Development/Moose/Functional/Tiresias.lua @@ -27,13 +27,13 @@ -- @module Functional.Tiresias -- @image Functional.Tiresias.jpg -- --- Last Update: Dec 2023 +-- Last Update: Jan 2024 ------------------------------------------------------------------------- --- **TIRESIAS** class, extends Core.Base#BASE -- @type TIRESIAS -- @field #string ClassName --- @field #booelan debug +-- @field #boolean debug -- @field #string version -- @field #number Interval -- @field Core.Set#SET_GROUP GroundSet @@ -47,7 +47,8 @@ -- @field #number HeloSwitchRange -- @field #number PlaneSwitchRange -- @field Core.Set#SET_GROUP FlightSet --- @field #boolean SwitchAAA +-- @field #boolean SwitchAAA +-- @field #boolean SwitchSAM -- @extends Core.Fsm#FSM --- @@ -97,7 +98,7 @@ TIRESIAS = { ClassName = "TIRESIAS", debug = false, - version = "0.0.5", + version = "0.0.6", Interval = 20, GroundSet = nil, VehicleSet = nil, @@ -107,7 +108,10 @@ TIRESIAS = { AAARange = 60, -- 60% HeloSwitchRange = 10, -- NM PlaneSwitchRange = 25, -- NM + SAMSwitchRange = 75, --NM SwitchAAA = true, + SwitchSAM = false, + MantisHandlingSAM = true } --- [USER] Create a new Tiresias object and start it up. @@ -129,7 +133,7 @@ function TIRESIAS:New() self:AddTransition("*", "Status", "*") -- TIRESIAS status update. self:AddTransition("*", "Stop", "Stopped") -- Stop FSM. - self.ExceptionSet = SET_GROUP:New():Clear(false) + --self.ExceptionSet = SET_GROUP:New():Clear(false) self:HandleEvent(EVENTS.PlayerEnterAircraft,self._EventHandler) @@ -169,10 +173,12 @@ end -- @param #TIRESIAS self -- @param #number HeloMiles Radius around a Helicopter in which AI ground units will be activated. Defaults to 10NM. -- @param #number PlaneMiles Radius around an Airplane in which AI ground units will be activated. Defaults to 25NM. +-- @param #number SAMMiles Radius around an Airplane in which SAM AI ground units will be activated. Defaults to 75NM. -- @return #TIRESIAS self -function TIRESIAS:SetActivationRanges(HeloMiles,PlaneMiles) +function TIRESIAS:SetActivationRanges(HeloMiles,PlaneMiles,SAMMiles) self.HeloSwitchRange = HeloMiles or 10 self.PlaneSwitchRange = PlaneMiles or 25 + self.SAMSwitchRange = SAMMiles or 75 return self end @@ -187,12 +193,28 @@ function TIRESIAS:SetAAARanges(FiringRange,SwitchAAA) return self end +--- [USER] Set if TIRESIAS is also taking care or SAM installtions. +-- @param #TIRESIAS self +-- @param #boolean OnOff Set to true to switch on, false to switch off. Default is false. +-- @param #boolean MantisPresent Set to true to switch on, false to switch off. Default is true. +-- @return #TIRESIAS self +function TIRESIAS:SetSwitchSAM(OnOff,MantisPresent) + if OnOff == nil or OnOff == false then + self.SwitchSAM = false + else + self.SwitchSAM = true + end + self.MantisHandlingSAM = MantisPresent or true + return self +end + --- [USER] Add a SET_GROUP of GROUP objects as exceptions. Can be done multiple times. Does **not** work work for GROUP objects spawned into the SET after start, i.e. the groups need to exist in the game already. -- @param #TIRESIAS self -- @param Core.Set#SET_GROUP Set to add to the exception list. -- @return #TIRESIAS self function TIRESIAS:AddExceptionSet(Set) self:T(self.lid.."AddExceptionSet") + if not self.ExceptionSet then self.ExceptionSet = SET_GROUP:New():Clear(false) end local exceptions = self.ExceptionSet Set:ForEachGroupAlive( function(grp) @@ -242,9 +264,9 @@ function TIRESIAS._FilterAAA(Group) local grp = Group -- Wrapper.Group#GROUP local isaaa = grp:IsAAA() if isaaa == true and grp:IsGround() and not grp:IsShip() then - return true -- remove from SET + return true -- keep in SET else - return false -- keep in SET + return false -- remove from SET end end @@ -255,9 +277,9 @@ function TIRESIAS._FilterSAM(Group) local grp = Group -- Wrapper.Group#GROUP local issam = grp:IsSAM() if issam == true and grp:IsGround() and not grp:IsShip() then - return true -- remove from SET + return true -- keep in SET else - return false -- keep in SET + return false -- remove from SET end end @@ -269,6 +291,7 @@ function TIRESIAS:_InitGroups() -- Set all groups invisible/motionless local EngageRange = self.AAARange local SwitchAAA = self.SwitchAAA + local SwitchSAM = self.SwitchSAM --- AAA self.AAASet:ForEachGroupAlive( function(grp) @@ -287,7 +310,7 @@ function TIRESIAS:_InitGroups() AIOff = SwitchAAA, } end - if grp.Tiresias and (not grp.Tiresias.exception == true) then + if grp.Tiresias and (grp.Tiresias.exception == false) then if grp.Tiresias.invisible and grp.Tiresias.invisible == false then grp:SetCommandInvisible(true) grp.Tiresias.invisible = true @@ -332,16 +355,18 @@ function TIRESIAS:_InitGroups() grp.Tiresias = { -- #TIRESIAS.Data type = "SAM", invisible = true, - exception = false, + exception = not SwitchSAM, + AIOff = SwitchSAM, } end - if grp.Tiresias and (not grp.Tiresias.exception == true) then + if grp.Tiresias and (grp.Tiresias.exception == false) then if grp.Tiresias and grp.Tiresias.invisible and grp.Tiresias.invisible == false then grp:SetCommandInvisible(true) grp.Tiresias.invisible = true + grp:SetAIOnOff(SwitchSAM) end end - --BASE:I(string.format("Init/Switch off SAM %s (Exception %s)",grp:GetName(),tostring(grp.Tiresias.exception))) + BASE:I(string.format("Init/Switch off SAM %s (Exception %s)",grp:GetName(),tostring(grp.Tiresias.exception))) end ) return self @@ -381,18 +406,22 @@ end function TIRESIAS:_SwitchOnGroups(group,radius) self:T(self.lid.."_SwitchOnGroups "..group:GetName().." Radius "..radius.." NM") local zone = ZONE_GROUP:New("Zone-"..group:GetName(),group,UTILS.NMToMeters(radius)) + local samzone = ZONE_GROUP:New("ZoneSAM-"..group:GetName(),group,UTILS.NMToMeters(self.SAMSwitchRange)) local ground = SET_GROUP:New():FilterCategoryGround():FilterZones({zone}):FilterOnce() + local sam = SET_GROUP:New():FilterFunction(self._FilterSAM):FilterZones({samzone}):FilterOnce() local count = ground:CountAlive() if self.debug then local text = string.format("There are %d groups around this plane or helo!",count) self:I(text) end local SwitchAAA = self.SwitchAAA + local SwitchSAM = self.SwitchSAM + local MantisHandling = self.MantisHandlingSAM if ground:CountAlive() > 0 then ground:ForEachGroupAlive( function(grp) local name = grp:GetName() - if grp.Tiresias and grp.Tiresias.type and (not grp.Tiresias.exception == true ) then + if grp.Tiresias and grp.Tiresias.exception and (grp.Tiresias.exception == false ) then if grp.Tiresias.invisible == true then grp:SetCommandInvisible(false) grp.Tiresias.invisible = false @@ -401,18 +430,39 @@ function TIRESIAS:_SwitchOnGroups(group,radius) grp:SetAIOn() grp.Tiresias.AIOff = false end - if SwitchAAA and grp.Tiresias.type == "AAA" and grp.Tiresias.AIOff and grp.Tiresias.AIOff == true then + if (SwitchAAA) and (grp.Tiresias.type == "AAA") and grp.Tiresias.AIOff and grp.Tiresias.AIOff == true then grp:SetAIOn() grp:EnableEmission(true) grp.Tiresias.AIOff = false - end - --BASE:I(string.format("TIRESIAS - Switch on %s %s (Exception %s)",tostring(grp.Tiresias.type),grp:GetName(),tostring(grp.Tiresias.exception))) + end + BASE:I(string.format("TIRESIAS - Switch on %s %s (Exception %s)",tostring(grp.Tiresias.type),grp:GetName(),tostring(grp.Tiresias.exception))) else BASE:T("TIRESIAS - This group "..tostring(name).. " has not been initialized or is an exception!") end end ) end + if sam:CountAlive() > 0 and self.SwitchSAM == true then + sam:ForEachGroupAlive( + function(grp) + local name = grp:GetName() + BASE:I(string.format("%s - %s",name,tostring(SwitchSAM))) + UTILS.PrintTableToLog(grp.Tiresias) + if SwitchSAM and grp.Tiresias.type == "SAM" and grp.Tiresias.AIOff and grp.Tiresias.AIOff == true then + BASE:I("First check passed") + if grp.Tiresias.exception ~= true then + BASE:I("Second check passed") + grp:SetAIOn() + if not MantisHandling then + grp:EnableEmission(true) + end + grp.Tiresias.AIOff = false + BASE:I(string.format("TIRESIAS - Switch on %s %s (Exception %s)",tostring(grp.Tiresias.type),grp:GetName(),tostring(grp.Tiresias.exception))) + end + end + end + ) + end return self end @@ -502,14 +552,22 @@ function TIRESIAS:onafterStart(From, Event, To) end end + local SwitchSAM = self.SwitchSAM + local MantisManages = self.MantisHandlingSAM + function SAMSet:OnAfterAdded(From,Event,To,ObjectName,Object) if Object and Object:IsAlive() then BASE:I("TIRESIAS: SAM Object Added: "..Object:GetName()) Object:SetCommandInvisible(true) + if SwitchSAM then + Object:SetAIOff() + Object:EnableEmission(not MantisManages) + end Object.Tiresias = { -- #TIRESIAS.Data type = "SAM", invisible = true, - exception = false, + exception = not SwitchSAM, + AIOff = SwitchSAM, } end end @@ -547,7 +605,7 @@ end -- @return #TIRESIAS self function TIRESIAS:onafterStatus(From, Event, To) self:T({From, Event, To}) - if self.debug then + if self.debug then local count = self.VehicleSet:CountAlive() local AAAcount = self.AAASet:CountAlive() local SAMcount = self.SAMSet:CountAlive() diff --git a/Moose Development/Moose/Ops/EasyGCICAP.lua b/Moose Development/Moose/Ops/EasyGCICAP.lua index ab45fa6c7..93f6fcf3b 100644 --- a/Moose Development/Moose/Ops/EasyGCICAP.lua +++ b/Moose Development/Moose/Ops/EasyGCICAP.lua @@ -348,9 +348,23 @@ function EASYGCICAP:SetTankerAndAWACSInvisible(Switch) return self end ---- Set Maximum of alive missions to stop airplanes spamming the map +--- Count alive missions in our internal stack. -- @param #EASYGCICAP self --- @param #number Maxiumum Maxmimum number of parallel missions allowed. Count is Cap-Missions + Intercept-Missions + Alert5-Missionsm default is 8 +-- @return #number count +function EASYGCICAP:_CountAliveAuftrags() + local alive = 0 + for _,_auftrag in pairs(self.ListOfAuftrag) do + local auftrag = _auftrag -- Ops.Auftrag#AUFTRAG + if auftrag and (not (auftrag:IsCancelled() or auftrag:IsDone() or auftrag:IsOver())) then + alive = alive + 1 + end + end + return alive +end + +--- Set Maximum of alive missions created by this instance to stop airplanes spamming the map +-- @param #EASYGCICAP self +-- @param #number Maxiumum Maxmimum number of parallel missions allowed. Count is Intercept-Missions + Alert5-Missions, default is 8 -- @return #EASYGCICAP self function EASYGCICAP:SetMaxAliveMissions(Maxiumum) self:T(self.lid.."SetMaxAliveMissions") @@ -1242,9 +1256,10 @@ function EASYGCICAP:_AssignIntercept(Cluster) -- Do we have a matching airwing? if targetairwing then local AssetCount = targetairwing:CountAssetsOnMission(MissionTypes,Cohort) + local missioncount = self:_CountAliveAuftrags() -- Enough airframes on mission already? self:T(self.lid.." Assets on Mission "..AssetCount) - if AssetCount <= MaxAliveMissions then + if missioncount < MaxAliveMissions then local repeats = repeatsonfailure local InterceptAuftrag = AUFTRAG:NewINTERCEPT(contact.group) :SetMissionRange(150) @@ -1429,12 +1444,14 @@ function EASYGCICAP:onafterStatus(From,Event,To) local text = "GCICAP "..self.alias text = text.."\nWings: "..wings.."\nSquads: "..squads.."\nCapPoints: "..caps.."\nAssets on Mission: "..assets.."\nAssets in Stock: "..instock text = text.."\nThreats: "..threatcount - text = text.."\nMissions: "..capmission+interceptmission + text = text.."\nAirWing managed Missions: "..capmission+awacsmission+tankermission+reconmission text = text.."\n - CAP: "..capmission - text = text.."\n - Intercept: "..interceptmission text = text.."\n - AWACS: "..awacsmission text = text.."\n - TANKER: "..tankermission text = text.."\n - Recon: "..reconmission + text = text.."\nSelf managed Missions:" + text = text.."\n - Mission Limit: "..self.MaxAliveMissions + text = text.."\n - Alert5+Intercept "..self:_CountAliveAuftrags() MESSAGE:New(text,15,"GCICAP"):ToAll():ToLogIf(self.debug) end self:__Status(30)