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) if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
return 0; return 0;
var time = (int)(unit.GetBuildTime() * Info.BuildSpeed); var time = unit.GetBuildTime() * Info.BuildSpeed / 100;
if (info.SpeedUp) if (info.SpeedUp)
{ {

View File

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

View File

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

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Velocity = 75; public readonly int Velocity = 75;
[Desc("Speed at which the particle turns.")] [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); } public object Create(ActorInitializer init) { return new ThrowsParticle(init, this); }
} }
@@ -53,8 +53,8 @@ namespace OpenRA.Mods.Common.Traits
int tick = 0; int tick = 0;
int length; int length;
float facing; WAngle facing;
float rotation; WAngle rotation;
public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info) 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 // TODO: Carry orientation over from the parent instead of just facing
var bodyFacing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0; 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 // Calculate final position
var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024)); var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
@@ -76,23 +76,23 @@ namespace OpenRA.Mods.Common.Traits
length = (finalPos - initialPos).Length / info.Velocity; length = (finalPos - initialPos).Length / info.Velocity;
// Facing rotation // 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); anim.PlayRepeating(info.Anim);
rs.Add(new AnimationWithOffset(anim, () => pos, null)); rs.Add(new AnimationWithOffset(anim, () => pos, null));
} }
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (tick == length) if (tick >= length)
return; return;
pos = WVec.LerpQuadratic(initialPos, finalPos, angle, tick++, length); pos = WVec.LerpQuadratic(initialPos, finalPos, angle, tick++, length);
// Spin the particle // Spin the particle
facing += rotation; 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"; 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); UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
} }
} }

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Traits
public readonly string AmmoPoolName = "primary"; public readonly string AmmoPoolName = "primary";
public readonly float MinefieldDepth = 1.5f; public readonly WDist MinefieldDepth = new WDist(1536);
public object Create(ActorInitializer init) { return new Minelayer(init.Self); } public object Create(ActorInitializer init) { return new Minelayer(init.Self); }
} }
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA.Traits
} }
} }
static IEnumerable<CPos> GetMinefieldCells(CPos start, CPos end, float depth) static IEnumerable<CPos> GetMinefieldCells(CPos start, CPos end, WDist depth)
{ {
var mins = CPos.Min(start, end); var mins = CPos.Min(start, end);
var maxs = CPos.Max(start, end); var maxs = CPos.Max(start, end);
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.RA.Traits
for (var i = mins.X; i <= maxs.X; i++) for (var i = mins.X; i <= maxs.X; i++)
for (var j = mins.Y; j <= maxs.Y; j++) for (var j = mins.Y; j <= maxs.Y; j++)
if (Math.Abs(q.X * i + q.Y * j + c) < depth) if (Math.Abs(q.X * i + q.Y * j + c) * 1024 < depth.Length)
yield return new CPos(i, j); yield return new CPos(i, j);
} }

View File

