Merge pull request #5758 from pchote/cell-world-conversions

Generalize cell/world coordinate conversions.
This commit is contained in:
Matthias Mailänder
2014-06-28 08:27:18 +02:00
100 changed files with 289 additions and 298 deletions

View File

@@ -37,13 +37,6 @@ namespace OpenRA
public static CPos Max(CPos a, CPos b) { return new CPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } public static CPos Max(CPos a, CPos b) { return new CPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
public static CPos Min(CPos a, CPos b) { return new CPos(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); } public static CPos Min(CPos a, CPos b) { return new CPos(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public WPos CenterPosition { get { return new WPos(1024 * X + 512, 1024 * Y + 512, 0); } }
public WPos TopLeft { get { return new WPos(1024 * X, 1024 * Y, 0); } }
public WPos BottomRight { get { return new WPos(1024 * X + 1023, 1024 * Y + 1023, 0); } }
public CPos Clamp(Rectangle r) public CPos Clamp(Rectangle r)
{ {
return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)), return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)),
@@ -108,16 +101,4 @@ namespace OpenRA
#endregion #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); }
public static CVec ToCVec(this WVec a) { return new CVec(a.X / 1024, a.Y / 1024); }
}
} }

View File

@@ -21,13 +21,8 @@ namespace OpenRA
public readonly int X, Y; public readonly int X, Y;
public CVec(int x, int y) { X = x; Y = y; } public CVec(int x, int y) { X = x; Y = y; }
public CVec(Size p) { X = p.Width; Y = p.Height; }
public static readonly CVec Zero = new CVec(0, 0); public static readonly CVec Zero = new CVec(0, 0);
public static explicit operator CVec(int2 a) { return new CVec(a.X, a.Y); }
public static explicit operator CVec(float2 a) { return new CVec((int)a.X, (int)a.Y); }
public static CVec operator +(CVec a, CVec b) { return new CVec(a.X + b.X, a.Y + b.Y); } public static CVec operator +(CVec a, CVec b) { return new CVec(a.X + b.X, a.Y + b.Y); }
public static CVec operator -(CVec a, CVec b) { return new CVec(a.X - b.X, a.Y - b.Y); } public static CVec operator -(CVec a, CVec b) { return new CVec(a.X - b.X, a.Y - b.Y); }
public static CVec operator *(int a, CVec b) { return new CVec(a * b.X, a * b.Y); } public static CVec operator *(int a, CVec b) { return new CVec(a * b.X, a * b.Y); }
@@ -49,10 +44,6 @@ namespace OpenRA
public int LengthSquared { get { return X * X + Y * Y; } } public int LengthSquared { get { return X * X + Y * Y; } }
public int Length { get { return (int)Math.Sqrt(LengthSquared); } } public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public WVec ToWVec() { return new WVec(X*1024, Y*1024, 0); }
public CVec Clamp(Rectangle r) public CVec Clamp(Rectangle r)
{ {
return new CVec( return new CVec(
@@ -122,7 +113,6 @@ namespace OpenRA
{ {
case "X": return X; case "X": return X;
case "Y": return Y; case "Y": return Y;
case "Facing": return Traits.Util.GetFacing(this, 0);
default: throw new LuaException("CVec does not define a member '{0}'".F(key)); default: throw new LuaException("CVec does not define a member '{0}'".F(key));
} }
} }

View File

@@ -179,7 +179,7 @@ namespace OpenRA.GameRules
if (target.Type == TargetType.Terrain) if (target.Type == TargetType.Terrain)
{ {
var cell = target.CenterPosition.ToCPos(); var cell = world.Map.CellContaining(target.CenterPosition);
if (!world.Map.Contains(cell)) if (!world.Map.Contains(cell))
return false; return false;

View File

@@ -67,13 +67,13 @@ namespace OpenRA.Graphics
// Start of the first line segment is the tail of the list - don't smooth it. // Start of the first line segment is the tail of the list - don't smooth it.
var curPos = trail[idx(next - skip - 1)]; var curPos = trail[idx(next - skip - 1)];
var curCell = curPos.ToCPos(); var curCell = wr.world.Map.CellContaining(curPos);
var curColor = color; var curColor = color;
for (var i = 0; i < length - skip - 4; i++) for (var i = 0; i < length - skip - 4; i++)
{ {
var j = next - skip - i - 2; 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 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); var nextColor = Exts.ColorLerp(i * 1f / (length - 4), color, Color.Transparent);
if (!world.FogObscures(curCell) && !world.FogObscures(nextCell)) if (!world.FogObscures(curCell) && !world.FogObscures(nextCell))

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Graphics
foreach (var cell in map.Cells) foreach (var cell in map.Cells)
{ {
var tile = wr.Theater.TileSprite(map.MapTiles.Value[cell]); var tile = wr.Theater.TileSprite(map.MapTiles.Value[cell]);
var pos = wr.ScreenPosition(cell.CenterPosition) - 0.5f * tile.size; var pos = wr.ScreenPosition(map.CenterOfCell(cell)) - 0.5f * tile.size;
Util.FastCreateQuad(vertices, pos, tile, terrainPalette, nv, tile.size); Util.FastCreateQuad(vertices, pos, tile, terrainPalette, nv, tile.size);
nv += 4; nv += 4;
} }

19
OpenRA.Game/Graphics/Viewport.cs Executable file → Normal file
View File

@@ -90,14 +90,21 @@ namespace OpenRA.Graphics
// Calculate map bounds in world-px // Calculate map bounds in world-px
var b = map.Bounds; var b = map.Bounds;
var tl = wr.ScreenPxPosition(new CPos(b.Left, b.Top).TopLeft);
var br = wr.ScreenPxPosition(new CPos(b.Right, b.Bottom).BottomRight); // Expand to corners of cells
var tl = wr.ScreenPxPosition(map.CenterOfCell(new CPos(b.Left, b.Top)) - new WVec(512, 512, 0));
var br = wr.ScreenPxPosition(map.CenterOfCell(new CPos(b.Right, b.Bottom)) + new WVec(511, 511, 0));
mapBounds = Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y); mapBounds = Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y);
CenterLocation = (tl + br) / 2; CenterLocation = (tl + br) / 2;
Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1; 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 ViewToWorldPx(int2 view) { return (1f / Zoom * view.ToFloat2()).ToInt2() + TopLeft; }
public int2 WorldToViewPx(int2 world) { return (Zoom * (world - TopLeft).ToFloat2()).ToInt2(); } public int2 WorldToViewPx(int2 world) { return (Zoom * (world - TopLeft).ToFloat2()).ToInt2(); }
@@ -131,8 +138,8 @@ namespace OpenRA.Graphics
{ {
get get
{ {
var ctl = VisibleCells.TopLeft.TopLeft; var ctl = worldRenderer.world.Map.CenterOfCell(VisibleCells.TopLeft) - new WVec(512, 512, 0);
var cbr = VisibleCells.BottomRight.BottomRight; var cbr = worldRenderer.world.Map.CenterOfCell(VisibleCells.BottomRight) + new WVec(511, 511, 0);
var tl = WorldToViewPx(worldRenderer.ScreenPxPosition(ctl)).Clamp(ScreenClip); var tl = WorldToViewPx(worldRenderer.ScreenPxPosition(ctl)).Clamp(ScreenClip);
var br = WorldToViewPx(worldRenderer.ScreenPxPosition(cbr)).Clamp(ScreenClip); var br = WorldToViewPx(worldRenderer.ScreenPxPosition(cbr)).Clamp(ScreenClip);
return Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y); return Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y);
@@ -147,8 +154,8 @@ namespace OpenRA.Graphics
{ {
// Calculate the intersection of the visible rectangle and the map. // Calculate the intersection of the visible rectangle and the map.
var map = worldRenderer.world.Map; var map = worldRenderer.world.Map;
var tl = map.Clamp(worldRenderer.Position(TopLeft).ToCPos() - new CVec(1, 1)); var tl = map.Clamp(map.CellContaining(worldRenderer.Position(TopLeft)) - new CVec(1, 1));
var br = map.Clamp(worldRenderer.Position(BottomRight).ToCPos()); var br = map.Clamp(map.CellContaining(worldRenderer.Position(BottomRight)));
cells = new CellRegion(tl, br); cells = new CellRegion(tl, br);
cellsDirty = false; cellsDirty = false;

View File

@@ -57,10 +57,10 @@ namespace OpenRA
public class LocationInit : IActorInit<CPos> public class LocationInit : IActorInit<CPos>
{ {
[FieldFromYamlKey] public readonly int2 value = int2.Zero; [FieldFromYamlKey] public readonly CPos value = CPos.Zero;
public LocationInit() { } public LocationInit() { }
public LocationInit(CPos init) { value = init.ToInt2(); } public LocationInit(CPos init) { value = init; }
public CPos Value(World world) { return (CPos)value; } public CPos Value(World world) { return value; }
} }
public class SubCellInit : IActorInit<SubCell> public class SubCellInit : IActorInit<SubCell>

View File

@@ -463,7 +463,25 @@ namespace OpenRA
return dataStream.ToArray(); return dataStream.ToArray();
} }
public bool Contains(CPos xy) { return Bounds.Contains(xy.X, xy.Y); } public bool Contains(CPos cell)
{
return Bounds.Contains(cell.X, cell.Y);
}
public WPos CenterOfCell(CPos c)
{
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 int FacingBetween(CPos cell, CPos towards, int fallbackfacing)
{
return Traits.Util.GetFacing(CenterOfCell(towards) - CenterOfCell(cell), fallbackfacing);
}
public void Resize(int width, int height) // editor magic. public void Resize(int width, int height) // editor magic.
{ {
@@ -604,8 +622,8 @@ namespace OpenRA
public WRange DistanceToEdge(WPos pos, WVec dir) public WRange DistanceToEdge(WPos pos, WVec dir)
{ {
var tl = Bounds.TopLeftAsCPos().TopLeft; var tl = CenterOfCell(new CPos(Bounds.Left, Bounds.Top)) - new WVec(512, 512, 0);
var br = Bounds.BottomRightAsCPos().BottomRight; var br = CenterOfCell(new CPos(Bounds.Right, Bounds.Bottom)) + new WVec(511, 511, 0);
var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? tl.X : br.X) - pos.X) / dir.X; var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? tl.X : br.X) - pos.X) / dir.X;
var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? tl.Y : br.Y) - pos.Y) / dir.Y; var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? tl.Y : br.Y) - pos.Y) / dir.Y;
return new WRange(Math.Min(x, y) * dir.Length); return new WRange(Math.Min(x, y) * dir.Length);

View File

@@ -113,11 +113,11 @@ namespace OpenRA
if (TargetActor != null) if (TargetActor != null)
w.Write(UIntFromActor(TargetActor)); w.Write(UIntFromActor(TargetActor));
if (TargetLocation != CPos.Zero) if (TargetLocation != CPos.Zero)
w.Write(TargetLocation.ToInt2()); w.Write(TargetLocation);
if (TargetString != null) if (TargetString != null)
w.Write(TargetString); w.Write(TargetString);
if (ExtraLocation != CPos.Zero) if (ExtraLocation != CPos.Zero)
w.Write(ExtraLocation.ToInt2()); w.Write(ExtraLocation);
if (ExtraData != 0) if (ExtraData != 0)
w.Write(ExtraData); w.Write(ExtraData);

View File

@@ -58,5 +58,11 @@ namespace OpenRA.Network
w.Write(p.X); w.Write(p.X);
w.Write(p.Y); w.Write(p.Y);
} }
public static void Write(this BinaryWriter w, CPos cell)
{
w.Write(cell.X);
w.Write(cell.Y);
}
} }
} }

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Orders
var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi) var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi)
.Where(a => a.Info.Traits.Contains<ITargetableInfo>()) .Where(a => a.Info.Traits.Contains<ITargetableInfo>())
.WithHighestSelectionPriority(); .WithHighestSelectionPriority();
target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(xy); target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(world, xy);
} }
var orders = world.Selection.Actors var orders = world.Selection.Actors
@@ -76,7 +76,7 @@ namespace OpenRA.Orders
var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi) var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi)
.Where(a => a.Info.Traits.Contains<ITargetableInfo>()) .Where(a => a.Info.Traits.Contains<ITargetableInfo>())
.WithHighestSelectionPriority(); .WithHighestSelectionPriority();
target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(xy); target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(world, xy);
} }
var orders = world.Selection.Actors var orders = world.Selection.Actors
@@ -103,7 +103,7 @@ namespace OpenRA.Orders
.Select(x => new { Trait = trait, Order = x })) .Select(x => new { Trait = trait, Order = x }))
.OrderByDescending(x => x.Order.OrderPriority)) .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; var modifiers = TargetModifiers.None;
if (mi.Modifiers.HasModifier(Modifiers.Ctrl)) if (mi.Modifiers.HasModifier(Modifiers.Ctrl))

View File

@@ -28,12 +28,12 @@ namespace OpenRA.Traits
int generation; int generation;
public static Target FromPos(WPos p) { return new Target { pos = p, type = TargetType.Terrain }; } public static Target FromPos(WPos p) { return new Target { pos = p, type = TargetType.Terrain }; }
public static Target FromCell(CPos c) { return new Target { pos = c.CenterPosition, type = TargetType.Terrain }; } public static Target FromCell(World w, CPos c) { return new Target { pos = w.Map.CenterOfCell(c), type = TargetType.Terrain }; }
public static Target FromOrder(Order o) public static Target FromOrder(World w, Order o)
{ {
return o.TargetActor != null return o.TargetActor != null
? FromActor(o.TargetActor) ? FromActor(o.TargetActor)
: FromCell(o.TargetLocation); : FromCell(w, o.TargetLocation);
} }
public static Target FromActor(Actor a) public static Target FromActor(Actor a)

