From bbf449566898089b6e089a3bff397ca2aa28d95b Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sat, 29 Jun 2019 22:39:41 +0200 Subject: [PATCH] Update rule for FlightDynamics --- .../Rules/20190314/AddFlightDynamics.cs | 75 +++++++++++++++++++ OpenRA.Mods.Common/UpdateRules/UpdatePath.cs | 1 + 2 files changed, 76 insertions(+) create mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/20190314/AddFlightDynamics.cs diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20190314/AddFlightDynamics.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20190314/AddFlightDynamics.cs new file mode 100644 index 0000000000..d847677640 --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20190314/AddFlightDynamics.cs @@ -0,0 +1,75 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class AddFlightDynamics : UpdateRule + { + public override string Name { get { return "Replaced Aircraft boolean fields with FlightDynamics"; } } + public override string Description + { + get + { + return "Various Aircraft boolean fields have been replaced with a single FlightDynamics flag list.\n" + + "Additionally, the old 'CanHover' behavior has been split into two flags:\n" + + "'Slide' to change flight direction independent of facing, and 'Hover' to be able to stand still mid-air."; + } + } + + static readonly string[] Properties = + { + "MoveIntoShroud", + "CanHover", + "VTOL", + "TurnToLand", + "TurnToDock", + "TakeOffOnResupply", + "TakeOffOnCreation", + }; + + readonly Dictionary> locations = new Dictionary>(); + + public override IEnumerable AfterUpdate(ModData modData) + { + if (locations.Any()) + yield return "The following aircraft definitions did not use the internal defaults\n" + + "and likely need a customized FlightDynamics flag list (and removal of the old booleans):\n" + + UpdateUtils.FormatMessageList(locations.Select( + kv => kv.Key + ":\n" + UpdateUtils.FormatMessageList(kv.Value))); + + locations.Clear(); + } + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + var aircraftTraits = actorNode.ChildrenMatching("Aircraft"); + foreach (var aircraft in aircraftTraits) + { + var used = new List(); + foreach (var p in Properties) + if (aircraft.LastChildMatching(p) != null) + used.Add(p); + + if (used.Any()) + { + var location = "{0} ({1})".F(actorNode.Key, actorNode.Location.Filename); + locations[location] = used; + } + } + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 1e9d984b88..088fcb82c5 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -130,6 +130,7 @@ namespace OpenRA.Mods.Common.UpdateRules new RenameHoversOffsetModifier(), new AddAirAttackTypes(), new RenameCarryallDelays(), + new AddFlightDynamics(), }) };