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 namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Will open and be passable for actors that appear friendly when there are no enemies in range.")] [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 OpeningSound = null;
public readonly string ClosingSound = 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 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 Actor self;
readonly Building building;
IEnumerable<CPos> blockedPositions; IEnumerable<CPos> blockedPositions;
public readonly IEnumerable<CPos> Footprint;
public readonly int OpenPosition; public readonly int OpenPosition;
[Sync] public int Position { get; private set; } [Sync] public int Position { get; private set; }
@@ -45,16 +47,18 @@ namespace OpenRA.Mods.Common.Traits
int remainingOpenTime; int remainingOpenTime;
public Gate(ActorInitializer init, GateInfo info) public Gate(ActorInitializer init, GateInfo info)
: base(init, info) : base(info)
{ {
this.info = info;
self = init.Self; 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) void ITick.Tick(Actor self)
{ {
if (self.IsDisabled() || Locked || !BuildComplete) if (IsTraitDisabled || IsTraitPaused || building.Locked || !building.BuildComplete)
return; return;
if (desiredPosition < Position) if (desiredPosition < Position)
@@ -62,8 +66,8 @@ namespace OpenRA.Mods.Common.Traits
// Gate was fully open // Gate was fully open
if (Position == OpenPosition) if (Position == OpenPosition)
{ {
Game.Sound.Play(SoundType.World, info.ClosingSound, self.CenterPosition); Game.Sound.Play(SoundType.World, Info.ClosingSound, self.CenterPosition);
self.World.ActorMap.AddInfluence(self, this); self.World.ActorMap.AddInfluence(self, building);
} }
Position--; Position--;
@@ -72,22 +76,22 @@ namespace OpenRA.Mods.Common.Traits
{ {
// Gate was fully closed // Gate was fully closed
if (Position == 0) if (Position == 0)
Game.Sound.Play(SoundType.World, info.OpeningSound, self.CenterPosition); Game.Sound.Play(SoundType.World, Info.OpeningSound, self.CenterPosition);
Position++; Position++;
// Gate is now fully open // Gate is now fully open
if (Position == OpenPosition) if (Position == OpenPosition)
{ {
self.World.ActorMap.RemoveInfluence(self, this); self.World.ActorMap.RemoveInfluence(self, building);
remainingOpenTime = info.CloseDelay; remainingOpenTime = Info.CloseDelay;
} }
} }
if (Position == OpenPosition) if (Position == OpenPosition)
{ {
if (IsBlocked()) if (IsBlocked())
remainingOpenTime = info.CloseDelay; remainingOpenTime = Info.CloseDelay;
else if (--remainingOpenTime <= 0) else if (--remainingOpenTime <= 0)
desiredPosition = 0; desiredPosition = 0;
} }
@@ -109,15 +113,19 @@ namespace OpenRA.Mods.Common.Traits
desiredPosition = OpenPosition; 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 = Enumerable.Empty<CPos>();
blockedPositions = Info.Tiles(self.Location); }
bool CanRemoveBlockage(Actor self, Actor blocking)
{
return !IsTraitDisabled && !IsTraitPaused && building.BuildComplete && !building.Locked && blocking.AppearsFriendlyTo(self);
} }
bool IsBlocked() bool IsBlocked()
@@ -129,7 +137,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
get 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) 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) var adjacent = Util.ExpandFootprint(footprint, true).Except(footprint)
.Where(self.World.Map.Contains).ToList(); .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); UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
} }

View File

@@ -707,22 +707,22 @@
Type: Heavy Type: Heavy
LineBuildNode: LineBuildNode:
Types: concrete, gate Types: concrete, gate
-Building:
-WithSpriteBody: -WithSpriteBody:
WithGateSpriteBody: WithGateSpriteBody:
Tooltip: Tooltip:
Name: Gate Name: Gate
Gate: Building:
BlocksProjectilesHeight: 0
BuildSounds: place2.aud BuildSounds: place2.aud
OpeningSound: cashturn.aud
ClosingSound: cashturn.aud
TerrainTypes: Clear, Road TerrainTypes: Clear, Road
RequiresBuildableArea: RequiresBuildableArea:
AreaTypes: building AreaTypes: building
Adjacent: 4 Adjacent: 4
EditorTilesetFilter: EditorTilesetFilter:
Categories: Wall Categories: Wall
Gate:
OpeningSound: cashturn.aud
ClosingSound: cashturn.aud
BlocksProjectilesHeight: 0
^TechBuilding: ^TechBuilding:
Inherits: ^BasicBuilding Inherits: ^BasicBuilding

