From cc9c253419845125956e2f58666c56503d5b95a0 Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Fri, 29 Aug 2014 12:55:19 -0500 Subject: [PATCH] Moved SellSounds from Building to Sellable & added upgrade to rules. --- OpenRA.Mods.RA/Buildings/Building.cs | 4 ---- OpenRA.Mods.RA/Sellable.cs | 16 ++++++++++++++-- OpenRA.Utility/UpgradeRules.cs | 27 +++++++++++++++++++++++++++ mods/cnc/rules/defaults.yaml | 3 ++- mods/d2k/rules/defaults.yaml | 2 +- mods/d2k/rules/structures.yaml | 5 +++-- mods/ra/rules/defaults.yaml | 2 ++ mods/ts/rules/defaults.yaml | 2 ++ 8 files changed, 51 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index 209f6df6b7..747b2ffb4b 100644 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -34,7 +34,6 @@ namespace OpenRA.Mods.RA.Buildings public readonly bool AllowInvalidPlacement = false; public readonly string[] BuildSounds = { "placbldg.aud", "build5.aud" }; - public readonly string[] SellSounds = { "cashturn.aud" }; public readonly string[] UndeploySounds = { "cashturn.aud" }; public object Create(ActorInitializer init) { return new Building(init, this); } @@ -176,9 +175,6 @@ namespace OpenRA.Mods.RA.Buildings public void Selling(Actor self) { - foreach (var s in Info.SellSounds) - Sound.PlayToPlayer(self.Owner, s, self.CenterPosition); - BuildComplete = false; } diff --git a/OpenRA.Mods.RA/Sellable.cs b/OpenRA.Mods.RA/Sellable.cs index e6e8a66b03..d52c7dc40e 100644 --- a/OpenRA.Mods.RA/Sellable.cs +++ b/OpenRA.Mods.RA/Sellable.cs @@ -8,6 +8,7 @@ */ #endregion +using System.Linq; using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Render; @@ -15,14 +16,22 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - [Desc("Building can be sold")] - public class SellableInfo : TraitInfo + + [Desc("Actor can be sold")] + public class SellableInfo : ITraitInfo { public readonly int RefundPercent = 50; + public readonly string[] SellSounds = { }; + + public object Create(ActorInitializer init) { return new Sellable(this); } } public class Sellable : IResolveOrder { + readonly SellableInfo info; + + public Sellable(SellableInfo info) { this.info = info; } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Sell") @@ -37,6 +46,9 @@ namespace OpenRA.Mods.RA self.CancelActivity(); + foreach (var s in info.SellSounds) + Sound.PlayToPlayer(self.Owner, s, self.CenterPosition); + foreach (var ns in self.TraitsImplementing()) ns.Selling(self); diff --git a/OpenRA.Utility/UpgradeRules.cs b/OpenRA.Utility/UpgradeRules.cs index d75ae47cda..69679182a1 100644 --- a/OpenRA.Utility/UpgradeRules.cs +++ b/OpenRA.Utility/UpgradeRules.cs @@ -488,6 +488,33 @@ namespace OpenRA.Utility node.Key = "DeathType"; } + // SellSounds from Building was moved into Sellable + if (engineVersion < 20140904) + { + if (depth == 0) + { + var actorTraits = node.Value.Nodes; + var building = actorTraits.FirstOrDefault(t => t.Key == "Building"); + if (building != null) + { + var buildingFields = building.Value.Nodes; + var sellSounds = buildingFields.FirstOrDefault(n => n.Key == "SellSounds"); + if (sellSounds != null) + { + buildingFields.Remove(sellSounds); + var sellable = actorTraits.FirstOrDefault(t => t.Key == "Sellable"); + if (sellable != null) + sellable.Value.Nodes.Add(sellSounds); + else + { + Console.WriteLine("Warning: Adding Sellable trait to {0} in {1}".F(node.Key, node.Location.Filename)); + actorTraits.Add(new MiniYamlNode("Sellable", new MiniYaml("", new List { sellSounds }))); + } + } + } + } + } + UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); } } diff --git a/mods/cnc/rules/defaults.yaml b/mods/cnc/rules/defaults.yaml index 984a718b71..0d78cbb8f8 100644 --- a/mods/cnc/rules/defaults.yaml +++ b/mods/cnc/rules/defaults.yaml @@ -334,7 +334,6 @@ Dimensions: 1,1 Footprint: x BuildSounds: constru2.aud, hvydoor1.aud - SellSounds: cashturn.aud TerrainTypes: Clear,Road SoundOnDamageTransition: DamagedSound: xplos.aud @@ -374,6 +373,7 @@ GivesBuildableArea: EngineerRepairable: Sellable: + SellSounds: cashturn.aud Capturable: ^CivBuilding: @@ -473,6 +473,7 @@ RelativeToTopLeft: yes AutoTargetIgnore: Sellable: + SellSounds: cashturn.aud Guardable: BodyOrientation: FrozenUnderFog: diff --git a/mods/d2k/rules/defaults.yaml b/mods/d2k/rules/defaults.yaml index a56bd7177d..df3a424206 100644 --- a/mods/d2k/rules/defaults.yaml +++ b/mods/d2k/rules/defaults.yaml @@ -243,7 +243,6 @@ Footprint: x TerrainTypes: Rock, Concrete BuildSounds: BUILD1.WAV - SellSounds: BUILD1.WAV Adjacent: 3 GivesBuildableArea: ExternalCapturable: @@ -268,6 +267,7 @@ ProximityCaptor: Types: Building Sellable: + SellSounds: BUILD1.WAV GivesBounty: CombatDebugOverlay: Guardable: diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index 25d54d2bba..ac7f08519d 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -3,7 +3,6 @@ Adjacent: 4 TerrainTypes: Rock BuildSounds: CHUNG.WAV - SellSounds: CHUNG.WAV AllowInvalidPlacement: true LaysTerrain: Template: 88 @@ -412,7 +411,6 @@ CONCRETEB: AppearsOnRadar: Building: BuildSounds: CHUNG.WAV - SellSounds: CHUNG.WAV Adjacent: 7 TerrainTypes: Rock, Concrete Health: @@ -436,6 +434,7 @@ CONCRETEB: ProximityCaptor: Types: Wall Sellable: + SellSounds: CHUNG.WAV Guardable: BodyOrientation: ThrowsShrapnel: @@ -462,6 +461,7 @@ WALL: Building: Adjacent: 4 BuildSounds: CHUNG.WAV + Sellable: SellSounds: CHUNG.WAV Selectable: Bounds: 32,40,0,-8 @@ -514,6 +514,7 @@ WALL: Building: Adjacent: 4 BuildSounds: CHUNG.WAV + Sellable: SellSounds: CHUNG.WAV Selectable: Bounds: 32,40,0,-8 diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index fc6c58e301..96acd3320a 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -298,6 +298,7 @@ ProximityCaptor: Types: Building Sellable: + SellSounds: cashturn.aud AcceptsSupplies: GivesBounty: UpdatesPlayerStatistics: @@ -348,6 +349,7 @@ ProximityCaptor: Types: Wall Sellable: + SellSounds: cashturn.aud Guardable: BodyOrientation: FrozenUnderFog: diff --git a/mods/ts/rules/defaults.yaml b/mods/ts/rules/defaults.yaml index b82ce337c0..64f4d78682 100644 --- a/mods/ts/rules/defaults.yaml +++ b/mods/ts/rules/defaults.yaml @@ -29,6 +29,7 @@ ProximityCaptor: Types: Building Sellable: + SellSounds: cashturn.aud AcceptsSupplies: GivesBounty: UpdatesPlayerStatistics: @@ -75,6 +76,7 @@ ProximityCaptor: Types: Wall Sellable: + SellSounds: cashturn.aud UpdatesPlayerStatistics: BodyOrientation: LuaScriptEvents: