Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhardcode defenses in BaseBuilderBotModule #20155

Merged
merged 2 commits into from Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs
Expand Up @@ -42,6 +42,9 @@ public class BaseBuilderBotModuleInfo : ConditionalTraitInfo
[Desc("Tells the AI what building types are considered silos (resource storage).")]
public readonly HashSet<string> SiloTypes = new HashSet<string>();

[Desc("Tells the AI what building types are considered defenses.")]
public readonly HashSet<string> DefenseTypes = new HashSet<string>();

[Desc("Production queues AI uses for buildings.")]
public readonly HashSet<string> BuildingQueues = new HashSet<string> { "Building" };

Expand Down
Expand Up @@ -156,7 +156,7 @@ bool TickQueue(IBot bot, ProductionQueue queue)
else
{
// Check if Building is a defense and if we should place it towards the enemy or not.
if (actorInfo.HasTraitInfo<AttackBaseInfo>() && world.LocalRandom.Next(100) < baseBuilder.Info.PlaceDefenseTowardsEnemyChance)
if (baseBuilder.Info.DefenseTypes.Contains(actorInfo.Name) && world.LocalRandom.Next(100) < baseBuilder.Info.PlaceDefenseTowardsEnemyChance)
abcdefg30 marked this conversation as resolved.
Show resolved Hide resolved
type = BuildingType.Defense;
else if (baseBuilder.Info.RefineryTypes.Contains(actorInfo.Name))
type = BuildingType.Refinery;
Expand Down
@@ -0,0 +1,39 @@
#region Copyright & License Information
/*
* Copyright 2007-2022 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits;

namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class UnhardcodeBaseBuilderBotModule : UpdateRule
{
public override string Name => "BaseBuilderBotModule got new fields to configure buildings that are defenses.";

public override string Description => "DefenseTypes were added.";

public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
var addNodes = new List<MiniYamlNode>();

var defense = modData.DefaultRules.Actors.Values.Where(a => a.HasTraitInfo<BuildingInfo>() && a.HasTraitInfo<AttackBaseInfo>()).Select(a => a.Name);
var defensetypes = new MiniYamlNode("DefenseTypes", FieldSaver.FormatValue(defense.ToList()));
addNodes.Add(defensetypes);

foreach (var baseBuilderManager in actorNode.ChildrenMatching("BaseBuilderBotModule"))
foreach (var addNode in addNodes)
baseBuilderManager.AddNode(addNode);

yield break;
}
}
}
1 change: 1 addition & 0 deletions OpenRA.Mods.Common/UpdateRules/UpdatePath.cs
Expand Up @@ -94,6 +94,7 @@ public class UpdatePath
new RenameCloakTypes(),
new SplitNukePowerMissileImage(),
new ReplaceSequenceEmbeddedPalette(),
new UnhardcodeBaseBuilderBotModule(),
})
};

Expand Down
3 changes: 3 additions & 0 deletions mods/cnc/rules/ai.yaml
Expand Up @@ -97,6 +97,7 @@ Player:
VehiclesFactoryTypes: weap, afld
ProductionTypes: pyle, hand, weap, afld, hpad
SiloTypes: silo
DefenseTypes: gtwr,gun,atwr,obli,sam
BuildingLimits:
proc: 4
pyle: 3
Expand Down Expand Up @@ -140,6 +141,7 @@ Player:
VehiclesFactoryTypes: weap,afld
ProductionTypes: pyle,hand,weap,afld,hpad
SiloTypes: silo
DefenseTypes: gtwr,gun,atwr,obli,sam
BuildingLimits:
proc: 4
pyle: 3
Expand Down Expand Up @@ -183,6 +185,7 @@ Player:
VehiclesFactoryTypes: weap,afld
ProductionTypes: pyle,hand,weap,afld,hpad
SiloTypes: silo
DefenseTypes: gtwr,gun,atwr,obli,sam
BuildingLimits:
proc: 4
pyle: 4
Expand Down
3 changes: 3 additions & 0 deletions mods/d2k/rules/ai.yaml
Expand Up @@ -78,6 +78,7 @@ Player:
VehiclesFactoryTypes: light_factory, heavy_factory, starport
ProductionTypes: light_factory, heavy_factory, barracks, starport
SiloTypes: silo
DefenseTypes: medium_gun_turret,large_gun_turret
BuildingLimits:
barracks: 1
refinery: 4
Expand Down Expand Up @@ -128,6 +129,7 @@ Player:
VehiclesFactoryTypes: light_factory, heavy_factory, starport
ProductionTypes: light_factory, heavy_factory, barracks, starport
SiloTypes: silo
DefenseTypes: medium_gun_turret,large_gun_turret
BuildingLimits:
barracks: 1
refinery: 4
Expand Down Expand Up @@ -178,6 +180,7 @@ Player:
VehiclesFactoryTypes: light_factory, heavy_factory, starport
ProductionTypes: light_factory, heavy_factory, barracks, starport
SiloTypes: silo
DefenseTypes: medium_gun_turret,large_gun_turret
BuildingLimits:
barracks: 1
refinery: 4
Expand Down
4 changes: 4 additions & 0 deletions mods/ra/rules/ai.yaml
Expand Up @@ -91,6 +91,7 @@ Player:
VehiclesFactoryTypes: weap
ProductionTypes: barr,tent,weap
SiloTypes: silo
DefenseTypes: hbox,pbox,gun,ftur,tsla,agun,sam
BuildingLimits:
proc: 4
barr: 1
Expand Down Expand Up @@ -133,6 +134,7 @@ Player:
ProductionTypes: barr,tent,weap,afld,hpad
NavalProductionTypes: spen, syrd
SiloTypes: silo
DefenseTypes: hbox,pbox,gun,ftur,tsla,agun,sam
BuildingLimits:
proc: 4
barr: 1
Expand Down Expand Up @@ -184,6 +186,7 @@ Player:
ProductionTypes: barr,tent,weap,afld,hpad
NavalProductionTypes: spen, syrd
SiloTypes: silo
DefenseTypes: hbox,pbox,gun,ftur,tsla,agun,sam
BuildingLimits:
proc: 4
barr: 1
Expand Down Expand Up @@ -236,6 +239,7 @@ Player:
ProductionTypes: barr,tent,weap,afld,hpad
NavalProductionTypes: spen, syrd
SiloTypes: silo
DefenseTypes: hbox,pbox,gun,ftur,tsla,agun,sam
BuildingLimits:
proc: 4
dome: 1
Expand Down
1 change: 1 addition & 0 deletions mods/ts/rules/ai.yaml
Expand Up @@ -22,6 +22,7 @@ Player:
VehiclesFactoryTypes: gaweap, naweap
ProductionTypes: gapile, nahand, gaweap, naweap, gahpad, nahpad
SiloTypes: gasilo
DefenseTypes: gavulc,garock,gacsam,gactwr,naobel,nalasr,nasam
BuildingLimits:
proc: 4
gasilo: 2
Expand Down