Fix do allow AI do place plugbuildings like RBG Tower on GDI Component Tower

This commit is contained in:
Alfred Lang
2020-05-27 23:54:14 +02:00
committed by abcdefg30
parent f0c808d2fc
commit 1c8c49dc8e
2 changed files with 31 additions and 8 deletions

View File

@@ -134,14 +134,34 @@ namespace OpenRA.Mods.Common.Traits
// HACK: HACK HACK HACK // HACK: HACK HACK HACK
// TODO: Derive this from BuildingCommonNames instead // TODO: Derive this from BuildingCommonNames instead
var type = BuildingType.Building; var type = BuildingType.Building;
CPos? location = null;
string orderString = "PlaceBuilding";
// Check if Building is a defense and if we should place it towards the enemy or not. // Check if Building is a plug for other Building
if (world.Map.Rules.Actors[currentBuilding.Item].HasTraitInfo<AttackBaseInfo>() && world.LocalRandom.Next(100) < baseBuilder.Info.PlaceDefenseTowardsEnemyChance) var actorInfo = world.Map.Rules.Actors[currentBuilding.Item];
type = BuildingType.Defense; var plugInfo = actorInfo.TraitInfoOrDefault<PlugInfo>();
else if (baseBuilder.Info.RefineryTypes.Contains(world.Map.Rules.Actors[currentBuilding.Item].Name)) if (plugInfo != null)
type = BuildingType.Refinery; {
var possibleBuilding = world.ActorsWithTrait<Pluggable>().FirstOrDefault(a =>
a.Actor.Owner == player && a.Trait.AcceptsPlug(a.Actor, plugInfo.Type));
if (possibleBuilding != null)
{
orderString = "PlacePlug";
location = possibleBuilding.Actor.Location + possibleBuilding.Trait.Info.Offset;
}
}
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)
type = BuildingType.Defense;
else if (baseBuilder.Info.RefineryTypes.Contains(actorInfo.Name))
type = BuildingType.Refinery;
location = ChooseBuildLocation(currentBuilding.Item, true, type);
}
var location = ChooseBuildLocation(currentBuilding.Item, true, type);
if (location == null) if (location == null)
{ {
AIUtils.BotDebug("AI: {0} has nowhere to place {1}".F(player, currentBuilding.Item)); AIUtils.BotDebug("AI: {0} has nowhere to place {1}".F(player, currentBuilding.Item));
@@ -158,7 +178,8 @@ namespace OpenRA.Mods.Common.Traits
else else
{ {
failCount = 0; failCount = 0;
bot.QueueOrder(new Order("PlaceBuilding", player.PlayerActor, Target.FromCell(world, location.Value), false)
bot.QueueOrder(new Order(orderString, player.PlayerActor, Target.FromCell(world, location.Value), false)
{ {
// Building to place // Building to place
TargetString = currentBuilding.Item, TargetString = currentBuilding.Item,

View File

@@ -17,7 +17,7 @@ Player:
ExcessPowerIncreaseThreshold: 4 ExcessPowerIncreaseThreshold: 4
ConstructionYardTypes: gacnst ConstructionYardTypes: gacnst
RefineryTypes: proc RefineryTypes: proc
PowerTypes: gapowr, napowr, naapwr PowerTypes: gapowr, gapowrup, napowr, naapwr
BarracksTypes: gapile, nahand BarracksTypes: gapile, nahand
VehiclesFactoryTypes: gaweap, naweap VehiclesFactoryTypes: gaweap, naweap
ProductionTypes: gapile, nahand, gaweap, naweap, gahpad, nahpad ProductionTypes: gapile, nahand, gaweap, naweap, gahpad, nahpad
@@ -41,6 +41,7 @@ Player:
gavulc: 8 gavulc: 8
garock: 2 garock: 2
gacsam: 4 gacsam: 4
gactwr: 14
naobel: 2 naobel: 2
nalasr: 8 nalasr: 8
nasam: 4 nasam: 4
@@ -61,6 +62,7 @@ Player:
gavulc: 10 gavulc: 10
garock: 3 garock: 3
gacsam: 6 gacsam: 6
gactwr: 18
nasam: 6 nasam: 6
naobel: 3 naobel: 3
BuildingRepairBotModule: BuildingRepairBotModule: