Replace AmmoPool lookup methods with properties
And gave the more suitable names while at it. This is more in line with how we do things in other places.
This commit is contained in:
@@ -540,7 +540,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var canRearmAtActor = rearmable != null && rearmable.Info.RearmActors.Contains(a.Info.Name);
|
||||
var canRepairAtActor = repairable != null && repairable.Info.RepairActors.Contains(a.Info.Name);
|
||||
|
||||
var allowedToEnterRearmer = canRearmAtActor && (allowedToForceEnter || rearmable.RearmableAmmoPools.Any(p => !p.FullAmmo()));
|
||||
var allowedToEnterRearmer = canRearmAtActor && (allowedToForceEnter || rearmable.RearmableAmmoPools.Any(p => !p.HasFullAmmo));
|
||||
var allowedToEnterRepairer = canRepairAtActor && (allowedToForceEnter || self.GetDamageState() != DamageState.Undamaged);
|
||||
|
||||
return allowedToEnterRearmer || allowedToEnterRepairer;
|
||||
@@ -654,7 +654,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanRearmAt(Actor host)
|
||||
{
|
||||
return rearmable != null && rearmable.Info.RearmActors.Contains(host.Info.Name) && rearmable.RearmableAmmoPools.Any(p => !p.FullAmmo());
|
||||
return rearmable != null && rearmable.Info.RearmActors.Contains(host.Info.Name) && rearmable.RearmableAmmoPools.Any(p => !p.HasFullAmmo);
|
||||
}
|
||||
|
||||
public bool CanRepairAt(Actor host)
|
||||
|
||||
@@ -67,34 +67,33 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public int RemainingTicks;
|
||||
|
||||
[Sync]
|
||||
int currentAmmo;
|
||||
public int CurrentAmmoCount { get; private set; }
|
||||
|
||||
public bool HasAmmo { get { return CurrentAmmoCount > 0; } }
|
||||
public bool HasFullAmmo { get { return CurrentAmmoCount == Info.Ammo; } }
|
||||
|
||||
public AmmoPool(Actor self, AmmoPoolInfo info)
|
||||
{
|
||||
Info = info;
|
||||
currentAmmo = Info.InitialAmmo < Info.Ammo && Info.InitialAmmo >= 0 ? Info.InitialAmmo : Info.Ammo;
|
||||
CurrentAmmoCount = Info.InitialAmmo < Info.Ammo && Info.InitialAmmo >= 0 ? Info.InitialAmmo : Info.Ammo;
|
||||
}
|
||||
|
||||
public int GetAmmoCount() { return currentAmmo; }
|
||||
public bool FullAmmo() { return currentAmmo == Info.Ammo; }
|
||||
public bool HasAmmo() { return currentAmmo > 0; }
|
||||
|
||||
public bool GiveAmmo(Actor self, int count)
|
||||
{
|
||||
if (currentAmmo >= Info.Ammo || count < 0)
|
||||
if (CurrentAmmoCount >= Info.Ammo || count < 0)
|
||||
return false;
|
||||
|
||||
currentAmmo = (currentAmmo + count).Clamp(0, Info.Ammo);
|
||||
CurrentAmmoCount = (CurrentAmmoCount + count).Clamp(0, Info.Ammo);
|
||||
UpdateCondition(self);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeAmmo(Actor self, int count)
|
||||
{
|
||||
if (currentAmmo <= 0 || count < 0)
|
||||
if (CurrentAmmoCount <= 0 || count < 0)
|
||||
return false;
|
||||
|
||||
currentAmmo = (currentAmmo - count).Clamp(0, Info.Ammo);
|
||||
CurrentAmmoCount = (CurrentAmmoCount - count).Clamp(0, Info.Ammo);
|
||||
UpdateCondition(self);
|
||||
return true;
|
||||
}
|
||||
@@ -121,10 +120,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (conditionManager == null || string.IsNullOrEmpty(Info.AmmoCondition))
|
||||
return;
|
||||
|
||||
while (currentAmmo > tokens.Count && tokens.Count < Info.Ammo)
|
||||
while (CurrentAmmoCount > tokens.Count && tokens.Count < Info.Ammo)
|
||||
tokens.Push(conditionManager.GrantCondition(self, Info.AmmoCondition));
|
||||
|
||||
while (currentAmmo < tokens.Count && tokens.Count > 0)
|
||||
while (CurrentAmmoCount < tokens.Count && tokens.Count > 0)
|
||||
conditionManager.RevokeCondition(self, tokens.Pop());
|
||||
}
|
||||
|
||||
@@ -133,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var pips = Info.PipCount >= 0 ? Info.PipCount : Info.Ammo;
|
||||
|
||||
return Enumerable.Range(0, pips).Select(i =>
|
||||
(currentAmmo * pips) / Info.Ammo > i ?
|
||||
(CurrentAmmoCount * pips) / Info.Ammo > i ?
|
||||
Info.PipType : Info.PipTypeEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,13 +114,13 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
protected static bool FullAmmo(Actor a)
|
||||
{
|
||||
var ammoPools = a.TraitsImplementing<AmmoPool>();
|
||||
return ammoPools.All(x => x.FullAmmo());
|
||||
return ammoPools.All(x => x.HasFullAmmo);
|
||||
}
|
||||
|
||||
protected static bool HasAmmo(Actor a)
|
||||
{
|
||||
var ammoPools = a.TraitsImplementing<AmmoPool>();
|
||||
return ammoPools.All(x => x.HasAmmo());
|
||||
return ammoPools.All(x => x.HasAmmo);
|
||||
}
|
||||
|
||||
protected static bool ReloadsAutomatically(Actor a)
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
protected virtual void Reload(Actor self, int reloadDelay, int reloadCount, string sound)
|
||||
{
|
||||
if (!ammoPool.FullAmmo() && --remainingTicks == 0)
|
||||
if (!ammoPool.HasFullAmmo && --remainingTicks == 0)
|
||||
{
|
||||
remainingTicks = Util.ApplyPercentageModifiers(reloadDelay, modifiers.Select(m => m.GetReloadAmmoModifier()));
|
||||
if (!string.IsNullOrEmpty(sound))
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
bool CanRearm()
|
||||
{
|
||||
return rearmable != null && rearmable.RearmableAmmoPools.Any(p => !p.FullAmmo());
|
||||
return rearmable != null && rearmable.RearmableAmmoPools.Any(p => !p.HasFullAmmo);
|
||||
}
|
||||
|
||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||
|
||||
Reference in New Issue
Block a user