Merge pull request #5345 from Squiggles211/ammo_reload_timing

Fixes inconsistency in reload times for Cnc Aircraft
This commit is contained in:
Paul Chote
2014-05-20 12:04:11 +12:00
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();
}
}
}