Make Mobile a PausableConditionalTrait

This commit is contained in:
tovl
2019-03-03 21:12:45 +01:00
committed by reaperrr
parent f63d0272a7
commit 2e5e7c22f4
20 changed files with 107 additions and 32 deletions

View File

@@ -190,7 +190,7 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceled && self.Location.Layer != CustomMovementLayerType.Tunnel) if (IsCanceled && self.Location.Layer != CustomMovementLayerType.Tunnel)
return NextActivity; return NextActivity;
if (mobile.IsTraitDisabled) if (mobile.IsTraitDisabled || mobile.IsTraitPaused)
return this; return this;
if (destination == mobile.ToCell) if (destination == mobile.ToCell)

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceled || target.Type == TargetType.Invalid) if (IsCanceled || target.Type == TargetType.Invalid)
return NextActivity; return NextActivity;
if (mobile.IsTraitDisabled) if (mobile.IsTraitDisabled || mobile.IsTraitPaused)
return this; return this;
var currentPos = self.CenterPosition; var currentPos = self.CenterPosition;

View File

@@ -594,6 +594,7 @@
<Compile Include="Traits\World\WeatherOverlay.cs" /> <Compile Include="Traits\World\WeatherOverlay.cs" />
<Compile Include="Traits\World\ActorSpawnManager.cs" /> <Compile Include="Traits\World\ActorSpawnManager.cs" />
<Compile Include="Traits\ActorSpawner.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\RemoveAttackIgnoresVisibility.cs" />
<Compile Include="UpdateRules\Rules\20181215\RemoveAttackSuicides.cs" /> <Compile Include="UpdateRules\Rules\20181215\RemoveAttackSuicides.cs" />
<Compile Include="UpdateRules\Rules\20181215\RemovedDemolishLocking.cs" /> <Compile Include="UpdateRules\Rules\20181215\RemovedDemolishLocking.cs" />

View File

@@ -64,6 +64,6 @@ namespace OpenRA.Mods.Common.Scripting
} }
[Desc("Whether the actor can move (false if immobilized).")] [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; } }
} }
} }

View File

