Make Gate more independent from Building and pausable-conditional

Replace Gate IsDisabled checks with IsTraitDisabled/Paused checks
This commit is contained in:
reaperrr
2017-11-19 17:10:29 +01:00
committed by Paul Chote
parent 383840135f
commit c1cba4ecc1
6 changed files with 93 additions and 37 deletions

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Will open and be passable for actors that appear friendly when there are no enemies in range.")]
public class GateInfo : BuildingInfo, IBlocksProjectilesInfo
public class GateInfo : PausableConditionalTraitInfo, IBlocksProjectilesInfo, Requires<BuildingInfo>
{
public readonly string OpeningSound = null;
public readonly string ClosingSound = null;
@@ -33,11 +33,13 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new Gate(init, this); }
}
public class Gate : Building, ITick, ITemporaryBlocker, IBlocksProjectiles, INotifyBlockingMove, ISync
public class Gate : PausableConditionalTrait<GateInfo>, ITick, ITemporaryBlocker, IBlocksProjectiles,
INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove, ISync
{
readonly GateInfo info;
readonly Actor self;
readonly Building building;
IEnumerable<CPos> blockedPositions;
public readonly IEnumerable<CPos> Footprint;
public readonly int OpenPosition;
[Sync] public int Position { get; private set; }
@@ -45,16 +47,18 @@ namespace OpenRA.Mods.Common.Traits
int remainingOpenTime;
public Gate(ActorInitializer init, GateInfo info)
: base(init, info)
: base(info)
{
this.info = info;
self = init.Self;
OpenPosition = info.TransitionDelay;
OpenPosition = Info.TransitionDelay;
building = self.Trait<Building>();
blockedPositions = building.Info.Tiles(self.Location);
Footprint = blockedPositions;
}
void ITick.Tick(Actor self)
{
if (self.IsDisabled() || Locked || !BuildComplete)
if (IsTraitDisabled || IsTraitPaused || building.Locked || !building.BuildComplete)
return;
if (desiredPosition < Position)
@@ -62,8 +66,8 @@ namespace OpenRA.Mods.Common.Traits
// Gate was fully open
if (Position == OpenPosition)
{
Game.Sound.Play(SoundType.World, info.ClosingSound, self.CenterPosition);
self.World.ActorMap.AddInfluence(self, this);
Game.Sound.Play(SoundType.World, Info.ClosingSound, self.CenterPosition);
self.World.ActorMap.AddInfluence(self, building);
}
Position--;
@@ -72,22 +76,22 @@ namespace OpenRA.Mods.Common.Traits
{
// Gate was fully closed
if (Position == 0)
Game.Sound.Play(SoundType.World, info.OpeningSound, self.CenterPosition);
Game.Sound.Play(SoundType.World, Info.OpeningSound, self.CenterPosition);
Position++;
// Gate is now fully open
if (Position == OpenPosition)
{
self.World.ActorMap.RemoveInfluence(self, this);
remainingOpenTime = info.CloseDelay;
self.World.ActorMap.RemoveInfluence(self, building);
remainingOpenTime = Info.CloseDelay;
}
}
if (Position == OpenPosition)
{
if (IsBlocked())
remainingOpenTime = info.CloseDelay;
remainingOpenTime = Info.CloseDelay;
else if (--remainingOpenTime <= 0)
desiredPosition = 0;
}
@@ -109,15 +113,19 @@ namespace OpenRA.Mods.Common.Traits
desiredPosition = OpenPosition;
}
bool CanRemoveBlockage(Actor self, Actor blocking)
void INotifyAddedToWorld.AddedToWorld(Actor self)
{
return !self.IsDisabled() && BuildComplete && blocking.AppearsFriendlyTo(self);
blockedPositions = Footprint;
}
protected override void AddedToWorld(Actor self)
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
{
base.AddedToWorld(self);
blockedPositions = Info.Tiles(self.Location);
blockedPositions = Enumerable.Empty<CPos>();
}
bool CanRemoveBlockage(Actor self, Actor blocking)
{
return !IsTraitDisabled && !IsTraitPaused && building.BuildComplete && !building.Locked && blocking.AppearsFriendlyTo(self);
}
bool IsBlocked()
@@ -129,7 +137,7 @@ namespace OpenRA.Mods.Common.Traits
{
get
{
return new WDist(info.BlocksProjectilesHeight.Length * (OpenPosition - Position) / OpenPosition);
return new WDist(Info.BlocksProjectilesHeight.Length * (OpenPosition - Position) / OpenPosition);
}
}
}

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits.Render
void UpdateNeighbours(Actor self)
{
var footprint = gate.Info.Tiles(self.Location).ToArray();
var footprint = gate.Footprint.ToArray();
var adjacent = Util.ExpandFootprint(footprint, true).Except(footprint)
.Where(self.World.Map.Contains).ToList();

View File

@@ -1498,6 +1498,55 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
// Made Gate not inherit Building
if (engineVersion < 20171119)
{
var gate = node.Value.Nodes.FirstOrDefault(n => n.Key == "Gate");
if (gate != null)
{
var openSound = gate.Value.Nodes.FirstOrDefault(n => n.Key == "OpeningSound");
var closeSound = gate.Value.Nodes.FirstOrDefault(n => n.Key == "ClosingSound");
var closeDelay = gate.Value.Nodes.FirstOrDefault(n => n.Key == "CloseDelay");
var transitDelay = gate.Value.Nodes.FirstOrDefault(n => n.Key == "TransitionDelay");
var blockHeight = gate.Value.Nodes.FirstOrDefault(n => n.Key == "BlocksProjectilesHeight");
gate.Key = "Building";
var newGate = new MiniYamlNode("Gate", "");
if (openSound != null)
{
newGate.Value.Nodes.Add(openSound);
gate.Value.Nodes.Remove(openSound);
}
if (closeSound != null)
{
newGate.Value.Nodes.Add(closeSound);
gate.Value.Nodes.Remove(closeSound);
}
if (closeDelay != null)
{
newGate.Value.Nodes.Add(closeDelay);
gate.Value.Nodes.Remove(closeDelay);
}
if (transitDelay != null)
{
newGate.Value.Nodes.Add(transitDelay);
gate.Value.Nodes.Remove(transitDelay);
}
if (blockHeight != null)
{
newGate.Value.Nodes.Add(blockHeight);
gate.Value.Nodes.Remove(blockHeight);
}
node.Value.Nodes.Add(newGate);
}
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}