View File

@@ -42,11 +42,6 @@ namespace OpenRA.Traits
return (angle / 4 - 0x40) & 0xFF; return (angle / 4 - 0x40) & 0xFF;
} }
public static int GetFacing(CVec d, int currentFacing)
{
return GetFacing(d.ToWVec(), currentFacing);
}
public static int GetNearestFacing(int facing, int desiredFacing) public static int GetNearestFacing(int facing, int desiredFacing)
{ {
var turn = desiredFacing - facing; var turn = desiredFacing - facing;
@@ -65,9 +60,9 @@ namespace OpenRA.Traits
return a / step; return a / step;
} }
public static WPos BetweenCells(CPos from, CPos to) public static WPos BetweenCells(World w, CPos from, CPos to)
{ {
return WPos.Lerp(from.CenterPosition, to.CenterPosition, 1, 2); return WPos.Lerp(w.Map.CenterOfCell(from), w.Map.CenterOfCell(to), 1, 2);
} }
public static Activity SequenceActivities(params Activity[] acts) public static Activity SequenceActivities(params Activity[] acts)
@@ -138,9 +133,9 @@ namespace OpenRA.Traits
return result.Keys; 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); return ExpandFootprint(cells, true);
} }
} }

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Traits
var c = render[cell]; var c = render[cell];
if (c.Sprite != null) if (c.Sprite != null)
new SpriteRenderable(c.Sprite, cell.CenterPosition, new SpriteRenderable(c.Sprite, wr.world.Map.CenterOfCell(cell),
WVec.Zero, -511, c.Type.Palette, 1f, true).Render(wr); WVec.Zero, -511, c.Type.Palette, 1f, true).Render(wr);
} }
} }

View File

@@ -65,12 +65,13 @@ namespace OpenRA.Traits
static IEnumerable<CPos> FindVisibleTiles(World world, CPos position, WRange radius) static IEnumerable<CPos> FindVisibleTiles(World world, CPos position, WRange radius)
{ {
var map = world.Map;
var r = (radius.Range + 1023) / 1024; var r = (radius.Range + 1023) / 1024;
var limit = radius.Range * radius.Range; var limit = radius.Range * radius.Range;
var pos = position.CenterPosition; var pos = map.CenterOfCell(position);
foreach (var cell in world.Map.FindTilesInCircle(position, r)) foreach (var cell in map.FindTilesInCircle(position, r))
if ((cell.CenterPosition - pos).HorizontalLengthSquared <= limit) if ((map.CenterOfCell(cell) - pos).HorizontalLengthSquared <= limit)
yield return cell; yield return cell;
} }
@@ -180,7 +181,7 @@ namespace OpenRA.Traits
return cells.Select(c => c.First); 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) public void Explore(World world, CPos center, WRange range)

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Widgets
public void UpdateMouseover() public void UpdateMouseover()
{ {
TooltipType = WorldTooltipType.None; 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)) if (!world.Map.Contains(cell))
return; return;

View File

@@ -141,8 +141,7 @@ namespace OpenRA.Widgets
return; return;
var pos = worldRenderer.Position(xy); 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); world.PlayVoiceForOrders(orders);
var flashed = false; var flashed = false;
@@ -180,7 +179,7 @@ namespace OpenRA.Widgets
var xy = worldRenderer.Viewport.ViewToWorldPx(screenPos); var xy = worldRenderer.Viewport.ViewToWorldPx(screenPos);
var pos = worldRenderer.Position(xy); var pos = worldRenderer.Position(xy);
var cell = pos.ToCPos(); var cell = World.Map.CellContaining(pos);
var mi = new MouseInput var mi = new MouseInput
{ {

View File

@@ -20,17 +20,6 @@ namespace OpenRA
{ {
public static class WorldUtils public static class WorldUtils
{ {
public static IEnumerable<Actor> FindActorsInBox(this World world, CPos tl, CPos br)
{
// TODO: Support diamond boxes for isometric maps?
return world.FindActorsInBox(tl.TopLeft, br.BottomRight);
}
public static IEnumerable<Actor> FindActorsInBox(this World world, WPos tl, WPos br)
{
return world.ActorMap.ActorsInBox(tl, br);
}
public static Actor ClosestTo(this IEnumerable<Actor> actors, Actor a) public static Actor ClosestTo(this IEnumerable<Actor> actors, Actor a)
{ {
return actors.ClosestTo(a.CenterPosition); return actors.ClosestTo(a.CenterPosition);
@@ -48,7 +37,7 @@ namespace OpenRA
// Target ranges are calculated in 2D, so ignore height differences // Target ranges are calculated in 2D, so ignore height differences
var vec = new WVec(r, r, WRange.Zero); var vec = new WVec(r, r, WRange.Zero);
var rSq = r.Range*r.Range; var rSq = r.Range*r.Range;
return world.FindActorsInBox(origin - vec, origin + vec).Where( return world.ActorMap.ActorsInBox(origin - vec, origin + vec).Where(
a => (a.CenterPosition - origin).HorizontalLengthSquared <= rSq); a => (a.CenterPosition - origin).HorizontalLengthSquared <= rSq);
} }
} }

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.Effects
this.firedBy = firedBy; this.firedBy = firedBy;
this.weapon = weapon; this.weapon = weapon;
this.palette = palette; this.palette = palette;
target = Target.FromCell(location); target = Target.FromCell(world, location);
anim = new Animation(world, effect); anim = new Animation(world, effect);
anim.PlayThen("idle", () => Finish(world)); anim.PlayThen("idle", () => Finish(world));
} }

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {
var info = Info as IonCannonPowerInfo; var info = Info as IonCannonPowerInfo;
Sound.Play(Info.LaunchSound, order.TargetLocation.CenterPosition); Sound.Play(Info.LaunchSound, self.World.Map.CenterOfCell(order.TargetLocation));
w.Add(new IonCannon(self.Owner, info.Weapon, w, order.TargetLocation, info.Effect, info.EffectPalette)); w.Add(new IonCannon(self.Owner, info.Weapon, w, order.TargetLocation, info.Effect, info.EffectPalette));
if (info.CameraActor == null) if (info.CameraActor == null)

View File

@@ -55,12 +55,12 @@ namespace OpenRA.Mods.Cnc
var altitude = self.World.Map.Rules.Actors[actorType].Traits.Get<PlaneInfo>().CruiseAltitude; var altitude = self.World.Map.Rules.Actors[actorType].Traits.Get<PlaneInfo>().CruiseAltitude;
var a = w.CreateActor(actorType, new TypeDictionary var a = w.CreateActor(actorType, new TypeDictionary
{ {
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)), new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(owner), new OwnerInit(owner),
new FacingInit(64) new FacingInit(64)
}); });
a.QueueActivity(new Fly(a, Target.FromCell(self.Location + new CVec(9, 0)))); a.QueueActivity(new Fly(a, Target.FromCell(w, self.Location + new CVec(9, 0))));
a.QueueActivity(new Land(Target.FromActor(self))); a.QueueActivity(new Land(Target.FromActor(self)));
a.QueueActivity(new CallFunc(() => a.QueueActivity(new CallFunc(() =>
{ {
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Cnc
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Country.Race); Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Country.Race);
})); }));
a.QueueActivity(new Fly(a, Target.FromCell(endPos))); a.QueueActivity(new Fly(a, Target.FromCell(w, endPos)));
a.QueueActivity(new RemoveSelf()); a.QueueActivity(new RemoveSelf());
}); });

View File

