Fix some more cases of stale Player references after capture.

This commit is contained in:
Paul Chote
2011-01-30 17:14:00 +13:00
parent 7f3f783187
commit ccf04240cf
3 changed files with 27 additions and 8 deletions

View File

@@ -17,13 +17,13 @@ namespace OpenRA.Mods.RA.Buildings
public object Create(ActorInitializer init) { return new CanPowerDown(init); } public object Create(ActorInitializer init) { return new CanPowerDown(init); }
} }
public class CanPowerDown : IResolveOrder, IDisable, ISync public class CanPowerDown : IResolveOrder, IDisable, INotifyCapture, ISync
{ {
[Sync] [Sync]
bool disabled = false; bool disabled = false;
int normalPower = 0; int normalPower = 0;
readonly PowerManager PowerManager; PowerManager PowerManager;
readonly TechTree TechTree; TechTree TechTree;
public CanPowerDown(ActorInitializer init) public CanPowerDown(ActorInitializer init)
{ {
@@ -47,5 +47,11 @@ namespace OpenRA.Mods.RA.Buildings
TechTree.Update(); TechTree.Update();
} }
} }
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
PowerManager = newOwner.PlayerActor.Trait<PowerManager>();
TechTree = newOwner.PlayerActor.Trait<TechTree>();
}
} }
} }

View File

@@ -17,9 +17,9 @@ namespace OpenRA.Mods.RA.Buildings
public object Create(ActorInitializer init) { return new RequiresPower(init.self); } public object Create(ActorInitializer init) { return new RequiresPower(init.self); }
} }
class RequiresPower : IDisable class RequiresPower : IDisable, INotifyCapture
{ {
readonly PowerManager power; PowerManager power;
public RequiresPower( Actor self ) public RequiresPower( Actor self )
{ {
power = self.Owner.PlayerActor.Trait<PowerManager>(); power = self.Owner.PlayerActor.Trait<PowerManager>();
@@ -29,5 +29,10 @@ namespace OpenRA.Mods.RA.Buildings
{ {
get { return power.PowerProvided < power.PowerDrained; } get { return power.PowerProvided < power.PowerDrained; }
} }
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
power = newOwner.PlayerActor.Trait<PowerManager>();
}
} }
} }

View File

@@ -31,12 +31,12 @@ 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 public class ProductionQueue : IResolveOrder, ITick, ITechTreeElement, INotifyCapture
{ {
public readonly Actor self; public readonly Actor self;
public ProductionQueueInfo Info; public ProductionQueueInfo Info;
readonly PowerManager PlayerPower; PowerManager PlayerPower;
readonly PlayerResources PlayerResources; PlayerResources PlayerResources;
// TODO: sync these // TODO: sync these
// A list of things we are currently building // A list of things we are currently building
@@ -65,6 +65,14 @@ namespace OpenRA.Mods.RA
} }
} }
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
PlayerResources = newOwner.PlayerActor.Trait<PlayerResources>();
Queue.Clear();
// Produceable contains the tech from the original owner - this is desired so we don't clear it.
}
IEnumerable<ActorInfo> AllBuildables(string category) IEnumerable<ActorInfo> AllBuildables(string category)
{ {
return Rules.Info.Values return Rules.Info.Values