changes facing (and desireFacing) on Mobile and on Turreted. range is now 0..255

This commit is contained in:
Bob
2009-10-19 23:45:14 +13:00
parent 451fdc1615
commit a7ce0f97d1
14 changed files with 162 additions and 150 deletions

View File

@@ -15,6 +15,7 @@ namespace OpenRa.Game.Traits
public int2 toCell { get { return self.Location; } }
public int moveFraction, moveFractionTotal;
public int facing;
public int? desiredFacing;
public Mobile(Actor self)
{
@@ -22,41 +23,6 @@ namespace OpenRa.Game.Traits
fromCell = destination = self.Location;
}
public bool Turn(int desiredFacing)
{
if (facing == desiredFacing)
return false;
int df = (desiredFacing - facing + 32) % 32;
facing = (facing + (df > 16 ? 31 : 1)) % 32;
return true;
}
static float2[] fvecs = Util.MakeArray<float2>(32,
i => -float2.FromAngle(i / 16.0f * (float)Math.PI) * new float2(1f, 1.3f));
// TODO: move this somewhere more appropriate, now that AttackTurreted uses it.
public int GetFacing(float2 d)
{
if (float2.WithinEpsilon(d, float2.Zero, 0.001f))
return facing;
int highest = -1;
float highestDot = -1.0f;
for (int i = 0; i < fvecs.Length; i++)
{
float dot = float2.Dot(fvecs[i], d);
if (dot > highestDot)
{
highestDot = dot;
highest = i;
}
}
return highest;
}
void UpdateCenterLocation()
{
float fraction = (moveFraction > 0) ? (float)moveFraction / moveFractionTotal : 0f;
@@ -71,13 +37,19 @@ namespace OpenRa.Game.Traits
void Move(Actor self, Game game, int dt)
{
if (fromCell != toCell)
{
if (Turn(GetFacing(toCell - fromCell)))
return;
if( fromCell != toCell )
desiredFacing = Util.GetFacing( toCell - fromCell, facing );
moveFraction += dt * ((UnitInfo.MobileInfo)self.unitInfo).Speed;
if( desiredFacing != null && desiredFacing != facing )
{
Util.TickFacing( ref facing, desiredFacing.Value, self.unitInfo.ROT );
return;
}
desiredFacing = null;
if( fromCell != toCell )
moveFraction += dt * ((UnitInfo.MobileInfo)self.unitInfo).Speed;
if (moveFraction < moveFractionTotal)
return;