@@ -21,7 +21,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Unit is able to move.")] [Desc("Unit is able to move.")]
public class MobileInfo : ConditionalTraitInfo, IMoveInfo, IPositionableInfo, IFacingInfo, IActorPreviewInitInfo, public class MobileInfo : PausableConditionalTraitInfo, IMoveInfo, IPositionableInfo, IFacingInfo, IActorPreviewInitInfo,
IEditorActorOptions IEditorActorOptions
{ {
[Desc("Which Locomotor does this trait use. Must be defined on the World actor.")] [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 IFacing, IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove, IActorPreviewInitModifier, INotifyBecomingIdle
{ {
readonly Actor self; readonly Actor self;
@@ -220,7 +220,7 @@ namespace OpenRA.Mods.Common.Traits
public void Nudge(Actor self, Actor nudger, bool force) public void Nudge(Actor self, Actor nudger, bool force)
{ {
if (IsTraitDisabled) if (IsTraitDisabled || IsTraitPaused)
return; return;
// Initial fairly braindead implementation. // Initial fairly braindead implementation.
@@ -683,7 +683,14 @@ namespace OpenRA.Mods.Common.Traits
Nudge(self, blocking, true); 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 // 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) 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) void IResolveOrder.ResolveOrder(Actor self, Order order)
{ {
if (IsTraitDisabled)
return;
if (order.OrderString == "Move") if (order.OrderString == "Move")
{ {
var cell = self.World.Map.Clamp(this.self.World.Map.CellContaining(order.Target.CenterPosition)); 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) string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
{ {
if (IsTraitDisabled)
return null;
switch (order.OrderString) switch (order.OrderString)
{ {
case "Move": case "Move":
@@ -770,7 +783,7 @@ namespace OpenRA.Mods.Common.Traits
cursor = self.World.Map.Contains(location) ? cursor = self.World.Map.Contains(location) ?
(self.World.Map.GetTerrainInfo(location).CustomCursor ?? mobile.Info.Cursor) : mobile.Info.BlockedCursor; (self.World.Map.GetTerrainInfo(location).CustomCursor ?? mobile.Info.Cursor) : mobile.Info.BlockedCursor;
if (mobile.IsTraitDisabled if (mobile.IsTraitPaused
|| (!explored && !locomotorInfo.MoveIntoShroud) || (!explored && !locomotorInfo.MoveIntoShroud)
|| (explored && locomotorInfo.MovementCostForCell(self.World, location) == int.MaxValue)) || (explored && locomotorInfo.MovementCostForCell(self.World, location) == int.MaxValue))
cursor = mobile.Info.BlockedCursor; cursor = mobile.Info.BlockedCursor;

View File

@@ -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;
}
}
}

View File

@@ -118,6 +118,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new UpdatePath("playtest-20190106", new UpdateRule[] new UpdatePath("playtest-20190106", new UpdateRule[]
{ {
new RemoveAttackSuicides(), new RemoveAttackSuicides(),
new MakeMobilePausableConditional(),
}) })
}; };

View File

@@ -64,7 +64,7 @@ LST:
InitialFacing: 0 InitialFacing: 0
TurnSpeed: 4 TurnSpeed: 4
Speed: 142 Speed: 142
RequiresCondition: !notmobile PauseOnCondition: notmobile
Health: Health:
HP: 40000 HP: 40000
Armor: Armor:

View File

@@ -109,7 +109,7 @@ APC:
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Speed: 132 Speed: 132
RequiresCondition: !notmobile PauseOnCondition: notmobile
Health: Health:
HP: 19000 HP: 19000
Repairable: Repairable:

View File

@@ -174,7 +174,7 @@
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Locomotor: vehicle Locomotor: vehicle
RequiresCondition: !notmobile PauseOnCondition: notmobile
SelectionDecorations: SelectionDecorations:
WithSpriteControlGroupDecoration: WithSpriteControlGroupDecoration:
Selectable: Selectable:

View File

@@ -343,7 +343,8 @@ devastator:
TurnSpeed: 3 TurnSpeed: 3
Speed: 31 Speed: 31
Locomotor: devastator Locomotor: devastator
RequiresCondition: !overload && !notmobile RequiresCondition: !overload
PauseOnCondition: notmobile
AutoCarryable: AutoCarryable:
RequiresCondition: !overload RequiresCondition: !overload
RevealsShroud: RevealsShroud:

View File

@@ -242,7 +242,7 @@
DrawLineToTarget: DrawLineToTarget:
UpdatesPlayerStatistics: UpdatesPlayerStatistics:
Mobile: Mobile:
RequiresCondition: !being-captured PauseOnCondition: being-captured
Locomotor: wheeled Locomotor: wheeled
TurnSpeed: 5 TurnSpeed: 5
SelectionDecorations: SelectionDecorations:

View File

@@ -22,7 +22,7 @@ DOG:
Mobile: Mobile:
Speed: 99 Speed: 99
Voice: Move Voice: Move
RequiresCondition: !attack-cooldown && !eating PauseOnCondition: attack-cooldown || eating
Guard: Guard:
Voice: Move Voice: Move
Passenger: Passenger:

View File

@@ -275,7 +275,7 @@ LST:
Mobile: Mobile:
Locomotor: lcraft Locomotor: lcraft
Speed: 113 Speed: 113
RequiresCondition: !notmobile PauseOnCondition: notmobile
RevealsShroud: RevealsShroud:
Range: 6c0 Range: 6c0
RevealGeneratedShroud: False RevealGeneratedShroud: False

View File

@@ -399,7 +399,7 @@ JEEP:
Mobile: Mobile:
TurnSpeed: 10 TurnSpeed: 10
Speed: 170 Speed: 170
RequiresCondition: !notmobile && !being-captured PauseOnCondition: notmobile || being-captured
RevealsShroud: RevealsShroud:
Range: 8c0 Range: 8c0
RevealGeneratedShroud: False RevealGeneratedShroud: False
@@ -444,7 +444,7 @@ APC:
Type: Heavy Type: Heavy
Mobile: Mobile:
Speed: 142 Speed: 142
RequiresCondition: !notmobile && !being-captured PauseOnCondition: notmobile || being-captured
RevealsShroud: RevealsShroud:
Range: 5c0 Range: 5c0
RevealGeneratedShroud: False RevealGeneratedShroud: False
@@ -802,7 +802,8 @@ QTNK:
Armor: Armor:
Type: Heavy Type: Heavy
Mobile: Mobile:
RequiresCondition: !deployed && !being-captured RequiresCondition: !deployed
PauseOnCondition: being-captured
Speed: 56 Speed: 56
Chronoshiftable: Chronoshiftable:
RequiresCondition: !deployed && !being-captured RequiresCondition: !deployed && !being-captured
@@ -842,7 +843,7 @@ STNK:
Mobile: Mobile:
Speed: 142 Speed: 142
Locomotor: heavywheeled Locomotor: heavywheeled
RequiresCondition: !notmobile && !being-captured PauseOnCondition: notmobile || being-captured
RevealsShroud: RevealsShroud:
Range: 7c0 Range: 7c0
RevealGeneratedShroud: False RevealGeneratedShroud: False

View File

@@ -97,7 +97,7 @@ BUS:
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Speed: 113 Speed: 113
RequiresCondition: !empdisable && !loading && !being-captured PauseOnCondition: empdisable || loading || being-captured
Health: Health:
HP: 10000 HP: 10000
Armor: Armor:
@@ -123,7 +123,7 @@ PICK:
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Speed: 113 Speed: 113
RequiresCondition: !empdisable && !loading && !being-captured PauseOnCondition: empdisable || loading || being-captured
Health: Health:
HP: 10000 HP: 10000
Armor: Armor:
@@ -149,7 +149,7 @@ CAR:
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Speed: 113 Speed: 113
RequiresCondition: !empdisable && !loading && !being-captured PauseOnCondition: empdisable || loading || being-captured
Health: Health:
HP: 10000 HP: 10000
Armor: Armor:
@@ -175,7 +175,7 @@ WINI:
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Speed: 113 Speed: 113
RequiresCondition: !empdisable && !loading && !being-captured PauseOnCondition: empdisable || loading || being-captured
Health: Health:
HP: 20000 HP: 20000
Armor: Armor:

View File

@@ -701,7 +701,7 @@
RequiresCondition: criticalspeed RequiresCondition: criticalspeed
Modifier: 50 Modifier: 50
Mobile: Mobile:
RequiresCondition: !empdisable PauseOnCondition: empdisable
^CivilianInfantry: ^CivilianInfantry:
Inherits@1: ^Infantry Inherits@1: ^Infantry
@@ -728,7 +728,7 @@
Action: Kill Action: Kill
DrawLineToTarget: DrawLineToTarget:
Mobile: Mobile:
RequiresCondition: !empdisable && !being-captured PauseOnCondition: empdisable || being-captured
Locomotor: wheeled Locomotor: wheeled
TurnSpeed: 5 TurnSpeed: 5
Voice: Move Voice: Move
@@ -1066,7 +1066,7 @@
TurnSpeed: 5 TurnSpeed: 5
Voice: Move Voice: Move
Speed: 113 Speed: 113
RequiresCondition: !empdisable PauseOnCondition: empdisable
Locomotor: train Locomotor: train
Cargo: Cargo:
Types: Infantry Types: Infantry

View File

@@ -15,7 +15,7 @@ APC:
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Speed: 113 Speed: 113
RequiresCondition: !empdisable && !loading && !being-captured PauseOnCondition: empdisable || loading || being-captured
Locomotor: amphibious Locomotor: amphibious
Health: Health:
HP: 20000 HP: 20000
@@ -326,7 +326,8 @@ JUGG:
Mobile: Mobile:
Speed: 71 Speed: 71
TurnSpeed: 5 TurnSpeed: 5
RequiresCondition: !empdisable && undeployed && !being-captured RequiresCondition: undeployed
PauseOnCondition: empdisable || being-captured
AlwaysConsiderTurnAsMove: true AlwaysConsiderTurnAsMove: true
RevealsShroud: RevealsShroud:
RequiresCondition: !inside-tunnel RequiresCondition: !inside-tunnel

View File

@@ -104,7 +104,8 @@ TTNK:
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Speed: 85 Speed: 85
RequiresCondition: !empdisable && undeployed && !being-captured RequiresCondition: undeployed
PauseOnCondition: empdisable || being-captured
Health: Health:
HP: 35000 HP: 35000
Armor: Armor:
@@ -223,7 +224,8 @@ ART2:
Mobile: Mobile:
Speed: 71 Speed: 71
TurnSpeed: 2 TurnSpeed: 2
RequiresCondition: !empdisable && undeployed && !being-captured RequiresCondition: undeployed
PauseOnCondition: empdisable || being-captured
RevealsShroud: RevealsShroud:
RequiresCondition: !inside-tunnel RequiresCondition: !inside-tunnel
Range: 9c0 Range: 9c0
@@ -378,7 +380,7 @@ SAPC:
Mobile: Mobile:
TurnSpeed: 5 TurnSpeed: 5
Speed: 71 Speed: 71
RequiresCondition: !empdisable && !loading && !being-captured PauseOnCondition: empdisable || loading || being-captured
Locomotor: subterranean Locomotor: subterranean
Health: Health:
HP: 17500 HP: 17500

View File

@@ -124,7 +124,8 @@ LPST:
Mobile: Mobile:
Speed: 85 Speed: 85
TurnSpeed: 5 TurnSpeed: 5
RequiresCondition: !empdisable && undeployed && !being-captured RequiresCondition: undeployed
PauseOnCondition: empdisable || being-captured
RevealsShroud: RevealsShroud:
RequiresCondition: !inside-tunnel && undeployed RequiresCondition: !inside-tunnel && undeployed
Range: 10c0 Range: 10c0