Implement "Enter Tunnel" cursor.
This commit is contained in:
@@ -802,6 +802,8 @@
|
|||||||
<Compile Include="WebServices.cs" />
|
<Compile Include="WebServices.cs" />
|
||||||
<Compile Include="Traits\Conditions\GrantConditionOnLineBuildDirection.cs" />
|
<Compile Include="Traits\Conditions\GrantConditionOnLineBuildDirection.cs" />
|
||||||
<Compile Include="Traits\Conditions\LineBuildSegmentExternalCondition.cs" />
|
<Compile Include="Traits\Conditions\LineBuildSegmentExternalCondition.cs" />
|
||||||
|
<Compile Include="Traits\EntersTunnels.cs" />
|
||||||
|
<Compile Include="Traits\TunnelEntrance.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
|
|||||||
132
OpenRA.Mods.Common/Traits/EntersTunnels.cs
Normal file
132
OpenRA.Mods.Common/Traits/EntersTunnels.cs
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2017 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, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Mods.Common.Orders;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[Desc("This actor can interact with TunnelEntrances to move through TerrainTunnels.")]
|
||||||
|
public class EntersTunnelsInfo : ITraitInfo, Requires<IMoveInfo>
|
||||||
|
{
|
||||||
|
public readonly string EnterCursor = "enter";
|
||||||
|
public readonly string EnterBlockedCursor = "enter-blocked";
|
||||||
|
|
||||||
|
[VoiceReference] public readonly string Voice = "Action";
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new EntersTunnels(init.Self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EntersTunnels : IIssueOrder, IResolveOrder, IOrderVoice
|
||||||
|
{
|
||||||
|
readonly EntersTunnelsInfo info;
|
||||||
|
readonly IMove move;
|
||||||
|
|
||||||
|
public EntersTunnels(Actor self, EntersTunnelsInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
move = self.Trait<IMove>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
yield return new EnterTunnelOrderTargeter(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||||
|
{
|
||||||
|
if (order.OrderID != "EnterTunnel")
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (target.Type == TargetType.FrozenActor)
|
||||||
|
return new Order(order.OrderID, self, queued) { ExtraData = target.FrozenActor.ID, SuppressVisualFeedback = true };
|
||||||
|
|
||||||
|
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor, SuppressVisualFeedback = true };
|
||||||
|
}
|
||||||
|
|
||||||
|
public string VoicePhraseForOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
return order.OrderString == "EnterTunnel" ? info.Voice : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResolveOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
if (order.OrderString != "EnterTunnel")
|
||||||
|
return;
|
||||||
|
|
||||||
|
var target = self.ResolveFrozenActorOrder(order, Color.Red);
|
||||||
|
if (target.Type != TargetType.Actor)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var tunnel = target.Actor.TraitOrDefault<TunnelEntrance>();
|
||||||
|
if (!tunnel.Exit.HasValue)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!order.Queued)
|
||||||
|
self.CancelActivity();
|
||||||
|
|
||||||
|
self.SetTargetLine(Target.FromCell(self.World, tunnel.Exit.Value), Color.Green);
|
||||||
|
self.QueueActivity(move.MoveTo(tunnel.Entrance, tunnel.NearEnough));
|
||||||
|
self.QueueActivity(move.MoveTo(tunnel.Exit.Value, tunnel.NearEnough));
|
||||||
|
}
|
||||||
|
|
||||||
|
class EnterTunnelOrderTargeter : UnitOrderTargeter
|
||||||
|
{
|
||||||
|
readonly EntersTunnelsInfo info;
|
||||||
|
|
||||||
|
public EnterTunnelOrderTargeter(EntersTunnelsInfo info)
|
||||||
|
: base("EnterTunnel", 6, info.EnterCursor, true, true)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||||
|
{
|
||||||
|
if (target.IsDead)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var tunnel = target.TraitOrDefault<TunnelEntrance>();
|
||||||
|
if (tunnel == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// HACK: The engine does not support HiddenUnderFog combined with buildings that use the "_" footprint
|
||||||
|
// We therefore have to use AlwaysVisible and then force-disable interacting with the entrance under shroud
|
||||||
|
var buildingInfo = target.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||||
|
if (buildingInfo != null)
|
||||||
|
{
|
||||||
|
var footprint = FootprintUtils.PathableTiles(target.Info.Name, buildingInfo, target.Location);
|
||||||
|
if (footprint.All(c => self.World.ShroudObscures(c)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tunnel.Exit.HasValue)
|
||||||
|
{
|
||||||
|
cursor = info.EnterBlockedCursor;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = info.EnterCursor;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||||
|
{
|
||||||
|
return CanTargetActor(self, target.Actor, modifiers, ref cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
74
OpenRA.Mods.Common/Traits/TunnelEntrance.cs
Normal file
74
OpenRA.Mods.Common/Traits/TunnelEntrance.cs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2017 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, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
[Desc("Provides a target for players to issue orders for units to move through a TerrainTunnel.",
|
||||||
|
"The host actor should be placed so that the Sensor position overlaps one of the TerrainTunnel portal cells.")]
|
||||||
|
public class TunnelEntranceInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
[FieldLoader.Require]
|
||||||
|
[Desc("Offset to use as a staging point for actors entering or exiting the tunnel.",
|
||||||
|
"Should be at least Margin cells away from the actual entrance.")]
|
||||||
|
public readonly CVec RallyPoint = CVec.Zero;
|
||||||
|
|
||||||
|
[Desc("Cell radius to use as a staging area around the RallyPoint.")]
|
||||||
|
public readonly int Margin = 2;
|
||||||
|
|
||||||
|
[Desc("Offset to check for the corresponding TerrainTunnel portal cell(s).")]
|
||||||
|
public readonly CVec Sensor = CVec.Zero;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new TunnelEntrance(init.Self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TunnelEntrance : INotifyCreated
|
||||||
|
{
|
||||||
|
readonly TunnelEntranceInfo info;
|
||||||
|
|
||||||
|
public readonly CPos Entrance;
|
||||||
|
public CPos? Exit { get; private set; }
|
||||||
|
public int NearEnough { get { return info.Margin; } }
|
||||||
|
|
||||||
|
public TunnelEntrance(Actor self, TunnelEntranceInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
|
||||||
|
Entrance = self.Location + info.RallyPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyCreated.Created(Actor self)
|
||||||
|
{
|
||||||
|
// Find the map tunnel associated with this entrance
|
||||||
|
var sensor = self.Location + info.Sensor;
|
||||||
|
var tunnel = self.World.WorldActor.Info.TraitInfos<TerrainTunnelInfo>()
|
||||||
|
.FirstOrDefault(tti => tti.PortalCells().Contains(sensor));
|
||||||
|
|
||||||
|
if (tunnel != null)
|
||||||
|
{
|
||||||
|
// Find the matching entrance at the other end of the tunnel
|
||||||
|
// Run at the end of the tick to make sure that all the entrances exist in the world
|
||||||
|
self.World.AddFrameEndTask(w =>
|
||||||
|
{
|
||||||
|
var portalCells = tunnel.PortalCells().ToList();
|
||||||
|
var other = self.World.ActorsWithTrait<TunnelEntrance>()
|
||||||
|
.FirstOrDefault(x => x.Actor != self && portalCells.Contains(x.Actor.Location + x.Trait.info.Sensor));
|
||||||
|
|
||||||
|
if (other.Trait != null)
|
||||||
|
Exit = other.Trait.Entrance;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -381,6 +381,8 @@
|
|||||||
ReferencePoint: Bottom, Right
|
ReferencePoint: Bottom, Right
|
||||||
RequiresCondition: hospitalheal
|
RequiresCondition: hospitalheal
|
||||||
RevealOnFire:
|
RevealOnFire:
|
||||||
|
EntersTunnels:
|
||||||
|
Voice: Move
|
||||||
|
|
||||||
^RegularInfantryDeath:
|
^RegularInfantryDeath:
|
||||||
WithDeathAnimation@normal:
|
WithDeathAnimation@normal:
|
||||||
@@ -565,6 +567,8 @@
|
|||||||
Carryable:
|
Carryable:
|
||||||
RequiresCondition: !inside-tunnel
|
RequiresCondition: !inside-tunnel
|
||||||
RevealOnFire:
|
RevealOnFire:
|
||||||
|
EntersTunnels:
|
||||||
|
Voice: Move
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
Inherits: ^Vehicle
|
Inherits: ^Vehicle
|
||||||
@@ -710,6 +714,8 @@
|
|||||||
Guardable:
|
Guardable:
|
||||||
WithFacingSpriteBody:
|
WithFacingSpriteBody:
|
||||||
RevealOnFire:
|
RevealOnFire:
|
||||||
|
EntersTunnels:
|
||||||
|
Voice: Move
|
||||||
|
|
||||||
^BlossomTree:
|
^BlossomTree:
|
||||||
Inherits@1: ^SpriteActor
|
Inherits@1: ^SpriteActor
|
||||||
@@ -883,6 +889,8 @@
|
|||||||
CustomBounds: 144, 144
|
CustomBounds: 144, 144
|
||||||
Targetable:
|
Targetable:
|
||||||
AlwaysVisible:
|
AlwaysVisible:
|
||||||
|
TunnelEntrance:
|
||||||
|
Dimensions: 3, 3
|
||||||
|
|
||||||
^Gate:
|
^Gate:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
|
|||||||
@@ -213,12 +213,24 @@ TRACKS16:
|
|||||||
|
|
||||||
TUNTOP01:
|
TUNTOP01:
|
||||||
Inherits: ^Tunnel
|
Inherits: ^Tunnel
|
||||||
|
TunnelEntrance:
|
||||||
|
RallyPoint: -3, 1
|
||||||
|
Sensor: 0, 1
|
||||||
|
|
||||||
TUNTOP02:
|
TUNTOP02:
|
||||||
Inherits: ^Tunnel
|
Inherits: ^Tunnel
|
||||||
|
TunnelEntrance:
|
||||||
|
RallyPoint: 1, -3
|
||||||
|
Sensor: 1, 0
|
||||||
|
|
||||||
TUNTOP03:
|
TUNTOP03:
|
||||||
Inherits: ^Tunnel
|
Inherits: ^Tunnel
|
||||||
|
TunnelEntrance:
|
||||||
|
RallyPoint: 3, 1
|
||||||
|
Sensor: 0, 1
|
||||||
|
|
||||||
TUNTOP04:
|
TUNTOP04:
|
||||||
Inherits: ^Tunnel
|
Inherits: ^Tunnel
|
||||||
|
TunnelEntrance:
|
||||||
|
RallyPoint: 1, 3
|
||||||
|
Sensor: 1, 0
|
||||||
|
|||||||
Reference in New Issue
Block a user