From 9487f49cd54d4e65d173d47e110d1abe373b30ff Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 17 Sep 2013 22:57:30 +1200 Subject: [PATCH] Replace WPos.ToCPos -> Map.CellContaining. --- OpenRA.Game/CPos.cs | 11 ----------- OpenRA.Game/GameRules/WeaponInfo.cs | 2 +- OpenRA.Game/Graphics/ContrailRenderable.cs | 4 ++-- OpenRA.Game/Graphics/Viewport.cs | 9 +++++++-- OpenRA.Game/Map/Map.cs | 5 +++++ OpenRA.Game/Orders/UnitOrderGenerator.cs | 2 +- OpenRA.Game/Traits/Util.cs | 4 ++-- OpenRA.Game/Traits/World/Shroud.cs | 2 +- OpenRA.Game/Widgets/ViewportControllerWidget.cs | 2 +- .../Widgets/WorldInteractionControllerWidget.cs | 5 ++--- OpenRA.Mods.RA/AI/States/GroundStates.cs | 4 ++-- OpenRA.Mods.RA/Activities/Enter.cs | 2 +- OpenRA.Mods.RA/Activities/EnterTransport.cs | 2 +- OpenRA.Mods.RA/Activities/LayMines.cs | 2 +- OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs | 6 +++--- OpenRA.Mods.RA/Air/Aircraft.cs | 6 +++--- OpenRA.Mods.RA/Air/TakeOff.cs | 2 +- OpenRA.Mods.RA/Attack/AttackBase.cs | 4 ++-- OpenRA.Mods.RA/Attack/AttackWander.cs | 2 +- OpenRA.Mods.RA/Cargo.cs | 4 ++-- OpenRA.Mods.RA/Combat.cs | 2 +- OpenRA.Mods.RA/Crate.cs | 4 ++-- OpenRA.Mods.RA/Effects/Bullet.cs | 4 ++-- OpenRA.Mods.RA/Effects/CashTick.cs | 2 +- OpenRA.Mods.RA/Effects/Corpse.cs | 2 +- OpenRA.Mods.RA/Effects/Explosion.cs | 2 +- OpenRA.Mods.RA/Effects/GravityBomb.cs | 2 +- OpenRA.Mods.RA/Effects/Missile.cs | 4 ++-- OpenRA.Mods.RA/Effects/Parachute.cs | 2 +- OpenRA.Mods.RA/Effects/Smoke.cs | 2 +- OpenRA.Mods.RA/Harvester.cs | 4 ++-- OpenRA.Mods.RA/Husk.cs | 2 +- OpenRA.Mods.RA/Minelayer.cs | 4 ++-- OpenRA.Mods.RA/Move/Mobile.cs | 6 +++--- OpenRA.Mods.RA/Move/PathFinder.cs | 2 +- OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs | 6 +++--- OpenRA.Mods.RA/PortableChrono.cs | 8 ++++---- OpenRA.Mods.RA/RallyPoint.cs | 4 ++-- OpenRA.Mods.RA/Repairable.cs | 2 +- OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs | 3 +-- OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs | 6 +++--- OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs | 4 ++-- OpenRA.Mods.RA/Widgets/RadarWidget.cs | 7 ++++--- 43 files changed, 81 insertions(+), 83 deletions(-) mode change 100755 => 100644 OpenRA.Mods.RA/Air/Aircraft.cs mode change 100755 => 100644 OpenRA.Mods.RA/RallyPoint.cs diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index 55183f8f82..35000092a8 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -104,15 +104,4 @@ namespace OpenRA #endregion } - - public static class RectangleExtensions - { - public static CPos TopLeftAsCPos(this Rectangle r) { return new CPos(r.Left, r.Top); } - public static CPos BottomRightAsCPos(this Rectangle r) { return new CPos(r.Right, r.Bottom); } - } - - public static class WorldCoordinateExtensions - { - public static CPos ToCPos(this WPos a) { return new CPos(a.X / 1024, a.Y / 1024); } - } } \ No newline at end of file diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index ef7bb5bbfc..30f09ffb1c 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -179,7 +179,7 @@ namespace OpenRA.GameRules if (target.Type == TargetType.Terrain) { - var cell = target.CenterPosition.ToCPos(); + var cell = world.Map.CellContaining(target.CenterPosition); if (!world.Map.Contains(cell)) return false; diff --git a/OpenRA.Game/Graphics/ContrailRenderable.cs b/OpenRA.Game/Graphics/ContrailRenderable.cs index 863a0d21d5..3968badd81 100644 --- a/OpenRA.Game/Graphics/ContrailRenderable.cs +++ b/OpenRA.Game/Graphics/ContrailRenderable.cs @@ -67,13 +67,13 @@ namespace OpenRA.Graphics // Start of the first line segment is the tail of the list - don't smooth it. var curPos = trail[idx(next - skip - 1)]; - var curCell = curPos.ToCPos(); + var curCell = wr.world.Map.CellContaining(curPos); var curColor = color; for (var i = 0; i < length - skip - 4; i++) { var j = next - skip - i - 2; var nextPos = Average(trail[idx(j)], trail[idx(j-1)], trail[idx(j-2)], trail[idx(j-3)]); - var nextCell = nextPos.ToCPos(); + var nextCell = wr.world.Map.CellContaining(nextPos); var nextColor = Exts.ColorLerp(i * 1f / (length - 4), color, Color.Transparent); if (!world.FogObscures(curCell) && !world.FogObscures(nextCell)) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index c28a9b7f6b..3c181f6480 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -100,6 +100,11 @@ namespace OpenRA.Graphics Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1; } + public CPos ViewToWorld(int2 view) + { + return worldRenderer.world.Map.CellContaining(worldRenderer.Position(ViewToWorldPx(view))); + } + public int2 ViewToWorldPx(int2 view) { return (1f / Zoom * view.ToFloat2()).ToInt2() + TopLeft; } public int2 WorldToViewPx(int2 world) { return (Zoom * (world - TopLeft).ToFloat2()).ToInt2(); } @@ -149,8 +154,8 @@ namespace OpenRA.Graphics { // Calculate the intersection of the visible rectangle and the map. var map = worldRenderer.world.Map; - var tl = map.Clamp(worldRenderer.Position(TopLeft).ToCPos() - new CVec(1, 1)); - var br = map.Clamp(worldRenderer.Position(BottomRight).ToCPos()); + var tl = map.Clamp(map.CellContaining(worldRenderer.Position(TopLeft)) - new CVec(1, 1)); + var br = map.Clamp(map.CellContaining(worldRenderer.Position(BottomRight))); cells = new CellRegion(tl, br); cellsDirty = false; diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index df9256d155..613c0ca986 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -471,6 +471,11 @@ namespace OpenRA return new WPos(1024 * c.X + 512, 1024 * c.Y + 512, 0); } + public CPos CellContaining(WPos pos) + { + return new CPos(pos.X / 1024, pos.Y / 1024); + } + public void Resize(int width, int height) // editor magic. { var oldMapTiles = MapTiles.Value; diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 3031ad7c30..559ad1fcd6 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -103,7 +103,7 @@ namespace OpenRA.Orders .Select(x => new { Trait = trait, Order = x })) .OrderByDescending(x => x.Order.OrderPriority)) { - var actorsAt = self.World.ActorMap.GetUnitsAt(target.CenterPosition.ToCPos()).ToList(); + var actorsAt = self.World.ActorMap.GetUnitsAt(self.World.Map.CellContaining(target.CenterPosition)).ToList(); var modifiers = TargetModifiers.None; if (mi.Modifiers.HasModifier(Modifiers.Ctrl)) diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 10f8973087..e7888cab6b 100644 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -138,9 +138,9 @@ namespace OpenRA.Traits return result.Keys; } - public static IEnumerable AdjacentCells(Target target) + public static IEnumerable AdjacentCells(World w, Target target) { - var cells = target.Positions.Select(p => p.ToCPos()).Distinct(); + var cells = target.Positions.Select(p => w.Map.CellContaining(p)).Distinct(); return ExpandFootprint(cells, true); } } diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 9692ddbff6..83c692c824 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -181,7 +181,7 @@ namespace OpenRA.Traits return cells.Select(c => c.First); } - return new[] { a.CenterPosition.ToCPos() }; + return new[] { a.World.Map.CellContaining(a.CenterPosition) }; } public void Explore(World world, CPos center, WRange range) diff --git a/OpenRA.Game/Widgets/ViewportControllerWidget.cs b/OpenRA.Game/Widgets/ViewportControllerWidget.cs index bd5a5327ab..b8d78831d9 100644 --- a/OpenRA.Game/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportControllerWidget.cs @@ -92,7 +92,7 @@ namespace OpenRA.Widgets public void UpdateMouseover() { TooltipType = WorldTooltipType.None; - var cell = worldRenderer.Position(worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); + var cell = worldRenderer.Viewport.ViewToWorld(Viewport.LastMousePos); if (!world.Map.Contains(cell)) return; diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 4f9ab0454f..f798ea70da 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -141,8 +141,7 @@ namespace OpenRA.Widgets return; var pos = worldRenderer.Position(xy); - var orders = world.OrderGenerator.Order(world, pos.ToCPos(), mi).ToArray(); - + var orders = world.OrderGenerator.Order(world, world.Map.CellContaining(pos), mi).ToArray(); world.PlayVoiceForOrders(orders); var flashed = false; @@ -180,7 +179,7 @@ namespace OpenRA.Widgets var xy = worldRenderer.Viewport.ViewToWorldPx(screenPos); var pos = worldRenderer.Position(xy); - var cell = pos.ToCPos(); + var cell = World.Map.CellContaining(pos); var mi = new MouseInput { diff --git a/OpenRA.Mods.RA/AI/States/GroundStates.cs b/OpenRA.Mods.RA/AI/States/GroundStates.cs index 8cd3da9f68..46557b60f2 100644 --- a/OpenRA.Mods.RA/AI/States/GroundStates.cs +++ b/OpenRA.Mods.RA/AI/States/GroundStates.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.AI if (owner.attackOrFleeFuzzy.CanAttack(owner.units, enemyUnits)) { foreach (var u in owner.units) - owner.world.IssueOrder(new Order("AttackMove", u, false) { TargetLocation = owner.Target.CenterPosition.ToCPos() }); + owner.world.IssueOrder(new Order("AttackMove", u, false) { TargetLocation = owner.Target.Location }); // We have gathered sufficient units. Attack the nearest enemy unit. owner.fsm.ChangeState(owner, new GroundUnitsAttackMoveState(), true); @@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA.AI { owner.world.IssueOrder(new Order("Stop", leader, false)); foreach (var unit in owner.units.Where(a => !ownUnits.Contains(a))) - owner.world.IssueOrder(new Order("AttackMove", unit, false) { TargetLocation = leader.CenterPosition.ToCPos() }); + owner.world.IssueOrder(new Order("AttackMove", unit, false) { TargetLocation = leader.Location }); } else { diff --git a/OpenRA.Mods.RA/Activities/Enter.cs b/OpenRA.Mods.RA/Activities/Enter.cs index 17d37773a2..efc30afc5d 100755 --- a/OpenRA.Mods.RA/Activities/Enter.cs +++ b/OpenRA.Mods.RA/Activities/Enter.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Activities if (target.Type != TargetType.Actor) return NextActivity; - if (!Util.AdjacentCells(target).Any(c => c == self.Location)) + if (!Util.AdjacentCells(self.World, target).Any(c => c == self.Location)) return Util.SequenceActivities(new MoveAdjacentTo(self, target), this); // Move to the middle of the target, ignoring impassable tiles diff --git a/OpenRA.Mods.RA/Activities/EnterTransport.cs b/OpenRA.Mods.RA/Activities/EnterTransport.cs index 1e4114e9bd..55597d7c31 100644 --- a/OpenRA.Mods.RA/Activities/EnterTransport.cs +++ b/OpenRA.Mods.RA/Activities/EnterTransport.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities // TODO: Queue a move order to the transport? need to be // careful about units that can't path to the transport - var cells = Util.AdjacentCells(Target.FromActor(transport)); + var cells = Util.AdjacentCells(self.World, Target.FromActor(transport)); if (!cells.Contains(self.Location)) return NextActivity; diff --git a/OpenRA.Mods.RA/Activities/LayMines.cs b/OpenRA.Mods.RA/Activities/LayMines.cs index b65fbc2e36..a3982c56ec 100644 --- a/OpenRA.Mods.RA/Activities/LayMines.cs +++ b/OpenRA.Mods.RA/Activities/LayMines.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities return Util.SequenceActivities( new MoveAdjacentTo(self, Target.FromActor(rearmTarget)), - movement.MoveTo(rearmTarget.CenterPosition.ToCPos(), rearmTarget), + movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget), new Rearm(self), new Repair(rearmTarget), this); diff --git a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs index d077a50de3..b488b5ce90 100755 --- a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs +++ b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities movementClass = (uint)mobile.Info.GetMovementClass(self.World.TileSet); if (target.IsValidFor(self)) - targetPosition = target.CenterPosition.ToCPos(); + targetPosition = self.World.Map.CellContaining(target.CenterPosition); repath = true; } @@ -73,7 +73,7 @@ namespace OpenRA.Mods.RA.Activities { // Check if the target has moved var oldTargetPosition = targetPosition; - targetPosition = target.CenterPosition.ToCPos(); + targetPosition = self.World.Map.CellContaining(target.CenterPosition); var shroudStop = ShouldStop(self, oldTargetPosition); if (shroudStop || (!repath && ShouldRepath(self, oldTargetPosition))) @@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA.Activities protected virtual IEnumerable CandidateMovementCells(Actor self) { - return Util.AdjacentCells(target); + return Util.AdjacentCells(self.World, target); } void UpdateInnerPath(Actor self) diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs old mode 100755 new mode 100644 index 5c2cb96416..61ecefd009 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Air [Sync] public int Facing { get; set; } [Sync] public WPos CenterPosition { get; private set; } - public CPos TopLeft { get { return CenterPosition.ToCPos(); } } + public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } } public IDisposable Reservation; public int ROT { get { return info.ROT; } } @@ -201,7 +201,7 @@ namespace OpenRA.Mods.RA.Air return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; if (order.OrderID == "Move") - return new Order(order.OrderID, self, queued) { TargetLocation = target.CenterPosition.ToCPos() }; + return new Order(order.OrderID, self, queued) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition) }; return null; } @@ -246,7 +246,7 @@ namespace OpenRA.Mods.RA.Air return false; IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); - cursor = self.World.Map.Contains(target.CenterPosition.ToCPos()) ? "move" : "move-blocked"; + cursor = self.World.Map.Contains(self.World.Map.CellContaining(target.CenterPosition)) ? "move" : "move-blocked"; return true; } diff --git a/OpenRA.Mods.RA/Air/TakeOff.cs b/OpenRA.Mods.RA/Air/TakeOff.cs index 97d23ed34d..6e9d728800 100644 --- a/OpenRA.Mods.RA/Air/TakeOff.cs +++ b/OpenRA.Mods.RA/Air/TakeOff.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Air var rp = hasHost ? host.TraitOrDefault() : null; var destination = rp != null ? rp.rallyPoint : - (hasHost ? host.CenterPosition.ToCPos() : self.CenterPosition.ToCPos()); + (hasHost ? self.World.Map.CellContaining(host.CenterPosition) : self.Location); return new AttackMove.AttackMoveActivity(self, self.Trait().MoveTo(destination, 1)); } diff --git a/OpenRA.Mods.RA/Attack/AttackBase.cs b/OpenRA.Mods.RA/Attack/AttackBase.cs index e17b27e917..4af7245ee1 100644 --- a/OpenRA.Mods.RA/Attack/AttackBase.cs +++ b/OpenRA.Mods.RA/Attack/AttackBase.cs @@ -107,7 +107,7 @@ namespace OpenRA.Mods.RA case TargetType.FrozenActor: return new Order("Attack", self, queued) { ExtraData = target.FrozenActor.ID }; case TargetType.Terrain: - return new Order("Attack", self, queued) { TargetLocation = target.CenterPosition.ToCPos() }; + return new Order("Attack", self, queued) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition) }; } } @@ -241,7 +241,7 @@ namespace OpenRA.Mods.RA case TargetType.FrozenActor: return CanTargetActor(self, target, modifiers, ref cursor); case TargetType.Terrain: - return CanTargetLocation(self, target.CenterPosition.ToCPos(), othersAtTarget, modifiers, ref cursor); + return CanTargetLocation(self, self.World.Map.CellContaining(target.CenterPosition), othersAtTarget, modifiers, ref cursor); default: return false; } diff --git a/OpenRA.Mods.RA/Attack/AttackWander.cs b/OpenRA.Mods.RA/Attack/AttackWander.cs index fb6adbd4d4..a3f96f7983 100644 --- a/OpenRA.Mods.RA/Attack/AttackWander.cs +++ b/OpenRA.Mods.RA/Attack/AttackWander.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA public void TickIdle(Actor self) { var target = self.CenterPosition + new WVec(0, -1024*Info.MoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255))); - self.Trait().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = target.ToCPos() }); + self.Trait().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = self.World.Map.CellContaining(target) }); } } } diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index d8dd2fd1f4..0a98f8e7cb 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -102,7 +102,7 @@ namespace OpenRA.Mods.RA IEnumerable GetAdjacentCells() { - return Util.AdjacentCells(Target.FromActor(self)).Where(c => self.Location != c); + return Util.AdjacentCells(self.World, Target.FromActor(self)).Where(c => self.Location != c); } bool CanUnload() @@ -218,7 +218,7 @@ namespace OpenRA.Mods.RA initialized = true; } - var cell = self.CenterPosition.ToCPos(); + var cell = self.World.Map.CellContaining(self.CenterPosition); if (currentCell != cell) { currentCell = cell; diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index ad28c5c17a..bc481652b1 100644 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA public static void DoImpact(WPos pos, WarheadInfo warhead, WeaponInfo weapon, Actor firedBy, float firepowerModifier) { var world = firedBy.World; - var targetTile = pos.ToCPos(); + var targetTile = world.Map.CellContaining(pos); if (!world.Map.Contains(targetTile)) return; diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index 22df8bdf43..e95b277c30 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -85,8 +85,8 @@ namespace OpenRA.Mods.RA public IEnumerable> OccupiedCells() { yield return Pair.New(Location, SubCell.FullCell); } public WPos CenterPosition { get; private set; } - public void SetPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); } - public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); } + public void SetPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); } + public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); } public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) { diff --git a/OpenRA.Mods.RA/Effects/Bullet.cs b/OpenRA.Mods.RA/Effects/Bullet.cs index c528a98a53..5f928fe8b9 100755 --- a/OpenRA.Mods.RA/Effects/Bullet.cs +++ b/OpenRA.Mods.RA/Effects/Bullet.cs @@ -134,7 +134,7 @@ namespace OpenRA.Mods.RA.Effects trail.Update(pos); if (ticks++ >= length || (!info.High && world.ActorMap - .GetUnitsAt(pos.ToCPos()).Any(a => a.HasTrait()))) + .GetUnitsAt(world.Map.CellContaining(pos)).Any(a => a.HasTrait()))) { Explode(world); } @@ -148,7 +148,7 @@ namespace OpenRA.Mods.RA.Effects if (anim == null || ticks >= length) yield break; - var cell = pos.ToCPos(); + var cell = wr.world.Map.CellContaining(pos); if (!args.SourceActor.World.FogObscures(cell)) { if (info.Shadow) diff --git a/OpenRA.Mods.RA/Effects/CashTick.cs b/OpenRA.Mods.RA/Effects/CashTick.cs index dd31afc3a0..b51d6ef9be 100644 --- a/OpenRA.Mods.RA/Effects/CashTick.cs +++ b/OpenRA.Mods.RA/Effects/CashTick.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render(WorldRenderer wr) { - if (wr.world.FogObscures(pos.ToCPos())) + if (wr.world.FogObscures(wr.world.Map.CellContaining(pos))) yield break; yield return new TextRenderable(font, pos, 0, color, text); diff --git a/OpenRA.Mods.RA/Effects/Corpse.cs b/OpenRA.Mods.RA/Effects/Corpse.cs index 17f49fd380..bbfc4a2970 100644 --- a/OpenRA.Mods.RA/Effects/Corpse.cs +++ b/OpenRA.Mods.RA/Effects/Corpse.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Effects { this.world = world; this.pos = pos; - this.cell = pos.ToCPos(); + this.cell = world.Map.CellContaining(pos); this.paletteName = paletteName; anim = new Animation(world, image); anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); diff --git a/OpenRA.Mods.RA/Effects/Explosion.cs b/OpenRA.Mods.RA/Effects/Explosion.cs index 2c4cd3900c..40e837f7a6 100644 --- a/OpenRA.Mods.RA/Effects/Explosion.cs +++ b/OpenRA.Mods.RA/Effects/Explosion.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Effects { this.world = world; this.pos = pos; - this.cell = pos.ToCPos(); + this.cell = world.Map.CellContaining(pos); this.palette = palette; anim = new Animation(world, "explosion"); anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); diff --git a/OpenRA.Mods.RA/Effects/GravityBomb.cs b/OpenRA.Mods.RA/Effects/GravityBomb.cs index 9d52e1258d..163aee1e15 100644 --- a/OpenRA.Mods.RA/Effects/GravityBomb.cs +++ b/OpenRA.Mods.RA/Effects/GravityBomb.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render(WorldRenderer wr) { - var cell = pos.ToCPos(); + var cell = wr.world.Map.CellContaining(pos); if (!args.SourceActor.World.FogObscures(cell)) { if (info.Shadow) diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 1404b41639..7ad4eb8a7e 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -154,7 +154,7 @@ namespace OpenRA.Mods.RA.Effects if (info.ContrailLength > 0) trail.Update(pos); - var cell = pos.ToCPos(); + var cell = world.Map.CellContaining(pos); var shouldExplode = (pos.Z < 0) // Hit the ground || (dist.LengthSquared < MissileCloseEnough.Range * MissileCloseEnough.Range) // Within range @@ -186,7 +186,7 @@ namespace OpenRA.Mods.RA.Effects if (info.ContrailLength > 0) yield return trail; - if (!args.SourceActor.World.FogObscures(pos.ToCPos())) + if (!args.SourceActor.World.FogObscures(wr.world.Map.CellContaining(pos))) { var palette = wr.Palette(args.Weapon.Palette); foreach (var r in anim.Render(pos, palette)) diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 2726d92725..f05adcc035 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Effects parachuteOffset = pai.Offset; // Adjust x,y to match the target subcell - cargo.Trait().SetPosition(cargo, dropPosition.ToCPos()); + cargo.Trait().SetPosition(cargo, cargo.World.Map.CellContaining(dropPosition)); var cp = cargo.CenterPosition; pos = new WPos(cp.X, cp.Y, dropPosition.Z); } diff --git a/OpenRA.Mods.RA/Effects/Smoke.cs b/OpenRA.Mods.RA/Effects/Smoke.cs index 857ef58c6a..ac8ba2679a 100644 --- a/OpenRA.Mods.RA/Effects/Smoke.cs +++ b/OpenRA.Mods.RA/Effects/Smoke.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Effects { this.world = world; this.pos = pos; - this.cell = pos.ToCPos(); + this.cell = world.Map.CellContaining(pos); anim = new Animation(world, trail); anim.PlayThen("idle", diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index c8de7d3183..a18a53e208 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -260,7 +260,7 @@ namespace OpenRA.Mods.RA return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; if (order.OrderID == "Harvest") - return new Order(order.OrderID, self, queued) { TargetLocation = target.CenterPosition.ToCPos() }; + return new Order(order.OrderID, self, queued) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition) }; return null; } @@ -437,7 +437,7 @@ namespace OpenRA.Mods.RA if (modifiers.HasModifier(TargetModifiers.ForceMove)) return false; - var location = target.CenterPosition.ToCPos(); + var location = self.World.Map.CellContaining(target.CenterPosition); // Don't leak info about resources under the shroud if (!self.Owner.Shroud.IsExplored(location)) return false; diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index e81151c1f6..aabf691e5a 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA { self.World.ActorMap.RemoveInfluence(self, this); CenterPosition = pos; - TopLeft = pos.ToCPos(); + TopLeft = self.World.Map.CellContaining(pos); self.World.ActorMap.AddInfluence(self, this); self.World.ActorMap.UpdatePosition(self, this); self.World.ScreenMap.Update(self); diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index d8679b7f5a..c3a1e0bda4 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA switch (order.OrderID) { case "BeginMinefield": - var start = target.CenterPosition.ToCPos(); + var start = self.World.Map.CellContaining(target.CenterPosition); self.World.OrderGenerator = new MinefieldOrderGenerator(self, start); return new Order("BeginMinefield", self, false) { TargetLocation = start }; case "PlaceMine": @@ -201,7 +201,7 @@ namespace OpenRA.Mods.RA if (target.Type != TargetType.Terrain) return false; - var location = target.CenterPosition.ToCPos(); + var location = self.World.Map.CellContaining(target.CenterPosition); if (!self.World.Map.Contains(location)) return false; diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 22a46dc35f..e6b6566a03 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -266,7 +266,7 @@ namespace OpenRA.Mods.RA.Move public void SetPosition(Actor self, WPos pos) { - var cell = pos.ToCPos(); + var cell = self.World.Map.CellContaining(pos); SetLocation(cell, fromSubCell, cell, fromSubCell); SetVisualPosition(self, pos); FinishedMoving(self); @@ -306,7 +306,7 @@ namespace OpenRA.Mods.RA.Move if (Info.OnRails) return null; - return new Order("Move", self, queued) { TargetLocation = target.CenterPosition.ToCPos() }; + return new Order("Move", self, queued) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition) }; } return null; } @@ -573,7 +573,7 @@ namespace OpenRA.Mods.RA.Move if (rejectMove || !target.IsValidFor(self)) return false; - var location = target.CenterPosition.ToCPos(); + var location = self.World.Map.CellContaining(target.CenterPosition); IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); cursor = "move"; diff --git a/OpenRA.Mods.RA/Move/PathFinder.cs b/OpenRA.Mods.RA/Move/PathFinder.cs index c1431f5445..abaeb49b74 100644 --- a/OpenRA.Mods.RA/Move/PathFinder.cs +++ b/OpenRA.Mods.RA/Move/PathFinder.cs @@ -85,7 +85,7 @@ namespace OpenRA.Mods.RA.Move using (new PerfSample("Pathfinder")) { var mi = self.Info.Traits.Get(); - var targetCell = target.ToCPos(); + var targetCell = self.World.Map.CellContaining(target); var rangeSquared = range.Range*range.Range; // Correct for SubCell offset diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 8d5742f97d..25a99409cb 100644 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -79,14 +79,14 @@ namespace OpenRA.Mods.RA.Orders public IEnumerable Render(WorldRenderer wr, World world) { yield break; } public void RenderAfterWorld(WorldRenderer wr, World world) { - var position = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); - var topLeft = position - FootprintUtils.AdjustForBuildingSize(BuildingInfo); + var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); + var topLeft = xy - FootprintUtils.AdjustForBuildingSize(BuildingInfo); var rules = world.Map.Rules; var actorInfo = rules.Actors[Building]; foreach (var dec in actorInfo.Traits.WithInterface()) - dec.Render(wr, world, actorInfo, world.Map.CenterOfCell(position)); + dec.Render(wr, world, actorInfo, world.Map.CenterOfCell(xy)); var cells = new Dictionary(); // Linebuild for walls. diff --git a/OpenRA.Mods.RA/PortableChrono.cs b/OpenRA.Mods.RA/PortableChrono.cs index da75f2a3d6..0107eb42d3 100644 --- a/OpenRA.Mods.RA/PortableChrono.cs +++ b/OpenRA.Mods.RA/PortableChrono.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA self.World.OrderGenerator = new PortableChronoOrderGenerator(self); if (order.OrderID == "PortableChronoTeleport") - return new Order(order.OrderID, self, queued) { TargetLocation = target.CenterPosition.ToCPos() }; + return new Order(order.OrderID, self, queued) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition) }; return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; } @@ -120,7 +120,7 @@ namespace OpenRA.Mods.RA // TODO: When target modifiers are configurable this needs to be revisited if (modifiers.HasModifier(TargetModifiers.ForceMove) || modifiers.HasModifier(TargetModifiers.ForceQueue)) { - var xy = target.CenterPosition.ToCPos(); + var xy = self.World.Map.CellContaining(target.CenterPosition); IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); @@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA yield break; } - if (self.IsInWorld && self.CenterPosition.ToCPos() != xy + if (self.IsInWorld && self.Location != xy && self.Trait().CanTeleport && self.Owner.Shroud.IsExplored(xy)) { world.CancelInputMode(); @@ -190,7 +190,7 @@ namespace OpenRA.Mods.RA public string GetCursor(World world, CPos xy, MouseInput mi) { - if (self.IsInWorld && self.CenterPosition.ToCPos() != xy + if (self.IsInWorld && self.Location != xy && self.Trait().CanTeleport && self.Owner.Shroud.IsExplored(xy)) return "chrono-target"; else diff --git a/OpenRA.Mods.RA/RallyPoint.cs b/OpenRA.Mods.RA/RallyPoint.cs old mode 100755 new mode 100644 index 3257659ab6..737f21e647 --- a/OpenRA.Mods.RA/RallyPoint.cs +++ b/OpenRA.Mods.RA/RallyPoint.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) { if (order.OrderID == "SetRallyPoint") - return new Order(order.OrderID, self, false) { TargetLocation = target.CenterPosition.ToCPos(), SuppressVisualFeedback = true }; + return new Order(order.OrderID, self, false) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition), SuppressVisualFeedback = true }; return null; } @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA if (target.Type != TargetType.Terrain) return false; - var location = target.CenterPosition.ToCPos(); + var location = self.World.Map.CellContaining(target.CenterPosition); if (self.World.Map.Contains(location)) { cursor = "ability"; diff --git a/OpenRA.Mods.RA/Repairable.cs b/OpenRA.Mods.RA/Repairable.cs index 96e8352da5..87d1b36408 100644 --- a/OpenRA.Mods.RA/Repairable.cs +++ b/OpenRA.Mods.RA/Repairable.cs @@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA self.CancelActivity(); self.QueueActivity(new MoveAdjacentTo(self, target)); - self.QueueActivity(movement.MoveTo(order.TargetActor.CenterPosition.ToCPos(), order.TargetActor)); + self.QueueActivity(movement.MoveTo(self.World.Map.CellContaining(order.TargetActor.CenterPosition), order.TargetActor)); self.QueueActivity(new Rearm(self)); self.QueueActivity(new Repair(order.TargetActor)); diff --git a/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs b/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs index 696e4dc16b..88ce26d616 100644 --- a/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs +++ b/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs @@ -41,8 +41,7 @@ namespace OpenRA.Mods.RA if (--ticks <= 0) { var position = self.CenterPosition; - if (position.Z > 0 && self.GetDamageState() >= info.MinDamage && - !self.World.FogObscures(position.ToCPos())) + if (position.Z > 0 && self.GetDamageState() >= info.MinDamage && !self.World.FogObscures(self)) { var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation)); var pos = position + body.LocalToWorld(offset); diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index 78e9ecdb1c..b07666206a 100644 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA public void RenderAfterWorld(WorldRenderer wr, World world) { - var xy = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); + var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var targetUnits = power.UnitsInRange(xy); foreach (var unit in targetUnits) if (manager.self.Owner.Shroud.IsTargetable(unit)) @@ -132,7 +132,7 @@ namespace OpenRA.Mods.RA public IEnumerable Render(WorldRenderer wr, World world) { - var xy = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); + var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var tiles = world.Map.FindTilesInCircle(xy, range); var pal = wr.Palette("terrain"); foreach (var t in tiles) @@ -212,7 +212,7 @@ namespace OpenRA.Mods.RA public IEnumerable Render(WorldRenderer wr, World world) { - var xy = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); + var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var pal = wr.Palette("terrain"); // Source tiles diff --git a/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs b/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs index 62fd6b944a..aeffdb40b8 100644 --- a/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs @@ -100,14 +100,14 @@ namespace OpenRA.Mods.RA public void RenderAfterWorld(WorldRenderer wr, World world) { - var xy = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); + var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); foreach (var unit in power.UnitsInRange(xy)) wr.DrawSelectionBox(unit, Color.Red); } public IEnumerable Render(WorldRenderer wr, World world) { - var xy = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); + var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var pal = wr.Palette("terrain"); foreach (var t in world.Map.FindTilesInCircle(xy, range)) diff --git a/OpenRA.Mods.RA/Widgets/RadarWidget.cs b/OpenRA.Mods.RA/Widgets/RadarWidget.cs index 51717074a2..13d5d0e8d3 100755 --- a/OpenRA.Mods.RA/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.RA/Widgets/RadarWidget.cs @@ -158,8 +158,8 @@ namespace OpenRA.Mods.RA.Widgets // Draw viewport rect if (hasRadar) { - var tl = CellToMinimapPixel(worldRenderer.Position(worldRenderer.Viewport.TopLeft).ToCPos()); - var br = CellToMinimapPixel(worldRenderer.Position(worldRenderer.Viewport.BottomRight).ToCPos()); + var tl = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.Position(worldRenderer.Viewport.TopLeft))); + var br = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.Position(worldRenderer.Viewport.BottomRight))); Game.Renderer.EnableScissor(mapRect); DrawRadarPings(); @@ -180,7 +180,8 @@ namespace OpenRA.Mods.RA.Widgets foreach (var radarPing in radarPings.Pings.Where(e => e.IsVisible())) { var c = radarPing.Color; - var points = radarPing.Points(CellToMinimapPixel(radarPing.Position.ToCPos())).ToArray(); + var pingCell = world.Map.CellContaining(radarPing.Position); + var points = radarPing.Points(CellToMinimapPixel(pingCell)).ToArray(); lr.DrawLine(points[0], points[1], c, c); lr.DrawLine(points[1], points[2], c, c);