diff --git a/OpenRA.FileFormats/FieldLoader.cs b/OpenRA.FileFormats/FieldLoader.cs index 3e49e2d4a1..ca6fb8e006 100755 --- a/OpenRA.FileFormats/FieldLoader.cs +++ b/OpenRA.FileFormats/FieldLoader.cs @@ -105,6 +105,14 @@ namespace OpenRA.FileFormats return InvalidValueAction(x,fieldType, field); } + else if (fieldType == typeof(decimal)) + { + decimal res; + if (decimal.TryParse(x.Replace("%",""), System.Globalization.NumberStyles.Any, NumberFormatInfo.InvariantInfo, out res)) + return res * (x.Contains( '%' ) ? 0.01m : 1m); + return InvalidValueAction(x,fieldType, field); + } + else if (fieldType == typeof(string)) return x; diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index a34ee90a6a..16318dd43b 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -107,7 +107,7 @@ namespace OpenRA.Traits public interface INotifyAttack { void Attacking(Actor self); } public interface IRenderModifier { IEnumerable ModifyRender(Actor self, IEnumerable r); } public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); } - public interface ISpeedModifier { float GetSpeedModifier(); } + public interface ISpeedModifier { decimal GetSpeedModifier(); } public interface IFirepowerModifier { float GetFirepowerModifier(); } public interface IPalette { void InitPalette( WorldRenderer wr ); } public interface IPaletteModifier { void AdjustPalette(Dictionary b); } diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index 8f668f57d2..e579adf35e 100755 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -81,11 +81,10 @@ namespace OpenRA.Mods.RA.Air { get { - //var modifier = self - // .TraitsImplementing() - // .Select( t => t.GetSpeedModifier() ) - // .Product(); - return Info.Speed;// *modifier; + decimal ret = Info.Speed; + foreach( var t in self.TraitsImplementing() ) + ret *= t.GetSpeedModifier(); + return (int)ret; } } diff --git a/OpenRA.Mods.RA/Air/Helicopter.cs b/OpenRA.Mods.RA/Air/Helicopter.cs index 5a3f92cdb0..feaceaa9db 100755 --- a/OpenRA.Mods.RA/Air/Helicopter.cs +++ b/OpenRA.Mods.RA/Air/Helicopter.cs @@ -150,7 +150,7 @@ namespace OpenRA.Mods.RA.Air if( InstabilityFacing != -1 ) aircraft.TickMove( Info.InstabilityMagnitude, InstabilityFacing ); - aircraft.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5)); + aircraft.Altitude += (int)(Info.InstabilityMagnitude / 1024 * self.World.SharedRandom.Gauss1D(5)); offsetTicks = Info.InstabilityTicks; } } diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index 62f46d2b75..e4dbbb2d7e 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA public readonly float[] CostThreshold = { 2, 4, 8, 16 }; public readonly float[] FirepowerModifier = { 1.1f, 1.15f, 1.2f, 1.5f }; public readonly float[] ArmorModifier = { 1.1f, 1.2f, 1.3f, 1.5f }; - public readonly float[] SpeedModifier = { 1.1f, 1.15f, 1.2f, 1.5f }; + public readonly decimal[] SpeedModifier = { 1.1m, 1.15m, 1.2m, 1.5m }; public object Create(ActorInitializer init) { return new GainsExperience(init.self, this); } } @@ -79,9 +79,9 @@ namespace OpenRA.Mods.RA return Level > 0 ? Info.FirepowerModifier[Level - 1] : 1; } - public float GetSpeedModifier() + public decimal GetSpeedModifier() { - return Level > 0 ? Info.SpeedModifier[Level - 1] : 1; + return Level > 0 ? Info.SpeedModifier[Level - 1] : 1m; } public IEnumerable ModifyRender(Actor self, IEnumerable rs) diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 0c8c1a27e4..7d82fe7256 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA public readonly int PipCount = 7; public readonly PipType PipColor = PipType.Yellow; public readonly string[] Resources = { }; - public readonly float FullyLoadedSpeed = .85f; + public readonly decimal FullyLoadedSpeed = .85m; public object Create(ActorInitializer init) { return new Harvester(init.self, this); } } @@ -208,10 +208,9 @@ namespace OpenRA.Mods.RA public bool ShouldExplode(Actor self) { return !IsEmpty; } - public float GetSpeedModifier() + public decimal GetSpeedModifier() { - return float2.Lerp(1f, Info.FullyLoadedSpeed, - contents.Values.Sum() / (float)Info.Capacity); + return 1m - ( 1m - 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 a0104ba2dc..acb85582aa 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Move Dictionary ret = new Dictionary(); foreach (var t in y.NodesDict["TerrainSpeeds"].Nodes) { - var speed = (float)FieldLoader.GetValue("speed", typeof(float),t.Value.Value); + var speed = (decimal)FieldLoader.GetValue("speed", typeof(decimal),t.Value.Value); var cost = t.Value.NodesDict.ContainsKey("PathingCost") ? (int)FieldLoader.GetValue("cost", typeof(int), t.Value.NodesDict["PathingCost"].Value) : (int)(10000/speed); ret.Add(t.Key, new TerrainInfo{Speed = speed, Cost = cost}); } @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Move public class TerrainInfo { public int Cost = int.MaxValue; - public float Speed = 0; + public decimal Speed = 0; } } @@ -275,18 +275,17 @@ namespace OpenRA.Mods.RA.Move return info.TerrainSpeeds[type].Cost; } - public float MovementSpeedForCell(Actor self, int2 cell) + public int MovementSpeedForCell(Actor self, int2 cell) { var type = self.World.GetTerrainType(cell); if (!Info.TerrainSpeeds.ContainsKey(type)) return 0; - - var modifier = self - .TraitsImplementing() - .Select(t => t.GetSpeedModifier()) - .Product(); - return Info.Speed * Info.TerrainSpeeds[type].Speed * modifier / 100f; + + decimal speed = Info.Speed * Info.TerrainSpeeds[type].Speed; + foreach( var t in self.TraitsImplementing() ) + speed *= t.GetSpeedModifier(); + return (int)(speed / 100); } public void AddInfluence() diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index cf84972bc2..753b472bbc 100755 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -290,7 +290,7 @@ namespace OpenRA.Mods.RA.Move IActivity InnerTick( Actor self, Mobile mobile ) { - moveFraction += (int)mobile.MovementSpeedForCell(self, mobile.toCell); + moveFraction += mobile.MovementSpeedForCell(self, mobile.toCell); if( moveFraction <= moveFractionTotal ) return this; diff --git a/OpenRA.Mods.RA/TakeCover.cs b/OpenRA.Mods.RA/TakeCover.cs index ce5f7e4478..900bed912d 100644 --- a/OpenRA.Mods.RA/TakeCover.cs +++ b/OpenRA.Mods.RA/TakeCover.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA { const int defaultProneTime = 100; /* ticks, =4s */ const float proneDamage = .5f; - const float proneSpeed = .5f; + const decimal proneSpeed = .5m; [Sync] int remainingProneTime = 0; @@ -45,9 +45,9 @@ namespace OpenRA.Mods.RA return IsProne ? proneDamage : 1f; } - public float GetSpeedModifier() + public decimal GetSpeedModifier() { - return IsProne ? proneSpeed : 1f; + return IsProne ? proneSpeed : 1m; } } }