Convert Altitude to world coords.

Removes the obsolete AltitudeInit: use CenterPositionInit instead.
This commit is contained in:
Paul Chote
2013-12-24 11:22:07 +13:00
parent c42a6f8386
commit aa2f865d5d
20 changed files with 61 additions and 86 deletions

View File

@@ -19,9 +19,9 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Air
{
public class AircraftInfo : ITraitInfo, IFacingInfo, IOccupySpaceInfo, UsesInit<AltitudeInit>, UsesInit<LocationInit>, UsesInit<FacingInit>
public class AircraftInfo : ITraitInfo, IFacingInfo, IOccupySpaceInfo, UsesInit<LocationInit>, UsesInit<FacingInit>
{
public readonly int CruiseAltitude = 30;
public readonly WRange CruiseAltitude = new WRange(1280);
[ActorReference]
public readonly string[] RepairBuildings = { "fix" };
@@ -57,13 +57,6 @@ namespace OpenRA.Mods.RA.Air
if (init.Contains<LocationInit>())
SetPosition(self, init.Get<LocationInit, CPos>());
if (init.Contains<AltitudeInit>())
{
var z = init.Get<AltitudeInit, int>() * 1024 / Game.CellSize;
SetPosition(self, CenterPosition + new WVec(0, 0, z - CenterPosition.Z));
}
if (init.Contains<CenterPositionInit>())
SetPosition(self, init.Get<CenterPositionInit, WPos>());

View File

@@ -51,13 +51,12 @@ namespace OpenRA.Mods.RA.Air
var plane = self.Trait<Plane>();
var desiredFacing = Util.GetFacing(d, plane.Facing);
var cruiseAltitude = new WRange(plane.Info.CruiseAltitude * 1024 / Game.CellSize);
// Don't turn until we've reached the cruise altitude
if (plane.CenterPosition.Z < cruiseAltitude.Range)
if (plane.CenterPosition.Z < plane.Info.CruiseAltitude.Range)
desiredFacing = plane.Facing;
FlyToward(self, plane, desiredFacing, cruiseAltitude);
FlyToward(self, plane, desiredFacing, plane.Info.CruiseAltitude);
return this;
}

View File

@@ -23,8 +23,7 @@ namespace OpenRA.Mods.RA.Air
// We can't possibly turn this fast
var desiredFacing = plane.Facing + 64;
var cruiseAltitude = new WRange(plane.Info.CruiseAltitude * 1024 / Game.CellSize);
Fly.FlyToward(self, plane, desiredFacing, cruiseAltitude);
Fly.FlyToward(self, plane, desiredFacing, plane.Info.CruiseAltitude);
return this;
}

View File

@@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA.Air
return NextActivity;
var plane = self.Trait<Plane>();
var cruiseAltitude = new WRange(plane.Info.CruiseAltitude * 1024 / Game.CellSize);
Fly.FlyToward(self, plane, plane.Facing, cruiseAltitude);
Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude);
return this;
}
@@ -39,8 +38,7 @@ namespace OpenRA.Mods.RA.Air
return NextActivity;
var plane = self.Trait<Plane>();
var cruiseAltitude = new WRange(plane.Info.CruiseAltitude * 1024 / Game.CellSize);
Fly.FlyToward(self, plane, plane.Facing, cruiseAltitude);
Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude);
return this;
}

View File

@@ -35,8 +35,7 @@ namespace OpenRA.Mods.RA.Air
var desiredFacing = Util.GetFacing(dist, helicopter.Facing);
helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.ROT);
var cruiseAltitude = new WRange(helicopter.Info.CruiseAltitude * 1024 / Game.CellSize);
if (HeliFly.AdjustAltitude(self, helicopter, cruiseAltitude))
if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude))
return this;
// Fly towards the target

View File

@@ -40,8 +40,7 @@ namespace OpenRA.Mods.RA.Air
var helicopter = self.Trait<Helicopter>();
var cruiseAltitude = new WRange(helicopter.Info.CruiseAltitude * 1024 / Game.CellSize);
if (AdjustAltitude(self, helicopter, cruiseAltitude))
if (AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude))
return this;
// Rotate towards the target
@@ -53,7 +52,7 @@ namespace OpenRA.Mods.RA.Air
var move = helicopter.FlyStep(desiredFacing);
if (dist.HorizontalLengthSquared < move.HorizontalLengthSquared)
{
helicopter.SetPosition(self, pos + new WVec(0, 0, cruiseAltitude.Range - pos.Z));
helicopter.SetPosition(self, pos + new WVec(0, 0, helicopter.Info.CruiseAltitude.Range - pos.Z));
return NextActivity;
}

View File

@@ -114,8 +114,7 @@ namespace OpenRA.Mods.RA.Air
// Repulsion only applies when we're flying!
var altitude = CenterPosition.Z;
var cruiseAltitude = Info.CruiseAltitude * 1024 / Game.CellSize;
if (altitude != cruiseAltitude)
if (altitude != Info.CruiseAltitude.Range)
return;
var otherHelis = self.World.FindActorsInCircle(self.CenterPosition, Info.IdealSeparation)

View File

@@ -49,10 +49,10 @@ namespace OpenRA.Mods.RA.Air
}
var landPos = dest.CenterPosition;
var altitude = planeInfo.CruiseAltitude.Range;
// Distance required for descent.
var landDistance = planeInfo.CruiseAltitude * 1024 * 1024 / (Game.CellSize * plane.Info.MaximumPitch.Tan());
var altitude = planeInfo.CruiseAltitude * 1024 / Game.CellSize;
var landDistance = altitude * 1024 / plane.Info.MaximumPitch.Tan();
// Land towards the east
var approachStart = landPos + new WVec(-landDistance, 0, altitude);