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

@@ -55,14 +55,6 @@ namespace OpenRA
public int Value( World world ) { return value; }
}
public class AltitudeInit : IActorInit<int>
{
[FieldFromYamlKey] public readonly int value = 0;
public AltitudeInit() { }
public AltitudeInit( int init ) { value = init; }
public int Value( World world ) { return value; }
}
public class LocationInit : IActorInit<CPos>
{
[FieldFromYamlKey] public readonly int2 value = int2.Zero;

View File

@@ -52,12 +52,12 @@ namespace OpenRA.Mods.Cnc
owner.World.AddFrameEndTask(w =>
{
var altitude = Rules.Info[actorType].Traits.Get<PlaneInfo>().CruiseAltitude;
var a = w.CreateActor(actorType, new TypeDictionary
{
new LocationInit(startPos),
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(owner),
new FacingInit(64),
new AltitudeInit(Rules.Info[actorType].Traits.Get<PlaneInfo>().CruiseAltitude),
new FacingInit(64)
});
a.QueueActivity(Fly.ToCell(self.Location + new CVec(9, 0)));

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);

View File

@@ -92,26 +92,26 @@ namespace OpenRA.Mods.RA
var pp = ChooseDropCell(self, inWater, 100);
if (pp == null) return;
var p = pp.Value; //
var p = pp.Value;
self.World.AddFrameEndTask(w =>
{
var crate = w.CreateActor(false, Info.CrateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) });
crates.Add(crate);
var startPos = w.ChooseRandomEdgeCell();
var altitude = Rules.Info[Info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude;
var plane = w.CreateActor(Info.DeliveryAircraft, new TypeDictionary
{
var crate = w.CreateActor(false, Info.CrateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) });
crates.Add(crate);
var startPos = w.ChooseRandomEdgeCell();
var plane = w.CreateActor(Info.DeliveryAircraft, new TypeDictionary
{
new LocationInit( startPos ),
new OwnerInit( w.WorldActor.Owner),
new FacingInit( Util.GetFacing(p - startPos, 0) ),
new AltitudeInit( Rules.Info[Info.DeliveryAircraft].Traits.Get<AircraftInfo>().CruiseAltitude ),
});
plane.CancelActivity();
plane.QueueActivity(new FlyAttack(Target.FromCell(p)));
plane.Trait<ParaDrop>().SetLZ(p);
plane.Trait<Cargo>().Load(plane, crate);
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(w.WorldActor.Owner),
new FacingInit(Util.GetFacing(p - startPos, 0))
});
plane.CancelActivity();
plane.QueueActivity(new FlyAttack(Target.FromCell(p)));
plane.Trait<ParaDrop>().SetLZ(p);
plane.Trait<Cargo>().Load(plane, crate);
});
}
}
}

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Effects
class Missile : IEffect, ISync
{
static readonly WRange MissileCloseEnough = new WRange(7 * 1024 / Game.CellSize);
static readonly WRange MissileCloseEnough = new WRange(298);
readonly MissileInfo info;
readonly ProjectileArgs args;

View File

@@ -54,10 +54,6 @@ namespace OpenRA.Mods.RA
td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location)));
}
var aircraft = self.TraitOrDefault<Aircraft>();
if (aircraft != null)
td.Add(new AltitudeInit(aircraft.CenterPosition.Z * Game.CellSize / 1024));
var facing = self.TraitOrDefault<IFacing>();
if (facing != null)
td.Add(new FacingInit(facing.Facing));

View File

