From 139d5efba828fcf6bff57d6b8415c17a30f007e4 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 13 Nov 2017 23:25:23 +0100 Subject: [PATCH] Remove RepairBuildings from Aircraft Require them to use Repairable trait instead. --- .../Activities/Air/HeliReturnToBase.cs | 4 +- .../Activities/Air/ReturnToBase.cs | 4 +- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 9 ++-- .../RemoveRepairBuildingsFromAircraft.cs | 50 +++++++++++++++++++ OpenRA.Mods.Common/UpdateRules/UpdatePath.cs | 1 + mods/cnc/rules/defaults.yaml | 3 +- mods/ra/rules/defaults.yaml | 3 +- mods/ts/rules/defaults.yaml | 4 +- 9 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemoveRepairBuildingsFromAircraft.cs diff --git a/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs index 7d154f04d3..101a54902e 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliReturnToBase.cs @@ -19,6 +19,7 @@ namespace OpenRA.Mods.Common.Activities public class HeliReturnToBase : Activity { readonly Aircraft aircraft; + readonly RepairableInfo repairableInfo; readonly bool alwaysLand; readonly bool abortOnResupply; Actor dest; @@ -26,6 +27,7 @@ namespace OpenRA.Mods.Common.Activities public HeliReturnToBase(Actor self, bool abortOnResupply, Actor dest = null, bool alwaysLand = true) { aircraft = self.Trait(); + repairableInfo = self.Info.TraitInfoOrDefault(); this.alwaysLand = alwaysLand; this.abortOnResupply = abortOnResupply; this.dest = dest; @@ -114,7 +116,7 @@ namespace OpenRA.Mods.Common.Activities if (alwaysLand) return true; - if (aircraft.Info.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged) + if (repairableInfo != null && repairableInfo.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged) return true; return aircraft.Info.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing() diff --git a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs index 5f4fe6f262..c76089d837 100644 --- a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs @@ -22,6 +22,7 @@ namespace OpenRA.Mods.Common.Activities { readonly Aircraft aircraft; readonly AircraftInfo aircraftInfo; + readonly RepairableInfo repairableInfo; readonly bool alwaysLand; readonly bool abortOnResupply; bool isCalculated; @@ -35,6 +36,7 @@ namespace OpenRA.Mods.Common.Activities this.abortOnResupply = abortOnResupply; aircraft = self.Trait(); aircraftInfo = self.Info.TraitInfo(); + repairableInfo = self.Info.TraitInfoOrDefault(); } public static Actor ChooseResupplier(Actor self, bool unreservedOnly) @@ -104,7 +106,7 @@ namespace OpenRA.Mods.Common.Activities if (alwaysLand) return true; - if (aircraftInfo.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged) + if (repairableInfo != null && repairableInfo.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged) return true; return aircraftInfo.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing() diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index a291e8038f..b6a714d0cf 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -929,6 +929,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 0592344dc0..0771aef519 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -36,9 +36,6 @@ namespace OpenRA.Mods.Common.Traits [Desc("The speed at which the aircraft is repulsed from other aircraft. Specify -1 for normal movement speed.")] public readonly int RepulsionSpeed = -1; - [ActorReference] - public readonly HashSet RepairBuildings = new HashSet { }; - [ActorReference] public readonly HashSet RearmBuildings = new HashSet { }; @@ -157,6 +154,7 @@ namespace OpenRA.Mods.Common.Traits public readonly AircraftInfo Info; readonly Actor self; + RepairableInfo repairableInfo; ConditionManager conditionManager; IDisposable reservation; IEnumerable speedModifiers; @@ -212,6 +210,7 @@ namespace OpenRA.Mods.Common.Traits protected virtual void Created(Actor self) { + repairableInfo = self.Info.TraitInfoOrDefault(); conditionManager = self.TraitOrDefault(); speedModifiers = self.TraitsImplementing().ToArray().Select(sm => sm.GetSpeedModifier()); cachedPosition = self.CenterPosition; @@ -452,7 +451,7 @@ namespace OpenRA.Mods.Common.Traits return false; return Info.RearmBuildings.Contains(a.Info.Name) - || Info.RepairBuildings.Contains(a.Info.Name); + || (repairableInfo != null && repairableInfo.RepairBuildings.Contains(a.Info.Name)); } public int MovementSpeed @@ -492,7 +491,7 @@ namespace OpenRA.Mods.Common.Traits yield return new Rearm(self, a, WDist.Zero); // The ResupplyAircraft activity guarantees that we're on the helipad - if (Info.RepairBuildings.Contains(name)) + if (repairableInfo != null && repairableInfo.RepairBuildings.Contains(name)) yield return new Repair(self, a, WDist.Zero); } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemoveRepairBuildingsFromAircraft.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemoveRepairBuildingsFromAircraft.cs new file mode 100644 index 0000000000..efbf9315e2 --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20180923/RemoveRepairBuildingsFromAircraft.cs @@ -0,0 +1,50 @@ +#region Copyright & License Information +/* + * Copyright 2007-2018 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.Collections.Generic; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class RemoveRepairBuildingsFromAircraft : UpdateRule + { + public override string Name { get { return "Removed RepairBuildings from Aircraft"; } } + public override string Description + { + get + { + return "Removed RepairBuildings from Aircraft in favor of using Repairable instead."; + } + } + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + // Aircraft isn't conditional or otherwise supports multiple traits, so LastChildMatching is fine. + var aircraftNode = actorNode.LastChildMatching("Aircraft"); + if (aircraftNode != null) + { + var repairBuildings = aircraftNode.LastChildMatching("RepairBuildings"); + if (repairBuildings != null) + { + var repariableNode = new MiniYamlNode("Repairable", ""); + repairBuildings.MoveAndRenameNode(aircraftNode, repariableNode, "RepairBuildings"); + + var voice = aircraftNode.LastChildMatching("Voice"); + if (voice != null) + repariableNode.AddNode(voice); + + actorNode.AddNode(repariableNode); + } + } + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index df9351b022..eb0d92de4c 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -99,6 +99,7 @@ namespace OpenRA.Mods.Common.UpdateRules new ChangeTakeOffSoundAndLandingSound(), new RemoveHealthPercentageRing(), new RenameCrateActionNotification(), + new RemoveRepairBuildingsFromAircraft(), }) }; diff --git a/mods/cnc/rules/defaults.yaml b/mods/cnc/rules/defaults.yaml index 229e30f09d..d68063424d 100644 --- a/mods/cnc/rules/defaults.yaml +++ b/mods/cnc/rules/defaults.yaml @@ -306,8 +306,9 @@ WithSpriteControlGroupDecoration: Selectable: Bounds: 24,24 - Aircraft: + Repairable: RepairBuildings: hpad + Aircraft: LandWhenIdle: false AirborneCondition: airborne CruisingCondition: cruising diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index b13be1afe0..be805249a2 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -526,7 +526,6 @@ Selectable: Bounds: 24,24 Aircraft: - RepairBuildings: fix AirborneCondition: airborne Targetable@GROUND: TargetTypes: Ground, Repair, Vehicle @@ -573,6 +572,8 @@ ^Plane: Inherits: ^NeutralPlane Inherits@2: ^GainsExperience + Repairable: + RepairBuildings: fix ^Helicopter: Inherits: ^Plane diff --git a/mods/ts/rules/defaults.yaml b/mods/ts/rules/defaults.yaml index 249e591ded..ceb383c2ab 100644 --- a/mods/ts/rules/defaults.yaml +++ b/mods/ts/rules/defaults.yaml @@ -821,9 +821,11 @@ WithTextControlGroupDecoration: SelectionDecorations: Palette: pips + Repairable: + RepairBuildings: gadept + Voice: Move Aircraft: AirborneCondition: airborne - RepairBuildings: gadept LandWhenIdle: false Voice: Move IdealSeparation: 853