add support for decimal to fieldLoader. use decimal for speedmodifiers

This commit is contained in:
Bob
2010-11-06 14:10:56 +13:00
parent 750fd84494
commit 155e7320cb
9 changed files with 32 additions and 27 deletions

View File

@@ -105,6 +105,14 @@ namespace OpenRA.FileFormats
return InvalidValueAction(x,fieldType, field); 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)) else if (fieldType == typeof(string))
return x; return x;

View File

@@ -107,7 +107,7 @@ namespace OpenRA.Traits
public interface INotifyAttack { void Attacking(Actor self); } public interface INotifyAttack { void Attacking(Actor self); }
public interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); } public interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); }
public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); } 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 IFirepowerModifier { float GetFirepowerModifier(); }
public interface IPalette { void InitPalette( WorldRenderer wr ); } public interface IPalette { void InitPalette( WorldRenderer wr ); }
public interface IPaletteModifier { void AdjustPalette(Dictionary<string,Palette> b); } public interface IPaletteModifier { void AdjustPalette(Dictionary<string,Palette> b); }

View File

@@ -81,11 +81,10 @@ namespace OpenRA.Mods.RA.Air
{ {
get get
{ {
//var modifier = self decimal ret = Info.Speed;
// .TraitsImplementing<ISpeedModifier>() foreach( var t in self.TraitsImplementing<ISpeedModifier>() )
// .Select( t => t.GetSpeedModifier() ) ret *= t.GetSpeedModifier();
// .Product(); return (int)ret;
return Info.Speed;// *modifier;
} }
} }

View File

@@ -150,7 +150,7 @@ namespace OpenRA.Mods.RA.Air
if( InstabilityFacing != -1 ) if( InstabilityFacing != -1 )
aircraft.TickMove( Info.InstabilityMagnitude, InstabilityFacing ); 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; offsetTicks = Info.InstabilityTicks;
} }
} }

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA
public readonly float[] CostThreshold = { 2, 4, 8, 16 }; public readonly float[] CostThreshold = { 2, 4, 8, 16 };
public readonly float[] FirepowerModifier = { 1.1f, 1.15f, 1.2f, 1.5f }; 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[] 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); } 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; 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<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> rs) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> rs)

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
public readonly int PipCount = 7; public readonly int PipCount = 7;
public readonly PipType PipColor = PipType.Yellow; public readonly PipType PipColor = PipType.Yellow;
public readonly string[] Resources = { }; 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); } 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 bool ShouldExplode(Actor self) { return !IsEmpty; }
public float GetSpeedModifier() public decimal GetSpeedModifier()
{ {
return float2.Lerp(1f, Info.FullyLoadedSpeed, return 1m - ( 1m - Info.FullyLoadedSpeed ) * contents.Values.Sum() / Info.Capacity;
contents.Values.Sum() / (float)Info.Capacity);
} }
class HarvestOrderTargeter : IOrderTargeter class HarvestOrderTargeter : IOrderTargeter

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Move
Dictionary<string,TerrainInfo> ret = new Dictionary<string, TerrainInfo>(); Dictionary<string,TerrainInfo> ret = new Dictionary<string, TerrainInfo>();
foreach (var t in y.NodesDict["TerrainSpeeds"].Nodes) 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); 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}); ret.Add(t.Key, new TerrainInfo{Speed = speed, Cost = cost});
} }
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Move
public class TerrainInfo public class TerrainInfo
{ {
public int Cost = int.MaxValue; 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; 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); var type = self.World.GetTerrainType(cell);
if (!Info.TerrainSpeeds.ContainsKey(type)) if (!Info.TerrainSpeeds.ContainsKey(type))
return 0; return 0;
var modifier = self decimal speed = Info.Speed * Info.TerrainSpeeds[type].Speed;
.TraitsImplementing<ISpeedModifier>() foreach( var t in self.TraitsImplementing<ISpeedModifier>() )
.Select(t => t.GetSpeedModifier()) speed *= t.GetSpeedModifier();
.Product(); return (int)(speed / 100);
return Info.Speed * Info.TerrainSpeeds[type].Speed * modifier / 100f;
} }
public void AddInfluence() public void AddInfluence()

View File

@@ -290,7 +290,7 @@ namespace OpenRA.Mods.RA.Move
IActivity InnerTick( Actor self, Mobile mobile ) IActivity InnerTick( Actor self, Mobile mobile )
{ {
moveFraction += (int)mobile.MovementSpeedForCell(self, mobile.toCell); moveFraction += mobile.MovementSpeedForCell(self, mobile.toCell);
if( moveFraction <= moveFractionTotal ) if( moveFraction <= moveFractionTotal )
return this; return this;

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA
{ {
const int defaultProneTime = 100; /* ticks, =4s */ const int defaultProneTime = 100; /* ticks, =4s */
const float proneDamage = .5f; const float proneDamage = .5f;
const float proneSpeed = .5f; const decimal proneSpeed = .5m;
[Sync] [Sync]
int remainingProneTime = 0; int remainingProneTime = 0;
@@ -45,9 +45,9 @@ namespace OpenRA.Mods.RA
return IsProne ? proneDamage : 1f; return IsProne ? proneDamage : 1f;
} }
public float GetSpeedModifier() public decimal GetSpeedModifier()
{ {
return IsProne ? proneSpeed : 1f; return IsProne ? proneSpeed : 1m;
} }
} }
} }