Added Gates
FIXUP: account for full gate footprint when updating neighbours. FIXUP: gate-wall connection adjacency yaml.
This commit is contained in:
@@ -220,12 +220,14 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
var nextCell = path[path.Count - 1];
|
||||
|
||||
var containsTemporaryBlocker = WorldUtils.ContainsTemporaryBlocker(self.World, nextCell, self);
|
||||
|
||||
// Next cell in the move is blocked by another actor
|
||||
if (!mobile.CanMoveFreelyInto(nextCell, ignoredActor, true))
|
||||
if (containsTemporaryBlocker || !mobile.CanMoveFreelyInto(nextCell, ignoredActor, true))
|
||||
{
|
||||
// Are we close enough?
|
||||
var cellRange = nearEnough.Length / 1024;
|
||||
if ((mobile.ToCell - destination.Value).LengthSquared <= cellRange * cellRange)
|
||||
if (!containsTemporaryBlocker && (mobile.ToCell - destination.Value).LengthSquared <= cellRange * cellRange)
|
||||
{
|
||||
path.Clear();
|
||||
return null;
|
||||
|
||||
@@ -289,6 +289,7 @@
|
||||
<Compile Include="Traits\Buildings\Exit.cs" />
|
||||
<Compile Include="Traits\Buildings\FootprintUtils.cs" />
|
||||
<Compile Include="Traits\Buildings\FreeActor.cs" />
|
||||
<Compile Include="Traits\Buildings\Gate.cs" />
|
||||
<Compile Include="Traits\Buildings\LineBuild.cs" />
|
||||
<Compile Include="Traits\Buildings\LineBuildNode.cs" />
|
||||
<Compile Include="Traits\Buildings\PrimaryBuilding.cs" />
|
||||
@@ -731,6 +732,7 @@
|
||||
<Compile Include="UtilityCommands\CheckExplicitInterfacesCommand.cs" />
|
||||
<Compile Include="FileFormats\LZOCompression.cs" />
|
||||
<Compile Include="Util.cs" />
|
||||
<Compile Include="Traits\Render\WithGateSpriteBody.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly string[] BuildSounds = { "placbldg.aud", "build5.aud" };
|
||||
public readonly string[] UndeploySounds = { "cashturn.aud" };
|
||||
|
||||
public object Create(ActorInitializer init) { return new Building(init, this); }
|
||||
public virtual object Create(ActorInitializer init) { return new Building(init, this); }
|
||||
|
||||
public Actor FindBaseProvider(World world, Player p, CPos topLeft)
|
||||
{
|
||||
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
NotifyBuildingComplete(self);
|
||||
}
|
||||
|
||||
public void AddedToWorld(Actor self)
|
||||
public virtual void AddedToWorld(Actor self)
|
||||
{
|
||||
self.World.ActorMap.AddInfluence(self, this);
|
||||
self.World.ActorMap.AddPosition(self, this);
|
||||
|
||||
135
OpenRA.Mods.Common/Traits/Buildings/Gate.cs
Normal file
135
OpenRA.Mods.Common/Traits/Buildings/Gate.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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
|
||||
{
|
||||
public readonly string OpeningSound = null;
|
||||
public readonly string ClosingSound = null;
|
||||
|
||||
[Desc("Ticks until the gate closes.")]
|
||||
public readonly int CloseDelay = 150;
|
||||
|
||||
[Desc("Ticks until the gate is considered open.")]
|
||||
public readonly int TransitionDelay = 33;
|
||||
|
||||
[Desc("Blocks bullets scaled to open value.")]
|
||||
public readonly int BlocksProjectilesHeight = 640;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new Gate(init, this); }
|
||||
}
|
||||
|
||||
public class Gate : Building, ITick, ITemporaryBlocker, IBlocksProjectiles, INotifyBlockingMove, ISync
|
||||
{
|
||||
readonly GateInfo info;
|
||||
readonly Actor self;
|
||||
IEnumerable<CPos> blockedPositions;
|
||||
|
||||
public readonly int OpenPosition;
|
||||
[Sync] public int Position { get; private set; }
|
||||
int desiredPosition;
|
||||
int remainingOpenTime;
|
||||
|
||||
public Gate(ActorInitializer init, GateInfo info)
|
||||
: base(init, info)
|
||||
{
|
||||
this.info = info;
|
||||
self = init.Self;
|
||||
OpenPosition = info.TransitionDelay;
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
if (self.IsDisabled() || Locked || !BuildComplete)
|
||||
return;
|
||||
|
||||
if (desiredPosition < Position)
|
||||
{
|
||||
// Gate was fully open
|
||||
if (Position == OpenPosition)
|
||||
{
|
||||
Game.Sound.Play(info.ClosingSound, self.CenterPosition);
|
||||
self.World.ActorMap.AddInfluence(self, this);
|
||||
}
|
||||
|
||||
Position--;
|
||||
}
|
||||
else if (desiredPosition > Position)
|
||||
{
|
||||
// Gate was fully closed
|
||||
if (Position == 0)
|
||||
Game.Sound.Play(info.OpeningSound, self.CenterPosition);
|
||||
|
||||
Position++;
|
||||
|
||||
// Gate is now fully open
|
||||
if (Position == OpenPosition)
|
||||
{
|
||||
self.World.ActorMap.RemoveInfluence(self, this);
|
||||
remainingOpenTime = info.CloseDelay;
|
||||
}
|
||||
}
|
||||
|
||||
if (Position == OpenPosition)
|
||||
{
|
||||
if (IsBlocked())
|
||||
remainingOpenTime = info.CloseDelay;
|
||||
else if (--remainingOpenTime <= 0)
|
||||
desiredPosition = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool ITemporaryBlocker.IsBlocking(Actor self, CPos cell)
|
||||
{
|
||||
return Position != OpenPosition && blockedPositions.Contains(cell);
|
||||
}
|
||||
|
||||
bool ITemporaryBlocker.CanRemoveBlockage(Actor self, Actor blocking)
|
||||
{
|
||||
return CanRemoveBlockage(self, blocking);
|
||||
}
|
||||
|
||||
void INotifyBlockingMove.OnNotifyBlockingMove(Actor self, Actor blocking)
|
||||
{
|
||||
if (Position != OpenPosition && CanRemoveBlockage(self, blocking))
|
||||
desiredPosition = OpenPosition;
|
||||
}
|
||||
|
||||
bool CanRemoveBlockage(Actor self, Actor blocking)
|
||||
{
|
||||
return !self.IsDisabled() && BuildComplete && blocking.AppearsFriendlyTo(self);
|
||||
}
|
||||
|
||||
public override void AddedToWorld(Actor self)
|
||||
{
|
||||
base.AddedToWorld(self);
|
||||
blockedPositions = FootprintUtils.Tiles(self);
|
||||
}
|
||||
|
||||
bool IsBlocked()
|
||||
{
|
||||
return blockedPositions.Any(loc => self.World.ActorMap.GetActorsAt(loc).Any(a => a != self));
|
||||
}
|
||||
|
||||
WDist IBlocksProjectiles.BlockingHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return new WDist(info.BlocksProjectilesHeight * (OpenPosition - Position) / OpenPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,6 +240,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
IsMovingInMyDirection(self, otherActor))
|
||||
return false;
|
||||
|
||||
// If there is a temporary blocker in our path, but we can remove it, we are not blocked.
|
||||
var temporaryBlocker = otherActor.TraitOrDefault<ITemporaryBlocker>();
|
||||
if (temporaryBlocker != null && temporaryBlocker.CanRemoveBlockage(otherActor, self))
|
||||
return false;
|
||||
|
||||
// If we cannot crush the other actor in our way, we are blocked.
|
||||
if (self == null || Crushes == null || Crushes.Count == 0)
|
||||
return true;
|
||||
|
||||
93
OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs
Normal file
93
OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class WithGateSpriteBodyInfo : WithSpriteBodyInfo, Requires<GateInfo>
|
||||
{
|
||||
[Desc("Cells (outside the gate footprint) that contain wall cells that can connect to the gate")]
|
||||
public readonly CVec[] WallConnections = { };
|
||||
|
||||
[Desc("Wall type for connections")]
|
||||
public readonly string Type = "wall";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new WithGateSpriteBody(init, this); }
|
||||
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var anim = new Animation(init.World, image);
|
||||
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, INotifyBuildComplete, IWallConnector
|
||||
{
|
||||
readonly WithGateSpriteBodyInfo gateInfo;
|
||||
readonly Gate gate;
|
||||
|
||||
public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info)
|
||||
: base(init, info, () => 0)
|
||||
{
|
||||
gateInfo = info;
|
||||
gate = init.Self.Trait<Gate>();
|
||||
}
|
||||
|
||||
int GetGateFrame()
|
||||
{
|
||||
return int2.Lerp(0, DefaultAnimation.CurrentSequence.Length - 1, gate.Position, gate.OpenPosition);
|
||||
}
|
||||
|
||||
public override void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame);
|
||||
}
|
||||
|
||||
public override void BuildingComplete(Actor self)
|
||||
{
|
||||
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame);
|
||||
UpdateNeighbours(self);
|
||||
}
|
||||
|
||||
void UpdateNeighbours(Actor self)
|
||||
{
|
||||
var footprint = FootprintUtils.Tiles(self).ToArray();
|
||||
var adjacent = Util.ExpandFootprint(footprint, true).Except(footprint)
|
||||
.Where(self.World.Map.Contains).ToList();
|
||||
|
||||
var adjacentActorTraits = adjacent.SelectMany(self.World.ActorMap.GetActorsAt)
|
||||
.SelectMany(a => a.TraitsImplementing<IWallConnector>());
|
||||
|
||||
foreach (var aat in adjacentActorTraits)
|
||||
aat.SetDirty();
|
||||
}
|
||||
|
||||
public void RemovedFromWorld(Actor self)
|
||||
{
|
||||
UpdateNeighbours(self);
|
||||
}
|
||||
|
||||
bool IWallConnector.AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType, out CVec facing)
|
||||
{
|
||||
facing = wallLocation - self.Location;
|
||||
return wallType == gateInfo.Type && gateInfo.WallConnections.Contains(facing);
|
||||
}
|
||||
|
||||
void IWallConnector.SetDirty() { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user