Files
OpenRA/OpenRA.Mods.RA/LimitedAmmo.cs
Squiggles211 0503ed7119 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.
2014-05-17 13:52:52 -05:00

71 lines
1.8 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class LimitedAmmoInfo : ITraitInfo
{
public readonly int Ammo = 0;
[Desc("Defaults to value in Ammo.")]
public readonly int PipCount = 0;
public readonly PipType PipType = PipType.Green;
public readonly PipType PipTypeEmpty = PipType.Transparent;
[Desc("Time to reload measured in ticks.")]
public readonly int ReloadTicks = 25 * 2;
public object Create(ActorInitializer init) { return new LimitedAmmo(this); }
}
public class LimitedAmmo : INotifyAttack, IPips, ISync
{
[Sync] int ammo;
LimitedAmmoInfo Info;
public LimitedAmmo(LimitedAmmoInfo info)
{
ammo = info.Ammo;
Info = info;
}
public bool FullAmmo() { return ammo == Info.Ammo; }
public bool HasAmmo() { return ammo > 0; }
public bool GiveAmmo()
{
if (ammo >= Info.Ammo) return false;
++ammo;
return true;
}
public bool TakeAmmo()
{
if (ammo <= 0) return false;
--ammo;
return true;
}
public int ReloadTimePerAmmo() { return Info.ReloadTicks; }
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;
return Exts.MakeArray(pips,
i => (ammo * pips) / Info.Ammo > i ? Info.PipType : Info.PipTypeEmpty);
}
}
}