Fix #931 ("Unit Ready" played when a production structure is destroyed).

This commit is contained in:
Paul Chote
2011-07-21 23:55:59 +12:00
parent d42cf25789
commit 9b96bfb33b

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA
public virtual object Create(ActorInitializer init) { return new ProductionQueue(init.self, init.self.Owner.PlayerActor, this); } public virtual object Create(ActorInitializer init) { return new ProductionQueue(init.self, init.self.Owner.PlayerActor, this); }
} }
public class ProductionQueue : IResolveOrder, ITick, ITechTreeElement, INotifyCapture, ISync public class ProductionQueue : IResolveOrder, ITick, ITechTreeElement, INotifyCapture, INotifyKilled, INotifySold, ISync
{ {
public readonly Actor self; public readonly Actor self;
public ProductionQueueInfo Info; public ProductionQueueInfo Info;
@@ -70,12 +70,22 @@ namespace OpenRA.Mods.RA
Race = self.Owner.Country.Race; Race = self.Owner.Country.Race;
Produceable = InitTech(playerActor); Produceable = InitTech(playerActor);
} }
void ClearQueue()
{
if (Queue.Count == 0)
return;
// Refund the current item
playerResources.GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost);
Queue.Clear();
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{ {
PlayerPower = newOwner.PlayerActor.Trait<PowerManager>(); PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
playerResources = newOwner.PlayerActor.Trait<PlayerResources>(); playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
Queue.Clear(); ClearQueue();
// Produceable contains the tech from the original owner - this is desired so we don't clear it. // Produceable contains the tech from the original owner - this is desired so we don't clear it.
Produceable = InitTech(self.Owner.PlayerActor); Produceable = InitTech(self.Owner.PlayerActor);
@@ -87,6 +97,10 @@ namespace OpenRA.Mods.RA
self.Owner.PlayerActor.Trait<TechTree>().Update(); self.Owner.PlayerActor.Trait<TechTree>().Update();
} }
public void Killed(Actor self, AttackInfo e) { ClearQueue(); }
public void Selling(Actor self) {}
public void Sold(Actor self) { ClearQueue(); }
Dictionary<ActorInfo, ProductionState> InitTech(Actor playerActor) Dictionary<ActorInfo, ProductionState> InitTech(Actor playerActor)
{ {
var tech = new Dictionary<ActorInfo, ProductionState>(); var tech = new Dictionary<ActorInfo, ProductionState>();