Fixes inconsistency in reload times for Cnc Aircraft

Fixes reload time inconsistency caused by always running the reload
counter even when not needing to reload.  Also adds the ability to
specify that the reload counter restarts when firing a shot.
This commit is contained in:
Squiggles211
2014-05-17 02:54:50 -05:00
parent a15564f54d
commit 0503ed7119
3 changed files with 18 additions and 1 deletions

View File

@@ -61,6 +61,7 @@ Also thanks to:
* Pavlos Touboulidis (pav)
* Pizzaoverhead
* Psydev
* Raymond Bedrossian (Squiggles211)
* Raymond Martineau (mart0258)
* Reaperrr
* Riderr3

View File

@@ -58,6 +58,8 @@ namespace OpenRA.Mods.RA
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { TakeAmmo(); }
public int GetAmmoCount() { return ammo; }
public IEnumerable<PipType> GetPips(Actor self)
{
var pips = Info.PipCount != 0 ? Info.PipCount : Info.Ammo;

View File

@@ -20,6 +20,8 @@ namespace OpenRA.Mods.RA
public readonly int Count = 0;
[Desc("How long it takes to do so.")]
public readonly int Period = 50;
[Desc("Whether or not reload counter should be reset when ammo has been fired.")]
public readonly bool ResetOnFire = false;
public object Create(ActorInitializer init) { return new Reloads(init.self, this); }
}
@@ -29,21 +31,33 @@ namespace OpenRA.Mods.RA
[Sync] int remainingTicks;
ReloadsInfo Info;
LimitedAmmo la;
int previousAmmo;
public Reloads(Actor self, ReloadsInfo info)
{
Info = info;
remainingTicks = info.Period;
la = self.Trait<LimitedAmmo>();
previousAmmo = la.GetAmmoCount();
}
public void Tick(Actor self)
{
if (--remainingTicks == 0)
if (!la.FullAmmo() && --remainingTicks == 0)
{
remainingTicks = Info.Period;
for (var i = 0; i < Info.Count; i++)
la.GiveAmmo();
previousAmmo = la.GetAmmoCount();
}
// Resets the tick counter if ammo was fired.
if (Info.ResetOnFire && la.GetAmmoCount() < previousAmmo)
{
remainingTicks = Info.Period;
previousAmmo = la.GetAmmoCount();
}
}
}