using System.Collections.Generic; using System.Linq; using OpenRa.Effects; using OpenRa.Traits; namespace OpenRa.Mods.RA { class MineInfo : ITraitInfo { public readonly int Damage = 0; public readonly UnitMovementType[] TriggeredBy = { }; public readonly string Warhead = "ATMine"; public readonly bool AvoidFriendly = true; public object Create(Actor self) { return new Mine(self); } } class Mine : ICrushable, IOccupySpace { readonly Actor self; public Mine(Actor self) { this.self = self; self.World.WorldActor.traits.Get().Add(self, this); } public void OnCrush(Actor crusher) { if (crusher.traits.Contains() && crusher.Owner == self.Owner) return; var info = self.Info.Traits.Get(); var warhead = Rules.WarheadInfo[info.Warhead]; self.World.AddFrameEndTask(w => { w.Remove(self); w.Add(new Explosion(w, self.CenterLocation.ToInt2(), warhead.Explosion, false)); crusher.InflictDamage(crusher, info.Damage, warhead); }); } public bool IsPathableCrush(UnitMovementType umt, Player player) { return !self.Info.Traits.Get().AvoidFriendly || (player != self.Owner); } public bool IsCrushableBy(UnitMovementType umt, Player player) { return self.Info.Traits.Get().TriggeredBy.Contains(umt); } public IEnumerable OccupiedCells() { yield return self.Location; } } }