Files
OpenRA/OpenRA.Mods.Cnc/PoisonedByTiberium.cs
Squiggles211 a0458eeb24 Fix crashes related to transports
Fixes two specific causes of transport related crashes, one prevents
infantry from continuing to take damage by Tiberium if loaded into the
transport over Tiberium, and one fixes the edge case where an infantry
dies in the same tick cycle as it was loaded into the transport.
2014-05-15 20:27:44 -05:00

50 lines
1.4 KiB
C#

#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.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc
{
class PoisonedByTiberiumInfo : ITraitInfo
{
[WeaponReference] public readonly string Weapon = "Tiberium";
public readonly string[] Resources = { "Tiberium", "BlueTiberium" };
public object Create(ActorInitializer init) { return new PoisonedByTiberium(this); }
}
class PoisonedByTiberium : ITick, ISync
{
PoisonedByTiberiumInfo info;
[Sync] int poisonTicks;
public PoisonedByTiberium(PoisonedByTiberiumInfo info) { this.info = info; }
public void Tick(Actor self)
{
if (--poisonTicks > 0) return;
// Prevents harming infantry in cargo.
if (!self.IsInWorld) return;
var rl = self.World.WorldActor.Trait<ResourceLayer>();
var r = rl.GetResource(self.Location);
if (r == null) return;
if (!info.Resources.Contains(r.Info.Name)) return;
var weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
self.InflictDamage(self.World.WorldActor, weapon.Warheads[0].Damage, weapon.Warheads[0]);
poisonTicks = weapon.ROF;
}
}
}