diff --git a/OpenRA.Game/Combat.cs b/OpenRA.Game/Combat.cs index 8791c2b494..ced800b60e 100644 --- a/OpenRA.Game/Combat.cs +++ b/OpenRA.Game/Combat.cs @@ -43,7 +43,7 @@ namespace OpenRA public static void DoImpact(WarheadInfo warhead, ProjectileArgs args) { var world = args.firedBy.World; - var targetTile = ((1f / Game.CellSize) * args.dest.ToFloat2()).ToInt2(); + var targetTile = Util.CellContaining(args.dest); if (!world.Map.IsInMap(targetTile)) return; diff --git a/OpenRA.Game/Effects/Bullet.cs b/OpenRA.Game/Effects/Bullet.cs index db5ae585c0..60c271f66b 100755 --- a/OpenRA.Game/Effects/Bullet.cs +++ b/OpenRA.Game/Effects/Bullet.cs @@ -98,7 +98,7 @@ namespace OpenRA.Effects { var at = (float)t / TotalTime(); var pos = float2.Lerp(Args.src, Args.dest, at); - var cell = ((1f/Game.CellSize) * pos).ToInt2(); + var cell = Traits.Util.CellContaining(pos); if (world.WorldActor.traits.Get().GetUnitsAt(cell).Any( a => a.traits.Contains())) diff --git a/OpenRA.Game/Effects/Missile.cs b/OpenRA.Game/Effects/Missile.cs index 33612daa60..b2d30808a2 100755 --- a/OpenRA.Game/Effects/Missile.cs +++ b/OpenRA.Game/Effects/Missile.cs @@ -113,7 +113,7 @@ namespace OpenRA.Effects if (!Info.High) // check for hitting a wall { - var cell = ((1f / Game.CellSize) * Pos).ToInt2(); + var cell = Traits.Util.CellContaining(Pos); if (world.WorldActor.traits.Get().GetUnitsAt(cell).Any( a => a.traits.Contains())) diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 70ffb12f98..54c75357a7 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -137,7 +137,7 @@ namespace OpenRA.Traits var move = self.GetCurrentActivity() as Activities.Move; if (move == null || move.path == null) return new float2[] { }; - return Enumerable.Reverse(move.path).Select( c => Game.CellSize * c + new float2(12,12) ); + return Enumerable.Reverse(move.path).Select( c => Util.CenterOfCell(c) ); } } } diff --git a/OpenRA.Game/Traits/Production.cs b/OpenRA.Game/Traits/Production.cs index 37ee83a2f2..d92397582e 100755 --- a/OpenRA.Game/Traits/Production.cs +++ b/OpenRA.Game/Traits/Production.cs @@ -36,19 +36,19 @@ namespace OpenRA.Traits { public virtual int2? CreationLocation( Actor self, ActorInfo producee ) { - var pos = (1 / 24f * self.CenterLocation).ToInt2(); + var pos = Util.CellContaining(self.CenterLocation); var pi = self.Info.Traits.Get(); if (pi.ProductionOffset != null) - pos += new int2(pi.ProductionOffset[0], pi.ProductionOffset[1]); + pos += pi.ProductionOffset.AsInt2(); return pos; } public virtual int2? ExitLocation(Actor self, ActorInfo producee) { - var pos = (1 / 24f * self.CenterLocation).ToInt2(); + var pos = Util.CellContaining(self.CenterLocation); var pi = self.Info.Traits.Get(); if (pi.ExitOffset != null) - pos += new int2(pi.ExitOffset[0], pi.ExitOffset[1]); + pos += pi.ExitOffset.AsInt2(); return pos; } @@ -68,23 +68,21 @@ namespace OpenRA.Traits var pi = self.Info.Traits.Get(); var rp = self.traits.GetOrDefault(); - if( rp != null || pi.ExitOffset != null) + if (rp != null || pi.ExitOffset != null) { var mobile = newUnit.traits.GetOrDefault(); - if( mobile != null ) + if (mobile != null) { if (pi.ExitOffset != null) - newUnit.QueueActivity(new Activities.Move(ExitLocation( self, producee).Value, 1)); - + newUnit.QueueActivity(new Activities.Move(ExitLocation(self, producee).Value, 1)); + if (rp != null) - newUnit.QueueActivity( new Activities.Move( rp.rallyPoint, 1 ) ); + newUnit.QueueActivity(new Activities.Move(rp.rallyPoint, 1)); } } - if (pi != null && pi.SpawnOffset != null) - newUnit.CenterLocation = self.CenterLocation - + new float2(pi.SpawnOffset[0], pi.SpawnOffset[1]); + newUnit.CenterLocation = self.CenterLocation + pi.SpawnOffset.AsInt2(); foreach (var t in self.traits.WithInterface()) t.UnitProduced(self, newUnit); diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 0fa517724c..efcc3297aa 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -127,6 +127,7 @@ namespace OpenRA.Traits + offset.AbsOffset(); } + public static int2 AsInt2(this int[] xs) { return new int2(xs[0], xs[1]); } public static float2 RelOffset(this int[] offset) { return new float2(offset[0], offset[1]); } public static float2 AbsOffset(this int[] offset) { return new float2(offset.ElementAtOrDefault(2), offset.ElementAtOrDefault(3)); } @@ -171,5 +172,7 @@ namespace OpenRA.Traits } public static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); } + + public static int2 CellContaining(float2 pos) { return (1 / 24f * pos).ToInt2(); } } } diff --git a/OpenRA.Mods.RA/Activities/Fly.cs b/OpenRA.Mods.RA/Activities/Fly.cs index a85acf7edd..bef5862549 100644 --- a/OpenRA.Mods.RA/Activities/Fly.cs +++ b/OpenRA.Mods.RA/Activities/Fly.cs @@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Activities var aircraft = self.traits.Get(); self.CenterLocation += speed * -float2.FromAngle((float)angle); - aircraft.Location = ((1 / 24f) * self.CenterLocation).ToInt2(); + aircraft.Location = Util.CellContaining(self.CenterLocation); unit.Altitude += Math.Sign(desiredAltitude - unit.Altitude); } diff --git a/OpenRA.Mods.RA/Activities/HeliFly.cs b/OpenRA.Mods.RA/Activities/HeliFly.cs index fd58e35096..1d95a61152 100644 --- a/OpenRA.Mods.RA/Activities/HeliFly.cs +++ b/OpenRA.Mods.RA/Activities/HeliFly.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Activities if (float2.WithinEpsilon(float2.Zero, dist, 2)) { self.CenterLocation = Dest; - aircraft.Location = ((1 / 24f) * self.CenterLocation).ToInt2(); + aircraft.Location = Util.CellContaining(self.CenterLocation); return NextActivity; } @@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA.Activities var rawSpeed = .2f * Util.GetEffectiveSpeed(self, UnitMovementType.Fly); self.CenterLocation += (rawSpeed / dist.Length) * dist; - aircraft.Location = ((1 / 24f) * self.CenterLocation).ToInt2(); + aircraft.Location = Util.CellContaining(self.CenterLocation); return this; } diff --git a/OpenRA.Mods.RA/Activities/Land.cs b/OpenRA.Mods.RA/Activities/Land.cs index 4e64474f01..46f138bfd0 100644 --- a/OpenRA.Mods.RA/Activities/Land.cs +++ b/OpenRA.Mods.RA/Activities/Land.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA.Activities var angle = unit.Facing / 128f * Math.PI; self.CenterLocation += speed * -float2.FromAngle((float)angle); - aircraft.Location = ((1 / 24f) * self.CenterLocation).ToInt2(); + aircraft.Location = Util.CellContaining(self.CenterLocation); return this; } diff --git a/OpenRA.Mods.RA/Activities/LayMines.cs b/OpenRA.Mods.RA/Activities/LayMines.cs index 3ac573caf0..ec7c05bcff 100644 --- a/OpenRA.Mods.RA/Activities/LayMines.cs +++ b/OpenRA.Mods.RA/Activities/LayMines.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Activities if (rearmTarget == null) return new Wait(20); - return new Move(((1 / 24f) * rearmTarget.CenterLocation).ToInt2(), rearmTarget) + return new Move(Util.CellContaining(rearmTarget.CenterLocation), rearmTarget) { NextActivity = new Rearm() { NextActivity = new Repair(rearmTarget) { NextActivity = this } } }; } diff --git a/OpenRA.Mods.RA/Aircraft.cs b/OpenRA.Mods.RA/Aircraft.cs index ccab6a4507..ab26c4124d 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -18,7 +18,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index d27905f41e..68d93c4908 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => { w.Remove(this); - int2 loc = ((1 / 24f) * location).ToInt2(); + var loc = Traits.Util.CellContaining(location); cargo.CancelActivity(); if (cargo.traits.Contains()) cargo.traits.Get().TeleportTo(cargo, loc); diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index fc26b1fa87..b8344c5bda 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -127,7 +127,7 @@ namespace OpenRA.Mods.RA offsetTicks = Info.InstabilityTicks; } - Location = ((1 / 24f) * self.CenterLocation).ToInt2(); + Location = Util.CellContaining(self.CenterLocation); } const float Epsilon = .5f; diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index 438cf85aef..7be1f36d6e 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -69,7 +69,7 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => w.Add( new Parachute(self.Owner, rs.anim.Name, - Util.CenterOfCell((1 / 24f * self.CenterLocation).ToInt2()), + Util.CenterOfCell(Util.CellContaining(self.CenterLocation)), self.traits.Get().Altitude, a))); Sound.Play("chute1.aud", self.CenterLocation); diff --git a/OpenRA.Mods.RA/Repairable.cs b/OpenRA.Mods.RA/Repairable.cs index 5baedce4aa..986c974495 100644 --- a/OpenRA.Mods.RA/Repairable.cs +++ b/OpenRA.Mods.RA/Repairable.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA var rp = order.TargetActor.traits.GetOrDefault(); self.CancelActivity(); - self.QueueActivity(new Move(((1 / 24f) * order.TargetActor.CenterLocation).ToInt2(), order.TargetActor)); + self.QueueActivity(new Move(Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor)); self.QueueActivity(new Rearm()); self.QueueActivity(new Repair(order.TargetActor));