diff --git a/OpenRA.Mods.Common/Traits/AmmoPool.cs b/OpenRA.Mods.Common/Traits/AmmoPool.cs index 76f0be4080..6a25a9b944 100644 --- a/OpenRA.Mods.Common/Traits/AmmoPool.cs +++ b/OpenRA.Mods.Common/Traits/AmmoPool.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits public readonly int ReloadDelay = 50; [GrantedConditionReference] - [Desc("The condition to grant to self if the pool has any ammo.")] + [Desc("The condition to grant to self for each ammo point in this pool.")] public readonly string AmmoCondition = null; public object Create(ActorInitializer init) { return new AmmoPool(init.Self, this); } @@ -59,8 +59,8 @@ namespace OpenRA.Mods.Common.Traits public class AmmoPool : INotifyCreated, INotifyAttack, IPips, ISync { public readonly AmmoPoolInfo Info; + readonly Stack tokens = new Stack(); ConditionManager conditionManager; - int token = ConditionManager.InvalidConditionToken; bool selfReloads; @@ -106,6 +106,7 @@ namespace OpenRA.Mods.Common.Traits { conditionManager = self.TraitOrDefault(); selfReloads = self.TraitsImplementing().Any(r => r.Info.AmmoPool == Info.Name && r.Info.RequiresCondition == null); + UpdateCondition(self); // HACK: Temporarily needed until Rearm activity is gone for good @@ -125,11 +126,11 @@ namespace OpenRA.Mods.Common.Traits if (conditionManager == null || string.IsNullOrEmpty(Info.AmmoCondition)) return; - if (HasAmmo() && token == ConditionManager.InvalidConditionToken) - token = conditionManager.GrantCondition(self, Info.AmmoCondition); + while (currentAmmo > tokens.Count && tokens.Count < Info.Ammo) + tokens.Push(conditionManager.GrantCondition(self, Info.AmmoCondition)); - if (!HasAmmo() && token != ConditionManager.InvalidConditionToken) - token = conditionManager.RevokeCondition(self, token); + while (currentAmmo < tokens.Count && tokens.Count > 0) + conditionManager.RevokeCondition(self, tokens.Pop()); } public IEnumerable GetPips(Actor self)