clean up some potential fp misbehavior in Repair.cs

This commit is contained in:
Chris Forbes
2011-01-05 08:58:02 +13:00
parent 558647b987
commit 418284672c
2 changed files with 8 additions and 6 deletions

View File

@@ -30,12 +30,14 @@ namespace OpenRA.Mods.RA.Activities
{
var health = self.TraitOrDefault<Health>();
if (health == null) return NextActivity;
var unitCost = self.Info.Traits.Get<ValuedInfo>().Cost;
var repairsUnits = host.Info.Traits.Get<RepairsUnitsInfo>();
var costPerHp = (repairsUnits.URepairPercent * unitCost) / health.MaxHP;
var unitCost = self.Info.Traits.Get<ValuedInfo>().Cost;
var hpToRepair = Math.Min(host.Info.Traits.Get<RepairsUnitsInfo>().URepairStep, health.MaxHP - health.HP);
var cost = (int)Math.Ceiling(costPerHp * hpToRepair);
var costPerHp = (repairsUnits.URepairPercent * unitCost) / health.MaxHP;
var fullRepairCost = (int)(repairsUnits.URepairPercent * unitCost);
var cost = fullRepairCost * hpToRepair / health.MaxHP;
if (!self.Owner.PlayerActor.Trait<PlayerResources>().TakeCash(cost))
{
remainingTicks = 1;
@@ -50,7 +52,7 @@ namespace OpenRA.Mods.RA.Activities
host.Trait<RenderBuilding>()
.PlayCustomAnim(host, "active");
remainingTicks = (int)(repairsUnits.RepairRate * 60 * 25);
remainingTicks = repairsUnits.Interval;
}
else
--remainingTicks;

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Mods.RA
{
public readonly float URepairPercent = 0.2f;
public readonly int URepairStep = 10;
public readonly float RepairRate = 0.016f;
public readonly int Interval = 24;
}
public class RepairsUnits { }