@@ -267,12 +267,12 @@ namespace OpenRA.Mods.RA.Missions
{
if (yak == null)
{
var altitude = Rules.Info[YakName].Traits.Get<PlaneInfo>().CruiseAltitude;
yak = world.CreateActor(YakName, new TypeDictionary
{
new LocationInit(yakEntryPoint.Location),
new CenterPositionInit(yakEntryPoint.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(soviets),
new FacingInit(Traits.Util.GetFacing(yakAttackPoint.Location - yakEntryPoint.Location, 0)),
new AltitudeInit(Rules.Info[YakName].Traits.Get<PlaneInfo>().CruiseAltitude)
new FacingInit(Traits.Util.GetFacing(yakAttackPoint.Location - yakEntryPoint.Location, 0))
});
}

View File

@@ -73,13 +73,14 @@ namespace OpenRA.Mods.RA.Missions
public static void Paradrop(World world, Player owner, IEnumerable<string> units, CPos entry, CPos location)
{
var altitude = Rules.Info["badr"].Traits.Get<PlaneInfo>().CruiseAltitude;
var badger = world.CreateActor("badr", new TypeDictionary
{
new LocationInit(entry),
new CenterPositionInit(entry.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(owner),
new FacingInit(Util.GetFacing(location - entry, 0)),
new AltitudeInit(Rules.Info["badr"].Traits.Get<PlaneInfo>().CruiseAltitude),
new FacingInit(Util.GetFacing(location - entry, 0))
});
badger.QueueActivity(new FlyAttack(Target.FromCell(location)));
badger.Trait<ParaDrop>().SetLZ(location);
var cargo = badger.Trait<Cargo>();
@@ -91,13 +92,14 @@ namespace OpenRA.Mods.RA.Missions
public static void Parabomb(World world, Player owner, CPos entry, CPos location)
{
var altitude = Rules.Info["badr.bomber"].Traits.Get<PlaneInfo>().CruiseAltitude;
var badger = world.CreateActor("badr.bomber", new TypeDictionary
{
new LocationInit(entry),
new CenterPositionInit(entry.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(owner),
new FacingInit(Util.GetFacing(location - entry, 0)),
new AltitudeInit(Rules.Info["badr.bomber"].Traits.Get<PlaneInfo>().CruiseAltitude),
new FacingInit(Util.GetFacing(location - entry, 0))
});
badger.Trait<AttackBomber>().SetTarget(location.CenterPosition);
badger.QueueActivity(Fly.ToCell(location));
badger.QueueActivity(new FlyOffMap());

View File

@@ -104,12 +104,12 @@ namespace OpenRA.Mods.RA.Missions
foreach (var airfield in airfields)
{
var entry = airfield.Location - new CVec(10, 0);
var altitude = Rules.Info["yak"].Traits.Get<PlaneInfo>().CruiseAltitude;
var yak = world.CreateActor("yak", new TypeDictionary
{
new CenterPositionInit(entry.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(ussr),
new LocationInit(entry),
new FacingInit(Traits.Util.GetFacing(airfield.Location - entry, 0)),
new AltitudeInit(Rules.Info["yak"].Traits.Get<PlaneInfo>().CruiseAltitude)
new FacingInit(Traits.Util.GetFacing(airfield.Location - entry, 0))
});
while (yak.Trait<LimitedAmmo>().TakeAmmo()) { }

View File

@@ -206,11 +206,10 @@ namespace OpenRA.Mods.RA.Move
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
if (init.Contains<AltitudeInit>())
{
var z = init.Get<AltitudeInit, int>() * 1024 / Game.CellSize;
SetVisualPosition(self, CenterPosition + new WVec(0, 0, z - CenterPosition.Z));
}
// Sets the visual position to WPos accuracy
// Use LocationInit if you want to insert the actor into the ActorMap!
if (init.Contains<CenterPositionInit>())
SetVisualPosition(self, init.Get<CenterPositionInit, WPos>());
}
public void SetPosition(Actor self, CPos cell)

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA
var attackRotation = WRot.FromFacing(attackFacing);
var delta = new WVec(0, -1024, 0).Rotate(attackRotation);
var altitude = Rules.Info[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude * 1024 / Game.CellSize;
var altitude = Rules.Info[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude.Range;
var target = order.TargetLocation.CenterPosition + new WVec(0, 0, altitude);
var startEdge = target - (self.World.DistanceToMapEdge(target, -delta) + info.Cordon).Range * delta / 1024;
var finishEdge = target + (self.World.DistanceToMapEdge(target, delta) + info.Cordon).Range * delta / 1024;

View File

@@ -53,12 +53,12 @@ namespace OpenRA.Mods.RA
flare.QueueActivity(new RemoveSelf());
}
var altitude = Rules.Info[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude;
var a = w.CreateActor(info.UnitType, new TypeDictionary
{
new LocationInit( startPos ),
new OwnerInit( self.Owner ),
new FacingInit( Util.GetFacing(order.TargetLocation - startPos, 0) ),
new AltitudeInit( Rules.Info[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude ),
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(self.Owner),
new FacingInit(Util.GetFacing(order.TargetLocation - startPos, 0))
});
a.CancelActivity();

View File

@@ -28,13 +28,13 @@ namespace OpenRA.Mods.RA
public override void Activate(Actor self, Order order)
{
var enterCell = self.World.ChooseRandomEdgeCell();
var altitude = Rules.Info["u2"].Traits.Get<PlaneInfo>().CruiseAltitude;
var plane = self.World.CreateActor("u2", new TypeDictionary
{
new LocationInit( enterCell ),
new OwnerInit( self.Owner ),
new FacingInit( Util.GetFacing(order.TargetLocation - enterCell, 0) ),
new AltitudeInit( Rules.Info["u2"].Traits.Get<PlaneInfo>().CruiseAltitude ),
new CenterPositionInit(enterCell.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(self.Owner),
new FacingInit(Util.GetFacing(order.TargetLocation - enterCell, 0))
});
plane.CancelActivity();