Require force move for all undeploy-triggering orders.

This commit is contained in:
Paul Chote
2019-06-07 23:08:11 +00:00
committed by reaperrr
parent 5d886b79f1
commit ebe37a44ad
19 changed files with 249 additions and 90 deletions

View File

@@ -15,12 +15,13 @@ using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
using OpenRA.Primitives;
using OpenRA.Support;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("This actor can be sent to a structure for repairs.")]
public class RepairableInfo : ITraitInfo, Requires<IHealthInfo>, Requires<IMoveInfo>
public class RepairableInfo : ITraitInfo, Requires<IHealthInfo>, Requires<IMoveInfo>, IObservesVariablesInfo
{
[ActorReference]
[FieldLoader.Require]
@@ -32,15 +33,20 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The amount the unit will be repaired at each step. Use -1 for fallback behavior where HpPerStep from RepairsUnits trait will be used.")]
public readonly int HpPerStep = -1;
[ConsumedConditionReference]
[Desc("Boolean expression defining the condition under which the regular (non-force) enter cursor is disabled.")]
public readonly BooleanExpression RequireForceMoveCondition = null;
public virtual object Create(ActorInitializer init) { return new Repairable(init.Self, this); }
}
public class Repairable : IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated
public class Repairable : IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, IObservesVariables
{
public readonly RepairableInfo Info;
readonly IHealth health;
readonly IMove movement;
Rearmable rearmable;
bool requireForceMove;
public Repairable(Actor self, RepairableInfo info)
{
@@ -75,9 +81,12 @@ namespace OpenRA.Mods.Common.Traits
return Info.RepairActors.Contains(target.Info.Name);
}
bool CanRearmAt(Actor target)
bool CanRepairAt(Actor target, TargetModifiers modifiers)
{
return rearmable != null && rearmable.Info.RearmActors.Contains(target.Info.Name);
if (requireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove))
return false;
return Info.RepairActors.Contains(target.Info.Name);
}
bool CanRepair()
@@ -95,7 +104,7 @@ namespace OpenRA.Mods.Common.Traits
return order.OrderString == "Repair" && (CanRepair() || CanRearm()) ? Info.Voice : null;
}
public void ResolveOrder(Actor self, Order order)
void IResolveOrder.ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "Repair")
{
@@ -174,5 +183,16 @@ namespace OpenRA.Mods.Common.Traits
foreach (var t in transports)
t.RequestTransport(self, targetCell, nextActivity);
}
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()
{
if (Info.RequireForceMoveCondition != null)
yield return new VariableObserver(RequireForceMoveConditionChanged, Info.RequireForceMoveCondition.Variables);
}
void RequireForceMoveConditionChanged(Actor self, IReadOnlyDictionary<string, int> conditions)
{
requireForceMove = Info.RequireForceMoveCondition.Evaluate(conditions);
}
}
}