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

@@ -14,12 +14,13 @@ using System.Collections.Generic;
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 enter Cargo actors.")]
public class PassengerInfo : ITraitInfo
public class PassengerInfo : ITraitInfo, IObservesVariablesInfo
{
public readonly string CargoType = null;
public readonly PipType PipType = PipType.Green;
@@ -39,13 +40,18 @@ namespace OpenRA.Mods.Common.Traits
[VoiceReference]
public readonly string Voice = "Action";
[ConsumedConditionReference]
[Desc("Boolean expression defining the condition under which the regular (non-force) enter cursor is disabled.")]
public readonly BooleanExpression RequireForceMoveCondition = null;
public object Create(ActorInitializer init) { return new Passenger(this); }
}
public class Passenger : INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, INotifyRemovedFromWorld, INotifyEnteredCargo, INotifyExitedCargo, INotifyKilled
public class Passenger : INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, INotifyRemovedFromWorld, INotifyEnteredCargo, INotifyExitedCargo, INotifyKilled, IObservesVariables
{
public readonly PassengerInfo Info;
public Actor Transport;
bool requireForceMove;
ConditionManager conditionManager;
int anyCargoToken = ConditionManager.InvalidConditionToken;
@@ -79,6 +85,14 @@ namespace OpenRA.Mods.Common.Traits
return null;
}
bool IsCorrectCargoType(Actor target, TargetModifiers modifiers)
{
if (requireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove))
return false;
return IsCorrectCargoType(target);
}
bool IsCorrectCargoType(Actor target)
{
var ci = target.Info.TraitInfo<CargoInfo>();
@@ -128,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits
specificCargoToken = conditionManager.RevokeCondition(self, specificCargoToken);
}
public void ResolveOrder(Actor self, Order order)
void IResolveOrder.ResolveOrder(Actor self, Order order)
{
if (order.OrderString != "EnterTransport")
return;
@@ -180,5 +194,16 @@ namespace OpenRA.Mods.Common.Traits
if (!Transport.IsDead)
Transport.Trait<Cargo>().Unload(Transport, self);
}
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);
}
}
}