From 0510a7fb7f36c69491805c01ec67bc91925ff7b9 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 21 Mar 2010 19:52:13 +1300 Subject: [PATCH] Begin generalizing crates; only give firepower bonus to units with weapons --- OpenRA.Game/Traits/Crate.cs | 2 +- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs | 13 ++++++++----- OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs | 11 +++++++---- .../Crates/FirepowerUpgradeCrateAction.cs | 15 ++++++++++----- OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs | 12 ++++++++---- OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs | 13 ++++++++----- mods/ra/rules.yaml | 7 +++++++ 8 files changed, 50 insertions(+), 25 deletions(-) diff --git a/OpenRA.Game/Traits/Crate.cs b/OpenRA.Game/Traits/Crate.cs index 70f1d093d5..81ebc31bbf 100644 --- a/OpenRA.Game/Traits/Crate.cs +++ b/OpenRA.Game/Traits/Crate.cs @@ -62,7 +62,7 @@ namespace OpenRA.Traits public void OnCrush(Actor crusher) { - var shares = self.traits.WithInterface().Select(a => Pair.New(a, a.SelectionShares)); + var shares = self.traits.WithInterface().Select(a => Pair.New(a, a.GetSelectionShares(crusher))); var totalShares = shares.Sum(a => a.Second); var n = self.World.SharedRandom.Next(totalShares); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index f95a53abcf..a5f5e5d5ee 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -85,7 +85,7 @@ namespace OpenRA.Traits public interface ICrateAction { - int SelectionShares { get; } + int GetSelectionShares(Actor collector); void Activate(Actor collector); } diff --git a/OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs b/OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs index 65fe882c58..469fe5f80c 100644 --- a/OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/ArmorUpgradeCrateAction.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -27,6 +27,8 @@ namespace OpenRA.Mods.RA { public float Multiplier = 2.0f; public int SelectionShares = 10; + public string Effect = null; + public string Notification = null; public object Create(Actor self) { return new ArmorUpgradeCrateAction(self); } } @@ -38,19 +40,20 @@ namespace OpenRA.Mods.RA this.self = self; } - public int SelectionShares + public int GetSelectionShares(Actor collector) { - get { return self.Info.Traits.Get().SelectionShares; } + return self.Info.Traits.Get().SelectionShares; } public void Activate(Actor collector) { - Sound.PlayToPlayer(collector.Owner, "armorup1.aud"); + Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); + collector.World.AddFrameEndTask(w => { var multiplier = self.Info.Traits.Get().Multiplier; collector.traits.Add(new ArmorUpgrade(multiplier)); - w.Add(new CrateEffect(collector, "armor")); + w.Add(new CrateEffect(collector, self.Info.Traits.Get().Effect)); }); } } diff --git a/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs b/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs index aa91e71f22..9b2b69d760 100644 --- a/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -11,7 +11,8 @@ namespace OpenRA.Mods.RA { public string Weapon = null; public int SelectionShares = 5; - + public string Effect = null; + public string Notification = null; public object Create(Actor self) { return new ExplodeCrateAction(self, this); } } @@ -26,13 +27,15 @@ namespace OpenRA.Mods.RA this.info = info; } - public int SelectionShares + public int GetSelectionShares(Actor collector) { - get { return info.SelectionShares; } + return info.SelectionShares; } public void Activate(Actor collector) { + Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); + self.World.AddFrameEndTask( w => w.Add(new Bullet(info.Weapon, self.Owner, self, self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(), diff --git a/OpenRA.Mods.RA/Crates/FirepowerUpgradeCrateAction.cs b/OpenRA.Mods.RA/Crates/FirepowerUpgradeCrateAction.cs index e21d586520..bb44e4b607 100644 --- a/OpenRA.Mods.RA/Crates/FirepowerUpgradeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/FirepowerUpgradeCrateAction.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -27,6 +27,8 @@ namespace OpenRA.Mods.RA { public float Multiplier = 2.0f; public int SelectionShares = 10; + public string Effect = null; + public string Notification = null; public object Create(Actor self) { return new FirepowerUpgradeCrateAction(self); } } @@ -38,19 +40,22 @@ namespace OpenRA.Mods.RA this.self = self; } - public int SelectionShares + public int GetSelectionShares(Actor collector) { - get { return self.Info.Traits.Get().SelectionShares; } + if (collector.GetPrimaryWeapon() == null && collector.GetSecondaryWeapon() == null) + return 0; + + return self.Info.Traits.Get().SelectionShares; } public void Activate(Actor collector) { - Sound.PlayToPlayer(collector.Owner, "firepo1.aud"); + Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); collector.World.AddFrameEndTask(w => { var multiplier = self.Info.Traits.Get().Multiplier; collector.traits.Add(new FirepowerUpgrade(multiplier)); - w.Add(new CrateEffect(collector, "fpower")); + w.Add(new CrateEffect(collector, self.Info.Traits.Get().Effect)); }); } } diff --git a/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs index cac401d52b..e7c4ab6c1c 100644 --- a/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveCashCrateAction.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -27,6 +27,8 @@ namespace OpenRA.Mods.RA { public int Amount = 2000; public int SelectionShares = 10; + public string Effect = null; + public string Notification = null; public object Create(Actor self) { return new GiveCashCrateAction(self); } } @@ -38,18 +40,20 @@ namespace OpenRA.Mods.RA this.self = self; } - public int SelectionShares + public int GetSelectionShares(Actor collector) { - get { return self.Info.Traits.Get().SelectionShares; } + return self.Info.Traits.Get().SelectionShares; } public void Activate(Actor collector) { + Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); + collector.World.AddFrameEndTask(w => { var amount = self.Info.Traits.Get().Amount; collector.Owner.GiveCash(amount); - w.Add(new CrateEffect(collector, "dollar")); + w.Add(new CrateEffect(collector, self.Info.Traits.Get().Effect)); }); } } diff --git a/OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs b/OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs index 09ff17e19d..18d5444470 100644 --- a/OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/SpeedUpgradeCrateAction.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -27,6 +27,8 @@ namespace OpenRA.Mods.RA { public float Multiplier = 1.7f; public int SelectionShares = 10; + public string Effect = null; + public string Notification = null; public object Create(Actor self) { return new SpeedUpgradeCrateAction(self); } } @@ -38,19 +40,20 @@ namespace OpenRA.Mods.RA this.self = self; } - public int SelectionShares + public int GetSelectionShares(Actor collector) { - get { return self.Info.Traits.Get().SelectionShares; } + return self.Info.Traits.Get().SelectionShares; } public void Activate(Actor collector) { - Sound.PlayToPlayer(collector.Owner, "unitspd1.aud"); + Sound.PlayToPlayer(collector.Owner, self.Info.Traits.Get().Notification); + collector.World.AddFrameEndTask(w => { var multiplier = self.Info.Traits.Get().Multiplier; collector.traits.Add(new SpeedUpgrade(multiplier)); - w.Add(new CrateEffect(collector, "speed")); + w.Add(new CrateEffect(collector, self.Info.Traits.Get().Effect)); }); } } diff --git a/mods/ra/rules.yaml b/mods/ra/rules.yaml index e0879ad236..28b7f662bc 100644 --- a/mods/ra/rules.yaml +++ b/mods/ra/rules.yaml @@ -637,15 +637,22 @@ CRATE: SpeedUpgradeCrateAction: Multiplier: 1.7 SelectionShares: 10 + Notification: unitspd1.aud + Effect: speed GiveCashCrateAction: Amount: 2000 SelectionShares: 50 + Effect: dollar FirepowerUpgradeCrateAction: Multiplier: 2.0 SelectionShares: 10 + Notification: firepo1.aud + Effect: fpower ArmorUpgradeCrateAction: Multiplier: 2.0 SelectionShares: 10 + Notification: armorup1.aud + Effect: armor ExplodeCrateAction@fire: Weapon: Napalm SelectionShares: 80