Cache trait look-ups in the constructor where possible for Air activities/traits

This commit is contained in:
reaperrr
2015-03-14 03:59:37 +01:00
parent 9a780ba07d
commit 1e9d1a6cb7
22 changed files with 160 additions and 93 deletions

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
{
public void TickIdle(Actor self)
{
self.QueueActivity(new FlyOffMap());
self.QueueActivity(new FlyOffMap(self));
self.QueueActivity(new RemoveSelf());
}
}

View File

@@ -35,7 +35,8 @@ namespace OpenRA.Mods.Common.Traits
public class Helicopter : Aircraft, ITick, IResolveOrder, IMove
{
public HelicopterInfo Info;
public readonly HelicopterInfo Info;
readonly bool fallsToEarth;
Actor self;
bool firstTick = true;
public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } }
@@ -45,6 +46,7 @@ namespace OpenRA.Mods.Common.Traits
{
self = init.Self;
Info = info;
fallsToEarth = self.HasTrait<FallsToEarth>();
}
public void ResolveOrder(Actor self, Order order)
@@ -74,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits
if (Info.TurnToLand)
self.QueueActivity(new Turn(self, Info.InitialFacing));
self.QueueActivity(new HeliLand(true));
self.QueueActivity(new HeliLand(self, true));
}
}
@@ -83,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
if (Reservable.IsReserved(order.TargetActor))
{
self.CancelActivity();
self.QueueActivity(new HeliReturn());
self.QueueActivity(new HeliReturn(self));
}
else
{
@@ -99,16 +101,16 @@ namespace OpenRA.Mods.Common.Traits
self.CancelActivity();
self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset)));
self.QueueActivity(new Turn(self, Info.InitialFacing));
self.QueueActivity(new HeliLand(false));
self.QueueActivity(new ResupplyAircraft());
self.QueueActivity(new TakeOff());
self.QueueActivity(new HeliLand(self, false));
self.QueueActivity(new ResupplyAircraft(self));
self.QueueActivity(new TakeOff(self));
}
}
if (order.OrderString == "ReturnToBase")
{
self.CancelActivity();
self.QueueActivity(new HeliReturn());
self.QueueActivity(new HeliReturn(self));
}
if (order.OrderString == "Stop")
@@ -120,7 +122,7 @@ namespace OpenRA.Mods.Common.Traits
if (Info.TurnToLand)
self.QueueActivity(new Turn(self, Info.InitialFacing));
self.QueueActivity(new HeliLand(true));
self.QueueActivity(new HeliLand(self, true));
}
}
}
@@ -130,14 +132,14 @@ namespace OpenRA.Mods.Common.Traits
if (firstTick)
{
firstTick = false;
if (!self.HasTrait<FallsToEarth>()) // TODO: Aircraft husks don't properly unreserve.
if (!fallsToEarth) // TODO: Aircraft husks don't properly unreserve.
ReserveSpawnBuilding();
var host = GetActorBelow();
if (host == null)
return;
self.QueueActivity(new TakeOff());
self.QueueActivity(new TakeOff(self));
}
Repulse();
@@ -155,7 +157,7 @@ namespace OpenRA.Mods.Common.Traits
return new HeliFly(self, Target.FromCell(self.World, cell, subCell));
}
public Activity MoveIntoTarget(Actor self, Target target) { return new HeliLand(false); }
public Activity MoveIntoTarget(Actor self, Target target) { return new HeliLand(self, false); }
public Activity MoveToTarget(Actor self, Target target)
{
return Util.SequenceActivities(new HeliFly(self, target), new Turn(self, Info.InitialFacing));

View File

@@ -26,6 +26,7 @@ namespace OpenRA.Mods.Common.Traits
public class Plane : Aircraft, IResolveOrder, IMove, ITick, ISync
{
public readonly PlaneInfo Info;
readonly bool fallsToEarth;
[Sync] public WPos RTBPathHash;
Actor self;
public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } }
@@ -35,6 +36,7 @@ namespace OpenRA.Mods.Common.Traits
{
self = init.Self;
Info = info;
fallsToEarth = self.HasTrait<FallsToEarth>();
}
bool firstTick = true;
@@ -43,14 +45,14 @@ namespace OpenRA.Mods.Common.Traits
if (firstTick)
{
firstTick = false;
if (!self.HasTrait<FallsToEarth>()) // TODO: Aircraft husks don't properly unreserve.
if (!fallsToEarth) // TODO: Aircraft husks don't properly unreserve.
ReserveSpawnBuilding();
var host = GetActorBelow();
if (host == null)
return;
self.QueueActivity(new TakeOff());
self.QueueActivity(new TakeOff(self));
}
Repulse();
@@ -89,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(target, Color.Green);
self.CancelActivity();
self.QueueActivity(new Fly(self, target));
self.QueueActivity(new FlyCircle());
self.QueueActivity(new FlyCircle(self));
}
else if (order.OrderString == "Enter")
{
@@ -101,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits
self.CancelActivity();
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
self.QueueActivity(new ResupplyAircraft());
self.QueueActivity(new ResupplyAircraft(self));
}
else if (order.OrderString == "Stop")
{
@@ -117,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
self.CancelActivity();
self.SetTargetLine(Target.FromActor(airfield), Color.Green);
self.QueueActivity(new ReturnToBase(self, airfield));
self.QueueActivity(new ResupplyAircraft());
self.QueueActivity(new ResupplyAircraft(self));
}
else
{
@@ -126,12 +128,12 @@ 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()); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle()); }
public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), new FlyCircle()); }
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 MoveWithinRange(Target target, WRange minRange, WRange maxRange)
{
return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle());
return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle(self));
}
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); }
@@ -144,6 +146,6 @@ namespace OpenRA.Mods.Common.Traits
}
public Activity MoveToTarget(Actor self, Target target) { return new Fly(self, target, WRange.FromCells(3), WRange.FromCells(5)); }
public Activity MoveIntoTarget(Actor self, Target target) { return new Land(target); }
public Activity MoveIntoTarget(Actor self, Target target) { return new Land(self, target); }
}
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
if (airfield != null)
{
self.QueueActivity(new ReturnToBase(self, airfield));
self.QueueActivity(new ResupplyAircraft());
self.QueueActivity(new ResupplyAircraft(self));
}
else
{
@@ -49,13 +49,13 @@ namespace OpenRA.Mods.Common.Traits
if (someBuilding == null)
{
// ... going down the garden to eat worms ...
self.QueueActivity(new FlyOffMap());
self.QueueActivity(new FlyOffMap(self));
self.QueueActivity(new RemoveSelf());
return;
}
self.QueueActivity(new Fly(self, Target.FromActor(someBuilding)));
self.QueueActivity(new FlyCircle());
self.QueueActivity(new FlyCircle(self));
}
}
}

View File

@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
Unloading = true;
self.CancelActivity();
if (helicopter != null)
self.QueueActivity(new HeliLand(true));
self.QueueActivity(new HeliLand(self, true));
self.QueueActivity(new UnloadCargo(self, true));
}
}