Replace CPos.CenterPosition -> Map.CenterOfCell.

This commit is contained in:
Paul Chote
2013-09-17 22:27:19 +12:00
parent b6d1d26eeb
commit 7b52fa52b6
48 changed files with 105 additions and 90 deletions

View File

@@ -40,10 +40,6 @@ namespace OpenRA
public float2 ToFloat2() { return new float2(X, Y); } public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(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)),

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

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

@@ -90,8 +90,10 @@ 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;
@@ -131,8 +133,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);

View File

@@ -461,7 +461,15 @@ 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 void Resize(int width, int height) // editor magic. public void Resize(int width, int height) // editor magic.
{ {
@@ -604,8 +612,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

@@ -28,7 +28,7 @@ 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(World w, 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(World w, Order o) public static Target FromOrder(World w, Order o)
{ {
return o.TargetActor != null return o.TargetActor != null

View File

@@ -67,7 +67,7 @@ namespace OpenRA.Traits
public static WPos BetweenCells(World w, 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)

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

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

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

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

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

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

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

View File

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

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

@@ -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(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);
@@ -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(Info);
BuildComplete = init.Contains<SkipMakeAnimsInit>(); BuildComplete = init.Contains<SkipMakeAnimsInit>();
} }

View File

@@ -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,7 +92,7 @@ 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(Util.GetFacing(p - startPos, 0))
}); });

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

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

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

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

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

@@ -151,7 +151,7 @@ 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(self.World, 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,
@@ -375,7 +375,7 @@ namespace OpenRA.Mods.RA.Move
var ret2 = new MoveSecondHalf( var ret2 = new MoveSecondHalf(
move, move,
Util.BetweenCells(self.World, 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

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

@@ -86,7 +86,7 @@ namespace OpenRA.Mods.RA.Orders
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(position));
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(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

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

@@ -57,7 +57,7 @@ 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;

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

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

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

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

@@ -136,7 +136,7 @@ namespace OpenRA.Mods.RA
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)
@@ -217,11 +217,11 @@ namespace OpenRA.Mods.RA
// 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))
@@ -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))
@@ -109,8 +109,9 @@ namespace OpenRA.Mods.RA
{ {
var xy = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos(); var xy = wr.Position(wr.Viewport.ViewToWorldPx(Viewport.LastMousePos)).ToCPos();
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,7 +58,7 @@ 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(Util.GetFacing(order.TargetLocation - startPos, 0))
}); });

View File

@@ -34,7 +34,7 @@ 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(Util.GetFacing(order.TargetLocation - enterCell, 0))
}); });

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

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

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