44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace OpenRa.Game.Traits.Activities
|
|
{
|
|
class Land : IActivity
|
|
{
|
|
readonly float2 Pos;
|
|
bool isCanceled;
|
|
|
|
public Land(float2 pos) { Pos = pos; }
|
|
|
|
public IActivity NextActivity { get; set; }
|
|
|
|
public IActivity Tick(Actor self)
|
|
{
|
|
if (isCanceled) return NextActivity;
|
|
|
|
var d = Pos - self.CenterLocation;
|
|
if (d.LengthSquared < 50) /* close enough */
|
|
return NextActivity;
|
|
|
|
var unit = self.traits.Get<Unit>();
|
|
|
|
if (unit.Altitude > 0)
|
|
--unit.Altitude;
|
|
|
|
var desiredFacing = Util.GetFacing(d, unit.Facing);
|
|
Util.TickFacing(ref unit.Facing, desiredFacing, self.LegacyInfo.ROT);
|
|
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();
|
|
|
|
return this;
|
|
}
|
|
|
|
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
|
}
|
|
}
|