diff --git a/OpenRA.Mods.Common/Traits/EmitInfantryOnSell.cs b/OpenRA.Mods.Common/Traits/EmitInfantryOnSell.cs index d9814a198e..60ab45657a 100644 --- a/OpenRA.Mods.Common/Traits/EmitInfantryOnSell.cs +++ b/OpenRA.Mods.Common/Traits/EmitInfantryOnSell.cs @@ -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(); 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().Cost }).ToList(); diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index a42e679d39..0875963d37 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -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("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("MinHpPercent", minHPNode.Value.Value); + var newValue = (int)oldValue; + minHPNode.Value.Value = newValue.ToString(); + } + } + } + UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); } }