Allow queueing up scatter and move Nudge to an activity

This commit is contained in:
Gustas
2022-12-02 00:31:07 +02:00
committed by Matthias Mailänder
parent 54dac39e83
commit 3ab421cbe3
8 changed files with 86 additions and 41 deletions

View File

@@ -283,7 +283,7 @@ namespace OpenRA.Mods.Common.Traits
public bool ForceLanding { get; private set; }
(CPos, SubCell)[] landingCells = Array.Empty<(CPos, SubCell)>();
bool requireForceMove;
public bool RequireForceMove;
readonly int creationActivityDelay;
@@ -354,7 +354,7 @@ namespace OpenRA.Mods.Common.Traits
void RequireForceMoveConditionChanged(Actor self, IReadOnlyDictionary<string, int> conditions)
{
requireForceMove = Info.RequireForceMoveCondition.Evaluate(conditions);
RequireForceMove = Info.RequireForceMoveCondition.Evaluate(conditions);
}
protected override void Created(Actor self)
@@ -586,7 +586,7 @@ namespace OpenRA.Mods.Common.Traits
bool AircraftCanEnter(Actor a, TargetModifiers modifiers)
{
if (requireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove))
if (RequireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove))
return false;
return AircraftCanEnter(a);
@@ -1144,29 +1144,14 @@ namespace OpenRA.Mods.Common.Traits
self.ShowTargetLines();
}
else if (orderString == "Scatter")
Nudge(self);
{
self.QueueActivity(order.Queued, new Nudge(self));
self.ShowTargetLines();
}
}
#endregion
void Nudge(Actor self)
{
if (IsTraitDisabled || IsTraitPaused || requireForceMove)
return;
// Disable nudging if the aircraft is outside the map
if (!self.World.Map.Contains(self.Location))
return;
var offset = new WVec(0, -self.World.SharedRandom.Next(512, 2048), 0)
.Rotate(WRot.FromFacing(self.World.SharedRandom.Next(256)));
var target = Target.FromPos(self.CenterPosition + offset);
self.QueueActivity(false, new Fly(self, target));
self.ShowTargetLines();
UnReserve();
}
#region Airborne conditions
void OnAirborneAltitudeReached()
@@ -1295,7 +1280,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual bool CanTarget(Actor self, in Target target, ref TargetModifiers modifiers, ref string cursor)
{
if (target.Type != TargetType.Terrain || (aircraft.requireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove)))
if (target.Type != TargetType.Terrain || (aircraft.RequireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove)))
return false;
var location = self.World.Map.CellContaining(target.CenterPosition);

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
var mobile = self.TraitOrDefault<Mobile>();
if (mobile != null && self.World.SharedRandom.Next(100) <= Info.WarnProbability)
mobile.Nudge(crusher);
self.QueueActivity(false, new Nudge(crusher));
}
void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td);
if (!inAir)
pilot.TraitOrDefault<Mobile>()?.Nudge(pilot);
pilot.QueueActivity(false, new Nudge(pilot));
else
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
});

View File

@@ -367,16 +367,6 @@ namespace OpenRA.Mods.Common.Traits
#region Local misc stuff
public void Nudge(Actor nudger)
{
if (IsTraitDisabled || IsTraitPaused || IsImmovable)
return;
var cell = GetAdjacentCell(nudger.Location);
if (cell != null)
self.QueueActivity(false, MoveTo(cell.Value, 0));
}
public CPos? GetAdjacentCell(CPos nextCell, Func<CPos, bool> preferToAvoid = null)
{
var availCells = new List<CPos>();
@@ -873,7 +863,7 @@ namespace OpenRA.Mods.Common.Traits
if (self.IsIdle)
{
Nudge(blocking);
self.QueueActivity(false, new Nudge(blocking));
return;
}
@@ -942,7 +932,10 @@ namespace OpenRA.Mods.Common.Traits
else if (order.OrderString == "Stop")
self.CancelActivity();
else if (order.OrderString == "Scatter")
Nudge(self);
{
self.QueueActivity(order.Queued, new Nudge(self));
self.ShowTargetLines();
}
}
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)