From 24536fa2962eff0f00b0ea11ee5c85f87e1577ac Mon Sep 17 00:00:00 2001 From: dnqbob Date: Sun, 10 Sep 2023 19:12:32 +0800 Subject: [PATCH] Fix Air Squad danger detection broken in RA --- .../Traits/BotModules/SquadManagerBotModule.cs | 3 +++ .../Traits/BotModules/Squads/States/AirStates.cs | 11 ++++------- mods/ra/rules/ai.yaml | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index edbde4899e..b85fc33972 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -47,6 +47,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Own actor types that are prioritized when defending.")] public readonly HashSet ProtectionTypes = new(); + [Desc("Target types are used for identifying aircraft.")] + public readonly BitSet AircraftTargetType = new("Air"); + [Desc("Minimum number of units AI must have before attacking.")] public readonly int SquadSize = 8; diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs index 6819d1232f..6f4609e61e 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/AirStates.cs @@ -11,18 +11,15 @@ using System.Collections.Generic; using System.Linq; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.BotModules.Squads { abstract class AirStateBase : StateBase { - static readonly BitSet AirTargetTypes = new("Air"); - protected const int MissileUnitMultiplier = 3; - protected static int CountAntiAirUnits(IReadOnlyCollection units) + protected static int CountAntiAirUnits(Squad owner, IReadOnlyCollection units) { if (units.Count == 0) return 0; @@ -40,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads foreach (var a in ab.Armaments) { - if (a.Weapon.IsValidTarget(AirTargetTypes)) + if (a.Weapon.IsValidTarget(owner.SquadManager.Info.AircraftTargetType)) { missileUnitsCount++; break; @@ -99,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads if (unitsAroundPos.Count == 0) return true; - if (CountAntiAirUnits(unitsAroundPos) * MissileUnitMultiplier < owner.Units.Count) + if (CountAntiAirUnits(owner, unitsAroundPos) * MissileUnitMultiplier < owner.Units.Count) { detectedEnemyTarget = unitsAroundPos.Random(owner.Random); return true; @@ -111,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads // Checks the number of anti air enemies around units protected virtual bool ShouldFlee(Squad owner) { - return ShouldFlee(owner, enemies => CountAntiAirUnits(enemies) * MissileUnitMultiplier > owner.Units.Count); + return ShouldFlee(owner, enemies => CountAntiAirUnits(owner, enemies) * MissileUnitMultiplier > owner.Units.Count); } } diff --git a/mods/ra/rules/ai.yaml b/mods/ra/rules/ai.yaml index b4390eff9f..512d91c8eb 100644 --- a/mods/ra/rules/ai.yaml +++ b/mods/ra/rules/ai.yaml @@ -292,6 +292,7 @@ Player: ExcludeFromSquadsTypes: harv, mcv, dog, badr.bomber, u2 ConstructionYardTypes: fact AirUnitsTypes: mig, yak, heli, hind, mh60 + AircraftTargetType: AirborneActor ProtectionTypes: harv, mcv, mslo, gap, spen, syrd, iron, pdox, tsla, agun, dome, pbox, hbox, gun, ftur, sam, atek, weap, fact, proc, silo, hpad, afld, afld.ukraine, powr, apwr, stek, barr, kenn, tent, fix, fpwr, tenf, syrf, spef, weaf, domf, fixf, fapw, atef, pdof, mslf, facf IgnoredEnemyTargetTypes: AirborneActor McvManagerBotModule: @@ -333,6 +334,7 @@ Player: ConstructionYardTypes: fact NavalProductionTypes: spen, syrd AirUnitsTypes: mig, yak, heli, hind, mh60 + AircraftTargetType: AirborneActor ProtectionTypes: harv, mcv, mslo, gap, spen, syrd, iron, pdox, tsla, agun, dome, pbox, hbox, gun, ftur, sam, atek, weap, fact, proc, silo, hpad, afld, afld.ukraine, powr, apwr, stek, barr, kenn, tent, fix, fpwr, tenf, syrf, spef, weaf, domf, fixf, fapw, atef, pdof, mslf, facf IgnoredEnemyTargetTypes: AirborneActor UnitBuilderBotModule@normal: @@ -378,6 +380,7 @@ Player: ConstructionYardTypes: fact NavalProductionTypes: spen, syrd AirUnitsTypes: mig, yak, heli, hind, mh60 + AircraftTargetType: AirborneActor ProtectionTypes: harv, mcv, mslo, gap, spen, syrd, iron, pdox, tsla, agun, dome, pbox, hbox, gun, ftur, sam, atek, weap, fact, proc, silo, hpad, afld, afld.ukraine, powr, apwr, stek, barr, kenn, tent, fix, fpwr, tenf, syrf, spef, weaf, domf, fixf, fapw, atef, pdof, mslf, facf IgnoredEnemyTargetTypes: AirborneActor UnitBuilderBotModule@turtle: @@ -431,6 +434,7 @@ Player: ConstructionYardTypes: fact NavalProductionTypes: spen, syrd AirUnitsTypes: mig, yak, heli, hind, mh60 + AircraftTargetType: AirborneActor ProtectionTypes: harv, mcv, mslo, gap, spen, syrd, iron, pdox, tsla, agun, dome, pbox, hbox, gun, ftur, sam, atek, weap, fact, proc, silo, hpad, afld, afld.ukraine, powr, apwr, stek, barr, kenn, tent, fix, fpwr, tenf, syrf, spef, weaf, domf, fixf, fapw, atef, pdof, mslf, facf IgnoredEnemyTargetTypes: AirborneActor UnitBuilderBotModule@naval: