From 6b4bf102273a9767cf05ba12af0f40a9d9ec207b Mon Sep 17 00:00:00 2001 From: penev92 Date: Tue, 26 May 2015 21:21:47 +0300 Subject: [PATCH] Add lint rule for Death Types --- OpenRA.Mods.Common/Lint/CheckDeathTypes.cs | 59 ++++++++++++++++++++ OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 4 +- 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 OpenRA.Mods.Common/Lint/CheckDeathTypes.cs diff --git a/OpenRA.Mods.Common/Lint/CheckDeathTypes.cs b/OpenRA.Mods.Common/Lint/CheckDeathTypes.cs new file mode 100644 index 0000000000..b3c6b427e9 --- /dev/null +++ b/OpenRA.Mods.Common/Lint/CheckDeathTypes.cs @@ -0,0 +1,59 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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.GameRules; +using OpenRA.Mods.Common.Traits; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Lint +{ + class CheckDeathTypes : ILintPass + { + public void Run(Action emitError, Action emitWarning, Map map) + { + foreach (var actorInfo in map.Rules.Actors) + { + var animations = actorInfo.Value.Traits.WithInterface().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.Traits.WithInterface().SelectMany(x => x.GetTargetTypes()).ToList(); + if (!targetable.Any()) + continue; + + foreach (var weaponInfo in map.Rules.Weapons) + { + var warheads = weaponInfo.Value.Warheads.OfType().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.Intersect(targetable).Any()) + continue; + + if (!warhead.DamageTypes.Intersect(deathTypes).Any()) + emitError("Actor type `{0}` does not define a death animation for weapon `{1}`!" + .F(actorInfo.Key, weaponInfo.Key)); + } + } + } + } + } +} diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index e9f82be475..f442976916 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -166,6 +166,7 @@ + @@ -664,7 +665,4 @@ cd "$(SolutionDir)" --> - - - \ No newline at end of file