Files
OpenRA/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs
reaperrr 31f4b0a5c4 Fix D2k bots wasting cash on building repairs
D2k bots not repairing buildings when damaged due to placement
without concrete was intentional, and this was bleed's default behavior
before BuildingRepairBotModule got introduced, too.
2019-02-03 18:24:15 +01:00

48 lines
1.7 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2019 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 OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Manages AI repairing base buildings.")]
public class BuildingRepairBotModuleInfo : ConditionalTraitInfo
{
public override object Create(ActorInitializer init) { return new BuildingRepairBotModule(init.Self, this); }
}
public class BuildingRepairBotModule : ConditionalTrait<BuildingRepairBotModuleInfo>, IBotRespondToAttack
{
public BuildingRepairBotModule(Actor self, BuildingRepairBotModuleInfo info)
: base(info) { }
void IBotRespondToAttack.RespondToAttack(IBot bot, Actor self, AttackInfo e)
{
// HACK: We don't want D2k bots to repair all their buildings on placement
// where half their HP is removed via neutral terrain damage.
// TODO: Implement concrete placement for D2k bots and remove this hack.
if (e.Attacker.Owner.Stances[self.Owner] == Stance.Neutral)
return;
var rb = self.TraitOrDefault<RepairableBuilding>();
if (rb != null)
{
if (e.DamageState > DamageState.Light && e.PreviousDamageState <= DamageState.Light && !rb.RepairActive)
{
AIUtils.BotDebug("Bot noticed damage {0} {1}->{2}, repairing.",
self, e.PreviousDamageState, e.DamageState);
bot.QueueOrder(new Order("RepairBuilding", self.Owner.PlayerActor, Target.FromActor(self), false));
}
}
}
}
}