@@ -348,7 +348,7 @@ namespace OpenRA.Mods.RA.AI
for (var k = MaxBaseDistance; k >= 0; k--) for (var k = MaxBaseDistance; k >= 0; k--)
{ {
var tlist = Map.FindTilesInCircle(center, k) var tlist = Map.FindTilesInCircle(center, k)
.OrderBy(a => (a.CenterPosition - pos).LengthSquared); .OrderBy(a => (world.Map.CenterOfCell(a) - pos).LengthSquared);
foreach (var t in tlist) foreach (var t in tlist)
if (world.CanPlaceBuilding(actorType, bi, t, null)) if (world.CanPlaceBuilding(actorType, bi, t, null))
@@ -360,10 +360,11 @@ namespace OpenRA.Mods.RA.AI
return null; return null;
}; };
var baseCenterPos = world.Map.CenterOfCell(baseCenter);
switch (type) switch (type)
{ {
case BuildingType.Defense: case BuildingType.Defense:
var enemyBase = FindEnemyBuildingClosestToPos(baseCenter.CenterPosition); var enemyBase = FindEnemyBuildingClosestToPos(baseCenterPos);
return enemyBase != null ? findPos(enemyBase.CenterPosition, defenseCenter) : null; return enemyBase != null ? findPos(enemyBase.CenterPosition, defenseCenter) : null;
case BuildingType.Refinery: case BuildingType.Refinery:
@@ -371,11 +372,12 @@ namespace OpenRA.Mods.RA.AI
.Where(a => resourceTypeIndices.Contains(Map.GetTerrainIndex(new CPos(a.X, a.Y)))); .Where(a => resourceTypeIndices.Contains(Map.GetTerrainIndex(new CPos(a.X, a.Y))));
if (tilesPos.Any()) if (tilesPos.Any())
{ {
var pos = tilesPos.MinBy(a => (a.CenterPosition - baseCenter.CenterPosition).LengthSquared); var pos = tilesPos.MinBy(a => (world.Map.CenterOfCell(a) - baseCenterPos).LengthSquared);
return findPos(pos.CenterPosition, baseCenter); return findPos(world.Map.CenterOfCell(pos), baseCenter);
} }
return null; return null;
case BuildingType.Building: case BuildingType.Building:
for (var k = 0; k < maxBaseDistance; k++) for (var k = 0; k < maxBaseDistance; k++)
{ {
@@ -441,7 +443,7 @@ namespace OpenRA.Mods.RA.AI
// Pick something worth attacking owned by that player // Pick something worth attacking owned by that player
var target = world.Actors var target = world.Actors
.Where(a => a.Owner == enemy && a.HasTrait<IOccupySpace>()) .Where(a => a.Owner == enemy && a.HasTrait<IOccupySpace>())
.ClosestTo(baseCenter.CenterPosition); .ClosestTo(world.Map.CenterOfCell(baseCenter));
if (target == null) if (target == null)
{ {
@@ -661,7 +663,7 @@ namespace OpenRA.Mods.RA.AI
if (!protectSq.IsValid) if (!protectSq.IsValid)
{ {
var ownUnits = world.FindActorsInCircle(baseCenter.CenterPosition, WRange.FromCells(Info.ProtectUnitScanRadius)) var ownUnits = world.FindActorsInCircle(world.Map.CenterOfCell(baseCenter), WRange.FromCells(Info.ProtectUnitScanRadius))
.Where(unit => unit.Owner == p && !unit.HasTrait<Building>() .Where(unit => unit.Owner == p && !unit.HasTrait<Building>()
&& unit.HasTrait<AttackBase>()).ToList(); && unit.HasTrait<AttackBase>()).ToList();
@@ -790,8 +792,8 @@ namespace OpenRA.Mods.RA.AI
{ {
for (var j = 0; j < y; j += radiusOfPower * 2) for (var j = 0; j < y; j += radiusOfPower * 2)
{ {
var pos = new CPos(i, j); var pos = world.Map.CenterOfCell(new CPos(i, j));
var targets = world.FindActorsInCircle(pos.CenterPosition, WRange.FromCells(radiusOfPower)).ToList(); var targets = world.FindActorsInCircle(pos, WRange.FromCells(radiusOfPower)).ToList();
var enemies = targets.Where(unit => p.Stances[unit.Owner] == Stance.Enemy).ToList(); var enemies = targets.Where(unit => p.Stances[unit.Owner] == Stance.Enemy).ToList();
var ally = targets.Where(unit => p.Stances[unit.Owner] == Stance.Ally || unit.Owner == p).ToList(); var ally = targets.Where(unit => p.Stances[unit.Owner] == Stance.Ally || unit.Owner == p).ToList();

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA.AI
for (var j = 0; j < y; j += DangerRadius * 2) for (var j = 0; j < y; j += DangerRadius * 2)
{ {
var pos = new CPos(i, j); var pos = new CPos(i, j);
if (NearToPosSafely(owner, pos.CenterPosition, out detectedEnemyTarget)) if (NearToPosSafely(owner, owner.world.Map.CenterOfCell(pos), out detectedEnemyTarget))
{ {
if (needTarget && detectedEnemyTarget == null) if (needTarget && detectedEnemyTarget == null)
continue; continue;

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.AI
if (owner.attackOrFleeFuzzy.CanAttack(owner.units, enemyUnits)) if (owner.attackOrFleeFuzzy.CanAttack(owner.units, enemyUnits))
{ {
foreach (var u in owner.units) 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. // We have gathered sufficient units. Attack the nearest enemy unit.
owner.fsm.ChangeState(owner, new GroundUnitsAttackMoveState(), true); owner.fsm.ChangeState(owner, new GroundUnitsAttackMoveState(), true);
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA.AI
{ {
owner.world.IssueOrder(new Order("Stop", leader, false)); owner.world.IssueOrder(new Order("Stop", leader, false));
foreach (var unit in owner.units.Where(a => !ownUnits.Contains(a))) 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 else
{ {

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Activities
if (target.Type != TargetType.Actor) if (target.Type != TargetType.Actor)
return NextActivity; 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); return Util.SequenceActivities(new MoveAdjacentTo(self, target), this);
// Move to the middle of the target, ignoring impassable tiles // Move to the middle of the target, ignoring impassable tiles

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities
// TODO: Queue a move order to the transport? need to be // TODO: Queue a move order to the transport? need to be
// careful about units that can't path to the transport // 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)) if (!cells.Contains(self.Location))
return NextActivity; return NextActivity;

View File

@@ -55,8 +55,8 @@ namespace OpenRA.Mods.RA.Activities
// TODO: calculate weapons ranges of units and factor those in instead of hard-coding 8. // TODO: calculate weapons ranges of units and factor those in instead of hard-coding 8.
var path = self.World.WorldActor.Trait<PathFinder>().FindPath( var path = self.World.WorldActor.Trait<PathFinder>().FindPath(
PathSearch.Search(self.World, mobileInfo, self, true) PathSearch.Search(self.World, mobileInfo, self, true)
.WithCustomCost(loc => self.World.FindActorsInCircle(loc.CenterPosition, WRange.FromCells(8)) .WithCustomCost(loc => self.World.FindActorsInCircle(self.World.Map.CenterOfCell(loc), WRange.FromCells(8))
.Where (u => !u.Destroyed && self.Owner.Stances[u.Owner] == Stance.Enemy) .Where(u => !u.Destroyed && self.Owner.Stances[u.Owner] == Stance.Enemy)
.Sum(u => Math.Max(0, 64 - (loc - u.Location).LengthSquared))) .Sum(u => Math.Max(0, 64 - (loc - u.Location).LengthSquared)))
.WithHeuristic(loc => .WithHeuristic(loc =>
{ {
@@ -114,13 +114,13 @@ namespace OpenRA.Mods.RA.Activities
if (harv.LastOrderLocation == null) if (harv.LastOrderLocation == null)
harv.LastOrderLocation = path[0]; harv.LastOrderLocation = path[0];
self.SetTargetLine(Target.FromCell(path[0]), Color.Red, false); self.SetTargetLine(Target.FromCell(self.World, path[0]), Color.Red, false);
return Util.SequenceActivities(mobile.MoveTo(path[0], 1), new HarvestResource(), new FindResources()); return Util.SequenceActivities(mobile.MoveTo(path[0], 1), new HarvestResource(), new FindResources());
} }
public override IEnumerable<Target> GetTargets(Actor self) public override IEnumerable<Target> GetTargets(Actor self)
{ {
yield return Target.FromCell(self.Location); yield return Target.FromCell(self.World, self.Location);
} }
} }

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities
return Util.SequenceActivities( return Util.SequenceActivities(
new MoveAdjacentTo(self, Target.FromActor(rearmTarget)), 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 Rearm(self),
new Repair(rearmTarget), new Repair(rearmTarget),
this); this);

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities
mobile.IsMoving = true; mobile.IsMoving = true;
from = self.CenterPosition; from = self.CenterPosition;
to = targetMobile.fromCell.CenterPosition + MobileInfo.SubCellOffsets[targetMobile.fromSubCell]; to = self.World.Map.CenterOfCell(targetMobile.fromCell) + MobileInfo.SubCellOffsets[targetMobile.fromSubCell];
length = Math.Max((to - from).Length / speed.Range, 1); length = Math.Max((to - from).Length / speed.Range, 1);
self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target)); self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target));

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Activities
movementClass = (uint)mobile.Info.GetMovementClass(self.World.TileSet); movementClass = (uint)mobile.Info.GetMovementClass(self.World.TileSet);
if (target.IsValidFor(self)) if (target.IsValidFor(self))
targetPosition = target.CenterPosition.ToCPos(); targetPosition = self.World.Map.CellContaining(target.CenterPosition);
repath = true; repath = true;
} }
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.RA.Activities
{ {
// Check if the target has moved // Check if the target has moved
var oldTargetPosition = targetPosition; var oldTargetPosition = targetPosition;
targetPosition = target.CenterPosition.ToCPos(); targetPosition = self.World.Map.CellContaining(target.CenterPosition);
var shroudStop = ShouldStop(self, oldTargetPosition); var shroudStop = ShouldStop(self, oldTargetPosition);
if (shroudStop || (!repath && ShouldRepath(self, oldTargetPosition))) if (shroudStop || (!repath && ShouldRepath(self, oldTargetPosition)))
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA.Activities
protected virtual IEnumerable<CPos> CandidateMovementCells(Actor self) protected virtual IEnumerable<CPos> CandidateMovementCells(Actor self)
{ {
return Util.AdjacentCells(target); return Util.AdjacentCells(self.World, target);
} }
void UpdateInnerPath(Actor self) void UpdateInnerPath(Actor self)

View File

@@ -43,11 +43,12 @@ namespace OpenRA.Mods.RA.Activities
protected override IEnumerable<CPos> CandidateMovementCells(Actor self) protected override IEnumerable<CPos> CandidateMovementCells(Actor self)
{ {
var map = self.World.Map;
var maxCells = (maxRange.Range + 1023) / 1024; var maxCells = (maxRange.Range + 1023) / 1024;
var outerCells = self.World.Map.FindTilesInCircle(targetPosition, maxCells); var outerCells = map.FindTilesInCircle(targetPosition, maxCells);
var minCells = minRange.Range / 1024; var minCells = minRange.Range / 1024;
var innerCells = self.World.Map.FindTilesInCircle(targetPosition, minCells); var innerCells = map.FindTilesInCircle(targetPosition, minCells);
var outerSq = maxRange.Range * maxRange.Range; var outerSq = maxRange.Range * maxRange.Range;
var innerSq = minRange.Range * minRange.Range; var innerSq = minRange.Range * minRange.Range;
@@ -55,7 +56,7 @@ namespace OpenRA.Mods.RA.Activities
return outerCells.Except(innerCells).Where(c => return outerCells.Except(innerCells).Where(c =>
{ {
var dxSq = (c.CenterPosition - center).HorizontalLengthSquared; var dxSq = (map.CenterOfCell(c) - center).HorizontalLengthSquared;
return dxSq >= innerSq && dxSq <= outerSq; return dxSq >= innerSq && dxSq <= outerSq;
}); });
} }

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Activities
destination = bestCell.Value; destination = bestCell.Value;
Sound.Play(sound, self.CenterPosition); Sound.Play(sound, self.CenterPosition);
Sound.Play(sound, destination.CenterPosition); Sound.Play(sound, self.World.Map.CenterOfCell(destination));
self.Trait<IPositionable>().SetPosition(self, destination); self.Trait<IPositionable>().SetPosition(self, destination);
self.Generation++; self.Generation++;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.RA.Activities
actor.CancelActivity(); actor.CancelActivity();
pos.SetVisualPosition(actor, spawn); pos.SetVisualPosition(actor, spawn);
actor.QueueActivity(move.MoveIntoWorld(actor, exitCell.Value)); actor.QueueActivity(move.MoveIntoWorld(actor, exitCell.Value));
actor.SetTargetLine(Target.FromCell(exitCell.Value), Color.Green, false); actor.SetTargetLine(Target.FromCell(w, exitCell.Value), Color.Green, false);
}); });
if (!unloadAll || cargo.IsEmpty(self)) if (!unloadAll || cargo.IsEmpty(self))

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA
{ {
// Not targeting a frozen actor // Not targeting a frozen actor
if (order.ExtraData == 0) if (order.ExtraData == 0)
return Target.FromOrder(order); return Target.FromOrder(self.World, order);
// Targeted an actor under the fog // Targeted an actor under the fog
var frozenLayer = self.Owner.PlayerActor.TraitOrDefault<FrozenActorLayer>(); var frozenLayer = self.Owner.PlayerActor.TraitOrDefault<FrozenActorLayer>();

8
OpenRA.Mods.RA/Air/Aircraft.cs Executable file → Normal file
View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Air
[Sync] public int Facing { get; set; } [Sync] public int Facing { get; set; }
[Sync] public WPos CenterPosition { get; private 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 IDisposable Reservation;
public int ROT { get { return info.ROT; } } public int ROT { get { return info.ROT; } }
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA.Air
} }
// Changes position, but not altitude // Changes position, but not altitude
public void SetPosition(Actor self, CPos cell) { SetPosition(self, cell.CenterPosition + new WVec(0, 0, CenterPosition.Z)); } public void SetPosition(Actor self, CPos cell) { SetPosition(self, self.World.Map.CenterOfCell(cell) + new WVec(0, 0, CenterPosition.Z)); }
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos); } public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos); }
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
@@ -201,7 +201,7 @@ namespace OpenRA.Mods.RA.Air
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
if (order.OrderID == "Move") 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; return null;
} }
@@ -246,7 +246,7 @@ namespace OpenRA.Mods.RA.Air
return false; return false;
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); 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; return true;
} }

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Air
if (order.OrderString == "Move") if (order.OrderString == "Move")
{ {
var cell = self.World.Map.Clamp(order.TargetLocation); var cell = self.World.Map.Clamp(order.TargetLocation);
var t = Target.FromCell(cell); var t = Target.FromCell(self.World, cell);
self.SetTargetLine(t, Color.Green); self.SetTargetLine(t, Color.Green);
self.CancelActivity(); self.CancelActivity();
@@ -161,8 +161,8 @@ namespace OpenRA.Mods.RA.Air
return (d * 1024 * 8) / (int)distSq; return (d * 1024 * 8) / (int)distSq;
} }
public Activity MoveTo(CPos cell, int nearEnough) { return new HeliFly(self, Target.FromCell(cell)); } public Activity MoveTo(CPos cell, int nearEnough) { return new HeliFly(self, Target.FromCell(self.World, cell)); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new HeliFly(self, Target.FromCell(cell)); } public Activity MoveTo(CPos cell, Actor ignoredActor) { return new HeliFly(self, Target.FromCell(self.World, cell)); }
public Activity MoveWithinRange(Target target, WRange range) { return new HeliFly(self, target, WRange.Zero, range); } public Activity MoveWithinRange(Target target, WRange range) { return new HeliFly(self, target, WRange.Zero, range); }
public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return new HeliFly(self, target, minRange, maxRange); } public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return new HeliFly(self, target, minRange, maxRange); }
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); } public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); }
@@ -170,7 +170,7 @@ namespace OpenRA.Mods.RA.Air
public Activity MoveIntoWorld(Actor self, CPos cell) public Activity MoveIntoWorld(Actor self, CPos cell)
{ {
return new HeliFly(self, Target.FromCell(cell)); return new HeliFly(self, Target.FromCell(self.World, cell));
} }
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos) public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA.Air
UnReserve(); UnReserve();
var cell = self.World.Map.Clamp(order.TargetLocation); var cell = self.World.Map.Clamp(order.TargetLocation);
var t = Target.FromCell(cell); var t = Target.FromCell(self.World, cell);
self.SetTargetLine(t, Color.Green); self.SetTargetLine(t, Color.Green);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Fly(self, t)); self.QueueActivity(new Fly(self, t));
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Air
UnReserve(); UnReserve();
self.SetTargetLine(Target.FromOrder(order), Color.Green); self.SetTargetLine(Target.FromOrder(self.World, order), Color.Green);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new ReturnToBase(self, order.TargetActor)); self.QueueActivity(new ReturnToBase(self, order.TargetActor));
@@ -101,14 +101,14 @@ namespace OpenRA.Mods.RA.Air
} }
} }
public Activity MoveTo(CPos cell, int nearEnough) { return Util.SequenceActivities(new Fly(self, Target.FromCell(cell)), new FlyCircle()); } public Activity MoveTo(CPos cell, int nearEnough) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle()); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(cell)), new FlyCircle()); } public Activity MoveTo(CPos cell, Actor ignoredActor) { return Util.SequenceActivities(new Fly(self, Target.FromCell(self.World, cell)), new FlyCircle()); }
public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), new FlyCircle()); } public Activity MoveWithinRange(Target target, WRange range) { return Util.SequenceActivities(new Fly(self, target, WRange.Zero, range), new FlyCircle()); }
public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle()); } public Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange) { return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), new FlyCircle()); }
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); } public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); }
public CPos NearestMoveableCell(CPos cell) { return cell; } public CPos NearestMoveableCell(CPos cell) { return cell; }
public Activity MoveIntoWorld(Actor self, CPos cell) { return new Fly(self, Target.FromCell(cell)); } public Activity MoveIntoWorld(Actor self, CPos cell) { return new Fly(self, Target.FromCell(self.World, cell)); }
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos) { return Util.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)), new Fly(self, Target.FromPos(toPos))); } public Activity VisualMove(Actor self, WPos fromPos, WPos toPos) { return Util.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)), new Fly(self, Target.FromPos(toPos))); }
} }
} }

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Air
var rp = hasHost ? host.TraitOrDefault<RallyPoint>() : null; var rp = hasHost ? host.TraitOrDefault<RallyPoint>() : null;
var destination = rp != null ? rp.rallyPoint : 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<IMove>().MoveTo(destination, 1)); return new AttackMove.AttackMoveActivity(self, self.Trait<IMove>().MoveTo(destination, 1));
} }

View File

@@ -107,7 +107,7 @@ namespace OpenRA.Mods.RA
case TargetType.FrozenActor: case TargetType.FrozenActor:
return new Order("Attack", self, queued) { ExtraData = target.FrozenActor.ID }; return new Order("Attack", self, queued) { ExtraData = target.FrozenActor.ID };
case TargetType.Terrain: 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) };
} }
} }
@@ -217,13 +217,13 @@ namespace OpenRA.Mods.RA
if (negativeDamage) if (negativeDamage)
return false; return false;
if (!ab.HasAnyValidWeapons(Target.FromCell(location))) if (!ab.HasAnyValidWeapons(Target.FromCell(self.World, location)))
return false; return false;
if (modifiers.HasModifier(TargetModifiers.ForceAttack)) if (modifiers.HasModifier(TargetModifiers.ForceAttack))
{ {
var maxRange = ab.GetMaximumRange().Range; var maxRange = ab.GetMaximumRange().Range;
var targetRange = (location.CenterPosition - self.CenterPosition).HorizontalLengthSquared; var targetRange = (self.World.Map.CenterOfCell(location) - self.CenterPosition).HorizontalLengthSquared;
if (targetRange > maxRange * maxRange) if (targetRange > maxRange * maxRange)
cursor = ab.info.OutsideRangeCursor; cursor = ab.info.OutsideRangeCursor;
@@ -241,7 +241,7 @@ namespace OpenRA.Mods.RA
case TargetType.FrozenActor: case TargetType.FrozenActor:
return CanTargetActor(self, target, modifiers, ref cursor); return CanTargetActor(self, target, modifiers, ref cursor);
case TargetType.Terrain: 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: default:
return false; return false;
} }

