Make Armament elements as overridable as possible

To allow downstream mods to ship customised Armament-derivatives.
This commit is contained in:
reaperrr
2016-08-18 15:54:23 +02:00
parent 398cb18043
commit 19c3e7c9e3

View File

@@ -107,8 +107,8 @@ namespace OpenRA.Mods.Common.Traits
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>(); List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
public WDist Recoil; public WDist Recoil;
public int FireDelay { get; private set; } public int FireDelay { get; protected set; }
public int Burst { get; private set; } public int Burst { get; protected set; }
public Armament(Actor self, ArmamentInfo info) public Armament(Actor self, ArmamentInfo info)
: base(info) : base(info)
@@ -134,12 +134,12 @@ namespace OpenRA.Mods.Common.Traits
Barrels = barrels.ToArray(); Barrels = barrels.ToArray();
} }
public WDist MaxRange() public virtual WDist MaxRange()
{ {
return new WDist(Util.ApplyPercentageModifiers(Weapon.Range.Length, rangeModifiers)); return new WDist(Util.ApplyPercentageModifiers(Weapon.Range.Length, rangeModifiers));
} }
public void Created(Actor self) public virtual void Created(Actor self)
{ {
turret = self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == Info.Turret); turret = self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == Info.Turret);
ammoPool = self.TraitsImplementing<AmmoPool>().FirstOrDefault(la => la.Info.Name == Info.AmmoPoolName); ammoPool = self.TraitsImplementing<AmmoPool>().FirstOrDefault(la => la.Info.Name == Info.AmmoPoolName);
@@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Traits
rangeModifiers = self.TraitsImplementing<IRangeModifier>().ToArray().Select(m => m.GetRangeModifier()); rangeModifiers = self.TraitsImplementing<IRangeModifier>().ToArray().Select(m => m.GetRangeModifier());
} }
public void Tick(Actor self) public virtual void Tick(Actor self)
{ {
if (IsTraitDisabled) if (IsTraitDisabled)
return; return;
@@ -168,7 +168,7 @@ namespace OpenRA.Mods.Common.Traits
delayedActions.RemoveAll(a => a.First <= 0); delayedActions.RemoveAll(a => a.First <= 0);
} }
void ScheduleDelayedAction(int t, Action a) protected void ScheduleDelayedAction(int t, Action a)
{ {
if (t > 0) if (t > 0)
delayedActions.Add(Pair.New(t, a)); delayedActions.Add(Pair.New(t, a));
@@ -178,7 +178,7 @@ namespace OpenRA.Mods.Common.Traits
// Note: facing is only used by the legacy positioning code // Note: facing is only used by the legacy positioning code
// The world coordinate model uses Actor.Orientation // The world coordinate model uses Actor.Orientation
public Barrel CheckFire(Actor self, IFacing facing, Target target) public virtual Barrel CheckFire(Actor self, IFacing facing, Target target)
{ {
if (IsReloading) if (IsReloading)
return null; return null;
@@ -260,11 +260,12 @@ namespace OpenRA.Mods.Common.Traits
return barrel; return barrel;
} }
public bool IsReloading { get { return FireDelay > 0 || IsTraitDisabled; } } public virtual bool OutOfAmmo { get { return ammoPool != null && !ammoPool.Info.SelfReloads && !ammoPool.HasAmmo(); } }
public bool ShouldExplode(Actor self) { return !IsReloading; } public virtual bool IsReloading { get { return FireDelay > 0 || IsTraitDisabled; } }
public bool OutOfAmmo { get { return ammoPool != null && !ammoPool.Info.SelfReloads && !ammoPool.HasAmmo(); } } public virtual bool AllowExplode { get { return !IsReloading; } }
bool IExplodeModifier.ShouldExplode(Actor self) { return AllowExplode; }
public WVec MuzzleOffset(Actor self, Barrel b) public virtual WVec MuzzleOffset(Actor self, Barrel b)
{ {
var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation); var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation);
var localOffset = b.Offset + new WVec(-Recoil, WDist.Zero, WDist.Zero); var localOffset = b.Offset + new WVec(-Recoil, WDist.Zero, WDist.Zero);
@@ -281,7 +282,7 @@ namespace OpenRA.Mods.Common.Traits
return coords.LocalToWorld(localOffset.Rotate(bodyOrientation)); return coords.LocalToWorld(localOffset.Rotate(bodyOrientation));
} }
public WRot MuzzleOrientation(Actor self, Barrel b) public virtual WRot MuzzleOrientation(Actor self, Barrel b)
{ {
var orientation = turret != null ? turret.WorldOrientation(self) : var orientation = turret != null ? turret.WorldOrientation(self) :
coords.QuantizeOrientation(self, self.Orientation); coords.QuantizeOrientation(self, self.Orientation);