From 276634d3da9cf7b539cd96641d7697c82181e15d Mon Sep 17 00:00:00 2001 From: Caleb Anderson Date: Fri, 1 Jan 2010 01:03:54 -0600 Subject: [PATCH 1/3] Don't crash on bad orders --- OpenRa.Game/Controller.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index a850cbd9e7..0cf12c1cb3 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -27,6 +27,7 @@ namespace OpenRa.Game if (orderGenerator == null) return; var orders = orderGenerator.Order(xy.ToInt2(), mi).ToArray(); + orders.Where(order => order.Validate()); recentOrders.AddRange( orders ); var voicedActor = orders.Select(o => o.Subject) From b4ba7ebaa7842acfda6e05b5cb486f0add5592af Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 2 Jan 2010 15:35:47 +1300 Subject: [PATCH 2/3] repairing units is no longer free --- OpenRa.Game/Traits/Activities/Repair.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/OpenRa.Game/Traits/Activities/Repair.cs b/OpenRa.Game/Traits/Activities/Repair.cs index 9d8e1d2002..e8e8090019 100644 --- a/OpenRa.Game/Traits/Activities/Repair.cs +++ b/OpenRa.Game/Traits/Activities/Repair.cs @@ -9,16 +9,24 @@ namespace OpenRa.Game.Traits.Activities { public IActivity NextActivity { get; set; } bool isCanceled; - int remainingTicks = ticksPerPoint; + int remainingTicks; - const int ticksPerPoint = 15; - const int hpPerPoint = 8; + public Repair() { remainingTicks = ticksPerPoint; } + + readonly int ticksPerPoint = (int)(Rules.General.RepairRate * 60 * 25); + readonly int hpPerPoint = Rules.General.URepairStep; public IActivity Tick(Actor self) { if (isCanceled) return NextActivity; - if (--remainingTicks == 0) + if (--remainingTicks <= 0) { + var costPerHp = (Rules.General.URepairPercent * self.Info.Cost) / self.Info.Strength; + var hpToRepair = Math.Min( hpPerPoint, self.Info.Strength - self.Health ); + var cost = (int)Math.Ceiling(costPerHp * hpToRepair); + if (!self.Owner.TakeCash(cost)) + return this; + self.InflictDamage(self, -hpPerPoint, Rules.WarheadInfo["Super"]); if (self.Health == self.Info.Strength) return NextActivity; From 32de21b135f733c6e09f67465bdb594b6b340601 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 2 Jan 2010 15:48:53 +1300 Subject: [PATCH 3/3] slightly nicer impl of Repair --- OpenRa.Game/Traits/Activities/Repair.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/OpenRa.Game/Traits/Activities/Repair.cs b/OpenRa.Game/Traits/Activities/Repair.cs index e8e8090019..63f6e1fd92 100644 --- a/OpenRa.Game/Traits/Activities/Repair.cs +++ b/OpenRa.Game/Traits/Activities/Repair.cs @@ -11,23 +11,21 @@ namespace OpenRa.Game.Traits.Activities bool isCanceled; int remainingTicks; - public Repair() { remainingTicks = ticksPerPoint; } - - readonly int ticksPerPoint = (int)(Rules.General.RepairRate * 60 * 25); - readonly int hpPerPoint = Rules.General.URepairStep; - public IActivity Tick(Actor self) { if (isCanceled) return NextActivity; - if (--remainingTicks <= 0) + if (remainingTicks == 0) { var costPerHp = (Rules.General.URepairPercent * self.Info.Cost) / self.Info.Strength; - var hpToRepair = Math.Min( hpPerPoint, self.Info.Strength - self.Health ); + var hpToRepair = Math.Min(Rules.General.URepairStep, self.Info.Strength - self.Health); var cost = (int)Math.Ceiling(costPerHp * hpToRepair); if (!self.Owner.TakeCash(cost)) + { + remainingTicks = 1; return this; + } - self.InflictDamage(self, -hpPerPoint, Rules.WarheadInfo["Super"]); + self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]); if (self.Health == self.Info.Strength) return NextActivity; @@ -35,10 +33,12 @@ namespace OpenRa.Game.Traits.Activities .FirstOrDefault(a => a.traits.Contains()); if (hostBuilding != null) - hostBuilding.traits.Get().PlayCustomAnim(hostBuilding, "active" ); + hostBuilding.traits.Get().PlayCustomAnim(hostBuilding, "active"); - remainingTicks = ticksPerPoint; + remainingTicks = (int)(Rules.General.RepairRate * 60 * 25); } + else + --remainingTicks; return this; }