View File

@@ -1912,7 +1912,7 @@ VGATE:
Type: Rectangle Type: Rectangle
TopLeft: -512, -1536 TopLeft: -512, -1536
BottomRight: 512, 1536 BottomRight: 512, 1536
Gate: Building:
Footprint: x x x Footprint: x x x
Dimensions: 1,3 Dimensions: 1,3
WithGateSpriteBody: WithGateSpriteBody:
@@ -1929,7 +1929,7 @@ HGATE:
Type: Rectangle Type: Rectangle
TopLeft: -1536, -512 TopLeft: -1536, -512
BottomRight: 1536, 512 BottomRight: 1536, 512
Gate: Building:
Footprint: xxx Footprint: xxx
Dimensions: 3,1 Dimensions: 3,1
WithGateSpriteBody: WithGateSpriteBody:

View File

@@ -307,7 +307,7 @@
Dimensions: 1,1 Dimensions: 1,1
Footprint: x Footprint: x
BuildSounds: place2.aud BuildSounds: place2.aud
TerrainTypes: Clear, Road, DirtRoad, Rough TerrainTypes: Clear, Rough, Road, DirtRoad, Green, Sand, Pavement
RequiresBuildableArea: RequiresBuildableArea:
AreaTypes: building AreaTypes: building
Adjacent: 4 Adjacent: 4
@@ -1128,6 +1128,7 @@
^Gate: ^Gate:
Inherits: ^Building Inherits: ^Building
Inherits@EMPDISABLE: ^EmpDisable
Huntable: Huntable:
Valued: Valued:
Cost: 250 Cost: 250
@@ -1137,7 +1138,6 @@
Type: Heavy Type: Heavy
LineBuildNode: LineBuildNode:
Types: wall, gate Types: wall, gate
-Building:
-Capturable: -Capturable:
-GivesBuildableArea: -GivesBuildableArea:
-MustBeDestroyed: -MustBeDestroyed:
@@ -1145,12 +1145,6 @@
WithGateSpriteBody: WithGateSpriteBody:
OpenSequence: open OpenSequence: open
Tooltip: Tooltip:
Gate:
BuildSounds: place2.aud
OpeningSound: gateup1.aud
ClosingSound: gatedwn1.aud
TerrainTypes: Clear, Rough, Road, DirtRoad, Green, Sand, Pavement
BlocksProjectilesHeight: 768
Buildable: Buildable:
Description: Automated barrier that opens for allied units. Description: Automated barrier that opens for allied units.
HitShape: HitShape:
@@ -1161,12 +1155,17 @@
VerticalTopOffset: 768 VerticalTopOffset: 768
EditorTilesetFilter: EditorTilesetFilter:
Categories: Wall Categories: Wall
Gate:
OpeningSound: gateup1.aud
ClosingSound: gatedwn1.aud
BlocksProjectilesHeight: 768
PauseOnCondition: empdisable
^Gate_A: ^Gate_A:
Inherits: ^Gate Inherits: ^Gate
Inherits@shape: ^3x1Shape Inherits@shape: ^3x1Shape
Health: Health:
Gate: Building:
Dimensions: 3,1 Dimensions: 3,1
Footprint: xxx Footprint: xxx
WithGateSpriteBody: WithGateSpriteBody:
@@ -1178,7 +1177,7 @@
Inherits: ^Gate Inherits: ^Gate
Inherits@shape: ^1x3Shape Inherits@shape: ^1x3Shape
Health: Health:
Gate: Building:
Dimensions: 1,3 Dimensions: 1,3
Footprint: x x x Footprint: x x x
WithGateSpriteBody: WithGateSpriteBody: