diff --git a/OpenRA.Game/ActorInitializer.cs b/OpenRA.Game/ActorInitializer.cs index 909c716b8e..56502cc00b 100755 --- a/OpenRA.Game/ActorInitializer.cs +++ b/OpenRA.Game/ActorInitializer.cs @@ -55,14 +55,6 @@ namespace OpenRA public int Value( World world ) { return value; } } - public class AltitudeInit : IActorInit - { - [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 { [FieldFromYamlKey] public readonly int2 value = int2.Zero; diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index 142ee657d9..da5fe24388 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -52,12 +52,12 @@ namespace OpenRA.Mods.Cnc owner.World.AddFrameEndTask(w => { + var altitude = Rules.Info[actorType].Traits.Get().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().CruiseAltitude), + new FacingInit(64) }); a.QueueActivity(Fly.ToCell(self.Location + new CVec(9, 0))); diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index 75765c97eb..9e83148263 100755 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -19,9 +19,9 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Air { - public class AircraftInfo : ITraitInfo, IFacingInfo, IOccupySpaceInfo, UsesInit, UsesInit, UsesInit + public class AircraftInfo : ITraitInfo, IFacingInfo, IOccupySpaceInfo, UsesInit, UsesInit { - 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()) SetPosition(self, init.Get()); - - if (init.Contains()) - { - var z = init.Get() * 1024 / Game.CellSize; - SetPosition(self, CenterPosition + new WVec(0, 0, z - CenterPosition.Z)); - } - if (init.Contains()) SetPosition(self, init.Get()); diff --git a/OpenRA.Mods.RA/Air/Fly.cs b/OpenRA.Mods.RA/Air/Fly.cs index 059a0fdf98..8ab14c0426 100755 --- a/OpenRA.Mods.RA/Air/Fly.cs +++ b/OpenRA.Mods.RA/Air/Fly.cs @@ -51,13 +51,12 @@ namespace OpenRA.Mods.RA.Air var plane = self.Trait(); 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; } diff --git a/OpenRA.Mods.RA/Air/FlyCircle.cs b/OpenRA.Mods.RA/Air/FlyCircle.cs index 8def5c77c9..705f033681 100644 --- a/OpenRA.Mods.RA/Air/FlyCircle.cs +++ b/OpenRA.Mods.RA/Air/FlyCircle.cs @@ -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; } diff --git a/OpenRA.Mods.RA/Air/FlyTimed.cs b/OpenRA.Mods.RA/Air/FlyTimed.cs index 03ee64688f..c99fdc47a6 100755 --- a/OpenRA.Mods.RA/Air/FlyTimed.cs +++ b/OpenRA.Mods.RA/Air/FlyTimed.cs @@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA.Air return NextActivity; var plane = self.Trait(); - 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(); - 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; } diff --git a/OpenRA.Mods.RA/Air/HeliAttack.cs b/OpenRA.Mods.RA/Air/HeliAttack.cs index 2268f6049c..1946d67945 100755 --- a/OpenRA.Mods.RA/Air/HeliAttack.cs +++ b/OpenRA.Mods.RA/Air/HeliAttack.cs @@ -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 diff --git a/OpenRA.Mods.RA/Air/HeliFly.cs b/OpenRA.Mods.RA/Air/HeliFly.cs index fba3c0aae0..dd61b4987c 100755 --- a/OpenRA.Mods.RA/Air/HeliFly.cs +++ b/OpenRA.Mods.RA/Air/HeliFly.cs @@ -40,8 +40,7 @@ namespace OpenRA.Mods.RA.Air var helicopter = self.Trait(); - 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; } diff --git a/OpenRA.Mods.RA/Air/Helicopter.cs b/OpenRA.Mods.RA/Air/Helicopter.cs index f83dbe344b..052e0b6052 100755 --- a/OpenRA.Mods.RA/Air/Helicopter.cs +++ b/OpenRA.Mods.RA/Air/Helicopter.cs @@ -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) diff --git a/OpenRA.Mods.RA/Air/ReturnToBase.cs b/OpenRA.Mods.RA/Air/ReturnToBase.cs index 9cfec5a821..2491b1e715 100755 --- a/OpenRA.Mods.RA/Air/ReturnToBase.cs +++ b/OpenRA.Mods.RA/Air/ReturnToBase.cs @@ -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); diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index d1312a9d21..8540d1b887 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -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().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().CruiseAltitude ), - }); - - plane.CancelActivity(); - plane.QueueActivity(new FlyAttack(Target.FromCell(p))); - plane.Trait().SetLZ(p); - plane.Trait().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().SetLZ(p); + plane.Trait().Load(plane, crate); + }); } } } diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 3f4e329340..f4cb119460 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -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; diff --git a/OpenRA.Mods.RA/LeavesHusk.cs b/OpenRA.Mods.RA/LeavesHusk.cs index f4e0cc17f9..43b81fd718 100644 --- a/OpenRA.Mods.RA/LeavesHusk.cs +++ b/OpenRA.Mods.RA/LeavesHusk.cs @@ -54,10 +54,6 @@ namespace OpenRA.Mods.RA td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location))); } - var aircraft = self.TraitOrDefault(); - if (aircraft != null) - td.Add(new AltitudeInit(aircraft.CenterPosition.Z * Game.CellSize / 1024)); - var facing = self.TraitOrDefault(); if (facing != null) td.Add(new FacingInit(facing.Facing)); diff --git a/OpenRA.Mods.RA/Missions/Allies02Script.cs b/OpenRA.Mods.RA/Missions/Allies02Script.cs index aa8755faab..4bf15e537a 100644 --- a/OpenRA.Mods.RA/Missions/Allies02Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies02Script.cs @@ -267,12 +267,12 @@ namespace OpenRA.Mods.RA.Missions { if (yak == null) { + var altitude = Rules.Info[YakName].Traits.Get().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().CruiseAltitude) + new FacingInit(Traits.Util.GetFacing(yakAttackPoint.Location - yakEntryPoint.Location, 0)) }); } diff --git a/OpenRA.Mods.RA/Missions/MissionUtils.cs b/OpenRA.Mods.RA/Missions/MissionUtils.cs index 5b8cf38044..cf0ba7084e 100644 --- a/OpenRA.Mods.RA/Missions/MissionUtils.cs +++ b/OpenRA.Mods.RA/Missions/MissionUtils.cs @@ -73,13 +73,14 @@ namespace OpenRA.Mods.RA.Missions public static void Paradrop(World world, Player owner, IEnumerable units, CPos entry, CPos location) { + var altitude = Rules.Info["badr"].Traits.Get().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().CruiseAltitude), + new FacingInit(Util.GetFacing(location - entry, 0)) }); + badger.QueueActivity(new FlyAttack(Target.FromCell(location))); badger.Trait().SetLZ(location); var cargo = badger.Trait(); @@ -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().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().CruiseAltitude), + new FacingInit(Util.GetFacing(location - entry, 0)) }); + badger.Trait().SetTarget(location.CenterPosition); badger.QueueActivity(Fly.ToCell(location)); badger.QueueActivity(new FlyOffMap()); diff --git a/OpenRA.Mods.RA/Missions/Soviet01ClassicScript.cs b/OpenRA.Mods.RA/Missions/Soviet01ClassicScript.cs index e180621abb..0b567afa2c 100644 --- a/OpenRA.Mods.RA/Missions/Soviet01ClassicScript.cs +++ b/OpenRA.Mods.RA/Missions/Soviet01ClassicScript.cs @@ -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().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().CruiseAltitude) + new FacingInit(Traits.Util.GetFacing(airfield.Location - entry, 0)) }); while (yak.Trait().TakeAmmo()) { } diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 23adda90f2..c2bf81bab3 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -206,11 +206,10 @@ namespace OpenRA.Mods.RA.Move this.Facing = init.Contains() ? init.Get() : info.InitialFacing; - if (init.Contains()) - { - var z = init.Get() * 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()) + SetVisualPosition(self, init.Get()); } public void SetPosition(Actor self, CPos cell) diff --git a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs index a04eb7ebf3..9ff9f55ee8 100755 --- a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs @@ -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().CruiseAltitude * 1024 / Game.CellSize; + var altitude = Rules.Info[info.UnitType].Traits.Get().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; diff --git a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs index df44e428f6..85a764017d 100755 --- a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs @@ -53,12 +53,12 @@ namespace OpenRA.Mods.RA flare.QueueActivity(new RemoveSelf()); } + var altitude = Rules.Info[info.UnitType].Traits.Get().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().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(); diff --git a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs index 648f1a571a..791cdf9c5f 100755 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -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().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().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();