Migrate EmitInfantryOnSell ValuePercent and MinHpPercent to int percentages

Additionally, MinHpPercent should now actually have the desired effect (previously there was not logic attached).
This commit is contained in:
reaperrr
2016-03-24 14:06:42 +01:00
parent 3a97757bfa
commit 82f23210d9
2 changed files with 36 additions and 4 deletions

View File

@@ -19,8 +19,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Spawn new actors when sold.")] [Desc("Spawn new actors when sold.")]
public class EmitInfantryOnSellInfo : ITraitInfo public class EmitInfantryOnSellInfo : ITraitInfo
{ {
public readonly float ValuePercent = 40; public readonly int ValuePercent = 40;
public readonly float MinHpPercent = 30; public readonly int MinHpPercent = 30;
[ActorReference] [ActorReference]
[Desc("Be sure to use lowercase. Default value is \"e1\".")] [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 health = self.TraitOrDefault<Health>();
var dudesValue = info.ValuePercent * cost; var dudesValue = info.ValuePercent * cost;
if (health != null) 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 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(); var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].TraitInfo<ValuedInfo>().Cost }).ToList();

View File

@@ -708,6 +708,34 @@ namespace OpenRA.Mods.Common.UtilityCommands
} }
} }
// Migrated EmitInfantryOnSell to use int percentage instead of float
if (engineVersion < 20160324)
{
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();
}
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
} }
} }