Make BaseProvider PausableConditional

This commit is contained in:
Mustafa Alperen Seki
2018-01-16 12:38:20 +03:00
committed by reaperrr
parent 12054506e1
commit c976bb1d7b
3 changed files with 14 additions and 9 deletions

View File

@@ -18,18 +18,17 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Limits the zone where buildings can be constructed to a radius around this actor.")] [Desc("Limits the zone where buildings can be constructed to a radius around this actor.")]
public class BaseProviderInfo : ITraitInfo public class BaseProviderInfo : PausableConditionalTraitInfo
{ {
public readonly WDist Range = WDist.FromCells(10); public readonly WDist Range = WDist.FromCells(10);
public readonly int Cooldown = 0; public readonly int Cooldown = 0;
public readonly int InitialDelay = 0; public readonly int InitialDelay = 0;
public object Create(ActorInitializer init) { return new BaseProvider(init.Self, this); } public override object Create(ActorInitializer init) { return new BaseProvider(init.Self, this); }
} }
public class BaseProvider : ITick, INotifyCreated, IRenderAboveShroudWhenSelected, ISelectionBar public class BaseProvider : PausableConditionalTrait<BaseProviderInfo>, ITick, INotifyCreated, IRenderAboveShroudWhenSelected, ISelectionBar
{ {
public readonly BaseProviderInfo Info;
readonly DeveloperMode devMode; readonly DeveloperMode devMode;
readonly Actor self; readonly Actor self;
readonly bool allyBuildEnabled; readonly bool allyBuildEnabled;
@@ -41,8 +40,8 @@ namespace OpenRA.Mods.Common.Traits
int progress; int progress;
public BaseProvider(Actor self, BaseProviderInfo info) public BaseProvider(Actor self, BaseProviderInfo info)
: base(info)
{ {
Info = info;
this.self = self; this.self = self;
devMode = self.Owner.PlayerActor.Trait<DeveloperMode>(); devMode = self.Owner.PlayerActor.Trait<DeveloperMode>();
progress = total = info.InitialDelay; progress = total = info.InitialDelay;
@@ -69,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
public bool Ready() public bool Ready()
{ {
if (building != null && building.Locked) if (IsTraitDisabled || IsTraitPaused || (building != null && building.Locked))
return false; return false;
return devMode.FastBuild || progress == 0; return devMode.FastBuild || progress == 0;
@@ -82,6 +81,9 @@ namespace OpenRA.Mods.Common.Traits
public IEnumerable<IRenderable> RangeCircleRenderables(WorldRenderer wr) public IEnumerable<IRenderable> RangeCircleRenderables(WorldRenderer wr)
{ {
if (IsTraitDisabled)
yield break;
// Visible to player and allies // Visible to player and allies
if (!ValidRenderPlayer()) if (!ValidRenderPlayer())
yield break; yield break;
@@ -103,6 +105,9 @@ namespace OpenRA.Mods.Common.Traits
float ISelectionBar.GetValue() float ISelectionBar.GetValue()
{ {
if (IsTraitDisabled)
return 0f;
// Visible to player and allies // Visible to player and allies
if (!ValidRenderPlayer()) if (!ValidRenderPlayer())
return 0f; return 0f;

View File

@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Traits
return (off - new WVec(0, 0, off.Z)) + LocalCenterOffset; return (off - new WVec(0, 0, off.Z)) + LocalCenterOffset;
} }
public Actor FindBaseProvider(World world, Player p, CPos topLeft) public BaseProvider FindBaseProvider(World world, Player p, CPos topLeft)
{ {
var center = world.Map.CenterOfCell(topLeft) + CenterOffset(world); var center = world.Map.CenterOfCell(topLeft) + CenterOffset(world);
var mapBuildRadius = world.WorldActor.Trait<MapBuildRadius>(); var mapBuildRadius = world.WorldActor.Trait<MapBuildRadius>();
@@ -161,7 +161,7 @@ namespace OpenRA.Mods.Common.Traits
// Range is counted from the center of the actor, not from each cell. // Range is counted from the center of the actor, not from each cell.
var target = Target.FromPos(bp.Actor.CenterPosition); var target = Target.FromPos(bp.Actor.CenterPosition);
if (target.IsInRange(center, bp.Trait.Info.Range)) if (target.IsInRange(center, bp.Trait.Info.Range))
return bp.Actor; return bp.Trait;
} }
return null; return null;

View File

@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits
// BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location // BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location
var provider = buildingInfo.FindBaseProvider(w, self.Owner, order.TargetLocation); var provider = buildingInfo.FindBaseProvider(w, self.Owner, order.TargetLocation);
if (provider != null) if (provider != null)
provider.Trait<BaseProvider>().BeginCooldown(); provider.BeginCooldown();
} }
if (GetNumBuildables(self.Owner) > prevItems) if (GetNumBuildables(self.Owner) > prevItems)