View File

@@ -31,8 +31,8 @@ namespace OpenRA.Mods.RA
public void TickIdle(Actor self) public void TickIdle(Actor self)
{ {
var offset = new WVec(0, -1024*Info.MoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255))).ToCVec(); var target = self.CenterPosition + new WVec(0, -1024*Info.MoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255)));
self.Trait<AttackMove>().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = self.Location + offset }); self.Trait<AttackMove>().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = self.World.Map.CellContaining(target) });
} }
} }
} }

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA
OnExitedAttackRange(self); OnExitedAttackRange(self);
} }
public void SetTarget(WPos pos) { target = Target.FromPos(pos); } public void SetTarget(World w, WPos pos) { target = Target.FromPos(pos); }
public void RemovedFromWorld(Actor self) public void RemovedFromWorld(Actor self)
{ {

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA
if (order.OrderString == "AttackMove") if (order.OrderString == "AttackMove")
{ {
TargetLocation = move.NearestMoveableCell(order.TargetLocation); TargetLocation = move.NearestMoveableCell(order.TargetLocation);
self.SetTargetLine(Target.FromCell(TargetLocation.Value), Color.Red); self.SetTargetLine(Target.FromCell(self.World, TargetLocation.Value), Color.Red);
Activate(self); Activate(self);
} }
} }

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
{ {
// Offset effective position to the top of the northernmost occupied cell // Offset effective position to the top of the northernmost occupied cell
var bi = self.Info.Traits.GetOrDefault<BuildingInfo>(); var bi = self.Info.Traits.GetOrDefault<BuildingInfo>();
offset = ((bi != null) ? -FootprintUtils.CenterOffset(bi).Y : 0) - 512; offset = ((bi != null) ? -FootprintUtils.CenterOffset(self.World, bi).Y : 0) - 512;
} }
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r) public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)

View File

@@ -122,7 +122,7 @@ namespace OpenRA.Mods.RA
{ {
return footprint.Select(c => (IRenderable)(new SpriteRenderable( return footprint.Select(c => (IRenderable)(new SpriteRenderable(
wr.Theater.TileSprite(new TerrainTile(template, c.Value)), wr.Theater.TileSprite(new TerrainTile(template, c.Value)),
c.Key.CenterPosition, WVec.Zero, -512, palette, 1f, true))).ToArray(); wr.world.Map.CenterOfCell(c.Key), WVec.Zero, -512, palette, 1f, true))).ToArray();
} }
bool initialized; bool initialized;

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Buildings
{ {
var width = bi.Dimensions.X; var width = bi.Dimensions.X;
var bibOffset = bi.Dimensions.Y - 1; var bibOffset = bi.Dimensions.Y - 1;
var centerOffset = FootprintUtils.CenterOffset(bi); var centerOffset = FootprintUtils.CenterOffset(self.World, bi);
var location = self.Location; var location = self.Location;
var rows = info.HasMinibib ? 1 : 2; var rows = info.HasMinibib ? 1 : 2;
var map = self.World.Map; var map = self.World.Map;
@@ -49,16 +49,17 @@ namespace OpenRA.Mods.RA.Buildings
var index = i; var index = i;
var anim = new Animation(self.World, rs.GetImage(self)); var anim = new Animation(self.World, rs.GetImage(self));
var cellOffset = new CVec(i % width, i / width + bibOffset); var cellOffset = new CVec(i % width, i / width + bibOffset);
var cell = location + cellOffset;
// Some mods may define terrain-specific bibs // Some mods may define terrain-specific bibs
var terrain = map.GetTerrainInfo(location + cellOffset).Type; var terrain = map.GetTerrainInfo(cell).Type;
var testSequence = info.Sequence + "-" + terrain; var testSequence = info.Sequence + "-" + terrain;
var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence; var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence;
anim.PlayFetchIndex(sequence, () => index); anim.PlayFetchIndex(sequence, () => index);
anim.IsDecoration = true; anim.IsDecoration = true;
// Z-order is one set to the top of the footprint // Z-order is one set to the top of the footprint
var offset = cellOffset.ToWVec() - centerOffset; var offset = self.World.Map.CenterOfCell(cell) - self.World.Map.CenterOfCell(location) - centerOffset;
var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512)); var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512));
rs.Add("bib_{0}".F(i), awo, info.Palette); rs.Add("bib_{0}".F(i), awo, info.Palette);
} }

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Buildings
public readonly int Adjacent = 2; public readonly int Adjacent = 2;
[Desc("x means space it blocks, _ is a part that is passable by actors.")] [Desc("x means space it blocks, _ is a part that is passable by actors.")]
public readonly string Footprint = "x"; public readonly string Footprint = "x";
public readonly int2 Dimensions = new int2(1, 1); public readonly CVec Dimensions = new CVec(1, 1);
public readonly bool RequiresBaseProvider = false; public readonly bool RequiresBaseProvider = false;
public readonly bool AllowInvalidPlacement = false; public readonly bool AllowInvalidPlacement = false;
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Buildings
public Actor FindBaseProvider(World world, Player p, CPos topLeft) public Actor FindBaseProvider(World world, Player p, CPos topLeft)
{ {
var center = topLeft.CenterPosition + FootprintUtils.CenterOffset(this); var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, this);
foreach (var bp in world.ActorsWithTrait<BaseProvider>()) foreach (var bp in world.ActorsWithTrait<BaseProvider>())
{ {
var validOwner = bp.Actor.Owner == p || (world.LobbyInfo.GlobalSettings.AllyBuildRadius && bp.Actor.Owner.Stances[p] == Stance.Ally); var validOwner = bp.Actor.Owner == p || (world.LobbyInfo.GlobalSettings.AllyBuildRadius && bp.Actor.Owner.Stances[p] == Stance.Ally);
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Buildings
if (RequiresBaseProvider && FindBaseProvider(world, p, topLeft) == null) if (RequiresBaseProvider && FindBaseProvider(world, p, topLeft) == null)
return false; return false;
var buildingMaxBounds = (CVec)Dimensions; var buildingMaxBounds = Dimensions;
var buildingTraits = world.Map.Rules.Actors[buildingName].Traits; var buildingTraits = world.Map.Rules.Actors[buildingName].Traits;
if (buildingTraits.Contains<BibInfo>() && !(buildingTraits.Get<BibInfo>().HasMinibib)) if (buildingTraits.Contains<BibInfo>() && !(buildingTraits.Get<BibInfo>().HasMinibib))
buildingMaxBounds += new CVec(0, 1); buildingMaxBounds += new CVec(0, 1);
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.RA.Buildings
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft ) occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); .Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
CenterPosition = topLeft.CenterPosition + FootprintUtils.CenterOffset(Info); CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info);
BuildComplete = init.Contains<SkipMakeAnimsInit>(); BuildComplete = init.Contains<SkipMakeAnimsInit>();
} }

View File

@@ -62,11 +62,10 @@ namespace OpenRA.Mods.RA.Buildings
return new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0); return new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0);
} }
public static WVec CenterOffset(BuildingInfo buildingInfo) public static WVec CenterOffset(World w, BuildingInfo buildingInfo)
{ {
var dim = buildingInfo.Dimensions; var dim = buildingInfo.Dimensions;
// Offset is measured relative to the center of the cell, so need to subtract an additional half cell. return (w.Map.CenterOfCell(CPos.Zero + new CVec(dim.X, dim.Y)) - w.Map.CenterOfCell(new CPos(1, 1))) / 2;
return new CVec(dim.X, dim.Y).ToWVec() / 2 - new WVec(512, 512, 0);
} }
} }
} }

View File

@@ -102,7 +102,7 @@ namespace OpenRA.Mods.RA
IEnumerable<CPos> GetAdjacentCells() IEnumerable<CPos> 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() bool CanUnload()
@@ -218,7 +218,7 @@ namespace OpenRA.Mods.RA
initialized = true; initialized = true;
} }
var cell = self.CenterPosition.ToCPos(); var cell = self.World.Map.CellContaining(self.CenterPosition);
if (currentCell != cell) if (currentCell != cell)
{ {
currentCell = cell; currentCell = cell;

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA
public static void DoImpact(WPos pos, WarheadInfo warhead, WeaponInfo weapon, Actor firedBy, float firepowerModifier) public static void DoImpact(WPos pos, WarheadInfo warhead, WeaponInfo weapon, Actor firedBy, float firepowerModifier)
{ {
var world = firedBy.World; var world = firedBy.World;
var targetTile = pos.ToCPos(); var targetTile = world.Map.CellContaining(pos);
if (!world.Map.Contains(targetTile)) if (!world.Map.Contains(targetTile))
return; return;

View File

@@ -85,8 +85,8 @@ namespace OpenRA.Mods.RA
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(Location, SubCell.FullCell); } public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(Location, SubCell.FullCell); }
public WPos CenterPosition { get; private set; } public WPos CenterPosition { get; private set; }
public void SetPosition(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, pos.ToCPos()); } public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); }
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
{ {
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.RA
{ {
self.World.ActorMap.RemoveInfluence(self, this); self.World.ActorMap.RemoveInfluence(self, this);
Location = cell; Location = cell;
CenterPosition = cell.CenterPosition; CenterPosition = self.World.Map.CenterOfCell(cell);
if (self.IsInWorld) if (self.IsInWorld)
{ {

View File

@@ -92,13 +92,13 @@ namespace OpenRA.Mods.RA
var altitude = w.Map.Rules.Actors[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude; var altitude = w.Map.Rules.Actors[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude;
var plane = w.CreateActor(info.DeliveryAircraft, new TypeDictionary var plane = w.CreateActor(info.DeliveryAircraft, new TypeDictionary
{ {
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)), new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(w.WorldActor.Owner), new OwnerInit(w.WorldActor.Owner),
new FacingInit(Util.GetFacing(p - startPos, 0)) new FacingInit(w.Map.FacingBetween(startPos, p, 0))
}); });
plane.CancelActivity(); plane.CancelActivity();
plane.QueueActivity(new FlyAttack(Target.FromCell(p))); plane.QueueActivity(new FlyAttack(Target.FromCell(w, p)));
plane.Trait<ParaDrop>().SetLZ(p); plane.Trait<ParaDrop>().SetLZ(p);
plane.Trait<Cargo>().Load(plane, crate); plane.Trait<Cargo>().Load(plane, crate);
} }

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Mods.RA.Effects
trail.Update(pos); trail.Update(pos);
if (ticks++ >= length || (!info.High && world.ActorMap if (ticks++ >= length || (!info.High && world.ActorMap
.GetUnitsAt(pos.ToCPos()).Any(a => a.HasTrait<IBlocksBullets>()))) .GetUnitsAt(world.Map.CellContaining(pos)).Any(a => a.HasTrait<IBlocksBullets>())))
{ {
Explode(world); Explode(world);
} }
@@ -148,7 +148,7 @@ namespace OpenRA.Mods.RA.Effects
if (anim == null || ticks >= length) if (anim == null || ticks >= length)
yield break; yield break;
var cell = pos.ToCPos(); var cell = wr.world.Map.CellContaining(pos);
if (!args.SourceActor.World.FogObscures(cell)) if (!args.SourceActor.World.FogObscures(cell))
{ {
if (info.Shadow) if (info.Shadow)

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<IRenderable> Render(WorldRenderer wr) public IEnumerable<IRenderable> Render(WorldRenderer wr)
{ {
if (wr.world.FogObscures(pos.ToCPos())) if (wr.world.FogObscures(wr.world.Map.CellContaining(pos)))
yield break; yield break;
yield return new TextRenderable(font, pos, 0, color, text); yield return new TextRenderable(font, pos, 0, color, text);

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Effects
{ {
this.world = world; this.world = world;
this.pos = pos; this.pos = pos;
this.cell = pos.ToCPos(); this.cell = world.Map.CellContaining(pos);
this.paletteName = paletteName; this.paletteName = paletteName;
anim = new Animation(world, image); anim = new Animation(world, image);
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this)));

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Effects
{ {
this.world = world; this.world = world;
this.pos = pos; this.pos = pos;
this.cell = pos.ToCPos(); this.cell = world.Map.CellContaining(pos);
this.palette = palette; this.palette = palette;
anim = new Animation(world, "explosion"); anim = new Animation(world, "explosion");
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this)));

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<IRenderable> Render(WorldRenderer wr) public IEnumerable<IRenderable> Render(WorldRenderer wr)
{ {
var cell = pos.ToCPos(); var cell = wr.world.Map.CellContaining(pos);
if (!args.SourceActor.World.FogObscures(cell)) if (!args.SourceActor.World.FogObscures(cell))
{ {
if (info.Shadow) if (info.Shadow)

View File

@@ -154,7 +154,7 @@ namespace OpenRA.Mods.RA.Effects
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
trail.Update(pos); trail.Update(pos);
var cell = pos.ToCPos(); var cell = world.Map.CellContaining(pos);
var shouldExplode = (pos.Z < 0) // Hit the ground var shouldExplode = (pos.Z < 0) // Hit the ground
|| (dist.LengthSquared < MissileCloseEnough.Range * MissileCloseEnough.Range) // Within range || (dist.LengthSquared < MissileCloseEnough.Range * MissileCloseEnough.Range) // Within range
@@ -186,7 +186,7 @@ namespace OpenRA.Mods.RA.Effects
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
yield return trail; 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); var palette = wr.Palette(args.Weapon.Palette);
foreach (var r in anim.Render(pos, palette)) foreach (var r in anim.Render(pos, palette))

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Effects
parachuteOffset = pai.Offset; parachuteOffset = pai.Offset;
// Adjust x,y to match the target subcell // Adjust x,y to match the target subcell
cargo.Trait<IPositionable>().SetPosition(cargo, dropPosition.ToCPos()); cargo.Trait<IPositionable>().SetPosition(cargo, cargo.World.Map.CellContaining(dropPosition));
var cp = cargo.CenterPosition; var cp = cargo.CenterPosition;
pos = new WPos(cp.X, cp.Y, dropPosition.Z); pos = new WPos(cp.X, cp.Y, dropPosition.Z);
} }

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA.Effects
if (!building.IsInWorld || !building.World.Selection.Actors.Contains(building)) if (!building.IsInWorld || !building.World.Selection.Actors.Contains(building))
return SpriteRenderable.None; return SpriteRenderable.None;
var pos = cachedLocation.CenterPosition; var pos = wr.world.Map.CenterOfCell(cachedLocation);
var palette = wr.Palette(palettePrefix+building.Owner.InternalName); var palette = wr.Palette(palettePrefix+building.Owner.InternalName);
return circles.Render(pos, palette).Concat(flag.Render(pos, palette)); return circles.Render(pos, palette).Concat(flag.Render(pos, palette));
} }

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Effects
{ {
this.world = world; this.world = world;
this.pos = pos; this.pos = pos;
this.cell = pos.ToCPos(); this.cell = world.Map.CellContaining(pos);
anim = new Animation(world, trail); anim = new Animation(world, trail);
anim.PlayThen("idle", anim.PlayThen("idle",

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA
[Desc("What the unit should start doing. Warning: If this is not a harvester", "it will break if you use FindResources.")] [Desc("What the unit should start doing. Warning: If this is not a harvester", "it will break if you use FindResources.")]
public readonly string InitialActivity = null; public readonly string InitialActivity = null;
[Desc("Offset relative to structure-center in 2D (e.g. 1, 2)")] [Desc("Offset relative to structure-center in 2D (e.g. 1, 2)")]
public readonly int2 SpawnOffset = int2.Zero; public readonly CVec SpawnOffset = CVec.Zero;
[Desc("Which direction the unit should face.")] [Desc("Which direction the unit should face.")]
public readonly int Facing = 0; public readonly int Facing = 0;
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA
var a = w.CreateActor(info.Actor, new TypeDictionary var a = w.CreateActor(info.Actor, new TypeDictionary
{ {
new ParentActorInit(init.self), new ParentActorInit(init.self),
new LocationInit(init.self.Location + (CVec)info.SpawnOffset), new LocationInit(init.self.Location + info.SpawnOffset),
new OwnerInit(init.self.Owner), new OwnerInit(init.self.Owner),
new FacingInit(info.Facing), new FacingInit(info.Facing),
}); });

View File

@@ -170,7 +170,7 @@ namespace OpenRA.Mods.RA
var moveTo = harv.LastHarvestedCell ?? (deliveryLoc + new CVec(0, 4)); var moveTo = harv.LastHarvestedCell ?? (deliveryLoc + new CVec(0, 4));
self.QueueActivity(mobile.MoveTo(moveTo, 1)); self.QueueActivity(mobile.MoveTo(moveTo, 1));
self.SetTargetLine(Target.FromCell(moveTo), Color.Gray, false); self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
var territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>(); var territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
if (territory != null) territory.ClaimResource(self, moveTo); if (territory != null) territory.ClaimResource(self, moveTo);
@@ -194,7 +194,7 @@ namespace OpenRA.Mods.RA
var cell = self.Location; var cell = self.Location;
var moveTo = mobile.NearestMoveableCell(cell, 2, 5); var moveTo = mobile.NearestMoveableCell(cell, 2, 5);
self.QueueActivity(mobile.MoveTo(moveTo, 0)); self.QueueActivity(mobile.MoveTo(moveTo, 0));
self.SetTargetLine(Target.FromCell(moveTo), Color.Gray, false); self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
// Find more resources but not at this location: // Find more resources but not at this location:
self.QueueActivity(new FindResources(cell)); self.QueueActivity(new FindResources(cell));
@@ -260,7 +260,7 @@ namespace OpenRA.Mods.RA
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
if (order.OrderID == "Harvest") 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; return null;
} }
@@ -299,7 +299,7 @@ namespace OpenRA.Mods.RA
} }
self.QueueActivity(mobile.MoveTo(loc, 0)); self.QueueActivity(mobile.MoveTo(loc, 0));
self.SetTargetLine(Target.FromCell(loc), Color.Red); self.SetTargetLine(Target.FromCell(self.World, loc), Color.Red);
LastOrderLocation = loc; LastOrderLocation = loc;
} }
@@ -312,7 +312,7 @@ namespace OpenRA.Mods.RA
return; return;
self.QueueActivity(mobile.MoveTo(loc.Value, 0)); self.QueueActivity(mobile.MoveTo(loc.Value, 0));
self.SetTargetLine(Target.FromCell(loc.Value), Color.Red); self.SetTargetLine(Target.FromCell(self.World, loc.Value), Color.Red);
LastOrderLocation = loc; LastOrderLocation = loc;
} }
@@ -336,7 +336,7 @@ namespace OpenRA.Mods.RA
idleSmart = true; idleSmart = true;
self.SetTargetLine(Target.FromOrder(order), Color.Green); self.SetTargetLine(Target.FromOrder(self.World, order), Color.Green);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new DeliverResources()); self.QueueActivity(new DeliverResources());
@@ -437,7 +437,7 @@ namespace OpenRA.Mods.RA
if (modifiers.HasModifier(TargetModifiers.ForceMove)) if (modifiers.HasModifier(TargetModifiers.ForceMove))
return false; return false;
var location = target.CenterPosition.ToCPos(); var location = self.World.Map.CellContaining(target.CenterPosition);
// Don't leak info about resources under the shroud // Don't leak info about resources under the shroud
if (!self.Owner.Shroud.IsExplored(location)) if (!self.Owner.Shroud.IsExplored(location))
return false; return false;

View File

@@ -42,13 +42,14 @@ namespace OpenRA.Mods.RA
this.self = init.self; this.self = init.self;
TopLeft = init.Get<LocationInit, CPos>(); TopLeft = init.Get<LocationInit, CPos>();
CenterPosition = init.Contains<CenterPositionInit>() ? init.Get<CenterPositionInit, WPos>() : TopLeft.CenterPosition; CenterPosition = init.Contains<CenterPositionInit>() ? init.Get<CenterPositionInit, WPos>() : init.world.Map.CenterOfCell(TopLeft);
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 128; Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 128;
var speed = init.Contains<HuskSpeedInit>() ? init.Get<HuskSpeedInit, int>() : 0; var speed = init.Contains<HuskSpeedInit>() ? init.Get<HuskSpeedInit, int>() : 0;
var distance = (TopLeft.CenterPosition - CenterPosition).Length; var finalPos = init.world.Map.CenterOfCell(TopLeft);
var distance = (finalPos - CenterPosition).Length;
if (speed > 0 && distance > 0) if (speed > 0 && distance > 0)
self.QueueActivity(new Drag(CenterPosition, TopLeft.CenterPosition, distance / speed)); self.QueueActivity(new Drag(CenterPosition, finalPos, distance / speed));
} }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
@@ -69,8 +70,8 @@ namespace OpenRA.Mods.RA
} }
public bool CanEnterCell(CPos cell) { return CanEnterCell(cell, null, true); } public bool CanEnterCell(CPos cell) { return CanEnterCell(cell, null, true); }
public void SetPosition(Actor self, CPos cell) { SetPosition(self, self.World.Map.CenterOfCell(cell)); }
public void SetPosition(Actor self, CPos cell) { SetPosition(self, cell.CenterPosition); }
public void SetVisualPosition(Actor self, WPos pos) public void SetVisualPosition(Actor self, WPos pos)
{ {
CenterPosition = pos; CenterPosition = pos;
@@ -81,7 +82,7 @@ namespace OpenRA.Mods.RA
{ {
self.World.ActorMap.RemoveInfluence(self, this); self.World.ActorMap.RemoveInfluence(self, this);
CenterPosition = pos; CenterPosition = pos;
TopLeft = pos.ToCPos(); TopLeft = self.World.Map.CellContaining(pos);
self.World.ActorMap.AddInfluence(self, this); self.World.ActorMap.AddInfluence(self, this);
self.World.ActorMap.UpdatePosition(self, this); self.World.ActorMap.UpdatePosition(self, this);
self.World.ScreenMap.Update(self); self.World.ScreenMap.Update(self);

View File

@@ -23,11 +23,13 @@ namespace OpenRA.Mods.RA
class Immobile : IOccupySpace, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld class Immobile : IOccupySpace, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld
{ {
[Sync] readonly CPos location; [Sync] readonly CPos location;
[Sync] readonly WPos position;
readonly IEnumerable<Pair<CPos, SubCell>> occupied; readonly IEnumerable<Pair<CPos, SubCell>> occupied;
public Immobile(ActorInitializer init, ImmobileInfo info) public Immobile(ActorInitializer init, ImmobileInfo info)
{ {
this.location = init.Get<LocationInit, CPos>(); location = init.Get<LocationInit, CPos>();
position = init.world.Map.CenterOfCell(location);
if (info.OccupiesSpace) if (info.OccupiesSpace)
occupied = new [] { Pair.New(TopLeft, SubCell.FullCell) }; occupied = new [] { Pair.New(TopLeft, SubCell.FullCell) };
@@ -36,8 +38,8 @@ namespace OpenRA.Mods.RA
} }
public CPos TopLeft { get { return location; } } public CPos TopLeft { get { return location; } }
public WPos CenterPosition { get { return position; } }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupied; } public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupied; }
public WPos CenterPosition { get { return location.CenterPosition; } }
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
// Set viewport // Set viewport
if (world.LocalPlayer != null && Start.ContainsKey(world.LocalPlayer)) if (world.LocalPlayer != null && Start.ContainsKey(world.LocalPlayer))
wr.Viewport.Center(Start[world.LocalPlayer].CenterPosition); wr.Viewport.Center(world.Map.CenterOfCell(Start[world.LocalPlayer]));
} }
static Player FindPlayerInSlot(World world, string pr) static Player FindPlayerInSlot(World world, string pr)

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA
switch (order.OrderID) switch (order.OrderID)
{ {
case "BeginMinefield": case "BeginMinefield":
var start = target.CenterPosition.ToCPos(); var start = self.World.Map.CellContaining(target.CenterPosition);
self.World.OrderGenerator = new MinefieldOrderGenerator(self, start); self.World.OrderGenerator = new MinefieldOrderGenerator(self, start);
return new Order("BeginMinefield", self, false) { TargetLocation = start }; return new Order("BeginMinefield", self, false) { TargetLocation = start };
case "PlaceMine": case "PlaceMine":
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.RA
var p = end - start; var p = end - start;
var q = new float2(p.Y, -p.X); var q = new float2(p.Y, -p.X);
q = (start != end) ? (1 / q.Length) * q : new float2(1, 0); q = (start != end) ? (1 / q.Length) * q : new float2(1, 0);
var c = -float2.Dot(q, start.ToInt2()); var c = -float2.Dot(q, new float2(start.X, start.Y));
/* return all points such that |ax + by + c| < depth */ /* return all points such that |ax + by + c| < depth */
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA
var pal = wr.Palette("terrain"); var pal = wr.Palette("terrain");
foreach (var c in Minefield) foreach (var c in Minefield)
new SpriteRenderable(tile, c.CenterPosition, new SpriteRenderable(tile, self.World.Map.CenterOfCell(c),
WVec.Zero, -511, pal, 1f, true).Render(wr); WVec.Zero, -511, pal, 1f, true).Render(wr);
} }
@@ -183,7 +183,7 @@ namespace OpenRA.Mods.RA
foreach (var c in minefield) foreach (var c in minefield)
{ {
var tile = movement.CanEnterCell(c) ? tileOk : tileBlocked; var tile = movement.CanEnterCell(c) ? tileOk : tileBlocked;
new SpriteRenderable(tile, c.CenterPosition, new SpriteRenderable(tile, world.Map.CenterOfCell(c),
WVec.Zero, -511, pal, 1f, true).Render(wr); WVec.Zero, -511, pal, 1f, true).Render(wr);
} }
} }
@@ -201,7 +201,7 @@ namespace OpenRA.Mods.RA
if (target.Type != TargetType.Terrain) if (target.Type != TargetType.Terrain)
return false; return false;
var location = target.CenterPosition.ToCPos(); var location = self.World.Map.CellContaining(target.CenterPosition);
if (!self.World.Map.Contains(location)) if (!self.World.Map.Contains(location))
return false; return false;

View File

@@ -246,7 +246,7 @@ namespace OpenRA.Mods.RA.Move
if (init.Contains<LocationInit>()) if (init.Contains<LocationInit>())
{ {
this.__fromCell = this.__toCell = init.Get<LocationInit, CPos>(); this.__fromCell = this.__toCell = init.Get<LocationInit, CPos>();
SetVisualPosition(self, fromCell.CenterPosition + MobileInfo.SubCellOffsets[fromSubCell]); SetVisualPosition(self, init.world.Map.CenterOfCell(fromCell) + MobileInfo.SubCellOffsets[fromSubCell]);
} }
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing; this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
@@ -260,13 +260,13 @@ namespace OpenRA.Mods.RA.Move
public void SetPosition(Actor self, CPos cell) public void SetPosition(Actor self, CPos cell)
{ {
SetLocation(cell, fromSubCell, cell, fromSubCell); SetLocation(cell, fromSubCell, cell, fromSubCell);
SetVisualPosition(self, fromCell.CenterPosition + MobileInfo.SubCellOffsets[fromSubCell]); SetVisualPosition(self, self.World.Map.CenterOfCell(fromCell) + MobileInfo.SubCellOffsets[fromSubCell]);
FinishedMoving(self); FinishedMoving(self);
} }
public void SetPosition(Actor self, WPos pos) public void SetPosition(Actor self, WPos pos)
{ {
var cell = pos.ToCPos(); var cell = self.World.Map.CellContaining(pos);
SetLocation(cell, fromSubCell, cell, fromSubCell); SetLocation(cell, fromSubCell, cell, fromSubCell);
SetVisualPosition(self, pos); SetVisualPosition(self, pos);
FinishedMoving(self); FinishedMoving(self);
@@ -306,7 +306,7 @@ namespace OpenRA.Mods.RA.Move
if (Info.OnRails) if (Info.OnRails)
return null; 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; return null;
} }
@@ -375,7 +375,7 @@ namespace OpenRA.Mods.RA.Move
self.QueueActivity(new Move(currentLocation, 8)); self.QueueActivity(new Move(currentLocation, 8));
self.SetTargetLine(Target.FromCell(currentLocation), Color.Green); self.SetTargetLine(Target.FromCell(self.World, currentLocation), Color.Green);
} }
protected void PerformMove(Actor self, CPos targetLocation, bool queued) protected void PerformMove(Actor self, CPos targetLocation, bool queued)
@@ -542,7 +542,7 @@ namespace OpenRA.Mods.RA.Move
if (moveTo.HasValue) if (moveTo.HasValue)
{ {
self.CancelActivity(); self.CancelActivity();
self.SetTargetLine(Target.FromCell(moveTo.Value), Color.Green, false); self.SetTargetLine(Target.FromCell(self.World, moveTo.Value), Color.Green, false);
self.QueueActivity(new Move(moveTo.Value, 0)); self.QueueActivity(new Move(moveTo.Value, 0));
Log.Write("debug", "OnNudge #{0} from {1} to {2}", Log.Write("debug", "OnNudge #{0} from {1} to {2}",
@@ -573,7 +573,7 @@ namespace OpenRA.Mods.RA.Move
if (rejectMove || !target.IsValidFor(self)) if (rejectMove || !target.IsValidFor(self))
return false; return false;
var location = target.CenterPosition.ToCPos(); var location = self.World.Map.CellContaining(target.CenterPosition);
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
cursor = "move"; cursor = "move";
@@ -611,7 +611,7 @@ namespace OpenRA.Mods.RA.Move
SetVisualPosition(self, pos); SetVisualPosition(self, pos);
// Animate transition // Animate transition
var to = cell.CenterPosition; var to = self.World.Map.CenterOfCell(cell);
var speed = MovementSpeedForCell(self, cell); var speed = MovementSpeedForCell(self, cell);
var length = speed > 0 ? (to - pos).Length / speed : 0; var length = speed > 0 ? (to - pos).Length / speed : 0;

View File

@@ -139,8 +139,7 @@ namespace OpenRA.Mods.RA.Move
if (nextCell == null) if (nextCell == null)
return this; return this;
var dir = nextCell.Value.First - mobile.fromCell; var firstFacing = self.World.Map.FacingBetween(mobile.fromCell, nextCell.Value.First, mobile.Facing);
var firstFacing = Util.GetFacing(dir, mobile.Facing);
if (firstFacing != mobile.Facing) if (firstFacing != mobile.Facing)
{ {
path.Add(nextCell.Value.First); path.Add(nextCell.Value.First);
@@ -151,8 +150,8 @@ namespace OpenRA.Mods.RA.Move
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second); mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second);
var move = new MoveFirstHalf( var move = new MoveFirstHalf(
this, this,
mobile.fromCell.CenterPosition + MobileInfo.SubCellOffsets[mobile.fromSubCell], self.World.Map.CenterOfCell(mobile.fromCell) + MobileInfo.SubCellOffsets[mobile.fromSubCell],
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (MobileInfo.SubCellOffsets[mobile.fromSubCell] + MobileInfo.SubCellOffsets[mobile.toSubCell]) / 2, Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (MobileInfo.SubCellOffsets[mobile.fromSubCell] + MobileInfo.SubCellOffsets[mobile.toSubCell]) / 2,
mobile.Facing, mobile.Facing,
mobile.Facing, mobile.Facing,
0); 0);
@@ -251,9 +250,9 @@ namespace OpenRA.Mods.RA.Move
public override IEnumerable<Target> GetTargets(Actor self) public override IEnumerable<Target> GetTargets(Actor self)
{ {
if (path != null) if (path != null)
return Enumerable.Reverse(path).Select(c => Target.FromCell(c)); return Enumerable.Reverse(path).Select(c => Target.FromCell(self.World, c));
if (destination != null) if (destination != null)
return new Target[] { Target.FromCell(destination.Value) }; return new Target[] { Target.FromCell(self.World, destination.Value) };
return Target.None; return Target.None;
} }
@@ -359,10 +358,10 @@ namespace OpenRA.Mods.RA.Move
var nextSubcellOffset = MobileInfo.SubCellOffsets[nextCell.Value.Second]; var nextSubcellOffset = MobileInfo.SubCellOffsets[nextCell.Value.Second];
var ret = new MoveFirstHalf( var ret = new MoveFirstHalf(
move, move,
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2, Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
Util.BetweenCells(mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2, Util.BetweenCells(self.World, mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
mobile.Facing, mobile.Facing,
Util.GetNearestFacing(mobile.Facing, Util.GetFacing(nextCell.Value.First - mobile.toCell, mobile.Facing)), Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.toCell, nextCell.Value.First, mobile.Facing)),
moveFraction - moveFractionTotal); moveFraction - moveFractionTotal);
mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second); mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second);
@@ -374,8 +373,8 @@ namespace OpenRA.Mods.RA.Move
var ret2 = new MoveSecondHalf( var ret2 = new MoveSecondHalf(
move, move,
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2, Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
mobile.toCell.CenterPosition + toSubcellOffset, self.World.Map.CenterOfCell(mobile.toCell) + toSubcellOffset,
mobile.Facing, mobile.Facing,
mobile.Facing, mobile.Facing,
moveFraction - moveFractionTotal); moveFraction - moveFractionTotal);

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Mods.RA.Move
using (new PerfSample("Pathfinder")) using (new PerfSample("Pathfinder"))
{ {
var mi = self.Info.Traits.Get<MobileInfo>(); var mi = self.Info.Traits.Get<MobileInfo>();
var targetCell = target.ToCPos(); var targetCell = self.World.Map.CellContaining(target);
var rangeSquared = range.Range*range.Range; var rangeSquared = range.Range*range.Range;
// Correct for SubCell offset // Correct for SubCell offset
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA.Move
// Select only the tiles that are within range from the requested SubCell // Select only the tiles that are within range from the requested SubCell
// This assumes that the SubCell does not change during the path traversal // This assumes that the SubCell does not change during the path traversal
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Range / 1024 + 1) var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Range / 1024 + 1)
.Where(t => (t.CenterPosition - target).LengthSquared <= rangeSquared .Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= rangeSquared
&& mi.CanEnterCell(self.World, self, t, null, true, true)); && mi.CanEnterCell(self.World, self, t, null, true, true));
// See if there is any cell within range that does not involve a cross-domain request // See if there is any cell within range that does not involve a cross-domain request

View File

@@ -79,14 +79,14 @@ namespace OpenRA.Mods.RA.Orders
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; } public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
public void RenderAfterWorld(WorldRenderer wr, World world) public void RenderAfterWorld(WorldRenderer wr, World world)
{ {
var position = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
var topLeft = position - FootprintUtils.AdjustForBuildingSize(BuildingInfo); var topLeft = xy - FootprintUtils.AdjustForBuildingSize(BuildingInfo);
var rules = world.Map.Rules; var rules = world.Map.Rules;
var actorInfo = rules.Actors[Building]; var actorInfo = rules.Actors[Building];
foreach (var dec in actorInfo.Traits.WithInterface<IPlaceBuildingDecoration>()) foreach (var dec in actorInfo.Traits.WithInterface<IPlaceBuildingDecoration>())
dec.Render(wr, world, actorInfo, position.CenterPosition); /* hack hack */ dec.Render(wr, world, actorInfo, world.Map.CenterOfCell(xy));
var cells = new Dictionary<CPos, bool>(); var cells = new Dictionary<CPos, bool>();
// Linebuild for walls. // Linebuild for walls.
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA.Orders
initialized = true; initialized = true;
} }
var offset = topLeft.CenterPosition + FootprintUtils.CenterOffset(BuildingInfo) - WPos.Zero; var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo) - WPos.Zero;
foreach (var r in preview) foreach (var r in preview)
r.OffsetBy(offset).Render(wr); r.OffsetBy(offset).Render(wr);
@@ -128,7 +128,7 @@ namespace OpenRA.Mods.RA.Orders
foreach (var c in cells) foreach (var c in cells)
{ {
var tile = c.Value ? buildOk : buildBlocked; var tile = c.Value ? buildOk : buildBlocked;
new SpriteRenderable(tile, c.Key.CenterPosition, new SpriteRenderable(tile, world.Map.CenterOfCell(c.Key),
WVec.Zero, -511, pal, 1f, true).Render(wr); WVec.Zero, -511, pal, 1f, true).Render(wr);
} }
} }

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA
{ {
public class OreRefineryInfo : ITraitInfo public class OreRefineryInfo : ITraitInfo
{ {
public readonly int2 DockOffset = new int2(1, 2); public readonly CVec DockOffset = new CVec(1, 2);
public readonly bool ShowTicks = true; public readonly bool ShowTicks = true;
public readonly int TickLifetime = 30; public readonly int TickLifetime = 30;
@@ -44,8 +44,7 @@ namespace OpenRA.Mods.RA
[Sync] bool preventDock = false; [Sync] bool preventDock = false;
public bool AllowDocking { get { return !preventDock; } } public bool AllowDocking { get { return !preventDock; } }
public CVec DeliverOffset { get { return Info.DockOffset; } }
public CVec DeliverOffset { get { return (CVec)Info.DockOffset; } }
public virtual Activity DockSequence(Actor harv, Actor self) { return new RAHarvesterDockSequence(harv, self, Info.DockAngle); } public virtual Activity DockSequence(Actor harv, Actor self) { return new RAHarvesterDockSequence(harv, self, Info.DockAngle); }

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA
if (!CanEnter(order.TargetActor)) return; if (!CanEnter(order.TargetActor)) return;
if (!IsCorrectCargoType(order.TargetActor)) return; if (!IsCorrectCargoType(order.TargetActor)) return;
var target = Target.FromOrder(order); var target = Target.FromOrder(self.World, order);
self.SetTargetLine(target, Color.Green); self.SetTargetLine(target, Color.Green);
self.CancelActivity(); self.CancelActivity();

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA
if (order.OrderString != "PlaceBeacon") if (order.OrderString != "PlaceBeacon")
return; return;
var pos = order.TargetLocation.CenterPosition; var pos = self.World.Map.CenterOfCell(order.TargetLocation);
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
self.World.OrderGenerator = new PortableChronoOrderGenerator(self); self.World.OrderGenerator = new PortableChronoOrderGenerator(self);
if (order.OrderID == "PortableChronoTeleport") 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 }; 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 // TODO: When target modifiers are configurable this needs to be revisited
if (modifiers.HasModifier(TargetModifiers.ForceMove) || modifiers.HasModifier(TargetModifiers.ForceQueue)) 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); IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
@@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA
yield break; yield break;
} }
if (self.IsInWorld && self.CenterPosition.ToCPos() != xy if (self.IsInWorld && self.Location != xy
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(xy)) && self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(xy))
{ {
world.CancelInputMode(); world.CancelInputMode();
@@ -190,7 +190,7 @@ namespace OpenRA.Mods.RA
public string GetCursor(World world, CPos xy, MouseInput mi) public string GetCursor(World world, CPos xy, MouseInput mi)
{ {
if (self.IsInWorld && self.CenterPosition.ToCPos() != xy if (self.IsInWorld && self.Location != xy
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(xy)) && self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(xy))
return "chrono-target"; return "chrono-target";
else else

View File

@@ -57,13 +57,13 @@ namespace OpenRA.Mods.RA
{ {
var exit = self.Location + exitinfo.ExitCell; var exit = self.Location + exitinfo.ExitCell;
var spawn = self.CenterPosition + exitinfo.SpawnOffset; var spawn = self.CenterPosition + exitinfo.SpawnOffset;
var to = exit.CenterPosition; var to = self.World.Map.CenterOfCell(exit);
var fi = producee.Traits.Get<IFacingInfo>(); var fi = producee.Traits.Get<IFacingInfo>();
var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi.GetInitialFacing()) : exitinfo.Facing; var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi.GetInitialFacing()) : exitinfo.Facing;
var exitLocation = rp.Value != null ? rp.Value.rallyPoint : exit; var exitLocation = rp.Value != null ? rp.Value.rallyPoint : exit;
var target = Target.FromCell(exitLocation); var target = Target.FromCell(self.World, exitLocation);
var nearEnough = rp.Value != null ? WRange.FromCells(rp.Value.nearEnough) : WRange.Zero; var nearEnough = rp.Value != null ? WRange.FromCells(rp.Value.nearEnough) : WRange.Zero;
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
@@ -87,7 +87,6 @@ namespace OpenRA.Mods.RA
if (exitinfo.MoveIntoWorld) if (exitinfo.MoveIntoWorld)
{ {
newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit)); newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
newUnit.QueueActivity(new AttackMove.AttackMoveActivity( newUnit.QueueActivity(new AttackMove.AttackMoveActivity(
newUnit, move.MoveWithinRange(target, nearEnough))); newUnit, move.MoveWithinRange(target, nearEnough)));
} }

4
OpenRA.Mods.RA/RallyPoint.cs Executable file → Normal file
View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
{ {
if (order.OrderID == "SetRallyPoint") 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; return null;
} }
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
if (target.Type != TargetType.Terrain) if (target.Type != TargetType.Terrain)
return false; return false;
var location = target.CenterPosition.ToCPos(); var location = self.World.Map.CellContaining(target.CenterPosition);
if (self.World.Map.Contains(location)) if (self.World.Map.Contains(location))
{ {
cursor = "ability"; cursor = "ability";

View File

@@ -51,8 +51,8 @@ namespace OpenRA.Mods.RA.Render
return; return;
// Update connection to neighbours // Update connection to neighbours
var vec = new CVec(1, 1); var adjacentActors = CVec.directions.SelectMany(dir =>
var adjacentActors = self.World.FindActorsInBox(self.Location - vec, self.Location + vec); self.World.ActorMap.GetUnitsAt(self.Location + dir));
adjacent = 0; adjacent = 0;
foreach (var a in adjacentActors) foreach (var a in adjacentActors)
@@ -79,12 +79,12 @@ namespace OpenRA.Mods.RA.Render
static void UpdateNeighbours(Actor self) static void UpdateNeighbours(Actor self)
{ {
var vec = new CVec(1, 1); var adjacentActors = CVec.directions.SelectMany(dir =>
var neighbours = self.World.FindActorsInBox(self.Location - vec, self.Location + vec) self.World.ActorMap.GetUnitsAt(self.Location + dir))
.Select(a => a.TraitOrDefault<RenderBuildingWall>()) .Select(a => a.TraitOrDefault<RenderBuildingWall>())
.Where(a => a != null); .Where(a => a != null);
foreach (var rb in neighbours) foreach (var rb in adjacentActors)
rb.dirty = true; rb.dirty = true;
} }

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Render
var bi = init.self.Info.Traits.Get<BuildingInfo>(); var bi = init.self.Info.Traits.Get<BuildingInfo>();
// Additional 512 units move from center -> top of cell // Additional 512 units move from center -> top of cell
var offset = FootprintUtils.CenterOffset(bi).Y + 512; var offset = FootprintUtils.CenterOffset(init.world, bi).Y + 512;
Add("roof", new AnimationWithOffset(roof, null, Add("roof", new AnimationWithOffset(roof, null,
() => !buildComplete, offset)); () => !buildComplete, offset));
} }

View File

@@ -22,8 +22,7 @@ namespace OpenRA.Mods.RA.Render
//TODO: Make palette for this customizable as well //TODO: Make palette for this customizable as well
var bi = self.Info.Traits.Get<BuildingInfo>(); var bi = self.Info.Traits.Get<BuildingInfo>();
FootprintUtils.UnpathableTiles(self.Info.Name, bi, self.Location).Do( FootprintUtils.UnpathableTiles(self.Info.Name, bi, self.Location).Do(
t => self.World.AddFrameEndTask( t => self.World.AddFrameEndTask(w => w.Add(new Explosion(w, w.Map.CenterOfCell(t), "building", "effect"))));
w => w.Add(new Explosion(w, t.CenterPosition, "building", "effect"))));
} }
} }
} }

View File

@@ -69,16 +69,16 @@ namespace OpenRA.Mods.RA
{ {
if (order.OrderString == "Repair") if (order.OrderString == "Repair")
{ {
if( !CanRepairAt( order.TargetActor ) || !CanRepair() ) if (!CanRepairAt(order.TargetActor) || !CanRepair())
return; return;
var movement = self.Trait<IMove>(); var movement = self.Trait<IMove>();
var target = Target.FromOrder(order); var target = Target.FromOrder(self.World, order);
self.SetTargetLine(target, Color.Green); self.SetTargetLine(target, Color.Green);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new MoveAdjacentTo(self, target)); 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 Rearm(self));
self.QueueActivity(new Repair(order.TargetActor)); self.QueueActivity(new Repair(order.TargetActor));
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.RA
if (rp != null) if (rp != null)
self.QueueActivity(new CallFunc(() => self.QueueActivity(new CallFunc(() =>
{ {
self.SetTargetLine(Target.FromCell(rp.rallyPoint), Color.Green); self.SetTargetLine(Target.FromCell(self.World, rp.rallyPoint), Color.Green);
self.QueueActivity(movement.MoveTo(rp.rallyPoint, order.TargetActor)); self.QueueActivity(movement.MoveTo(rp.rallyPoint, order.TargetActor));
})); }));
} }

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA
if (order.OrderString == "RepairNear" && CanRepairAt(order.TargetActor) && ShouldRepair()) if (order.OrderString == "RepairNear" && CanRepairAt(order.TargetActor) && ShouldRepair())
{ {
var movement = self.Trait<IMove>(); var movement = self.Trait<IMove>();
var target = Target.FromOrder(order); var target = Target.FromOrder(self.World, order);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(movement.MoveWithinRange(target, new WRange(1024*info.CloseEnough))); self.QueueActivity(movement.MoveWithinRange(target, new WRange(1024*info.CloseEnough)));

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA
if (bridge.BridgeDamageState == DamageState.Undamaged) if (bridge.BridgeDamageState == DamageState.Undamaged)
return; return;
self.SetTargetLine(Target.FromOrder(order), Color.Yellow); self.SetTargetLine(Target.FromOrder(self.World, order), Color.Yellow);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Enter(order.TargetActor, new RepairBridge(order.TargetActor))); self.QueueActivity(new Enter(order.TargetActor, new RepairBridge(order.TargetActor)));

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA.Scripting
[Desc("Returns the center of a cell in world coordinates.")] [Desc("Returns the center of a cell in world coordinates.")]
public WPos CenterOfCell(CPos cell) public WPos CenterOfCell(CPos cell)
{ {
return cell.CenterPosition; return context.World.Map.CenterOfCell(cell);
} }
} }
} }

View File

@@ -229,7 +229,7 @@ namespace OpenRA.Mods.RA.Scripting
public int GetFacing(object vec, double currentFacing) public int GetFacing(object vec, double currentFacing)
{ {
if (vec is CVec) if (vec is CVec)
return Util.GetFacing((CVec)vec, (int)currentFacing); return world.Map.FacingBetween(CPos.Zero, CPos.Zero + (CVec)vec, (int)currentFacing);
if (vec is WVec) if (vec is WVec)
return Util.GetFacing((WVec)vec, (int)currentFacing); return Util.GetFacing((WVec)vec, (int)currentFacing);
throw new ArgumentException("Unsupported vector type: {0}".F(vec.GetType())); throw new ArgumentException("Unsupported vector type: {0}".F(vec.GetType()));
@@ -298,7 +298,7 @@ namespace OpenRA.Mods.RA.Scripting
[LuaGlobal] [LuaGlobal]
public void FlyAttackCell(Actor actor, CPos location) public void FlyAttackCell(Actor actor, CPos location)
{ {
actor.QueueActivity(new FlyAttack(Target.FromCell(location))); actor.QueueActivity(new FlyAttack(Target.FromCell(actor.World, location)));
} }
[LuaGlobal] [LuaGlobal]
@@ -369,7 +369,7 @@ namespace OpenRA.Mods.RA.Scripting
[LuaGlobal] [LuaGlobal]
public Actor[] FindActorsInBox(WPos topLeft, WPos bottomRight) public Actor[] FindActorsInBox(WPos topLeft, WPos bottomRight)
{ {
return world.FindActorsInBox(topLeft, bottomRight).ToArray(); return world.ActorMap.ActorsInBox(topLeft, bottomRight).ToArray();
} }
[LuaGlobal] [LuaGlobal]

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Scripting
public void Paradrop(CPos cell) public void Paradrop(CPos cell)
{ {
paradrop.SetLZ(cell); paradrop.SetLZ(cell);
self.QueueActivity(new FlyAttack(Target.FromCell(cell))); self.QueueActivity(new FlyAttack(Target.FromCell(self.World, cell)));
} }
} }
} }

View File

@@ -199,7 +199,7 @@ namespace OpenRA.Mods.RA
// Initialize tile cache // Initialize tile cache
foreach (var cell in map.Cells) foreach (var cell in map.Cells)
{ {
var screen = wr.ScreenPosition(cell.CenterPosition); var screen = wr.ScreenPosition(w.Map.CenterOfCell(cell));
var variant = Game.CosmeticRandom.Next(info.ShroudVariants.Length); var variant = Game.CosmeticRandom.Next(info.ShroudVariants.Length);
tiles[cell] = new ShroudTile(cell, screen, variant); tiles[cell] = new ShroudTile(cell, screen, variant);
} }

View File

@@ -41,8 +41,7 @@ namespace OpenRA.Mods.RA
if (--ticks <= 0) if (--ticks <= 0)
{ {
var position = self.CenterPosition; var position = self.CenterPosition;
if (position.Z > 0 && self.GetDamageState() >= info.MinDamage && if (position.Z > 0 && self.GetDamageState() >= info.MinDamage && !self.World.FogObscures(self))
!self.World.FogObscures(position.ToCPos()))
{ {
var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation)); var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
var pos = position + body.LocalToWorld(offset); var pos = position + body.LocalToWorld(offset);

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA
var delta = new WVec(0, -1024, 0).Rotate(attackRotation); var delta = new WVec(0, -1024, 0).Rotate(attackRotation);
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude.Range; var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude.Range;
var target = order.TargetLocation.CenterPosition + new WVec(0, 0, altitude); var target = self.World.Map.CenterOfCell(order.TargetLocation) + new WVec(0, 0, altitude);
var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Range * delta / 1024; var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Range * delta / 1024;
var finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Range * delta / 1024; var finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Range * delta / 1024;
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA
}); });
var attack = a.Trait<AttackBomber>(); var attack = a.Trait<AttackBomber>();
attack.SetTarget(target + targetOffset); attack.SetTarget(w, target + targetOffset);
attack.OnEnteredAttackRange += onEnterRange; attack.OnEnteredAttackRange += onEnterRange;
attack.OnExitedAttackRange += onExitRange; attack.OnExitedAttackRange += onExitRange;
attack.OnRemovedFromWorld += onExitRange; attack.OnRemovedFromWorld += onExitRange;
@@ -174,7 +174,7 @@ namespace OpenRA.Mods.RA
beacon = new Beacon( beacon = new Beacon(
order.Player, order.Player,
order.TargetLocation.CenterPosition, self.World.Map.CenterOfCell(order.TargetLocation),
Info.BeaconPalettePrefix, Info.BeaconPalettePrefix,
Info.BeaconPoster, Info.BeaconPoster,
Info.BeaconPosterPalette, Info.BeaconPosterPalette,

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA
public void RenderAfterWorld(WorldRenderer wr, World world) 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); var targetUnits = power.UnitsInRange(xy);
foreach (var unit in targetUnits) foreach (var unit in targetUnits)
if (manager.self.Owner.Shroud.IsTargetable(unit)) if (manager.self.Owner.Shroud.IsTargetable(unit))
@@ -132,11 +132,11 @@ namespace OpenRA.Mods.RA
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) public IEnumerable<IRenderable> 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 tiles = world.Map.FindTilesInCircle(xy, range);
var pal = wr.Palette("terrain"); var pal = wr.Palette("terrain");
foreach (var t in tiles) foreach (var t in tiles)
yield return new SpriteRenderable(tile, t.CenterPosition, WVec.Zero, -511, pal, 1f, true); yield return new SpriteRenderable(tile, wr.world.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
} }
public string GetCursor(World world, CPos xy, MouseInput mi) public string GetCursor(World world, CPos xy, MouseInput mi)
@@ -212,21 +212,21 @@ namespace OpenRA.Mods.RA
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) public IEnumerable<IRenderable> 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"); var pal = wr.Palette("terrain");
// Source tiles // Source tiles
foreach (var t in world.Map.FindTilesInCircle(sourceLocation, range)) foreach (var t in world.Map.FindTilesInCircle(sourceLocation, range))
yield return new SpriteRenderable(sourceTile, t.CenterPosition, WVec.Zero, -511, pal, 1f, true); yield return new SpriteRenderable(sourceTile, wr.world.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
// Destination tiles // Destination tiles
foreach (var t in world.Map.FindTilesInCircle(xy, range)) foreach (var t in world.Map.FindTilesInCircle(xy, range))
yield return new SpriteRenderable(sourceTile, t.CenterPosition, WVec.Zero, -511, pal, 1f, true); yield return new SpriteRenderable(sourceTile, wr.world.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
// Unit previews // Unit previews
foreach (var unit in power.UnitsInRange(sourceLocation)) foreach (var unit in power.UnitsInRange(sourceLocation))
{ {
var offset = (xy - sourceLocation).ToWVec(); var offset = world.Map.CenterOfCell(xy) - world.Map.CenterOfCell(sourceLocation);
if (manager.self.Owner.Shroud.IsTargetable(unit)) if (manager.self.Owner.Shroud.IsTargetable(unit))
foreach (var r in unit.Render(wr)) foreach (var r in unit.Render(wr))
yield return r.OffsetBy(offset); yield return r.OffsetBy(offset);
@@ -241,7 +241,7 @@ namespace OpenRA.Mods.RA
var canEnter = manager.self.Owner.Shroud.IsExplored(targetCell) && var canEnter = manager.self.Owner.Shroud.IsExplored(targetCell) &&
unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit, targetCell); unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit, targetCell);
var tile = canEnter ? validTile : invalidTile; var tile = canEnter ? validTile : invalidTile;
yield return new SpriteRenderable(tile, targetCell.CenterPosition, WVec.Zero, -511, pal, 1f, true); yield return new SpriteRenderable(tile, wr.world.Map.CenterOfCell(targetCell), WVec.Zero, -511, pal, 1f, true);
} }
} }
} }

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
self.Trait<RenderBuilding>().PlayCustomAnim(self, "active"); self.Trait<RenderBuilding>().PlayCustomAnim(self, "active");
Sound.Play(info.IronCurtainSound, order.TargetLocation.CenterPosition); Sound.Play(info.IronCurtainSound, self.World.Map.CenterOfCell(order.TargetLocation));
foreach (var target in UnitsInRange(order.TargetLocation) foreach (var target in UnitsInRange(order.TargetLocation)
.Where(a => a.Owner.Stances[self.Owner] == Stance.Ally)) .Where(a => a.Owner.Stances[self.Owner] == Stance.Ally))
@@ -100,17 +100,18 @@ namespace OpenRA.Mods.RA
public void RenderAfterWorld(WorldRenderer wr, World world) 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)) foreach (var unit in power.UnitsInRange(xy))
wr.DrawSelectionBox(unit, Color.Red); wr.DrawSelectionBox(unit, Color.Red);
} }
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) public IEnumerable<IRenderable> 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"); var pal = wr.Palette("terrain");
foreach (var t in world.Map.FindTilesInCircle(xy, range)) foreach (var t in world.Map.FindTilesInCircle(xy, range))
yield return new SpriteRenderable(tile, t.CenterPosition, WVec.Zero, -511, pal, 1f, true); yield return new SpriteRenderable(tile, wr.world.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
} }
public string GetCursor(World world, CPos xy, MouseInput mi) public string GetCursor(World world, CPos xy, MouseInput mi)

View File

@@ -77,9 +77,10 @@ namespace OpenRA.Mods.RA
var rb = self.Trait<RenderSimple>(); var rb = self.Trait<RenderSimple>();
rb.PlayCustomAnim(self, "active"); rb.PlayCustomAnim(self, "active");
var targetPosition = self.World.Map.CenterOfCell(order.TargetLocation);
var missile = new NukeLaunch(self.Owner, npi.MissileWeapon, var missile = new NukeLaunch(self.Owner, npi.MissileWeapon,
self.CenterPosition + body.LocalToWorld(npi.SpawnOffset), self.CenterPosition + body.LocalToWorld(npi.SpawnOffset),
order.TargetLocation.CenterPosition, targetPosition,
npi.FlightVelocity, npi.FlightDelay, npi.SkipAscent); npi.FlightVelocity, npi.FlightDelay, npi.SkipAscent);
self.World.AddFrameEndTask(w => w.Add(missile)); self.World.AddFrameEndTask(w => w.Add(missile));
@@ -103,7 +104,7 @@ namespace OpenRA.Mods.RA
{ {
var beacon = new Beacon( var beacon = new Beacon(
order.Player, order.Player,
order.TargetLocation.CenterPosition, targetPosition,
Info.BeaconPalettePrefix, Info.BeaconPalettePrefix,
Info.BeaconPoster, Info.BeaconPoster,
Info.BeaconPosterPalette, Info.BeaconPosterPalette,

View File

@@ -58,13 +58,13 @@ namespace OpenRA.Mods.RA
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude; var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude;
var a = w.CreateActor(info.UnitType, new TypeDictionary var a = w.CreateActor(info.UnitType, new TypeDictionary
{ {
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)), new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(self.Owner), new OwnerInit(self.Owner),
new FacingInit(Util.GetFacing(order.TargetLocation - startPos, 0)) new FacingInit(w.Map.FacingBetween(startPos, order.TargetLocation, 0))
}); });
a.CancelActivity(); a.CancelActivity();
a.QueueActivity(new FlyAttack(Target.FromOrder(order))); a.QueueActivity(new FlyAttack(Target.FromOrder(self.World, order)));
a.Trait<ParaDrop>().SetLZ(order.TargetLocation); a.Trait<ParaDrop>().SetLZ(order.TargetLocation);
var cargo = a.Trait<Cargo>(); var cargo = a.Trait<Cargo>();

View File

@@ -34,13 +34,13 @@ namespace OpenRA.Mods.RA
var plane = self.World.CreateActor("u2", new TypeDictionary var plane = self.World.CreateActor("u2", new TypeDictionary
{ {
new CenterPositionInit(enterCell.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)), new CenterPositionInit(self.World.Map.CenterOfCell(enterCell) + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(self.Owner), new OwnerInit(self.Owner),
new FacingInit(Util.GetFacing(order.TargetLocation - enterCell, 0)) new FacingInit(self.World.Map.FacingBetween(enterCell, order.TargetLocation, 0))
}); });
plane.CancelActivity(); plane.CancelActivity();
plane.QueueActivity(new Fly(plane, Target.FromCell(order.TargetLocation))); plane.QueueActivity(new Fly(plane, Target.FromCell(self.World, order.TargetLocation)));
plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w => plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w =>
{ {
var camera = w.CreateActor("camera", new TypeDictionary var camera = w.CreateActor("camera", new TypeDictionary

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
{ {
ping = manager.RadarPings.Value.Add( ping = manager.RadarPings.Value.Add(
() => order.Player.IsAlliedWith(self.World.RenderPlayer), () => order.Player.IsAlliedWith(self.World.RenderPlayer),
order.TargetLocation.CenterPosition, self.World.Map.CenterOfCell(order.TargetLocation),
order.Player.Color.RGB, order.Player.Color.RGB,
Info.RadarPingDuration); Info.RadarPingDuration);
} }

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA
public IEnumerable<WPos> TargetablePositions(Actor self) public IEnumerable<WPos> TargetablePositions(Actor self)
{ {
return building.OccupiedCells().Select(c => c.First.CenterPosition); return building.OccupiedCells().Select(c => self.World.Map.CenterOfCell(c.First));
} }
public bool RequiresForceFire { get { return info.RequiresForceFire; } } public bool RequiresForceFire { get { return info.RequiresForceFire; } }

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA
class TransformsInfo : ITraitInfo class TransformsInfo : ITraitInfo
{ {
[ActorReference] public readonly string IntoActor = null; [ActorReference] public readonly string IntoActor = null;
public readonly int2 Offset = int2.Zero; public readonly CVec Offset = CVec.Zero;
public readonly int Facing = 96; public readonly int Facing = 96;
public readonly string[] TransformSounds = { }; public readonly string[] TransformSounds = { };
public readonly string[] NoTransformSounds = { }; public readonly string[] NoTransformSounds = { };
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
if (b != null && b.Locked) if (b != null && b.Locked)
return false; return false;
return bi == null || self.World.CanPlaceBuilding(info.IntoActor, bi, self.Location + (CVec)info.Offset, self); return bi == null || self.World.CanPlaceBuilding(info.IntoActor, bi, self.Location + info.Offset, self);
} }
public IEnumerable<IOrderTargeter> Orders public IEnumerable<IOrderTargeter> Orders
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation) if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make"))); self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make")));
self.QueueActivity(new Transform(self, info.IntoActor) { Offset = (CVec)info.Offset, Facing = info.Facing, Sounds = info.TransformSounds, Race = race }); self.QueueActivity(new Transform(self, info.IntoActor) { Offset = info.Offset, Facing = info.Facing, Sounds = info.TransformSounds, Race = race });
} }
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)

View File

@@ -88,7 +88,7 @@ namespace OpenRA.Mods.RA.Widgets
return null; return null;
var cell = MinimapPixelToCell(pos); var cell = MinimapPixelToCell(pos);
var location = worldRenderer.Viewport.WorldToViewPx(worldRenderer.ScreenPxPosition(cell.CenterPosition)); var location = worldRenderer.Viewport.WorldToViewPx(worldRenderer.ScreenPxPosition(world.Map.CenterOfCell(cell)));
var mi = new MouseInput var mi = new MouseInput
{ {
@@ -113,9 +113,9 @@ namespace OpenRA.Mods.RA.Widgets
return true; return true;
var cell = MinimapPixelToCell(mi.Location); var cell = MinimapPixelToCell(mi.Location);
var pos = cell.CenterPosition; var pos = world.Map.CenterOfCell(cell);
if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left) if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left)
worldRenderer.Viewport.Center(cell.CenterPosition); worldRenderer.Viewport.Center(world.Map.CenterOfCell(cell));
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right) if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right)
{ {
@@ -158,8 +158,8 @@ namespace OpenRA.Mods.RA.Widgets
// Draw viewport rect // Draw viewport rect
if (hasRadar) if (hasRadar)
{ {
var tl = CellToMinimapPixel(worldRenderer.Position(worldRenderer.Viewport.TopLeft).ToCPos()); var tl = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.Position(worldRenderer.Viewport.TopLeft)));
var br = CellToMinimapPixel(worldRenderer.Position(worldRenderer.Viewport.BottomRight).ToCPos()); var br = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.Position(worldRenderer.Viewport.BottomRight)));
Game.Renderer.EnableScissor(mapRect); Game.Renderer.EnableScissor(mapRect);
DrawRadarPings(); DrawRadarPings();
@@ -180,7 +180,8 @@ namespace OpenRA.Mods.RA.Widgets
foreach (var radarPing in radarPings.Pings.Where(e => e.IsVisible())) foreach (var radarPing in radarPings.Pings.Where(e => e.IsVisible()))
{ {
var c = radarPing.Color; 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[0], points[1], c, c);
lr.DrawLine(points[1], points[2], c, c); lr.DrawLine(points[1], points[2], c, c);
@@ -241,18 +242,18 @@ namespace OpenRA.Mods.RA.Widgets
int2 CellToMinimapPixel(CPos p) int2 CellToMinimapPixel(CPos p)
{ {
var viewOrigin = new float2(mapRect.X, mapRect.Y);
var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top); var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top);
var mapOffset = p - mapOrigin;
return (viewOrigin + previewScale * (p - mapOrigin).ToFloat2()).ToInt2(); return new int2(mapRect.X, mapRect.Y) + (previewScale * new float2(mapOffset.X, mapOffset.Y)).ToInt2();
} }
CPos MinimapPixelToCell(int2 p) CPos MinimapPixelToCell(int2 p)
{ {
var viewOrigin = new float2(mapRect.X, mapRect.Y); var viewOrigin = new float2(mapRect.X, mapRect.Y);
var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top); var mapOrigin = new float2(world.Map.Bounds.Left, world.Map.Bounds.Top);
var fcell = mapOrigin + (1f / previewScale) * (p - viewOrigin);
return (CPos)(mapOrigin.ToFloat2() + (1f / previewScale) * (p - viewOrigin)).ToInt2(); return new CPos((int)fcell.X, (int)fcell.Y);
} }
} }
} }

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.RA
if (wr.world.ShroudObscures(kv.Key)) if (wr.world.ShroudObscures(kv.Key))
continue; continue;
new SpriteRenderable(kv.Value, kv.Key.CenterPosition, new SpriteRenderable(kv.Value, wr.world.Map.CenterOfCell(kv.Key),
WVec.Zero, -511, pal, 1f, true).Render(wr); WVec.Zero, -511, pal, 1f, true).Render(wr);
} }
} }

View File

@@ -76,8 +76,9 @@ namespace OpenRA.Mods.RA
layer[cell] = layer[cell] * 5 / 6; layer[cell] = layer[cell] * 5 / 6;
// TODO: This doesn't make sense for isometric terrain // TODO: This doesn't make sense for isometric terrain
var tl = wr.ScreenPxPosition(cell.TopLeft); var pos = wr.world.Map.CenterOfCell(cell);
var br = wr.ScreenPxPosition(cell.BottomRight); var tl = wr.ScreenPxPosition(pos - new WVec(512, 512, 0));
var br = wr.ScreenPxPosition(pos + new WVec(511, 511, 0));
qr.FillRect(RectangleF.FromLTRB(tl.X, tl.Y, br.X, br.Y), Color.FromArgb(w, c)); qr.FillRect(RectangleF.FromLTRB(tl.X, tl.Y, br.X, br.Y), Color.FromArgb(w, c));
} }
} }

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA
public void AddSmudge(CPos loc) public void AddSmudge(CPos loc)
{ {
if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage) if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage)
world.AddFrameEndTask(w => w.Add(new Smoke(w, loc.CenterPosition, Info.SmokeType))); world.AddFrameEndTask(w => w.Add(new Smoke(w, world.Map.CenterOfCell(loc), Info.SmokeType)));
if (!dirty.ContainsKey(loc) && !tiles.ContainsKey(loc)) if (!dirty.ContainsKey(loc) && !tiles.ContainsKey(loc))
{ {
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.RA
if (world.ShroudObscures(kv.Key)) if (world.ShroudObscures(kv.Key))
continue; continue;
new SpriteRenderable(kv.Value.Sprite, kv.Key.CenterPosition, new SpriteRenderable(kv.Value.Sprite, world.Map.CenterOfCell(kv.Key),
WVec.Zero, -511, pal, 1f, true).Render(wr); WVec.Zero, -511, pal, 1f, true).Render(wr);
} }
} }