Make Mobile a PausableConditionalTrait
This commit is contained in:
@@ -190,7 +190,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (IsCanceled && self.Location.Layer != CustomMovementLayerType.Tunnel)
|
||||
return NextActivity;
|
||||
|
||||
if (mobile.IsTraitDisabled)
|
||||
if (mobile.IsTraitDisabled || mobile.IsTraitPaused)
|
||||
return this;
|
||||
|
||||
if (destination == mobile.ToCell)
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (IsCanceled || target.Type == TargetType.Invalid)
|
||||
return NextActivity;
|
||||
|
||||
if (mobile.IsTraitDisabled)
|
||||
if (mobile.IsTraitDisabled || mobile.IsTraitPaused)
|
||||
return this;
|
||||
|
||||
var currentPos = self.CenterPosition;
|
||||
|
||||
@@ -594,6 +594,7 @@
|
||||
<Compile Include="Traits\World\WeatherOverlay.cs" />
|
||||
<Compile Include="Traits\World\ActorSpawnManager.cs" />
|
||||
<Compile Include="Traits\ActorSpawner.cs" />
|
||||
<Compile Include="UpdateRules\Rules\20181215\MakeMobilePausableConditional.cs" />
|
||||
<Compile Include="UpdateRules\Rules\20181215\RemoveAttackIgnoresVisibility.cs" />
|
||||
<Compile Include="UpdateRules\Rules\20181215\RemoveAttackSuicides.cs" />
|
||||
<Compile Include="UpdateRules\Rules\20181215\RemovedDemolishLocking.cs" />
|
||||
|
||||
@@ -64,6 +64,6 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
|
||||
[Desc("Whether the actor can move (false if immobilized).")]
|
||||
public bool IsMobile { get { return !mobile.IsTraitDisabled; } }
|
||||
public bool IsMobile { get { return !mobile.IsTraitDisabled && !mobile.IsTraitPaused; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Unit is able to move.")]
|
||||
public class MobileInfo : ConditionalTraitInfo, IMoveInfo, IPositionableInfo, IFacingInfo, IActorPreviewInitInfo,
|
||||
public class MobileInfo : PausableConditionalTraitInfo, IMoveInfo, IPositionableInfo, IFacingInfo, IActorPreviewInitInfo,
|
||||
IEditorActorOptions
|
||||
{
|
||||
[Desc("Which Locomotor does this trait use. Must be defined on the World actor.")]
|
||||
@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class Mobile : ConditionalTrait<MobileInfo>, INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove,
|
||||
public class Mobile : PausableConditionalTrait<MobileInfo>, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove,
|
||||
IFacing, IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove, IActorPreviewInitModifier, INotifyBecomingIdle
|
||||
{
|
||||
readonly Actor self;
|
||||
@@ -220,7 +220,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Nudge(Actor self, Actor nudger, bool force)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
if (IsTraitDisabled || IsTraitPaused)
|
||||
return;
|
||||
|
||||
// Initial fairly braindead implementation.
|
||||
@@ -683,7 +683,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Nudge(self, blocking, true);
|
||||
}
|
||||
|
||||
IEnumerable<IOrderTargeter> IIssueOrder.Orders { get { yield return new MoveOrderTargeter(self, this); } }
|
||||
IEnumerable<IOrderTargeter> IIssueOrder.Orders
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsTraitDisabled)
|
||||
yield return new MoveOrderTargeter(self, this);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: Returns a valid order even if the unit can't move to the target
|
||||
Order IIssueOrder.IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
@@ -696,6 +703,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void IResolveOrder.ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return;
|
||||
|
||||
if (order.OrderString == "Move")
|
||||
{
|
||||
var cell = self.World.Map.Clamp(this.self.World.Map.CellContaining(order.Target.CenterPosition));
|
||||
@@ -718,6 +728,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return null;
|
||||
|
||||
switch (order.OrderString)
|
||||
{
|
||||
case "Move":
|
||||
@@ -770,7 +783,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
cursor = self.World.Map.Contains(location) ?
|
||||
(self.World.Map.GetTerrainInfo(location).CustomCursor ?? mobile.Info.Cursor) : mobile.Info.BlockedCursor;
|
||||
|
||||
if (mobile.IsTraitDisabled
|
||||
if (mobile.IsTraitPaused
|
||||
|| (!explored && !locomotorInfo.MoveIntoShroud)
|
||||
|| (explored && locomotorInfo.MovementCostForCell(self.World, location) == int.MaxValue))
|
||||
cursor = mobile.Info.BlockedCursor;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2019 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.Linq;
|
||||
|
||||
namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
{
|
||||
public class MakeMobilePausableConditional : UpdateRule
|
||||
{
|
||||
public override string Name { get { return "Change Mobile>RequiresCondition to PauseOnCondition"; } }
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Mobile is now a PausableConditionalTrait instead of a ConditionalTrait.\n" +
|
||||
"RequiresCondition is changed to PauseOnCondition.";
|
||||
}
|
||||
}
|
||||
|
||||
bool displayedMessage;
|
||||
public override IEnumerable<string> AfterUpdate(ModData modData)
|
||||
{
|
||||
var message = "You may want to update the result of PauseOnCondition, as this update\n" +
|
||||
"just adds ! prefix to RequiresCondition's value to reverse it.";
|
||||
|
||||
if (!displayedMessage)
|
||||
yield return message;
|
||||
|
||||
displayedMessage = true;
|
||||
}
|
||||
|
||||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
|
||||
{
|
||||
foreach (var node in actorNode.ChildrenMatching("Mobile").Where(t => t.ChildrenMatching("RequiresCondition").Any()))
|
||||
{
|
||||
var rc = node.LastChildMatching("RequiresCondition");
|
||||
|
||||
rc.ReplaceValue("!(" + rc.Value.Value + ")");
|
||||
rc.RenameKey("PauseOnCondition");
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
||||
new UpdatePath("playtest-20190106", new UpdateRule[]
|
||||
{
|
||||
new RemoveAttackSuicides(),
|
||||
new MakeMobilePausableConditional(),
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user