@@ -25,7 +25,7 @@ FACT:
Type: Building.GDI Type: Building.GDI
Factions: gdi Factions: gdi
Group: Building Group: Building
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 2 LowPowerSlowdown: 2
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: ConstructionComplete ReadyAudio: ConstructionComplete
@@ -33,7 +33,7 @@ FACT:
Type: Building.Nod Type: Building.Nod
Factions: nod Factions: nod
Group: Building Group: Building
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 2 LowPowerSlowdown: 2
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: ConstructionComplete ReadyAudio: ConstructionComplete
@@ -41,7 +41,7 @@ FACT:
Type: Defence.GDI Type: Defence.GDI
Factions: gdi Factions: gdi
Group: Defence Group: Defence
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: ConstructionComplete ReadyAudio: ConstructionComplete
@@ -49,7 +49,7 @@ FACT:
Type: Defence.Nod Type: Defence.Nod
Factions: nod Factions: nod
Group: Defence Group: Defence
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: ConstructionComplete ReadyAudio: ConstructionComplete
@@ -260,7 +260,7 @@ PYLE:
Type: Infantry.GDI Type: Infantry.GDI
Group: Infantry Group: Infantry
RequireOwner: false RequireOwner: false
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
ProductionBar: ProductionBar:
Power: Power:
@@ -300,7 +300,7 @@ HAND:
Type: Infantry.Nod Type: Infantry.Nod
Group: Infantry Group: Infantry
RequireOwner: false RequireOwner: false
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
ProductionBar: ProductionBar:
Power: Power:
@@ -344,7 +344,7 @@ AFLD:
Type: Vehicle.Nod Type: Vehicle.Nod
Group: Vehicle Group: Vehicle
RequireOwner: false RequireOwner: false
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
ReadyAudio: ReadyAudio:
ProductionBar: ProductionBar:
@@ -391,7 +391,7 @@ WEAP:
Type: Vehicle.GDI Type: Vehicle.GDI
RequireOwner: false RequireOwner: false
Group: Vehicle Group: Vehicle
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
ProductionBar: ProductionBar:
Power: Power:
@@ -428,13 +428,13 @@ HPAD:
Type: Aircraft.GDI Type: Aircraft.GDI
Factions: gdi Factions: gdi
Group: Aircraft Group: Aircraft
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
ProductionQueue@Nod: ProductionQueue@Nod:
Type: Aircraft.Nod Type: Aircraft.Nod
Factions: nod Factions: nod
Group: Aircraft Group: Aircraft
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
ProductionBar@GDI: ProductionBar@GDI:
ProductionType: Aircraft.GDI ProductionType: Aircraft.GDI

View File

@@ -65,7 +65,7 @@ BIO:
Type: Biolab Type: Biolab
Group: Infantry Group: Infantry
RequireOwner: false RequireOwner: false
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
ProductionBar: ProductionBar:
RallyPoint: RallyPoint:

View File

@@ -3,7 +3,7 @@ Player:
TechTree: TechTree:
ClassicProductionQueue@Building: ClassicProductionQueue@Building:
Type: Building Type: Building
BuildSpeed: 1.0 BuildSpeed: 100
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: BuildingReady ReadyAudio: BuildingReady
@@ -11,7 +11,7 @@ Player:
SpeedUp: true SpeedUp: true
ClassicProductionQueue@Upgrade: ClassicProductionQueue@Upgrade:
Type: Upgrade Type: Upgrade
BuildSpeed: 1.0 BuildSpeed: 100
LowPowerSlowdown: 0 LowPowerSlowdown: 0
QueuedAudio: Upgrading QueuedAudio: Upgrading
ReadyAudio: NewOptions ReadyAudio: NewOptions
@@ -19,34 +19,34 @@ Player:
SpeedUp: true SpeedUp: true
ClassicProductionQueue@Infantry: ClassicProductionQueue@Infantry:
Type: Infantry Type: Infantry
BuildSpeed: 1.0 BuildSpeed: 100
LowPowerSlowdown: 3 LowPowerSlowdown: 3
BlockedAudio: NoRoom BlockedAudio: NoRoom
SpeedUp: true SpeedUp: true
ClassicProductionQueue@Vehicle: ClassicProductionQueue@Vehicle:
Type: Vehicle Type: Vehicle
BuildSpeed: 1.0 BuildSpeed: 100
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
BlockedAudio: NoRoom BlockedAudio: NoRoom
SpeedUp: true SpeedUp: true
ClassicProductionQueue@Armor: ClassicProductionQueue@Armor:
Type: Armor Type: Armor
BuildSpeed: 1.0 BuildSpeed: 100
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
BlockedAudio: NoRoom BlockedAudio: NoRoom
SpeedUp: true SpeedUp: true
ClassicProductionQueue@Starport: ClassicProductionQueue@Starport:
Type: Starport Type: Starport
BuildSpeed: 0.85 BuildSpeed: 85
LowPowerSlowdown: 0 LowPowerSlowdown: 0
BlockedAudio: NoRoom BlockedAudio: NoRoom
QueuedAudio: OrderPlaced QueuedAudio: OrderPlaced
ReadyAudio: ReadyAudio:
ClassicProductionQueue@Aircraft: ClassicProductionQueue@Aircraft:
Type: Aircraft Type: Aircraft
BuildSpeed: 1.25 BuildSpeed: 125
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
BlockedAudio: NoRoom BlockedAudio: NoRoom

