Files
OpenRA/OpenRA.Mods.Common/Lint/CheckDeathTypes.cs
2016-02-21 16:27:31 +00:00

60 lines
1.7 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2016 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;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Lint
{
class CheckDeathTypes : ILintRulesPass
{
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
{
foreach (var actorInfo in rules.Actors)
{
var animations = actorInfo.Value.TraitInfos<WithDeathAnimationInfo>().ToList();
if (!animations.Any())
continue;
var deathTypes = animations.SelectMany(x => x.DeathTypes.Select(y => y.Key)).ToList();
if (!deathTypes.Any())
continue;
var targetable = actorInfo.Value.TraitInfos<ITargetableInfo>().SelectMany(x => x.GetTargetTypes()).ToList();
if (!targetable.Any())
continue;
foreach (var weaponInfo in rules.Weapons)
{
var warheads = weaponInfo.Value.Warheads.OfType<DamageWarhead>().Where(dw => dw.Damage > 0);
foreach (var warhead in warheads)
{
// This is a special warhead, like the one on `weathering` in D2k.
if (!warhead.DamageTypes.Any())
continue;
// This warhead cannot affect this actor.
if (!warhead.ValidTargets.Overlaps(targetable))
continue;
if (!warhead.DamageTypes.Overlaps(deathTypes))
emitError("Actor type `{0}` does not define a death animation for weapon `{1}`!"
.F(actorInfo.Key, weaponInfo.Key));
}
}
}
}
}
}