Allow queueing up scatter and move Nudge to an activity
This commit is contained in:
committed by
Matthias Mailänder
parent
54dac39e83
commit
3ab421cbe3
@@ -249,7 +249,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
new LocationInit(self.Location),
|
new LocationInit(self.Location),
|
||||||
new OwnerInit(self.Owner)
|
new OwnerInit(self.Owner)
|
||||||
});
|
});
|
||||||
driver.TraitOrDefault<Mobile>()?.Nudge(driver);
|
driver.QueueActivity(false, new Nudge(driver));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
66
OpenRA.Mods.Common/Activities/Move/Nudge.cs
Normal file
66
OpenRA.Mods.Common/Activities/Move/Nudge.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright (c) The OpenRA Developers and Contributors
|
||||||
|
* 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 OpenRA.Activities;
|
||||||
|
using OpenRA.Mods.Common.Activities;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
public class Nudge : Activity
|
||||||
|
{
|
||||||
|
readonly Actor nudger;
|
||||||
|
public Nudge(Actor nudger)
|
||||||
|
{
|
||||||
|
this.nudger = nudger;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFirstRun(Actor self)
|
||||||
|
{
|
||||||
|
var move = self.Trait<IMove>();
|
||||||
|
if (move is Mobile mobile)
|
||||||
|
{
|
||||||
|
if (mobile.IsTraitDisabled || mobile.IsTraitPaused || mobile.IsImmovable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var cell = mobile.GetAdjacentCell(nudger.Location);
|
||||||
|
if (cell != null)
|
||||||
|
QueueChild(mobile.MoveTo(cell.Value, 0, targetLineColor: mobile.Info.TargetLineColor));
|
||||||
|
}
|
||||||
|
else if (move is Aircraft aircraft)
|
||||||
|
{
|
||||||
|
if (aircraft.IsTraitDisabled || aircraft.IsTraitPaused || aircraft.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);
|
||||||
|
QueueChild(new Fly(self, target, targetLineColor: aircraft.Info.TargetLineColor));
|
||||||
|
aircraft.UnReserve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
||||||
|
{
|
||||||
|
if (ChildActivity != null)
|
||||||
|
foreach (var n in ChildActivity.TargetLineNodes(self))
|
||||||
|
yield return n;
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
[Desc("Leave the current position in a random direction.")]
|
[Desc("Leave the current position in a random direction.")]
|
||||||
public void Scatter()
|
public void Scatter()
|
||||||
{
|
{
|
||||||
mobile.Nudge(Self);
|
Self.QueueActivity(false, new Nudge(Self));
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public bool ForceLanding { get; private set; }
|
public bool ForceLanding { get; private set; }
|
||||||
|
|
||||||
(CPos, SubCell)[] landingCells = Array.Empty<(CPos, SubCell)>();
|
(CPos, SubCell)[] landingCells = Array.Empty<(CPos, SubCell)>();
|
||||||
bool requireForceMove;
|
public bool RequireForceMove;
|
||||||
|
|
||||||
readonly int creationActivityDelay;
|
readonly int creationActivityDelay;
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void RequireForceMoveConditionChanged(Actor self, IReadOnlyDictionary<string, int> conditions)
|
void RequireForceMoveConditionChanged(Actor self, IReadOnlyDictionary<string, int> conditions)
|
||||||
{
|
{
|
||||||
requireForceMove = Info.RequireForceMoveCondition.Evaluate(conditions);
|
RequireForceMove = Info.RequireForceMoveCondition.Evaluate(conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
@@ -586,7 +586,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
bool AircraftCanEnter(Actor a, TargetModifiers modifiers)
|
bool AircraftCanEnter(Actor a, TargetModifiers modifiers)
|
||||||
{
|
{
|
||||||
if (requireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove))
|
if (RequireForceMove && !modifiers.HasModifier(TargetModifiers.ForceMove))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return AircraftCanEnter(a);
|
return AircraftCanEnter(a);
|
||||||
@@ -1144,29 +1144,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.ShowTargetLines();
|
self.ShowTargetLines();
|
||||||
}
|
}
|
||||||
else if (orderString == "Scatter")
|
else if (orderString == "Scatter")
|
||||||
Nudge(self);
|
{
|
||||||
|
self.QueueActivity(order.Queued, new Nudge(self));
|
||||||
|
self.ShowTargetLines();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#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
|
#region Airborne conditions
|
||||||
|
|
||||||
void OnAirborneAltitudeReached()
|
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)
|
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;
|
return false;
|
||||||
|
|
||||||
var location = self.World.Map.CellContaining(target.CenterPosition);
|
var location = self.World.Map.CellContaining(target.CenterPosition);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var mobile = self.TraitOrDefault<Mobile>();
|
var mobile = self.TraitOrDefault<Mobile>();
|
||||||
if (mobile != null && self.World.SharedRandom.Next(100) <= Info.WarnProbability)
|
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)
|
void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td);
|
var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td);
|
||||||
|
|
||||||
if (!inAir)
|
if (!inAir)
|
||||||
pilot.TraitOrDefault<Mobile>()?.Nudge(pilot);
|
pilot.QueueActivity(false, new Nudge(pilot));
|
||||||
else
|
else
|
||||||
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
|
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -367,16 +367,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
#region Local misc stuff
|
#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)
|
public CPos? GetAdjacentCell(CPos nextCell, Func<CPos, bool> preferToAvoid = null)
|
||||||
{
|
{
|
||||||
var availCells = new List<CPos>();
|
var availCells = new List<CPos>();
|
||||||
@@ -873,7 +863,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (self.IsIdle)
|
if (self.IsIdle)
|
||||||
{
|
{
|
||||||
Nudge(blocking);
|
self.QueueActivity(false, new Nudge(blocking));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -942,7 +932,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
else if (order.OrderString == "Stop")
|
else if (order.OrderString == "Stop")
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
else if (order.OrderString == "Scatter")
|
else if (order.OrderString == "Scatter")
|
||||||
Nudge(self);
|
{
|
||||||
|
self.QueueActivity(order.Queued, new Nudge(self));
|
||||||
|
self.ShowTargetLines();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||||
|
|||||||
@@ -142,7 +142,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (highlightOnButtonPress)
|
if (highlightOnButtonPress)
|
||||||
scatterHighlighted = 2;
|
scatterHighlighted = 2;
|
||||||
|
|
||||||
PerformKeyboardOrderOnSelection(a => new Order("Scatter", a, false));
|
var queued = Game.GetModifierKeys().HasModifier(Modifiers.Shift);
|
||||||
|
PerformKeyboardOrderOnSelection(a => new Order("Scatter", a, queued));
|
||||||
};
|
};
|
||||||
|
|
||||||
scatterButton.OnKeyPress = ki => { scatterHighlighted = 2; scatterButton.OnClick(); };
|
scatterButton.OnKeyPress = ki => { scatterHighlighted = 2; scatterButton.OnClick(); };
|
||||||
@@ -211,7 +212,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
var keyOverrides = widget.GetOrNull<LogicKeyListenerWidget>("MODIFIER_OVERRIDES");
|
var keyOverrides = widget.GetOrNull<LogicKeyListenerWidget>("MODIFIER_OVERRIDES");
|
||||||
if (keyOverrides != null)
|
if (keyOverrides != null)
|
||||||
{
|
{
|
||||||
var noShiftButtons = new[] { guardButton, deployButton, attackMoveButton };
|
var noShiftButtons = new[] { guardButton, deployButton, scatterButton, attackMoveButton };
|
||||||
var keyUpButtons = new[] { guardButton, attackMoveButton };
|
var keyUpButtons = new[] { guardButton, attackMoveButton };
|
||||||
keyOverrides.AddHandler(e =>
|
keyOverrides.AddHandler(e =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user