Expose Plane turn-to-attack delay to yaml.

Require Plane in some ctors.
This commit is contained in:
Taryn Hill
2015-04-01 00:12:20 -05:00
parent c0c7ad1035
commit 02da41e5c5
13 changed files with 60 additions and 45 deletions

View File

@@ -14,19 +14,24 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
public class AttackPlaneInfo : AttackFrontalInfo
public class AttackPlaneInfo : AttackFrontalInfo, Requires<PlaneInfo>
{
public override object Create(ActorInitializer init) { return new AttackPlane(init.Self, this); }
}
public class AttackPlane : AttackFrontal
{
readonly Plane plane;
public AttackPlane(Actor self, AttackPlaneInfo info)
: base(self, info) { }
: base(self, info)
{
plane = self.Trait<Plane>();
}
public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{
return new FlyAttack(self, newTarget);
return new FlyAttack(self, newTarget, plane);
}
protected override bool CanAttack(Actor self, Target target)

View File

@@ -20,6 +20,9 @@ namespace OpenRA.Mods.Common.Traits
{
public readonly WAngle MaximumPitch = WAngle.FromDegrees(10);
[Desc("Delay, in game ticks, before turning to attack.")]
public readonly int AttackTurnDelay = 50;
public override object Create(ActorInitializer init) { return new Plane(init, this); }
}
@@ -88,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
var target = Target.FromCell(self.World, cell);
self.SetTargetLine(target, Color.Green);
self.CancelActivity();
self.QueueActivity(new Fly(self, target));
self.QueueActivity(new Fly(self, target, this));
self.QueueActivity(new FlyCircle(self));
}
else if (order.OrderString == "Enter")
@@ -100,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(Target.FromOrder(self.World, order), Color.Green);
self.CancelActivity();
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
self.QueueActivity(new ReturnToBase(self, order.TargetActor, this));
self.QueueActivity(new ResupplyAircraft(self));
}
else if (order.OrderString == "Stop")
@@ -116,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
UnReserve();
self.CancelActivity();
self.SetTargetLine(Target.FromActor(airfield), Color.Green);
self.QueueActivity(new ReturnToBase(self, airfield));
self.QueueActivity(new ReturnToBase(self, airfield, this));
self.QueueActivity(new ResupplyAircraft(self));
}
else
@@ -126,24 +129,24 @@ namespace OpenRA.Mods.Common.Traits
}
}
public Activity MoveTo(CPos cell, int nearEnough) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle(self)); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle(self)); }
public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), new FlyCircle(self)); }
public Activity MoveTo(CPos cell, int nearEnough) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell), this), new FlyCircle(self)); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell), this), new FlyCircle(self)); }
public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, this, WRange.Zero, range), new FlyCircle(self)); }
public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange)
{
return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle(self));
return Util.SequenceActivities(new Fly(self, target, this, minRange, maxRange), new FlyCircle(self));
}
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); }
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, this, minRange, maxRange); }
public CPos NearestMoveableCell(CPos cell) { return cell; }
public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any) { return new Fly(self, Target.FromCell(self.World, cell)); }
public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any) { return new Fly(self, Target.FromCell(self.World, cell), this); }
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
{
return Util.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)), new Fly(self, Target.FromPos(toPos)));
return Util.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)), new Fly(self, Target.FromPos(toPos), this));
}
public Activity MoveToTarget(Actor self, Target target) { return new Fly(self, target, WRange.FromCells(3), WRange.FromCells(5)); }
public Activity MoveToTarget(Actor self, Target target) { return new Fly(self, target, this, WRange.FromCells(3), WRange.FromCells(5)); }
public Activity MoveIntoTarget(Actor self, Target target) { return new Land(self, target); }
}
}

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
var airfield = ReturnToBase.ChooseAirfield(self, true);
if (airfield != null)
{
self.QueueActivity(new ReturnToBase(self, airfield));
self.QueueActivity(new ReturnToBase(self, airfield, self.Trait<Plane>()));
self.QueueActivity(new ResupplyAircraft(self));
}
else
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
return;
}
self.QueueActivity(new Fly(self, Target.FromActor(someBuilding)));
self.QueueActivity(new Fly(self, Target.FromActor(someBuilding), self.Trait<Plane>()));
self.QueueActivity(new FlyCircle(self));
}
}

View File

@@ -155,8 +155,10 @@ namespace OpenRA.Mods.Common.Traits
attack.OnExitedAttackRange += onExitRange;
attack.OnRemovedFromWorld += onExitRange;
a.QueueActivity(new Fly(a, Target.FromPos(target + spawnOffset)));
a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset)));
var plane = a.Trait<Plane>();
a.QueueActivity(new Fly(a, Target.FromPos(target + spawnOffset), plane));
a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset), plane));
a.QueueActivity(new RemoveSelf());
aircraftInRange.Add(a, false);
distanceTestActor = a;

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.Common.Traits
plane.Trait<Cargo>().Load(plane, crate);
plane.CancelActivity();
plane.QueueActivity(new Fly(plane, Target.FromPos(finishEdge)));
plane.QueueActivity(new Fly(plane, Target.FromPos(finishEdge), plane.Trait<Plane>()));
plane.QueueActivity(new RemoveSelf());
}
else