Added IDisableMove

This commit is contained in:
atlimit8
2014-10-02 14:23:32 -05:00
parent cead66668f
commit 3f6e1a608a
15 changed files with 40 additions and 24 deletions

View File

@@ -101,6 +101,7 @@ namespace OpenRA.Traits
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
public interface INotifyHarvest { void Harvested(Actor self, ResourceType resource); } public interface INotifyHarvest { void Harvested(Actor self, ResourceType resource); }
public interface INotifyInfiltrated { void Infiltrated(Actor self, Actor infiltrator); } public interface INotifyInfiltrated { void Infiltrated(Actor self, Actor infiltrator); }
public interface IDisableMove { bool MoveDisabled(Actor self); }
public interface IUpgradable public interface IUpgradable
{ {

View File

@@ -47,10 +47,10 @@ namespace OpenRA.Mods.Cnc
return this; return this;
case State.Turn: case State.Turn:
state = State.DragIn; state = State.DragIn;
return Util.SequenceActivities(new Turn(112), this); return Util.SequenceActivities(new Turn(self, 112), this);
case State.DragIn: case State.DragIn:
state = State.Dock; 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: case State.Dock:
ru.PlayCustomAnimation(self, "dock", () => { ru.PlayCustomAnimation(self, "dock", () => {
ru.PlayCustomAnimRepeating(self, "dock-loop"); ru.PlayCustomAnimRepeating(self, "dock-loop");
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Cnc
state = State.Wait; state = State.Wait;
return this; return this;
case State.DragOut: 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"); throw new InvalidOperationException("Invalid harvester dock state");

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Activities
var desiredFacing = Util.GetFacing(Target.CenterPosition - self.CenterPosition, 0); var desiredFacing = Util.GetFacing(Target.CenterPosition - self.CenterPosition, 0);
if (facing.Facing != desiredFacing) if (facing.Facing != desiredFacing)
return Util.SequenceActivities(new Turn(desiredFacing), this); return Util.SequenceActivities(new Turn(self, desiredFacing), this);
attack.DoAttack(self, Target); attack.DoAttack(self, Target);

View File

@@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA.Activities
var facing = self.Trait<IFacing>().Facing; var facing = self.Trait<IFacing>().Facing;
var desired = Util.QuantizeFacing(facing, harvInfo.HarvestFacings) * (256 / harvInfo.HarvestFacings); var desired = Util.QuantizeFacing(facing, harvInfo.HarvestFacings) * (256 / harvInfo.HarvestFacings);
if (desired != facing) 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>(); var resLayer = self.World.WorldActor.Trait<ResourceLayer>();

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA
return this; return this;
case State.Turn: case State.Turn:
state = State.Dock; state = State.Dock;
return Util.SequenceActivities(new Turn(angle), this); return Util.SequenceActivities(new Turn(self, angle), this);
case State.Dock: case State.Dock:
ru.PlayCustomAnimation(self, "dock", () => { ru.PlayCustomAnimation(self, "dock", () => {
ru.PlayCustomAnimRepeating(self, "dock-loop"); ru.PlayCustomAnimRepeating(self, "dock-loop");

View File

@@ -8,22 +8,30 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Turn : Activity 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; this.desiredFacing = desiredFacing;
} }
public override Activity Tick( Actor self ) 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>(); var facing = self.Trait<IFacing>();
if( desiredFacing == facing.Facing ) if( desiredFacing == facing.Facing )

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Air
.ClosestTo(self); .ClosestTo(self);
if (nearestHpad == null) 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 else
return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad))); return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
} }
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA.Air
return Util.SequenceActivities( return Util.SequenceActivities(
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)), new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
new Turn(initialFacing), new Turn(self, initialFacing),
new HeliLand(false), new HeliLand(false),
new ResupplyAircraft()); new ResupplyAircraft());
} }

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Air
if (Info.LandWhenIdle) if (Info.LandWhenIdle)
{ {
if (Info.TurnToLand) if (Info.TurnToLand)
self.QueueActivity(new Turn(Info.InitialFacing)); self.QueueActivity(new Turn(self, Info.InitialFacing));
self.QueueActivity(new HeliLand(true)); self.QueueActivity(new HeliLand(true));
} }
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA.Air
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset))); 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 HeliLand(false));
self.QueueActivity(new ResupplyAircraft()); self.QueueActivity(new ResupplyAircraft());
self.QueueActivity(new TakeOff()); self.QueueActivity(new TakeOff());
@@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA.Air
if (Info.LandWhenIdle) if (Info.LandWhenIdle)
{ {
if (Info.TurnToLand) if (Info.TurnToLand)
self.QueueActivity(new Turn(Info.InitialFacing)); self.QueueActivity(new Turn(self, Info.InitialFacing));
self.QueueActivity(new HeliLand(true)); 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 MoveIntoTarget(Actor self, Target target) { return new HeliLand(false); }
public Activity MoveToTarget(Actor self, Target target) 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) public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
var finalPos = init.world.Map.CenterOfCell(TopLeft); var finalPos = init.world.Map.CenterOfCell(TopLeft);
var distance = (finalPos - CenterPosition).Length; var distance = (finalPos - CenterPosition).Length;
if (speed > 0 && distance > 0) 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); } public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }

View File

@@ -9,18 +9,25 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA.Move namespace OpenRA.Mods.RA.Move
{ {
public class Drag : Activity public class Drag : Activity
{ {
readonly IPositionable positionable;
readonly IMove movement;
readonly IEnumerable<IDisableMove> moveDisablers;
WPos start, end; WPos start, end;
int length; int length;
int ticks = 0; 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.start = start;
this.end = end; this.end = end;
this.length = length; this.length = length;
@@ -28,8 +35,8 @@ namespace OpenRA.Mods.RA.Move
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var positionable = self.Trait<IPositionable>(); if (moveDisablers.Any(d => d.MoveDisabled(self)))
var movement = self.TraitOrDefault<IMove>(); return this;
var pos = length > 1 var pos = length > 1
? WPos.Lerp(start, end, ticks, length - 1) ? WPos.Lerp(start, end, ticks, length - 1)

View File

@@ -695,7 +695,7 @@ namespace OpenRA.Mods.RA.Move
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0; var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
var facing = Util.GetFacing(toPos - fromPos, Facing); 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));
} }
} }
} }

View File

@@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA.Move
if (firstFacing != mobile.Facing) if (firstFacing != mobile.Facing)
{ {
path.Add(nextCell.Value.First); path.Add(nextCell.Value.First);
return Util.SequenceActivities(new Turn(firstFacing), this); return Util.SequenceActivities(new Turn(self, firstFacing), this);
} }
else else
{ {

View File

@@ -177,7 +177,7 @@ namespace OpenRA.Mods.RA.Scripting
var heli = transport.TraitOrDefault<Helicopter>(); var heli = transport.TraitOrDefault<Helicopter>();
if (heli != null) 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 HeliLand(true));
transport.QueueActivity(new Wait(15)); transport.QueueActivity(new Wait(15));
} }

View File

@@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA
self.CancelActivity(); self.CancelActivity();
if (self.HasTrait<IFacing>()) if (self.HasTrait<IFacing>())
self.QueueActivity(new Turn(info.Facing)); self.QueueActivity(new Turn(self, info.Facing));
foreach (var nt in self.TraitsImplementing<INotifyTransform>()) foreach (var nt in self.TraitsImplementing<INotifyTransform>())
nt.BeforeTransform(self); nt.BeforeTransform(self);

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.TS
{ {
case State.Turn: case State.Turn:
state = State.Dock; state = State.Dock;
return Util.SequenceActivities(new Turn(160), this); return Util.SequenceActivities(new Turn(self, 160), this);
case State.Dock: case State.Dock:
if (proc.IsInWorld && !proc.IsDead()) if (proc.IsInWorld && !proc.IsDead())
foreach (var nd in proc.TraitsImplementing<INotifyDocking>()) foreach (var nd in proc.TraitsImplementing<INotifyDocking>())