Convert speed modifiers to integer percentages.

This commit is contained in:
Paul Chote
2014-08-09 21:54:03 +12:00
parent 0425416ce2
commit 84d3497e96
8 changed files with 33 additions and 20 deletions

View File

@@ -156,7 +156,7 @@ namespace OpenRA.Traits
public interface IRenderModifier { IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> 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<string, MutablePalette> b); }

View File

@@ -203,10 +203,9 @@ namespace OpenRA.Mods.RA.Air
{
get
{
decimal ret = info.Speed;
foreach (var t in self.TraitsImplementing<ISpeedModifier>())
ret *= t.GetSpeedModifier();
return (int)ret;
var modifiers = self.TraitsImplementing<ISpeedModifier>()
.Select(m => m.GetSpeedModifier());
return Util.ApplyPercentageModifiers(info.Speed, modifiers);
}
}

View File

@@ -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;
}
}
}

View File

@@ -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

View File

@@ -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<ISpeedModifier>())
speed *= t.GetSpeedModifier();
speed *= t.GetSpeedModifier() / 100m;
return (int)(speed / 100);
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}

View File

@@ -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);