Add crushable infantry support, enabled in C&C.

This commit is contained in:
Paul Chote
2011-07-10 17:57:52 +12:00
parent 7173d193cf
commit e9bd03b686
6 changed files with 118 additions and 15 deletions

View File

@@ -0,0 +1,60 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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 System.Linq;
using OpenRA.Traits;
using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{
class CrushableInfantryInfo : ITraitInfo, Requires<MobileInfo>
{
public readonly string CrushSound = "squish2.aud";
public readonly string CorpseSequence = "die-crushed";
public readonly string[] CrushClasses = { "infantry" };
public readonly int WarnProbability = 90;
public object Create(ActorInitializer init) { return new CrushableInfantry(init.self, this); }
}
class CrushableInfantry : ICrushable
{
readonly Actor self;
readonly CrushableInfantryInfo Info;
public CrushableInfantry(Actor self, CrushableInfantryInfo info)
{
this.self = self;
this.Info = info;
}
public void WarnCrush(Actor crusher)
{
if (self.World.SharedRandom.Next(100) <= Info.WarnProbability)
self.Trait<Mobile>().OnNudge(self, crusher, true);
}
public void OnCrush(Actor crusher)
{
Sound.Play(Info.CrushSound);
self.World.AddFrameEndTask(w => w.Add(new Corpse(self, Info.CorpseSequence)));
self.Kill(crusher);
}
public bool CrushableBy(string[] crushClasses, Player crushOwner)
{
if (crushOwner.Stances[self.Owner] == Stance.Ally)
return false;
return Info.CrushClasses.Intersect(crushClasses).Any();
}
}
}