remove a bunch of trait lookups for PlayerResources
This commit is contained in:
@@ -22,37 +22,40 @@ namespace OpenRA.Traits
|
|||||||
public object Create(ActorInitializer init) { return new PlayerResources(init.self, this); }
|
public object Create(ActorInitializer init) { return new PlayerResources(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DebugResourceCashInfo : ITraitInfo
|
public class DebugResourceCashInfo : ITraitInfo, Requires<PlayerResourcesInfo>
|
||||||
{
|
{
|
||||||
public object Create(ActorInitializer init) { return new DebugResourceCash(init.self); }
|
public object Create(ActorInitializer init) { return new DebugResourceCash(init.self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DebugResourceCash : ISync
|
public class DebugResourceCash : ISync
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly PlayerResources pr;
|
||||||
public DebugResourceCash(Actor self){this.self = self;}
|
public DebugResourceCash(Actor self) { pr = self.Trait<PlayerResources>(); }
|
||||||
[Sync] public int foo { get { return self.Trait<PlayerResources>().Cash; } }
|
[Sync] public int foo { get { return pr.Cash; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DebugResourceOreInfo : ITraitInfo
|
public class DebugResourceOreInfo : ITraitInfo, Requires<PlayerResourcesInfo>
|
||||||
{
|
{
|
||||||
public object Create(ActorInitializer init) { return new DebugResourceOre(init.self); }
|
public object Create(ActorInitializer init) { return new DebugResourceOre(init.self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DebugResourceOre : ISync
|
public class DebugResourceOre : ISync
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly PlayerResources pr;
|
||||||
public DebugResourceOre(Actor self){this.self = self;}
|
public DebugResourceOre(Actor self) { pr = self.Trait<PlayerResources>(); }
|
||||||
[Sync] public int foo { get { return self.Trait<PlayerResources>().Ore; } }
|
[Sync] public int foo { get { return pr.Ore; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DebugResourceOreCapacityInfo : ITraitInfo
|
public class DebugResourceOreCapacityInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public object Create(ActorInitializer init) { return new DebugResourceOreCapacity(init.self); }
|
public object Create(ActorInitializer init) { return new DebugResourceOreCapacity(init.self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DebugResourceOreCapacity : ISync
|
public class DebugResourceOreCapacity : ISync
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly PlayerResources pr;
|
||||||
public DebugResourceOreCapacity(Actor self){this.self = self;}
|
public DebugResourceOreCapacity(Actor self) { pr = self.Trait<PlayerResources>(); }
|
||||||
[Sync] public int foo { get { return self.Trait<PlayerResources>().OreCapacity; } }
|
[Sync] public int foo { get { return pr.OreCapacity; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerResources : ITick, ISync
|
public class PlayerResources : ITick, ISync
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
|
|||||||
public readonly Actor self;
|
public readonly Actor self;
|
||||||
public ProductionQueueInfo Info;
|
public ProductionQueueInfo Info;
|
||||||
PowerManager PlayerPower;
|
PowerManager PlayerPower;
|
||||||
PlayerResources PlayerResources;
|
PlayerResources playerResources;
|
||||||
string Race;
|
string Race;
|
||||||
|
|
||||||
// A list of things we are currently building
|
// A list of things we are currently building
|
||||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
this.Info = info;
|
this.Info = info;
|
||||||
PlayerResources = playerActor.Trait<PlayerResources>();
|
playerResources = playerActor.Trait<PlayerResources>();
|
||||||
PlayerPower = playerActor.Trait<PowerManager>();
|
PlayerPower = playerActor.Trait<PowerManager>();
|
||||||
|
|
||||||
Race = self.Owner.Country.Race;
|
Race = self.Owner.Country.Race;
|
||||||
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.RA
|
|||||||
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();
|
Queue.Clear();
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -160,11 +160,11 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
while( Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item) )
|
while( Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item) )
|
||||||
{
|
{
|
||||||
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far.
|
playerResources.GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far.
|
||||||
FinishProduction();
|
FinishProduction();
|
||||||
}
|
}
|
||||||
if( Queue.Count > 0 )
|
if( Queue.Count > 0 )
|
||||||
Queue[ 0 ].Tick( PlayerResources, PlayerPower );
|
Queue[ 0 ].Tick( playerResources, PlayerPower );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResolveOrder( Actor self, Order order )
|
public void ResolveOrder( Actor self, Order order )
|
||||||
@@ -256,8 +256,7 @@ namespace OpenRA.Mods.RA
|
|||||||
else if (lastIndex == 0)
|
else if (lastIndex == 0)
|
||||||
{
|
{
|
||||||
var item = Queue[0];
|
var item = Queue[0];
|
||||||
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(
|
playerResources.GiveCash(item.TotalCost - item.RemainingCost); // refund what has been paid
|
||||||
item.TotalCost - item.RemainingCost); // refund what has been paid
|
|
||||||
FinishProduction();
|
FinishProduction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user