flying off map simplification
This commit is contained in:
@@ -44,21 +44,33 @@ namespace OpenRA.Traits.Activities
|
|||||||
|
|
||||||
var unit = self.traits.Get<Unit>();
|
var unit = self.traits.Get<Unit>();
|
||||||
|
|
||||||
|
var desiredFacing = Util.GetFacing(d, unit.Facing);
|
||||||
|
if (unit.Altitude == CruiseAltitude)
|
||||||
|
Util.TickFacing(ref unit.Facing, desiredFacing,
|
||||||
|
self.Info.Traits.Get<UnitInfo>().ROT);
|
||||||
|
|
||||||
if (unit.Altitude < CruiseAltitude)
|
if (unit.Altitude < CruiseAltitude)
|
||||||
++unit.Altitude;
|
++unit.Altitude;
|
||||||
|
|
||||||
var desiredFacing = Util.GetFacing(d, unit.Facing);
|
FlyUtil.Fly(self, CruiseAltitude);
|
||||||
if (unit.Altitude == CruiseAltitude)
|
return this;
|
||||||
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get<UnitInfo>().ROT);
|
}
|
||||||
|
|
||||||
|
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FlyUtil
|
||||||
|
{
|
||||||
|
public static void Fly(Actor self, int desiredAltitude )
|
||||||
|
{
|
||||||
|
var unit = self.traits.Get<Unit>();
|
||||||
var speed = .2f * Util.GetEffectiveSpeed(self);
|
var speed = .2f * Util.GetEffectiveSpeed(self);
|
||||||
var angle = unit.Facing / 128f * Math.PI;
|
var angle = unit.Facing / 128f * Math.PI;
|
||||||
|
|
||||||
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
||||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
||||||
|
|
||||||
return this;
|
unit.Altitude += Math.Sign(desiredAltitude - unit.Altitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ using System;
|
|||||||
|
|
||||||
namespace OpenRA.Traits.Activities
|
namespace OpenRA.Traits.Activities
|
||||||
{
|
{
|
||||||
class FlyTimed : IActivity
|
public class FlyTimed : IActivity
|
||||||
{
|
{
|
||||||
public IActivity NextActivity { get; set; }
|
public IActivity NextActivity { get; set; }
|
||||||
int remainingTicks;
|
int remainingTicks;
|
||||||
@@ -32,22 +32,30 @@ namespace OpenRA.Traits.Activities
|
|||||||
|
|
||||||
public IActivity Tick(Actor self)
|
public IActivity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (remainingTicks == 0)
|
if (remainingTicks-- == 0) return NextActivity;
|
||||||
return NextActivity;
|
FlyUtil.Fly(self, targetAltitude);
|
||||||
|
|
||||||
--remainingTicks;
|
|
||||||
|
|
||||||
var unit = self.traits.Get<Unit>();
|
|
||||||
var speed = .2f * Util.GetEffectiveSpeed(self);
|
|
||||||
var angle = unit.Facing / 128f * Math.PI;
|
|
||||||
|
|
||||||
self.CenterLocation += speed * -float2.FromAngle((float)angle);
|
|
||||||
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
|
|
||||||
|
|
||||||
unit.Altitude += Math.Sign(targetAltitude - unit.Altitude);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self) { remainingTicks = 0; NextActivity = null; }
|
public void Cancel(Actor self) { remainingTicks = 0; NextActivity = null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class FlyOffMap : IActivity
|
||||||
|
{
|
||||||
|
public IActivity NextActivity { get; set; }
|
||||||
|
readonly int targetAltitude;
|
||||||
|
bool isCanceled;
|
||||||
|
|
||||||
|
public FlyOffMap(int targetAltitude) { this.targetAltitude = targetAltitude; }
|
||||||
|
|
||||||
|
public IActivity Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (isCanceled || !self.World.Map.IsInMap(self.Location)) return NextActivity;
|
||||||
|
FlyUtil.Fly(self, targetAltitude);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,9 +73,8 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
void FinishedDropping(Actor self)
|
void FinishedDropping(Actor self)
|
||||||
{
|
{
|
||||||
// this kindof sucks, actually.
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(new Fly(Util.CenterOfCell(self.World.ChooseRandomEdgeCell())));
|
self.QueueActivity(new FlyOffMap(20));
|
||||||
self.QueueActivity(new RemoveSelf());
|
self.QueueActivity(new RemoveSelf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ namespace OpenRA.Mods.RA
|
|||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
var enterCell = self.World.ChooseRandomEdgeCell();
|
var enterCell = self.World.ChooseRandomEdgeCell();
|
||||||
var exitCell = self.World.ChooseRandomEdgeCell();
|
|
||||||
|
|
||||||
var plane = self.World.CreateActor("U2", enterCell, self.Owner);
|
var plane = self.World.CreateActor("U2", enterCell, self.Owner);
|
||||||
plane.CancelActivity();
|
plane.CancelActivity();
|
||||||
@@ -59,7 +58,7 @@ namespace OpenRA.Mods.RA
|
|||||||
plane.QueueActivity(new CallFunc(
|
plane.QueueActivity(new CallFunc(
|
||||||
() => Owner.Shroud.Explore(Owner.World, order.TargetLocation,
|
() => Owner.Shroud.Explore(Owner.World, order.TargetLocation,
|
||||||
(Info as SpyPlanePowerInfo).Range)));
|
(Info as SpyPlanePowerInfo).Range)));
|
||||||
plane.QueueActivity(new Fly(Util.CenterOfCell(exitCell)));
|
plane.QueueActivity(new FlyOffMap(20));
|
||||||
plane.QueueActivity(new RemoveSelf());
|
plane.QueueActivity(new RemoveSelf());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user