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:
reaperrr
2019-10-19 17:25:25 +02:00
committed by reaperrr
parent c77aa4c8f9
commit ee00954f2e
9 changed files with 24 additions and 24 deletions

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Cnc.Activities
if ((minefield == null || minefield.Contains(self.Location)) && CanLayMine(self, self.Location))
{
if (rearmableInfo != null && ammoPools.Any(p => p.Info.Name == minelayer.Info.AmmoPoolName && !p.HasAmmo()))
if (rearmableInfo != null && ammoPools.Any(p => p.Info.Name == minelayer.Info.AmmoPoolName && !p.HasAmmo))
{
// Rearm (and possibly repair) at rearm building, then back out here to refill the minefield some more
rearmTarget = self.World.Actors.Where(a => self.Owner.Stances[a.Owner] == Stance.Ally && rearmableInfo.RearmActors.Contains(a.Info.Name))
@@ -137,6 +137,7 @@ namespace OpenRA.Mods.Cnc.Activities
var pool = ammoPools.FirstOrDefault(x => x.Info.Name == minelayer.Info.AmmoPoolName);
if (pool == null)
return;
pool.TakeAmmo(self, 1);
}

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Activities
return true;
return rearmable != null && rearmable.Info.RearmActors.Contains(dest.Info.Name)
&& rearmable.RearmableAmmoPools.Any(p => !p.FullAmmo());
&& rearmable.RearmableAmmoPools.Any(p => !p.HasFullAmmo);
}
public override bool Tick(Actor self)

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Activities
wasRepaired = true;
}
var cannotRearmAtHost = rearmable == null || !rearmable.Info.RearmActors.Contains(host.Info.Name) || rearmable.RearmableAmmoPools.All(p => p.FullAmmo());
var cannotRearmAtHost = rearmable == null || !rearmable.Info.RearmActors.Contains(host.Info.Name) || rearmable.RearmableAmmoPools.All(p => p.HasFullAmmo);
if (!cannotRearmAtHost)
activeResupplyTypes |= ResupplyType.Rearm;
}
@@ -277,7 +277,7 @@ namespace OpenRA.Mods.Common.Activities
var rearmComplete = true;
foreach (var ammoPool in rearmable.RearmableAmmoPools)
{
if (!ammoPool.FullAmmo())
if (!ammoPool.HasFullAmmo)
{
if (--ammoPool.RemainingTicks <= 0)
{

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Scripting
if (pool == null)
throw new LuaException("Invalid ammopool name {0} queried on actor {1}.".F(poolName, self));
return pool.GetAmmoCount();
return pool.CurrentAmmoCount;
}
[Desc("Returns the maximum count of ammo the actor can load.")]

View File

@@ -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)

View File

@@ -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);
}
}

View File

@@ -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)

View File

@@ -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))

View File

@@ -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)