diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 702fb2b1ee..9b43c0cace 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -27,7 +27,7 @@ namespace OpenRA public readonly uint ActorID; public int2 Location { get { return Trait().TopLeft; } } - public float2 CenterLocation { get { return Trait().PxPosition; } } + public int2 CenterLocation { get { return Trait().PxPosition; } } [Sync] public Player Owner; diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index ac383cc7ee..c7e631b1da 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -116,11 +116,10 @@ namespace OpenRA.Graphics { if (!actors.Any()) return; - var avgPos = (1f / actors.Count()) * actors + var avgPos = actors .Select(a => a.CenterLocation) - .Aggregate((a, b) => a + b); - - scrollPosition = this.NormalizeScrollPosition((avgPos.ToInt2() - screenSize / 2)); + .Aggregate((a, b) => a + b) / actors.Count(); + scrollPosition = this.NormalizeScrollPosition((avgPos - screenSize / 2)); } public Rectangle ViewBounds(World world) diff --git a/OpenRA.Game/Traits/DrawLineToTarget.cs b/OpenRA.Game/Traits/DrawLineToTarget.cs index dee9cf7cef..a2f60d2d6d 100644 --- a/OpenRA.Game/Traits/DrawLineToTarget.cs +++ b/OpenRA.Game/Traits/DrawLineToTarget.cs @@ -59,7 +59,7 @@ namespace OpenRA.Traits var p = target.CenterLocation; var move = self.TraitOrDefault(); - var origin = move != null ? self.CenterLocation - new float2(0, move.Altitude) : self.CenterLocation; + var origin = move != null ? self.CenterLocation - new int2(0, move.Altitude) : self.CenterLocation; Game.Renderer.LineRenderer.DrawLine(origin, p, c, c); for (bool b = false; !b; p = origin, b = true) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 684c3b0038..2f7d3504ed 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -231,7 +231,7 @@ namespace OpenRA.Traits public bool IsValid { get { return valid && (actor == null || actor.IsInWorld); } } public int2 PxPosition { get { return IsActor ? actor.Trait().PxPosition : pos.ToInt2(); } } - public float2 CenterLocation { get { return PxPosition; } } + public int2 CenterLocation { get { return PxPosition; } } public Actor Actor { get { return IsActor ? actor : null; } } public bool IsActor { get { return actor != null && !actor.Destroyed; } } diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index f4e675f94a..41b02315b1 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -34,8 +34,9 @@ namespace OpenRA.Traits static float2[] fvecs = Graphics.Util.MakeArray( 32, i => -float2.FromAngle( i / 16.0f * (float)Math.PI ) * new float2( 1f, 1.3f ) ); - public static int GetFacing( float2 d, int currentFacing ) + public static int GetFacing( int2 dd, int currentFacing ) { + var d = dd.ToFloat2(); if (float2.WithinEpsilon(d, float2.Zero, 0.001f)) return currentFacing; diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 36e93802f3..bd371a7bdd 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -139,7 +139,7 @@ namespace OpenRA.Traits if (cells.Any()) return cells; } - return new[] { (1f / Game.CellSize * a.CenterLocation).ToInt2() }; + return new[] { a.CenterLocation / Game.CellSize }; } void RemoveActor(Actor a) diff --git a/OpenRA.Mods.RA/Air/Fly.cs b/OpenRA.Mods.RA/Air/Fly.cs index c9c8328923..e3a81de969 100755 --- a/OpenRA.Mods.RA/Air/Fly.cs +++ b/OpenRA.Mods.RA/Air/Fly.cs @@ -17,11 +17,11 @@ namespace OpenRA.Mods.RA.Air { public class Fly : CancelableActivity { - public readonly float2 Pos; + public readonly int2 Pos; - private Fly( float2 px ) { Pos = px; } + private Fly( int2 px ) { Pos = px; } - public static Fly ToPx( float2 px ) { return new Fly( px ); } + public static Fly ToPx( int2 px ) { return new Fly( px ); } public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); } public override IActivity Tick(Actor self) diff --git a/OpenRA.Mods.RA/Air/ReturnToBase.cs b/OpenRA.Mods.RA/Air/ReturnToBase.cs index 5f27b1188f..c562a9ca72 100755 --- a/OpenRA.Mods.RA/Air/ReturnToBase.cs +++ b/OpenRA.Mods.RA/Air/ReturnToBase.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Air bool isCalculated; Actor dest; - float2 w1, w2, w3; /* tangent points to turn circles */ + int2 w1, w2, w3; /* tangent points to turn circles */ public static Actor ChooseAirfield(Actor self) { @@ -74,9 +74,9 @@ namespace OpenRA.Mods.RA.Air if (f.X > 0) f = -f; - w1 = c1 + f; - w2 = c2 + f; - w3 = approachStart; + w1 = (c1 + f).ToInt2(); + w2 = (c2 + f).ToInt2(); + w3 = (approachStart).ToInt2(); isCalculated = true; } diff --git a/OpenRA.Mods.RA/CarpetBomb.cs b/OpenRA.Mods.RA/CarpetBomb.cs index 37c9533adb..4069b4c3ae 100644 --- a/OpenRA.Mods.RA/CarpetBomb.cs +++ b/OpenRA.Mods.RA/CarpetBomb.cs @@ -47,8 +47,8 @@ namespace OpenRA.Mods.RA { srcAltitude = self.Trait().Altitude, destAltitude = 0, - src = self.CenterLocation.ToInt2(), - dest = self.CenterLocation.ToInt2(), + src = self.CenterLocation, + dest = self.CenterLocation, facing = self.Trait().Facing, firedBy = self, weapon = weapon diff --git a/OpenRA.Mods.RA/Effects/LaserZap.cs b/OpenRA.Mods.RA/Effects/LaserZap.cs index 30a2f61a21..c038071235 100755 --- a/OpenRA.Mods.RA/Effects/LaserZap.cs +++ b/OpenRA.Mods.RA/Effects/LaserZap.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Effects if (!doneDamage) { if (args.target.IsValid) - args.dest = args.target.CenterLocation.ToInt2(); + args.dest = args.target.CenterLocation; Combat.DoImpacts(args); doneDamage = true; diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 1b54363036..047cd6314d 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Effects readonly ProjectileArgs Args; int2 offset; - float2 Pos; + int2 Pos; readonly Animation anim; int Facing; int t; @@ -93,12 +93,13 @@ namespace OpenRA.Mods.RA.Effects var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f); var angle = Facing / 128f * Math.PI; - var move = speed * -float2.FromAngle((float)angle); + // TODO: Replace float2.FromAngle with int2.FromFacing + var move = (speed * -float2.FromAngle((float)angle)).ToInt2(); Pos += move; if (Info.Trail != null) world.AddFrameEndTask(w => w.Add( - new Smoke(w, (Pos - 1.5f * move - new int2(0, Altitude)).ToInt2(), Info.Trail))); + new Smoke(w, (Pos - 1.5f * move.ToFloat2() - new int2(0, Altitude)).ToInt2(), Info.Trail))); if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40) Explode(world); @@ -116,7 +117,7 @@ namespace OpenRA.Mods.RA.Effects void Explode(World world) { world.AddFrameEndTask(w => w.Remove(this)); - Args.dest = Pos.ToInt2(); + Args.dest = Pos; if (t > Info.Arm * 40) /* don't blow up in our launcher's face! */ Combat.DoImpacts(Args); } diff --git a/OpenRA.Mods.RA/Effects/TeslaZap.cs b/OpenRA.Mods.RA/Effects/TeslaZap.cs index 151d76b499..b214e35e43 100755 --- a/OpenRA.Mods.RA/Effects/TeslaZap.cs +++ b/OpenRA.Mods.RA/Effects/TeslaZap.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Effects if (!doneDamage) { if (Args.target.IsValid) - Args.dest = Args.target.CenterLocation.ToInt2(); + Args.dest = Args.target.CenterLocation; Combat.DoImpacts(Args); doneDamage = true; diff --git a/OpenRA.Mods.RA/Weapon.cs b/OpenRA.Mods.RA/Weapon.cs index f6f3275aa8..67d418d509 100644 --- a/OpenRA.Mods.RA/Weapon.cs +++ b/OpenRA.Mods.RA/Weapon.cs @@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA + Combat.GetTurretPosition(self, facing, Turret) + Combat.GetBarrelPosition(self, facing, Turret, barrel)).ToInt2(), srcAltitude = move != null ? move.Altitude : 0, - dest = target.CenterLocation.ToInt2(), + dest = target.CenterLocation, destAltitude = destMove != null ? destMove.Altitude : 0, facing = barrel.Facing +