View File

@@ -54,7 +54,7 @@ SILO:
Player: Player:
ClassicProductionQueue@Building: ClassicProductionQueue@Building:
BuildSpeed: 0.4 BuildSpeed: 40
Shroud: Shroud:
FogLocked: True FogLocked: True
FogEnabled: True FogEnabled: True

View File

@@ -76,7 +76,7 @@ FORTCRATE:
Player: Player:
ClassicProductionQueue@Infantry: ClassicProductionQueue@Infantry:
BuildSpeed: 1 BuildSpeed: 100
-EnemyWatcher: -EnemyWatcher:
Shroud: Shroud:
FogLocked: True FogLocked: True

View File

@@ -18,6 +18,5 @@ Player:
StrategicVictoryConditions: StrategicVictoryConditions:
HoldDuration: 3000 HoldDuration: 3000
ResetOnHoldLost: true ResetOnHoldLost: true
RatioRequired: 0.65 RatioRequired: 65
CriticalRatioRequired: 0.65
-ConquestVictoryConditions: -ConquestVictoryConditions:

View File

@@ -11,9 +11,9 @@ World:
Player: Player:
ClassicProductionQueue@Infantry: ClassicProductionQueue@Infantry:
BuildSpeed: 1 BuildSpeed: 100
ClassicProductionQueue@Vehicle: ClassicProductionQueue@Vehicle:
BuildSpeed: 1 BuildSpeed: 100
Shroud: Shroud:
FogLocked: True FogLocked: True
FogEnabled: True FogEnabled: True

View File

@@ -3,36 +3,36 @@ Player:
TechTree: TechTree:
ClassicProductionQueue@Building: ClassicProductionQueue@Building:
Type: Building Type: Building
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: ConstructionComplete ReadyAudio: ConstructionComplete
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Defense: ClassicProductionQueue@Defense:
Type: Defense Type: Defense
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: ConstructionComplete ReadyAudio: ConstructionComplete
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Vehicle: ClassicProductionQueue@Vehicle:
Type: Vehicle Type: Vehicle
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Infantry: ClassicProductionQueue@Infantry:
Type: Infantry Type: Infantry
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Ship: ClassicProductionQueue@Ship:
Type: Ship Type: Ship
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Aircraft: ClassicProductionQueue@Aircraft:
Type: Aircraft Type: Aircraft
BuildSpeed: .4 BuildSpeed: 40
LowPowerSlowdown: 3 LowPowerSlowdown: 3
SpeedUp: True SpeedUp: True
PlaceBuilding: PlaceBuilding:

View File

@@ -4,31 +4,31 @@ Player:
GlobalUpgradeManager: GlobalUpgradeManager:
ClassicProductionQueue@Building: ClassicProductionQueue@Building:
Type: Building Type: Building
BuildSpeed: .4 BuildSpeed: 48
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: ConstructionComplete ReadyAudio: ConstructionComplete
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Defense: ClassicProductionQueue@Defense:
Type: Defense Type: Defense
BuildSpeed: .4 BuildSpeed: 48
LowPowerSlowdown: 3 LowPowerSlowdown: 3
QueuedAudio: Building QueuedAudio: Building
ReadyAudio: ConstructionComplete ReadyAudio: ConstructionComplete
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Vehicle: ClassicProductionQueue@Vehicle:
Type: Vehicle Type: Vehicle
BuildSpeed: .4 BuildSpeed: 48
LowPowerSlowdown: 3 LowPowerSlowdown: 3
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Infantry: ClassicProductionQueue@Infantry:
Type: Infantry Type: Infantry
BuildSpeed: .4 BuildSpeed: 48
LowPowerSlowdown: 3 LowPowerSlowdown: 3
SpeedUp: True SpeedUp: True
ClassicProductionQueue@Air: ClassicProductionQueue@Air:
Type: Air Type: Air
BuildSpeed: .4 BuildSpeed: 48
LowPowerSlowdown: 3 LowPowerSlowdown: 3
SpeedUp: True SpeedUp: True
PlaceBuilding: PlaceBuilding: