Replace WPos.ToCPos -> Map.CellContaining.
This commit is contained in:
@@ -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); }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -138,9 +138,9 @@ namespace OpenRA.Traits
|
||||
return result.Keys;
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> AdjacentCells(Target target)
|
||||
public static IEnumerable<CPos> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user