Merge pull request #10973 from reaperrr/fp-to-int2

Getting rid of float in simulation code Part 2
This commit is contained in:
Matthias Mailänder
2016-03-28 17:13:52 +02:00
15 changed files with 100 additions and 53 deletions

View File

@@ -128,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
return 0;
var time = (int)(unit.GetBuildTime() * Info.BuildSpeed);
var time = unit.GetBuildTime() * Info.BuildSpeed / 100;
if (info.SpeedUp)
{

View File

@@ -34,8 +34,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Should the prerequisite remain enabled if the owner changes?")]
public readonly bool Sticky = true;
[Desc("This value is used to translate the unit cost into build time.")]
public readonly float BuildSpeed = 0.4f;
[Desc("This percentage value is multiplied with actor cost to translate into build time (lower means faster).")]
public readonly int BuildSpeed = 40;
[Desc("The build time is multiplied with this value on low power.")]
public readonly int LowPowerSlowdown = 3;
@@ -319,8 +319,8 @@ namespace OpenRA.Mods.Common.Traits
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
return 0;
var time = unit.GetBuildTime() * Info.BuildSpeed;
return (int)time;
var time = unit.GetBuildTime() * Info.BuildSpeed / 100;
return time;
}
protected void CancelProduction(string itemName, uint numberToCancel)

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool ResetOnHoldLost = true;
[Desc("Percentage of all strategic points the player has to hold to win.")]
public readonly float RatioRequired = 0.5f;
public readonly int RatioRequired = 50;
[Desc("Delay for the end game notification in milliseconds.")]
public readonly int NotificationDelay = 1500;
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
public int Total { get { return AllPoints.Count(); } }
int Owned { get { return AllPoints.Count(a => WorldUtils.AreMutualAllies(player, a.Owner)); } }
public bool Holding { get { return Owned >= info.RatioRequired * Total; } }
public bool Holding { get { return Owned >= info.RatioRequired * Total / 100; } }
public void Tick(Actor self)
{

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Velocity = 75;
[Desc("Speed at which the particle turns.")]
public readonly float TurnSpeed = 15;
public readonly int TurnSpeed = 15;
public object Create(ActorInitializer init) { return new ThrowsParticle(init, this); }
}
@@ -53,8 +53,8 @@ namespace OpenRA.Mods.Common.Traits
int tick = 0;
int length;
float facing;
float rotation;
WAngle facing;
WAngle rotation;
public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
{
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
// TODO: Carry orientation over from the parent instead of just facing
var bodyFacing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
facing = Turreted.GetInitialTurretFacing(init, 0);
facing = WAngle.FromFacing(Turreted.GetInitialTurretFacing(init, 0));
// Calculate final position
var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
@@ -76,23 +76,23 @@ namespace OpenRA.Mods.Common.Traits
length = (finalPos - initialPos).Length / info.Velocity;
// Facing rotation
rotation = WDist.FromPDF(Game.CosmeticRandom, 2).Length * info.TurnSpeed / 1024;
rotation = WAngle.FromFacing(WDist.FromPDF(Game.CosmeticRandom, 2).Length * info.TurnSpeed / 1024);
var anim = new Animation(init.World, rs.GetImage(self), () => (int)facing);
var anim = new Animation(init.World, rs.GetImage(self), () => facing.Angle / 4);
anim.PlayRepeating(info.Anim);
rs.Add(new AnimationWithOffset(anim, () => pos, null));
}
public void Tick(Actor self)
{
if (tick == length)
if (tick >= length)
return;
pos = WVec.LerpQuadratic(initialPos, finalPos, angle, tick++, length);
// Spin the particle
facing += rotation;
rotation *= .9f;
rotation = new WAngle(rotation.Angle * 90 / 100);
}
}
}

View File

@@ -644,6 +644,54 @@ namespace OpenRA.Mods.Common.UtilityCommands
node.Key = "ReloadDelay";
}
// Migrated ProductionQueue BuildSpeed to use int percentage instead of float
if (engineVersion < 20160325)
{
if (node.Key.StartsWith("ProductionQueue") || node.Key.StartsWith("ClassicProductionQueue"))
{
var buildSpeedNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "BuildSpeed");
if (buildSpeedNode != null)
{
// The BuildSpeed value is now an int percentage, so multiply the float with 100.
var oldValue = FieldLoader.GetValue<float>("BuildSpeed", buildSpeedNode.Value.Value);
var newValue = (int)(oldValue * 100);
buildSpeedNode.Value.Value = newValue.ToString();
}
}
}
// Migrated StrategicVictoryConditions RatioRequired to use int percentage instead of float
if (engineVersion < 20160325)
{
if (node.Key.StartsWith("StrategicVictoryConditions"))
{
var ratioNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "RatioRequired");
if (ratioNode != null)
{
// The RatioRequired value is now an int percentage, so multiply the float with 100.
var oldValue = FieldLoader.GetValue<float>("RatioRequired", ratioNode.Value.Value);
var newValue = (int)(oldValue * 100);
ratioNode.Value.Value = newValue.ToString();
}
}
}
// Migrated Minelayer.MinefieldDepth to use WDist instead of float
if (engineVersion < 20160325)
{
if (node.Key.StartsWith("Minelayer"))
{
var depthNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "MinefieldDepth");
if (depthNode != null)
{
// The MinefieldDepth value is now a WDist, so multiply the float value with 1024.
var oldValue = FieldLoader.GetValue<float>("MinefieldDepth", depthNode.Value.Value);
var newValue = (int)(oldValue * 1024);
depthNode.Value.Value = newValue.ToString();
}
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}