Replace IDisableMove with upgradability
This commit is contained in:
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
readonly IPositionable positionable;
|
||||
readonly IMove movement;
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
readonly IDisabledTrait disableable;
|
||||
WPos start, end;
|
||||
int length;
|
||||
int ticks = 0;
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
positionable = self.Trait<IPositionable>();
|
||||
movement = self.TraitOrDefault<IMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
disableable = movement as IDisabledTrait;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.length = length;
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
if (disableable != null && disableable.IsTraitDisabled)
|
||||
return this;
|
||||
|
||||
var pos = length > 1
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
static readonly List<CPos> NoPath = new List<CPos>();
|
||||
|
||||
readonly Mobile mobile;
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
readonly WDist nearEnough;
|
||||
readonly Func<List<CPos>> getPath;
|
||||
readonly Actor ignoredActor;
|
||||
@@ -43,7 +42,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
{
|
||||
@@ -65,7 +63,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, WDist nearEnough)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () => self.World.WorldActor.Trait<IPathFinder>()
|
||||
.FindUnitPath(mobile.ToCell, destination, self);
|
||||
@@ -76,7 +73,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, SubCell subCell, WDist nearEnough)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () => self.World.WorldActor.Trait<IPathFinder>()
|
||||
.FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self);
|
||||
@@ -87,7 +83,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, Actor ignoredActor)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
{
|
||||
@@ -107,7 +102,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, Target target, WDist range)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
{
|
||||
@@ -125,7 +119,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, Func<List<CPos>> getPath)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
this.getPath = getPath;
|
||||
|
||||
@@ -155,7 +148,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
|
||||
if (mobile.IsTraitDisabled || moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
if (mobile.IsTraitDisabled)
|
||||
return this;
|
||||
|
||||
if (destination == mobile.ToCell)
|
||||
|
||||
@@ -11,18 +11,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class Turn : Activity
|
||||
{
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
readonly IDisabledTrait disablable;
|
||||
readonly int desiredFacing;
|
||||
|
||||
public Turn(Actor self, int desiredFacing)
|
||||
{
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
disablable = self.TraitOrDefault<IMove>() as IDisabledTrait;
|
||||
this.desiredFacing = desiredFacing;
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
if (disablable != null && disablable.IsTraitDisabled)
|
||||
return this;
|
||||
|
||||
var facing = self.Trait<IFacing>();
|
||||
|
||||
@@ -483,7 +483,6 @@
|
||||
<Compile Include="Traits\ProducibleWithLevel.cs" />
|
||||
<Compile Include="Traits\Upgrades\DeployToUpgrade.cs" />
|
||||
<Compile Include="Traits\Upgrades\DisableOnUpgrade.cs" />
|
||||
<Compile Include="Traits\Upgrades\DisableMovementOnUpgrade.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradeActorsNear.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
|
||||
INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, IDisableMove, INotifyActorDisposing
|
||||
INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, INotifyActorDisposing
|
||||
{
|
||||
public readonly CargoInfo Info;
|
||||
readonly Actor self;
|
||||
@@ -228,7 +228,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return Info.UnloadVoice;
|
||||
}
|
||||
|
||||
public bool MoveDisabled(Actor self) { return reserves.Any(); }
|
||||
public bool HasSpace(int weight) { return totalWeight + reservedWeight + weight <= Info.MaxWeight; }
|
||||
public bool IsEmpty(Actor self) { return cargo.Count == 0; }
|
||||
|
||||
|
||||
@@ -695,14 +695,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
readonly Mobile mobile;
|
||||
readonly bool rejectMove;
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
public bool OverrideSelection { get { return false; } }
|
||||
|
||||
public MoveOrderTargeter(Actor self, Mobile unit)
|
||||
{
|
||||
this.mobile = unit;
|
||||
rejectMove = !self.AcceptsOrder("Move");
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
}
|
||||
|
||||
public string OrderID { get { return "Move"; } }
|
||||
@@ -723,8 +721,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (mobile.IsTraitDisabled
|
||||
|| (!explored && !mobile.Info.MoveIntoShroud)
|
||||
|| (explored && mobile.Info.MovementCostForCell(self.World, location) == int.MaxValue)
|
||||
|| moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
|| (explored && mobile.Info.MovementCostForCell(self.World, location) == int.MaxValue))
|
||||
cursor = mobile.Info.BlockedCursor;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Disable the ability to move and turn of the actor when this trait is enabled by an upgrade.")]
|
||||
public class DisableMovementInfo : UpgradableTraitInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new DisableMovementOnUpgrade(this); }
|
||||
}
|
||||
|
||||
public class DisableMovementOnUpgrade : UpgradableTrait<DisableMovementInfo>, IDisableMove
|
||||
{
|
||||
public DisableMovementOnUpgrade(DisableMovementInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public bool MoveDisabled(Actor self) { return !IsTraitDisabled; }
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override object Create(ActorInitializer init) { return new DisableOnUpgrade(this); }
|
||||
}
|
||||
|
||||
public class DisableOnUpgrade : UpgradableTrait<DisableOnUpgradeInfo>, IDisable, IDisableMove
|
||||
public class DisableOnUpgrade : UpgradableTrait<DisableOnUpgradeInfo>, IDisable
|
||||
{
|
||||
public DisableOnUpgrade(DisableOnUpgradeInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public bool Disabled { get { return !IsTraitDisabled; } }
|
||||
public bool MoveDisabled(Actor self) { return !IsTraitDisabled; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2510,6 +2510,32 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
// Notify how to restore blocking movement of Mobile actors with Carryable and/or Cargo
|
||||
if (engineVersion < 20151204 && depth == 2)
|
||||
{
|
||||
if (node.Key == "Carryable")
|
||||
{
|
||||
Console.WriteLine("Use CarryableUpgrades of Carryable to disable Mobile while " + parent.Key + " is waiting or being carried.");
|
||||
}
|
||||
else if (node.Key == "Cargo")
|
||||
{
|
||||
Console.WriteLine("Use LoadingUpgrades of Cargo to disable Mobile while " + parent.Key + " is loading cargo.");
|
||||
}
|
||||
else if (node.Key == "DeployToUpgrade")
|
||||
{
|
||||
Console.WriteLine("Use Upgrades of DeployToUpgrade to disable Mobile while " + parent.Key + " is deployed (instead of DisableUpgrade).");
|
||||
}
|
||||
else if (node.Key == "DisableUpgrade")
|
||||
{
|
||||
Console.WriteLine("DisableUpgrade no longer disables Mobile. Use Mobile upgradablility instead for " + parent.Key + ".");
|
||||
}
|
||||
else if (node.Key == "DisableMovementOnUpgrade")
|
||||
{
|
||||
parent.Value.Nodes.Remove(node);
|
||||
Console.WriteLine("DisableMovementOnUpgrade is removed. Use Mobile upgradablility instead for " + parent.Key + ".");
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user