Added IDisableMove
This commit is contained in:
@@ -101,6 +101,7 @@ namespace OpenRA.Traits
|
||||
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
|
||||
public interface INotifyHarvest { void Harvested(Actor self, ResourceType resource); }
|
||||
public interface INotifyInfiltrated { void Infiltrated(Actor self, Actor infiltrator); }
|
||||
public interface IDisableMove { bool MoveDisabled(Actor self); }
|
||||
|
||||
public interface IUpgradable
|
||||
{
|
||||
|
||||
@@ -47,10 +47,10 @@ namespace OpenRA.Mods.Cnc
|
||||
return this;
|
||||
case State.Turn:
|
||||
state = State.DragIn;
|
||||
return Util.SequenceActivities(new Turn(112), this);
|
||||
return Util.SequenceActivities(new Turn(self, 112), this);
|
||||
case State.DragIn:
|
||||
state = State.Dock;
|
||||
return Util.SequenceActivities(new Drag(startDock, endDock, 12), this);
|
||||
return Util.SequenceActivities(new Drag(self, startDock, endDock, 12), this);
|
||||
case State.Dock:
|
||||
ru.PlayCustomAnimation(self, "dock", () => {
|
||||
ru.PlayCustomAnimRepeating(self, "dock-loop");
|
||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Cnc
|
||||
state = State.Wait;
|
||||
return this;
|
||||
case State.DragOut:
|
||||
return Util.SequenceActivities(new Drag(endDock, startDock, 12), NextActivity);
|
||||
return Util.SequenceActivities(new Drag(self, endDock, startDock, 12), NextActivity);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Invalid harvester dock state");
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
var desiredFacing = Util.GetFacing(Target.CenterPosition - self.CenterPosition, 0);
|
||||
if (facing.Facing != desiredFacing)
|
||||
return Util.SequenceActivities(new Turn(desiredFacing), this);
|
||||
return Util.SequenceActivities(new Turn(self, desiredFacing), this);
|
||||
|
||||
attack.DoAttack(self, Target);
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
var facing = self.Trait<IFacing>().Facing;
|
||||
var desired = Util.QuantizeFacing(facing, harvInfo.HarvestFacings) * (256 / harvInfo.HarvestFacings);
|
||||
if (desired != facing)
|
||||
return Util.SequenceActivities(new Turn(desired), this);
|
||||
return Util.SequenceActivities(new Turn(self, desired), this);
|
||||
}
|
||||
|
||||
var resLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA
|
||||
return this;
|
||||
case State.Turn:
|
||||
state = State.Dock;
|
||||
return Util.SequenceActivities(new Turn(angle), this);
|
||||
return Util.SequenceActivities(new Turn(self, angle), this);
|
||||
case State.Dock:
|
||||
ru.PlayCustomAnimation(self, "dock", () => {
|
||||
ru.PlayCustomAnimRepeating(self, "dock-loop");
|
||||
|
||||
@@ -8,22 +8,30 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Turn : Activity
|
||||
{
|
||||
int desiredFacing;
|
||||
readonly IEnumerable<IDisableMove> moveDisablers;
|
||||
readonly int desiredFacing;
|
||||
|
||||
public Turn( int desiredFacing )
|
||||
public Turn(Actor self, int desiredFacing)
|
||||
{
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
this.desiredFacing = desiredFacing;
|
||||
}
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
return this;
|
||||
|
||||
var facing = self.Trait<IFacing>();
|
||||
|
||||
if( desiredFacing == facing.Facing )
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
.ClosestTo(self);
|
||||
|
||||
if (nearestHpad == null)
|
||||
return Util.SequenceActivities(new Turn(initialFacing), new HeliLand(true), NextActivity);
|
||||
return Util.SequenceActivities(new Turn(self, initialFacing), new HeliLand(true), NextActivity);
|
||||
else
|
||||
return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
|
||||
}
|
||||
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
|
||||
return Util.SequenceActivities(
|
||||
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
|
||||
new Turn(initialFacing),
|
||||
new Turn(self, initialFacing),
|
||||
new HeliLand(false),
|
||||
new ResupplyAircraft());
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
if (Info.LandWhenIdle)
|
||||
{
|
||||
if (Info.TurnToLand)
|
||||
self.QueueActivity(new Turn(Info.InitialFacing));
|
||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||
|
||||
self.QueueActivity(new HeliLand(true));
|
||||
}
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset)));
|
||||
self.QueueActivity(new Turn(Info.InitialFacing));
|
||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||
self.QueueActivity(new HeliLand(false));
|
||||
self.QueueActivity(new ResupplyAircraft());
|
||||
self.QueueActivity(new TakeOff());
|
||||
@@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
if (Info.LandWhenIdle)
|
||||
{
|
||||
if (Info.TurnToLand)
|
||||
self.QueueActivity(new Turn(Info.InitialFacing));
|
||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||
|
||||
self.QueueActivity(new HeliLand(true));
|
||||
}
|
||||
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
public Activity MoveIntoTarget(Actor self, Target target) { return new HeliLand(false); }
|
||||
public Activity MoveToTarget(Actor self, Target target)
|
||||
{
|
||||
return Util.SequenceActivities(new HeliFly(self, target), new Turn(Info.InitialFacing));
|
||||
return Util.SequenceActivities(new HeliFly(self, target), new Turn(self, Info.InitialFacing));
|
||||
}
|
||||
|
||||
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
|
||||
var finalPos = init.world.Map.CenterOfCell(TopLeft);
|
||||
var distance = (finalPos - CenterPosition).Length;
|
||||
if (speed > 0 && distance > 0)
|
||||
self.QueueActivity(new Drag(CenterPosition, finalPos, distance / speed));
|
||||
self.QueueActivity(new Drag(init.self, CenterPosition, finalPos, distance / speed));
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
|
||||
|
||||
@@ -9,18 +9,25 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
public class Drag : Activity
|
||||
{
|
||||
readonly IPositionable positionable;
|
||||
readonly IMove movement;
|
||||
readonly IEnumerable<IDisableMove> moveDisablers;
|
||||
WPos start, end;
|
||||
int length;
|
||||
int ticks = 0;
|
||||
|
||||
public Drag(WPos start, WPos end, int length)
|
||||
public Drag(Actor self, WPos start, WPos end, int length)
|
||||
{
|
||||
positionable = self.Trait<IPositionable>();
|
||||
movement = self.TraitOrDefault<IMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.length = length;
|
||||
@@ -28,8 +35,8 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
var positionable = self.Trait<IPositionable>();
|
||||
var movement = self.TraitOrDefault<IMove>();
|
||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
return this;
|
||||
|
||||
var pos = length > 1
|
||||
? WPos.Lerp(start, end, ticks, length - 1)
|
||||
|
||||
@@ -695,7 +695,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
|
||||
|
||||
var facing = Util.GetFacing(toPos - fromPos, Facing);
|
||||
return Util.SequenceActivities(new Turn(facing), new Drag(fromPos, toPos, length));
|
||||
return Util.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
if (firstFacing != mobile.Facing)
|
||||
{
|
||||
path.Add(nextCell.Value.First);
|
||||
return Util.SequenceActivities(new Turn(firstFacing), this);
|
||||
return Util.SequenceActivities(new Turn(self, firstFacing), this);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace OpenRA.Mods.RA.Scripting
|
||||
var heli = transport.TraitOrDefault<Helicopter>();
|
||||
if (heli != null)
|
||||
{
|
||||
transport.QueueActivity(new Turn(heli.Info.InitialFacing));
|
||||
transport.QueueActivity(new Turn(transport, heli.Info.InitialFacing));
|
||||
transport.QueueActivity(new HeliLand(true));
|
||||
transport.QueueActivity(new Wait(15));
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA
|
||||
self.CancelActivity();
|
||||
|
||||
if (self.HasTrait<IFacing>())
|
||||
self.QueueActivity(new Turn(info.Facing));
|
||||
self.QueueActivity(new Turn(self, info.Facing));
|
||||
|
||||
foreach (var nt in self.TraitsImplementing<INotifyTransform>())
|
||||
nt.BeforeTransform(self);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.TS
|
||||
{
|
||||
case State.Turn:
|
||||
state = State.Dock;
|
||||
return Util.SequenceActivities(new Turn(160), this);
|
||||
return Util.SequenceActivities(new Turn(self, 160), this);
|
||||
case State.Dock:
|
||||
if (proc.IsInWorld && !proc.IsDead())
|
||||
foreach (var nd in proc.TraitsImplementing<INotifyDocking>())
|
||||
|
||||
Reference in New Issue
Block a user