From 84d3497e96c4ba232844110911444312b3329404 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 9 Aug 2014 21:54:03 +1200 Subject: [PATCH] Convert speed modifiers to integer percentages. --- OpenRA.Game/Traits/TraitsInterfaces.cs | 2 +- OpenRA.Mods.RA/Air/Aircraft.cs | 7 +++---- OpenRA.Mods.RA/GainsStatUpgrades.cs | 6 +++--- OpenRA.Mods.RA/Harvester.cs | 8 ++++---- OpenRA.Mods.RA/Move/Mobile.cs | 4 +++- OpenRA.Mods.RA/ScaredyCat.cs | 6 +++--- OpenRA.Mods.RA/TakeCover.cs | 8 ++++---- OpenRA.Utility/UpgradeRules.cs | 12 ++++++++++++ 8 files changed, 33 insertions(+), 20 deletions(-) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 2314ead991..14e000f83b 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -156,7 +156,7 @@ namespace OpenRA.Traits public interface IRenderModifier { IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r); } public interface IDamageModifier { int GetDamageModifier(Actor attacker, DamageWarhead warhead); } - public interface ISpeedModifier { decimal GetSpeedModifier(); } + public interface ISpeedModifier { int GetSpeedModifier(); } public interface IFirepowerModifier { float GetFirepowerModifier(); } public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); } public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary b); } diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index 55964bdfee..61fef40569 100644 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -203,10 +203,9 @@ namespace OpenRA.Mods.RA.Air { get { - decimal ret = info.Speed; - foreach (var t in self.TraitsImplementing()) - ret *= t.GetSpeedModifier(); - return (int)ret; + var modifiers = self.TraitsImplementing() + .Select(m => m.GetSpeedModifier()); + return Util.ApplyPercentageModifiers(info.Speed, modifiers); } } diff --git a/OpenRA.Mods.RA/GainsStatUpgrades.cs b/OpenRA.Mods.RA/GainsStatUpgrades.cs index 80e1e7543a..7849a4b931 100644 --- a/OpenRA.Mods.RA/GainsStatUpgrades.cs +++ b/OpenRA.Mods.RA/GainsStatUpgrades.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA public readonly int[] ArmorModifier = { 110, 120, 130, 150 }; public readonly string SpeedUpgrade = "speed"; - public readonly decimal[] SpeedModifier = { 1.1m, 1.15m, 1.2m, 1.5m }; + public readonly int[] SpeedModifier = { 110, 115, 120, 150 }; public object Create(ActorInitializer init) { return new GainsStatUpgrades(this); } } @@ -70,9 +70,9 @@ namespace OpenRA.Mods.RA return firepowerLevel > 0 ? info.FirepowerModifier[firepowerLevel - 1] : 1; } - public decimal GetSpeedModifier() + public int GetSpeedModifier() { - return speedLevel > 0 ? info.SpeedModifier[speedLevel - 1] : 1m; + return speedLevel > 0 ? info.SpeedModifier[speedLevel - 1] : 100; } } } diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index a18a53e208..1a06bd35e3 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -31,8 +31,8 @@ namespace OpenRA.Mods.RA public readonly int HarvestFacings = 0; [Desc("Which resources it can harvest.")] public readonly string[] Resources = { }; - [Desc("How much it is slowed down when returning to the refinery.")] - public readonly decimal FullyLoadedSpeed = .85m; + [Desc("Percentage of maximum speed when fully loaded.")] + public readonly int FullyLoadedSpeed = 85; [Desc("Initial search radius (in cells) from the refinery that created us.")] public readonly int SearchFromProcRadius = 24; [Desc("Search radius (in cells) from the last harvest order location to find more resources.")] @@ -418,9 +418,9 @@ namespace OpenRA.Mods.RA public bool ShouldExplode(Actor self) { return !IsEmpty; } - public decimal GetSpeedModifier() + public int GetSpeedModifier() { - return 1m - (1m - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity; + return 100 - (100 - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity; } class HarvestOrderTargeter : IOrderTargeter diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index b83ea123cc..0a8b94f030 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -487,13 +487,15 @@ namespace OpenRA.Mods.RA.Move if (index == -1) return 0; + // TODO: Convert to integers var speed = Info.TilesetTerrainInfo[self.World.TileSet][index].Speed; if (speed == decimal.Zero) return 0; speed *= Info.Speed; foreach (var t in self.TraitsImplementing()) - speed *= t.GetSpeedModifier(); + speed *= t.GetSpeedModifier() / 100m; + return (int)(speed / 100); } diff --git a/OpenRA.Mods.RA/ScaredyCat.cs b/OpenRA.Mods.RA/ScaredyCat.cs index 01904e1de2..0e5a526818 100644 --- a/OpenRA.Mods.RA/ScaredyCat.cs +++ b/OpenRA.Mods.RA/ScaredyCat.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA class ScaredyCatInfo : ITraitInfo { public readonly int PanicLength = 25 * 10; - public readonly decimal PanicSpeedModifier = 2; + public readonly int PanicSpeedModifier = 200; public readonly int AttackPanicChance = 20; public object Create(ActorInitializer init) { return new ScaredyCat(init.self, this); } @@ -74,9 +74,9 @@ namespace OpenRA.Mods.RA Panic(); } - public decimal GetSpeedModifier() + public int GetSpeedModifier() { - return Panicking ? Info.PanicSpeedModifier : 1; + return Panicking ? Info.PanicSpeedModifier : 100; } } } diff --git a/OpenRA.Mods.RA/TakeCover.cs b/OpenRA.Mods.RA/TakeCover.cs index c8d60071b2..1dfb49c38e 100644 --- a/OpenRA.Mods.RA/TakeCover.cs +++ b/OpenRA.Mods.RA/TakeCover.cs @@ -21,8 +21,8 @@ namespace OpenRA.Mods.RA "Measured in game ticks. Default is 4 seconds.")] public readonly int ProneTime = 100; - [Desc("How quickly we should go from standing to prone.")] - public readonly decimal ProneSpeed = .5m; + [Desc("Prone movement speed as a percentage of the normal speed.")] + public readonly int ProneSpeed = 50; public readonly WVec ProneOffset = new WVec(85, 0, -171); @@ -66,9 +66,9 @@ namespace OpenRA.Mods.RA return IsProne && warhead != null ? warhead.ProneModifier : 100; } - public decimal GetSpeedModifier() + public int GetSpeedModifier() { - return IsProne ? Info.ProneSpeed : 1m; + return IsProne ? Info.ProneSpeed : 100; } } diff --git a/OpenRA.Utility/UpgradeRules.cs b/OpenRA.Utility/UpgradeRules.cs index a8a2027182..c4100d840e 100644 --- a/OpenRA.Utility/UpgradeRules.cs +++ b/OpenRA.Utility/UpgradeRules.cs @@ -416,6 +416,18 @@ namespace OpenRA.Utility if (depth == 2 && node.Key == "ArmorModifier" && parentKey == "GainsStatUpgrades") ConvertFloatArrayToPercentArray(ref node.Value.Value); + + if (depth == 2 && node.Key == "FullyLoadedSpeed" && parentKey == "Harvester") + ConvertFloatArrayToPercentArray(ref node.Value.Value); + + if (depth == 2 && node.Key == "PanicSpeedModifier" && parentKey == "ScaredyCat") + ConvertFloatArrayToPercentArray(ref node.Value.Value); + + if (depth == 2 && node.Key == "ProneSpeed" && parentKey == "TakeCover") + ConvertFloatArrayToPercentArray(ref node.Value.Value); + + if (depth == 2 && node.Key == "SpeedModifier" && parentKey == "GainsStatUpgrades") + ConvertFloatArrayToPercentArray(ref node.Value.Value); } UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);