Replace WPos.ToCPos -> Map.CellContaining.

This commit is contained in:
Paul Chote
2013-09-17 22:57:30 +12:00
parent 4bc09692e0
commit 9487f49cd5
43 changed files with 81 additions and 83 deletions

View File

@@ -104,15 +104,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); }
}
} }

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

@@ -100,6 +100,11 @@ namespace OpenRA.Graphics
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(); }
@@ -149,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

@@ -471,6 +471,11 @@ namespace OpenRA
return new WPos(1024 * c.X + 512, 1024 * c.Y + 512, 0); return new WPos(1024 * c.X + 512, 1024 * c.Y + 512, 0);
} }
public CPos CellContaining(WPos pos)
{
return new CPos(pos.X / 1024, pos.Y / 1024);
}
public void Resize(int width, int height) // editor magic. public void Resize(int width, int height) // editor magic.
{ {
var oldMapTiles = MapTiles.Value; var oldMapTiles = MapTiles.Value;

View File

@@ -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

@@ -138,9 +138,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

@@ -181,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

@@ -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

@@ -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

@@ -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)

6
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; } }
@@ -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

@@ -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) };
} }
} }
@@ -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

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

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)
{ {

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

@@ -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

@@ -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;
} }
@@ -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

@@ -82,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

@@ -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":
@@ -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

@@ -266,7 +266,7 @@ namespace OpenRA.Mods.RA.Move
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;
} }
@@ -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";

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

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, world.Map.CenterOfCell(position)); 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.

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

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

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA
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));

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

@@ -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,7 +132,7 @@ 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)
@@ -212,7 +212,7 @@ 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

View File

@@ -100,14 +100,14 @@ 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))

View File

@@ -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);