Merge pull request #10972 from reaperrr/fp-to-int1
Migrated some remaining floats in simulation to integers (and decimals)
This commit is contained in:
@@ -64,8 +64,8 @@ namespace OpenRA
|
||||
return ret;
|
||||
|
||||
// Add an additional quadratic variation to height
|
||||
// Attempts to avoid integer overflow by keeping the intermediate variables reasonably sized
|
||||
var offset = (int)(((((((long)(b - a).Length * mul) / div) * (div - mul)) / div) * pitch.Tan()) / 1024);
|
||||
// Uses decimal to avoid integer overflow
|
||||
var offset = (int)((decimal)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div));
|
||||
return new WPos(ret.X, ret.Y, ret.Z + offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ namespace OpenRA
|
||||
return ret;
|
||||
|
||||
// Add an additional quadratic variation to height
|
||||
// Uses fp to avoid integer overflow
|
||||
var offset = (int)((float)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div));
|
||||
// Uses decimal to avoid integer overflow
|
||||
var offset = (int)((decimal)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div));
|
||||
return new WVec(ret.X, ret.Y, ret.Z + offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
int CalculateTurnRadius(int speed)
|
||||
{
|
||||
return (int)(141 * speed / planeInfo.TurnSpeed / (float)Math.PI);
|
||||
return 45 * speed / planeInfo.TurnSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (actor.IsDead || capturable.BeingCaptured)
|
||||
return;
|
||||
|
||||
var lowEnoughHealth = health.HP <= capturable.Info.CaptureThreshold * health.MaxHP;
|
||||
var lowEnoughHealth = health.HP <= capturable.Info.CaptureThreshold * health.MaxHP / 100;
|
||||
if (!capturesInfo.Sabotage || lowEnoughHealth || actor.Owner.NonCombatant)
|
||||
{
|
||||
var oldOwner = actor.Owner;
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
}
|
||||
else
|
||||
{
|
||||
var damage = (int)(health.MaxHP * capturesInfo.SabotageHPRemoval);
|
||||
var damage = health.MaxHP * capturesInfo.SabotageHPRemoval / 100;
|
||||
actor.InflictDamage(self, damage, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly bool AllowNeutral = true;
|
||||
public readonly bool AllowEnemies = true;
|
||||
[Desc("Health percentage the target must be at (or below) before it can be captured.")]
|
||||
public readonly float CaptureThreshold = 0.5f;
|
||||
public readonly int CaptureThreshold = 50;
|
||||
public readonly bool CancelActivity = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Capturable(this); }
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Unit will do damage to the actor instead of capturing it. Unit is destroyed when sabotaging.")]
|
||||
public readonly bool Sabotage = true;
|
||||
[Desc("Only used if Sabotage=true. Sabotage damage expressed as a percentage of enemy health removed.")]
|
||||
public readonly float SabotageHPRemoval = 0.5f;
|
||||
public readonly int SabotageHPRemoval = 50;
|
||||
|
||||
[VoiceReference] public readonly string Voice = "Action";
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
var health = target.Trait<Health>();
|
||||
var lowEnoughHealth = health.HP <= c.CaptureThreshold * health.MaxHP;
|
||||
var lowEnoughHealth = health.HP <= c.CaptureThreshold * health.MaxHP / 100;
|
||||
|
||||
cursor = !sabotage || lowEnoughHealth || target.Owner.NonCombatant
|
||||
? "enter" : "capture";
|
||||
@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
var health = target.Info.TraitInfoOrDefault<HealthInfo>();
|
||||
var lowEnoughHealth = target.HP <= c.CaptureThreshold * health.HP;
|
||||
var lowEnoughHealth = target.HP <= c.CaptureThreshold * health.HP / 100;
|
||||
|
||||
cursor = !sabotage || lowEnoughHealth || target.Owner.NonCombatant
|
||||
? "enter" : "capture";
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Spawn new actors when sold.")]
|
||||
public class EmitInfantryOnSellInfo : ITraitInfo
|
||||
{
|
||||
public readonly float ValuePercent = 40;
|
||||
public readonly float MinHpPercent = 30;
|
||||
public readonly int ValuePercent = 40;
|
||||
public readonly int MinHpPercent = 30;
|
||||
|
||||
[ActorReference]
|
||||
[Desc("Be sure to use lowercase. Default value is \"e1\".")]
|
||||
@@ -59,8 +59,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
var dudesValue = info.ValuePercent * cost;
|
||||
if (health != null)
|
||||
dudesValue = dudesValue * health.HP / health.MaxHP;
|
||||
dudesValue /= 100;
|
||||
{
|
||||
if (100 * health.HP >= info.MinHpPercent * health.MaxHP)
|
||||
dudesValue = health.HP * dudesValue / health.MaxHP;
|
||||
else
|
||||
dudesValue = 0;
|
||||
}
|
||||
|
||||
var eligibleLocations = FootprintUtils.Tiles(self).ToList();
|
||||
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].TraitInfo<ValuedInfo>().Cost }).ToList();
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public readonly int Step = 5;
|
||||
public readonly int Delay = 5;
|
||||
public readonly float HealIfBelow = .5f;
|
||||
[Desc("Heal if current health is below this percentage of full health.")]
|
||||
public readonly int HealIfBelow = 50;
|
||||
public readonly int DamageCooldown = 0;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new SelfHealing(init.Self, this); }
|
||||
@@ -42,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.IsDead || IsTraitDisabled)
|
||||
return;
|
||||
|
||||
if (health.HP >= Info.HealIfBelow * health.MaxHP)
|
||||
if (health.HP >= Info.HealIfBelow * health.MaxHP / 100)
|
||||
return;
|
||||
|
||||
if (damageTicks > 0)
|
||||
|
||||
@@ -644,9 +644,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
node.Key = "ReloadDelay";
|
||||
}
|
||||
|
||||
// Migrated ProductionQueue BuildSpeed to use int percentage instead of float
|
||||
if (engineVersion < 20160325)
|
||||
// Got rid of most remaining usages of float in a bid to further reduce desync risk
|
||||
if (engineVersion < 20160328)
|
||||
{
|
||||
// Migrated ProductionQueue BuildSpeed to use int percentage instead of float
|
||||
if (node.Key.StartsWith("ProductionQueue") || node.Key.StartsWith("ClassicProductionQueue"))
|
||||
{
|
||||
var buildSpeedNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "BuildSpeed");
|
||||
@@ -658,11 +659,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
buildSpeedNode.Value.Value = newValue.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Migrated StrategicVictoryConditions RatioRequired to use int percentage instead of float
|
||||
if (engineVersion < 20160325)
|
||||
{
|
||||
// Migrated StrategicVictoryConditions RatioRequired to use int percentage instead of float
|
||||
if (node.Key.StartsWith("StrategicVictoryConditions"))
|
||||
{
|
||||
var ratioNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "RatioRequired");
|
||||
@@ -674,11 +672,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
ratioNode.Value.Value = newValue.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Migrated Minelayer.MinefieldDepth to use WDist instead of float
|
||||
if (engineVersion < 20160325)
|
||||
{
|
||||
// Migrated Minelayer.MinefieldDepth to use WDist instead of float
|
||||
if (node.Key.StartsWith("Minelayer"))
|
||||
{
|
||||
var depthNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "MinefieldDepth");
|
||||
@@ -690,6 +685,69 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
depthNode.Value.Value = newValue.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// Migrated SelfHealing to use int percentage instead of float
|
||||
if (node.Key == "SelfHealing")
|
||||
{
|
||||
var healIfBelowNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "HealIfBelow");
|
||||
if (healIfBelowNode != null)
|
||||
{
|
||||
// The HealIfBelow value is now an int percentage, so multiply the float with 100.
|
||||
var oldValue = FieldLoader.GetValue<float>("HealIfBelow", healIfBelowNode.Value.Value);
|
||||
var newValue = (int)(oldValue * 100);
|
||||
healIfBelowNode.Value.Value = newValue.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// Migrated EmitInfantryOnSell to use int percentage instead of float
|
||||
if (node.Key == "EmitInfantryOnSell")
|
||||
{
|
||||
var valueNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "ValuePercent");
|
||||
var minHPNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "MinHpPercent");
|
||||
|
||||
if (valueNode != null)
|
||||
{
|
||||
// The ValuePercent value is now an int percentage, but was previously geared towards
|
||||
// percentage rather than float and divided by 100 internally so division by 100 is NOT needed.
|
||||
var oldValue = FieldLoader.GetValue<float>("ValuePercent", valueNode.Value.Value);
|
||||
var newValue = (int)oldValue;
|
||||
valueNode.Value.Value = newValue.ToString();
|
||||
}
|
||||
|
||||
if (minHPNode != null)
|
||||
{
|
||||
// The MinHpPercent value is now an int percentage, but was previously geared towards
|
||||
// percentage rather than float and divided by 100 internally so division by 100 is NOT needed.
|
||||
var oldValue = FieldLoader.GetValue<float>("MinHpPercent", minHPNode.Value.Value);
|
||||
var newValue = (int)oldValue;
|
||||
minHPNode.Value.Value = newValue.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// Migrated Captures and Capturable to use int percentage instead of float
|
||||
if (node.Key == "Captures")
|
||||
{
|
||||
var sabotageHPRemNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "SabotageHPRemoval");
|
||||
if (sabotageHPRemNode != null)
|
||||
{
|
||||
// The SabotageHPRemoval value is now an int percentage, so multiply the float with 100.
|
||||
var oldValue = FieldLoader.GetValue<float>("SabotageHPRemoval", sabotageHPRemNode.Value.Value);
|
||||
var newValue = (int)(oldValue * 100);
|
||||
sabotageHPRemNode.Value.Value = newValue.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
if (node.Key == "Capturable")
|
||||
{
|
||||
var captThreshNode = node.Value.Nodes.FirstOrDefault(x => x.Key == "CaptureThreshold");
|
||||
if (captThreshNode != null)
|
||||
{
|
||||
// The CaptureThreshold value is now an int percentage, so multiply the float with 100.
|
||||
var oldValue = FieldLoader.GetValue<float>("CaptureThreshold", captThreshNode.Value.Value);
|
||||
var newValue = (int)(oldValue * 100);
|
||||
captThreshNode.Value.Value = newValue.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
|
||||
@@ -70,7 +70,7 @@ RMBO.easy:
|
||||
HP: 300
|
||||
SelfHealing:
|
||||
Delay: 10
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
DamageCooldown: 200
|
||||
RenderSprites:
|
||||
Image: RMBO
|
||||
|
||||
@@ -89,4 +89,4 @@ MISS:
|
||||
Tooltip:
|
||||
Name: Prison
|
||||
Capturable:
|
||||
CaptureThreshold: 1
|
||||
CaptureThreshold: 100
|
||||
|
||||
@@ -89,4 +89,4 @@ MISS:
|
||||
Tooltip:
|
||||
Name: Prison
|
||||
Capturable:
|
||||
CaptureThreshold: 1
|
||||
CaptureThreshold: 100
|
||||
|
||||
@@ -688,7 +688,7 @@
|
||||
Capturable:
|
||||
Type: husk
|
||||
AllowAllies: yes
|
||||
CaptureThreshold: 1.0
|
||||
CaptureThreshold: 100
|
||||
TransformOnCapture:
|
||||
ForceHealthPercentage: 25
|
||||
Tooltip:
|
||||
|
||||
@@ -411,7 +411,7 @@ HTNK:
|
||||
AutoTarget:
|
||||
SelfHealing:
|
||||
Delay: 10
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
DamageCooldown: 200
|
||||
SpawnActorOnDeath:
|
||||
Actor: HTNK.Husk
|
||||
|
||||
@@ -39,7 +39,7 @@ carryall.reinforce:
|
||||
SelfHealing:
|
||||
Step: 5
|
||||
Delay: 3
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
|
||||
carryall:
|
||||
Inherits: carryall.reinforce
|
||||
|
||||
@@ -254,7 +254,7 @@
|
||||
Adjacent: 3
|
||||
GivesBuildableArea:
|
||||
Capturable:
|
||||
CaptureThreshold: 1.0
|
||||
CaptureThreshold: 100
|
||||
SoundOnDamageTransition:
|
||||
DamagedSounds: EXPLSML1.WAV
|
||||
DestroyedSounds: EXPLHG1.WAV
|
||||
|
||||
@@ -44,7 +44,7 @@ mcv:
|
||||
SelfHealing:
|
||||
Step: 5
|
||||
Delay: 3
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
|
||||
harvester:
|
||||
Inherits: ^Vehicle
|
||||
@@ -95,7 +95,7 @@ harvester:
|
||||
SelfHealing:
|
||||
Step: 5
|
||||
Delay: 3
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
|
||||
trike:
|
||||
Inherits: ^Vehicle
|
||||
@@ -336,7 +336,7 @@ devastator:
|
||||
SelfHealing:
|
||||
Step: 5
|
||||
Delay: 3
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
|
||||
raider:
|
||||
Inherits: ^Vehicle
|
||||
|
||||
@@ -52,7 +52,7 @@ World:
|
||||
|
||||
^Building:
|
||||
Capturable:
|
||||
CaptureThreshold: 0.25
|
||||
CaptureThreshold: 25
|
||||
Tooltip:
|
||||
GenericVisibility: Enemy
|
||||
ShowOwnerRow: false
|
||||
|
||||
@@ -52,7 +52,7 @@ World:
|
||||
|
||||
^Building:
|
||||
Capturable:
|
||||
CaptureThreshold: 0.25
|
||||
CaptureThreshold: 25
|
||||
Tooltip:
|
||||
GenericVisibility: Enemy
|
||||
ShowOwnerRow: false
|
||||
|
||||
@@ -160,7 +160,7 @@ MINVV:
|
||||
SelfHealing:
|
||||
Step: -1
|
||||
Delay: 1
|
||||
HealIfBelow: 101%
|
||||
HealIfBelow: 101
|
||||
DamageCooldown: 0
|
||||
Explodes:
|
||||
Weapon: CrateNuke
|
||||
|
||||
@@ -307,7 +307,7 @@ V2RL:
|
||||
SelfHealing:
|
||||
Step: 2
|
||||
Delay: 1
|
||||
HealIfBelow: 40%
|
||||
HealIfBelow: 40
|
||||
|
||||
BADR.Bomber:
|
||||
Health:
|
||||
|
||||
@@ -42,7 +42,7 @@ MISS:
|
||||
AllowAllies: False
|
||||
AllowNeutral: False
|
||||
AllowEnemies: True
|
||||
CaptureThreshold: 1.0
|
||||
CaptureThreshold: 100
|
||||
|
||||
E6.MOD:
|
||||
Inherits: E6
|
||||
|
||||
@@ -160,7 +160,7 @@ PBOX:
|
||||
SelfHealing:
|
||||
Step: 1
|
||||
Delay: 1
|
||||
HealIfBelow: 100%
|
||||
HealIfBelow: 100
|
||||
DamageCooldown: 150
|
||||
Selectable:
|
||||
Bounds: 44,38,0,-4
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
AllowUnsuitableCell: false
|
||||
Capturable:
|
||||
Type: vehicle
|
||||
CaptureThreshold: 1
|
||||
CaptureThreshold: 100
|
||||
CancelActivity: True
|
||||
CaptureNotification:
|
||||
Notification: UnitStolen
|
||||
@@ -620,7 +620,7 @@
|
||||
Capturable:
|
||||
Type: husk
|
||||
AllowAllies: true
|
||||
CaptureThreshold: 1.0
|
||||
CaptureThreshold: 100
|
||||
TransformOnCapture:
|
||||
ForceHealthPercentage: 25
|
||||
DisabledOverlay:
|
||||
|
||||
@@ -192,7 +192,7 @@ V2RL:
|
||||
SelfHealing:
|
||||
Step: 1
|
||||
Delay: 3
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
DamageCooldown: 150
|
||||
SelectionDecorations:
|
||||
VisualBounds: 44,38,0,-4
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
AutoTarget:
|
||||
SelfHealing:
|
||||
Delay: 10
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
DamageCooldown: 200
|
||||
WithVoxelTurret:
|
||||
WithVoxelBarrel:
|
||||
|
||||
@@ -418,7 +418,7 @@
|
||||
ActorLostNotification:
|
||||
Capturable:
|
||||
Type: Vehicle
|
||||
CaptureThreshold: 1
|
||||
CaptureThreshold: 100
|
||||
CancelActivity: True
|
||||
Guard:
|
||||
Voice: Move
|
||||
|
||||
@@ -246,7 +246,7 @@ WEED:
|
||||
HP: 600
|
||||
SelfHealing:
|
||||
Delay: 10
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
DamageCooldown: 200
|
||||
Armor:
|
||||
Type: Heavy
|
||||
|
||||
@@ -76,7 +76,7 @@ HARV:
|
||||
HP: 1000
|
||||
SelfHealing:
|
||||
Delay: 10
|
||||
HealIfBelow: 50%
|
||||
HealIfBelow: 50
|
||||
DamageCooldown: 200
|
||||
Armor:
|
||||
Type: Heavy
|
||||
|
||||
Reference in New Issue
Block a user