Unhardcode AI defensive priorities.

This commit is contained in:
Matthias Mailänder
2021-10-17 16:30:13 +02:00
committed by reaperrr
parent e82aa9977e
commit 5eaba4f893
7 changed files with 19 additions and 6 deletions

View File

@@ -36,6 +36,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Enemy building types around which to scan for targets for naval squads.")]
public readonly HashSet<string> NavalProductionTypes = new HashSet<string>();
[Desc("Own actor types that are prioritized when defending.")]
public readonly HashSet<string> ProtectionTypes = new HashSet<string>();
[Desc("Minimum number of units AI must have before attacking.")]
public readonly int SquadSize = 8;
@@ -321,7 +324,7 @@ namespace OpenRA.Mods.Common.Traits
{
// Don't rush enemy aircraft!
var enemies = World.FindActorsInCircle(b.CenterPosition, WDist.FromCells(Info.RushAttackScanRadius))
.Where(unit => IsPreferredEnemyUnit(unit) && unit.Info.HasTraitInfo<AttackBaseInfo>() && !unit.Info.HasTraitInfo<AircraftInfo>() && !Info.NavalUnitsTypes.Contains(unit.Info.Name)).ToList();
.Where(unit => IsPreferredEnemyUnit(unit) && unit.Info.HasTraitInfo<AttackBaseInfo>() && !Info.AirUnitsTypes.Contains(unit.Info.Name) && !Info.NavalUnitsTypes.Contains(unit.Info.Name)).ToList();
if (AttackOrFleeFuzzy.Rush.CanAttack(ownUnits, enemies))
{
@@ -350,8 +353,7 @@ namespace OpenRA.Mods.Common.Traits
if (!protectSq.IsValid)
{
var ownUnits = World.FindActorsInCircle(World.Map.CenterOfCell(GetRandomBaseCenter()), WDist.FromCells(Info.ProtectUnitScanRadius))
.Where(unit => unit.Owner == Player && !unit.Info.HasTraitInfo<BuildingInfo>() && !unit.Info.HasTraitInfo<HarvesterInfo>()
&& unit.Info.HasTraitInfo<AttackBaseInfo>());
.Where(unit => unit.Owner == Player && !Info.ProtectionTypes.Contains(unit.Info.Name) && unit.Info.HasTraitInfo<AttackBaseInfo>());
foreach (var a in ownUnits)
protectSq.Units.Add(a);
@@ -370,9 +372,7 @@ namespace OpenRA.Mods.Common.Traits
if (!IsPreferredEnemyUnit(e.Attacker))
return;
// Protected priority assets, MCVs, harvesters and buildings
// TODO: Use *CommonNames, instead of hard-coding trait(info)s.
if (self.Info.HasTraitInfo<HarvesterInfo>() || self.Info.HasTraitInfo<BuildingInfo>() || self.Info.HasTraitInfo<BaseBuildingInfo>())
if (Info.ProtectionTypes.Contains(self.Info.Name))
{
foreach (var n in notifyPositionsUpdated)
n.UpdatedDefenseCenter(e.Attacker.Location);

View File

@@ -219,6 +219,7 @@ Player:
ExcludeFromSquadsTypes: harv, mcv, a10
ConstructionYardTypes: fact
AirUnitsTypes: heli, orca
ProtectionTypes: fact, fact.gdi, fact.nod, nuke, nuk2, proc, silo, pyle, hand, afld, weap, hpad, hq, fix, eye, tmpl, gun, sam, obli, gtwr, atwr, mcv, harv, miss
UnitBuilderBotModule@cabal:
RequiresCondition: enable-cabal-ai
UnitQueues: Vehicle.Nod, Vehicle.GDI, Infantry.Nod, Infantry.GDI, Aircraft.Nod, Aircraft.GDI
@@ -254,6 +255,7 @@ Player:
ExcludeFromSquadsTypes: harv, mcv, a10
ConstructionYardTypes: fact
AirUnitsTypes: heli, orca
ProtectionTypes: fact, fact.gdi, fact.nod, nuke, nuk2, proc, silo, pyle, hand, afld, weap, hpad, hq, fix, eye, tmpl, gun, sam, obli, gtwr, atwr, mcv, harv, miss
UnitBuilderBotModule@watson:
RequiresCondition: enable-watson-ai
UnitQueues: Vehicle.Nod, Vehicle.GDI, Infantry.Nod, Infantry.GDI, Aircraft.Nod, Aircraft.GDI
@@ -284,6 +286,7 @@ Player:
ExcludeFromSquadsTypes: harv, mcv, a10
ConstructionYardTypes: fact
AirUnitsTypes: heli, orca
ProtectionTypes: fact, fact.gdi, fact.nod, nuke, nuk2, proc, silo, pyle, hand, afld, weap, hpad, hq, fix, eye, tmpl, gun, sam, obli, gtwr, atwr, mcv, harv, miss
UnitBuilderBotModule@hal9001:
RequiresCondition: enable-hal9001-ai
UnitQueues: Vehicle.Nod, Vehicle.GDI, Infantry.Nod, Infantry.GDI, Aircraft.Nod, Aircraft.GDI

View File

@@ -81,6 +81,7 @@ fact.colorpicker:
Inherits: FACT
-Buildable:
-MapEditorData:
-BaseBuilding:
RenderSprites:
Image: fact
Palette: colorpicker

View File

@@ -222,6 +222,7 @@ Player:
ExcludeFromSquadsTypes: harvester, mcv, carryall, carryall.reinforce, ornithopter
ConstructionYardTypes: construction_yard
IgnoredEnemyTargetTypes: Creep
ProtectionTypes: mcv, harvester, construction_yard, conyard.atreides, conyard.harkonnen, conyard.ordos, wind_trap, barracks, refinery, silo, light_factory, heavy_factory, outpost, starport, medium_gun_turret, large_gun_turret, repair_pad, high_tech_factory, research_centre, palace, mcv.starport, harvester.starport
UnitBuilderBotModule@omnius:
RequiresCondition: enable-omnius-ai
UnitQueues: Infantry, Vehicle, Armor, Starport, Aircraft
@@ -266,6 +267,7 @@ Player:
ExcludeFromSquadsTypes: harvester, mcv, carryall, carryall.reinforce, ornithopter
ConstructionYardTypes: construction_yard
IgnoredEnemyTargetTypes: Creep
ProtectionTypes: mcv, harvester, construction_yard, conyard.atreides, conyard.harkonnen, conyard.ordos, wind_trap, barracks, refinery, silo, light_factory, heavy_factory, outpost, starport, medium_gun_turret, large_gun_turret, repair_pad, high_tech_factory, research_centre, palace, mcv.starport, harvester.starport
UnitBuilderBotModule@vidious:
RequiresCondition: enable-vidious-ai
UnitQueues: Infantry, Vehicle, Armor, Starport, Aircraft
@@ -305,6 +307,7 @@ Player:
ExcludeFromSquadsTypes: harvester, mcv, carryall, carryall.reinforce, ornithopter
ConstructionYardTypes: construction_yard
IgnoredEnemyTargetTypes: Creep
ProtectionTypes: mcv, harvester, construction_yard, conyard.atreides, conyard.harkonnen, conyard.ordos, wind_trap, barracks, refinery, silo, light_factory, heavy_factory, outpost, starport, medium_gun_turret, large_gun_turret, repair_pad, high_tech_factory, research_centre, palace, mcv.starport, harvester.starport
UnitBuilderBotModule@gladius:
RequiresCondition: enable-gladius-ai
UnitQueues: Infantry, Vehicle, Armor, Starport, Aircraft

View File

@@ -278,6 +278,7 @@ Player:
ExcludeFromSquadsTypes: harv, mcv, dog, badr.bomber, u2
ConstructionYardTypes: fact
AirUnitsTypes: mig, yak, heli, hind, mh60
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
McvManagerBotModule:
RequiresCondition: enable-rush-ai || enable-normal-ai || enable-turtle-ai || enable-naval-ai
McvTypes: mcv
@@ -317,6 +318,7 @@ Player:
ConstructionYardTypes: fact
NavalProductionTypes: spen,syrd
AirUnitsTypes: mig, yak, heli, hind, mh60
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
UnitBuilderBotModule@normal:
RequiresCondition: enable-normal-ai
UnitsToBuild:
@@ -360,6 +362,7 @@ Player:
ConstructionYardTypes: fact
NavalProductionTypes: spen,syrd
AirUnitsTypes: mig, yak, heli, hind, mh60
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
UnitBuilderBotModule@turtle:
RequiresCondition: enable-turtle-ai
UnitsToBuild:
@@ -403,6 +406,7 @@ Player:
ConstructionYardTypes: fact
NavalProductionTypes: spen,syrd
AirUnitsTypes: mig, yak, heli, hind, mh60
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
UnitBuilderBotModule@naval:
RequiresCondition: enable-naval-ai
UnitsToBuild:

View File

@@ -442,6 +442,7 @@ fact.colorpicker:
Inherits: FACT
-Buildable:
-MapEditorData:
-BaseBuilding:
RenderSprites:
Image: fact
Palette: colorpicker

View File

@@ -73,6 +73,7 @@ Player:
ExcludeFromSquadsTypes: harv, mcv, dpod, hunter
ConstructionYardTypes: gacnst
AirUnitsTypes: orca, orcab, scrin, apache, jumpjet
ProtectionTypes: gapowr, gapowrup, gapile, gaweap, gahpad, gadept, garadr, gatech, gaplug, gagate_a, gagate_b, gactwr, gavulc, garock, gacsam, napowr, naapwr, nahand, naweap, nahpad, naradr, natech, nastlh, natmpl, namisl, nawast, nagate_a, nagate_b, nalasr, naobel, nasam, weed, gacnst, proc, gasilo, napuls, mcv, harv
UnitBuilderBotModule@test:
RequiresCondition: enable-test-ai
UnitQueues: Vehicle, Infantry, Air