remove DeathWeapon; IExplodeModifier implemented for resource actors (and for V2, which was the original purpose)

This commit is contained in:
Chris Forbes
2010-07-05 17:43:20 +12:00
parent 68b63dc89e
commit 2ed8045736
6 changed files with 20 additions and 39 deletions

View File

@@ -18,6 +18,7 @@
*/
#endregion
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -49,12 +50,10 @@ namespace OpenRA.Mods.RA
string ChooseWeaponForExplosion(Actor self)
{
var shouldExplode = self.traits.WithInterface<IExplodeModifier>().All(a => a.ShouldExplode(self));
var info = self.Info.Traits.Get<ExplodesInfo>();
var attack = self.traits.GetOrDefault<AttackBase>();
if (attack == null) return info.Weapon;
return attack.IsReloading() ? info.EmptyWeapon : info.Weapon;
return shouldExplode ? info.Weapon : info.EmptyWeapon;
}
}
}

View File

@@ -32,13 +32,11 @@ namespace OpenRA.Mods.RA
public readonly int PipCount = 7;
public readonly PipType PipColor = PipType.Yellow;
public readonly string[] Resources = { };
[WeaponReference]
public readonly string DeathWeapon = null;
public object Create(ActorInitializer init) { return new Harvester(init.self, this); }
}
public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips, IRenderModifier
public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips, IRenderModifier, IExplodeModifier
{
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
@@ -143,16 +141,8 @@ namespace OpenRA.Mods.RA
public void Damaged(Actor self, AttackInfo e)
{
if (self.IsDead)
{
if (Info.DeathWeapon != null && contents.Count > 0)
{
Combat.DoExplosion(e.Attacker, Info.DeathWeapon,
self.CenterLocation.ToInt2(), 0);
}
if (LinkedProc != null)
LinkedProc.traits.WithInterface<IAcceptOre>().FirstOrDefault().UnlinkHarvester(LinkedProc,self);
}
}
public void LinkProc(Actor self, Actor proc)
@@ -185,6 +175,8 @@ namespace OpenRA.Mods.RA
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{
return Visible ? r : new Renderable[] { };
}
}
public bool ShouldExplode(Actor self) { return !IsEmpty; }
}
}

View File

@@ -36,13 +36,11 @@ namespace OpenRA.Mods.RA
public readonly int Capacity = 0;
public readonly int ProcessTick = 25;
public readonly int ProcessAmount = 50;
[WeaponReference]
public readonly string DeathWeapon = null;
public object Create(ActorInitializer init) { return new OreRefinery(init.self, this); }
}
class OreRefinery : ITick, IAcceptOre, INotifyDamage, INotifySold, INotifyCapture, IPips
class OreRefinery : ITick, IAcceptOre, INotifyDamage, INotifySold, INotifyCapture, IPips, IExplodeModifier
{
readonly Actor self;
readonly OreRefineryInfo Info;
@@ -106,14 +104,9 @@ namespace OpenRA.Mods.RA
public void Damaged (Actor self, AttackInfo e)
{
if (self.IsDead) {
if (Info.DeathWeapon != null && Ore > 0) {
Combat.DoExplosion (e.Attacker, Info.DeathWeapon, self.CenterLocation.ToInt2 (), 0);
}
if (self.IsDead)
foreach (var harv in LinkedHarv)
harv.traits.Get<Harvester> ().UnlinkProc(harv, self);
}
}
public int2 DeliverOffset {get{ return Info.DockOffset; }}
@@ -146,5 +139,7 @@ namespace OpenRA.Mods.RA
return Graphics.Util.MakeArray (Info.PipCount, i => (Ore * 1f / Info.Capacity > i * 1f / Info.PipCount) ? Info.PipColor : PipType.Transparent);
}
public bool ShouldExplode(Actor self) { return Ore > 0; }
}
}