Replace CPos.CenterPosition -> Map.CenterOfCell.
This commit is contained in:
@@ -40,10 +40,6 @@ namespace OpenRA
|
||||
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)
|
||||
{
|
||||
return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)),
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Graphics
|
||||
foreach (var cell in map.Cells)
|
||||
{
|
||||
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);
|
||||
nv += 4;
|
||||
}
|
||||
|
||||
10
OpenRA.Game/Graphics/Viewport.cs
Executable file → Normal file
10
OpenRA.Game/Graphics/Viewport.cs
Executable file → Normal file
@@ -90,8 +90,10 @@ namespace OpenRA.Graphics
|
||||
|
||||
// Calculate map bounds in world-px
|
||||
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);
|
||||
|
||||
CenterLocation = (tl + br) / 2;
|
||||
@@ -131,8 +133,8 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
get
|
||||
{
|
||||
var ctl = VisibleCells.TopLeft.TopLeft;
|
||||
var cbr = VisibleCells.BottomRight.BottomRight;
|
||||
var ctl = worldRenderer.world.Map.CenterOfCell(VisibleCells.TopLeft) - new WVec(512, 512, 0);
|
||||
var cbr = worldRenderer.world.Map.CenterOfCell(VisibleCells.BottomRight) + new WVec(511, 511, 0);
|
||||
var tl = WorldToViewPx(worldRenderer.ScreenPxPosition(ctl)).Clamp(ScreenClip);
|
||||
var br = WorldToViewPx(worldRenderer.ScreenPxPosition(cbr)).Clamp(ScreenClip);
|
||||
return Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y);
|
||||
|
||||
@@ -461,7 +461,15 @@ namespace OpenRA
|
||||
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.
|
||||
{
|
||||
@@ -604,8 +612,8 @@ namespace OpenRA
|
||||
|
||||
public WRange DistanceToEdge(WPos pos, WVec dir)
|
||||
{
|
||||
var tl = Bounds.TopLeftAsCPos().TopLeft;
|
||||
var br = Bounds.BottomRightAsCPos().BottomRight;
|
||||
var tl = CenterOfCell(new CPos(Bounds.Left, Bounds.Top)) - new WVec(512, 512, 0);
|
||||
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 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);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Traits
|
||||
int generation;
|
||||
|
||||
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)
|
||||
{
|
||||
return o.TargetActor != null
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Traits
|
||||
|
||||
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)
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Traits
|
||||
|
||||
var c = render[cell];
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,12 +65,13 @@ namespace OpenRA.Traits
|
||||
|
||||
static IEnumerable<CPos> FindVisibleTiles(World world, CPos position, WRange radius)
|
||||
{
|
||||
var map = world.Map;
|
||||
var r = (radius.Range + 1023) / 1024;
|
||||
var limit = radius.Range * radius.Range;
|
||||
var pos = position.CenterPosition;
|
||||
var pos = map.CenterOfCell(position);
|
||||
|
||||
foreach (var cell in world.Map.FindTilesInCircle(position, r))
|
||||
if ((cell.CenterPosition - pos).HorizontalLengthSquared <= limit)
|
||||
foreach (var cell in map.FindTilesInCircle(position, r))
|
||||
if ((map.CenterOfCell(cell) - pos).HorizontalLengthSquared <= limit)
|
||||
yield return cell;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
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));
|
||||
|
||||
if (info.CameraActor == null)
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Cnc
|
||||
var altitude = self.World.Map.Rules.Actors[actorType].Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||
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 FacingInit(64)
|
||||
});
|
||||
|
||||
@@ -348,7 +348,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
for (var k = MaxBaseDistance; k >= 0; 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)
|
||||
if (world.CanPlaceBuilding(actorType, bi, t, null))
|
||||
@@ -360,10 +360,11 @@ namespace OpenRA.Mods.RA.AI
|
||||
return null;
|
||||
};
|
||||
|
||||
var baseCenterPos = world.Map.CenterOfCell(baseCenter);
|
||||
switch (type)
|
||||
{
|
||||
case BuildingType.Defense:
|
||||
var enemyBase = FindEnemyBuildingClosestToPos(baseCenter.CenterPosition);
|
||||
var enemyBase = FindEnemyBuildingClosestToPos(baseCenterPos);
|
||||
return enemyBase != null ? findPos(enemyBase.CenterPosition, defenseCenter) : null;
|
||||
|
||||
case BuildingType.Refinery:
|
||||
@@ -371,11 +372,12 @@ namespace OpenRA.Mods.RA.AI
|
||||
.Where(a => resourceTypeIndices.Contains(Map.GetTerrainIndex(new CPos(a.X, a.Y))));
|
||||
if (tilesPos.Any())
|
||||
{
|
||||
var pos = tilesPos.MinBy(a => (a.CenterPosition - baseCenter.CenterPosition).LengthSquared);
|
||||
return findPos(pos.CenterPosition, baseCenter);
|
||||
var pos = tilesPos.MinBy(a => (world.Map.CenterOfCell(a) - baseCenterPos).LengthSquared);
|
||||
return findPos(world.Map.CenterOfCell(pos), baseCenter);
|
||||
}
|
||||
return null;
|
||||
|
||||
|
||||
case BuildingType.Building:
|
||||
for (var k = 0; k < maxBaseDistance; k++)
|
||||
{
|
||||
@@ -441,7 +443,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
// Pick something worth attacking owned by that player
|
||||
var target = world.Actors
|
||||
.Where(a => a.Owner == enemy && a.HasTrait<IOccupySpace>())
|
||||
.ClosestTo(baseCenter.CenterPosition);
|
||||
.ClosestTo(world.Map.CenterOfCell(baseCenter));
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
@@ -661,7 +663,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
|
||||
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>()
|
||||
&& unit.HasTrait<AttackBase>()).ToList();
|
||||
|
||||
@@ -790,8 +792,8 @@ namespace OpenRA.Mods.RA.AI
|
||||
{
|
||||
for (var j = 0; j < y; j += radiusOfPower * 2)
|
||||
{
|
||||
var pos = new CPos(i, j);
|
||||
var targets = world.FindActorsInCircle(pos.CenterPosition, WRange.FromCells(radiusOfPower)).ToList();
|
||||
var pos = world.Map.CenterOfCell(new CPos(i, j));
|
||||
var targets = world.FindActorsInCircle(pos, WRange.FromCells(radiusOfPower)).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();
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
for (var j = 0; j < y; j += DangerRadius * 2)
|
||||
{
|
||||
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)
|
||||
continue;
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
// TODO: calculate weapons ranges of units and factor those in instead of hard-coding 8.
|
||||
var path = self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||
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)
|
||||
.Sum(u => Math.Max(0, 64 - (loc - u.Location).LengthSquared)))
|
||||
.WithHeuristic(loc =>
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
mobile.IsMoving = true;
|
||||
|
||||
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);
|
||||
|
||||
self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target));
|
||||
|
||||
@@ -43,11 +43,12 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
protected override IEnumerable<CPos> CandidateMovementCells(Actor self)
|
||||
{
|
||||
var map = self.World.Map;
|
||||
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 innerCells = self.World.Map.FindTilesInCircle(targetPosition, minCells);
|
||||
var innerCells = map.FindTilesInCircle(targetPosition, minCells);
|
||||
|
||||
var outerSq = maxRange.Range * maxRange.Range;
|
||||
var innerSq = minRange.Range * minRange.Range;
|
||||
@@ -55,7 +56,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
return outerCells.Except(innerCells).Where(c =>
|
||||
{
|
||||
var dxSq = (c.CenterPosition - center).HorizontalLengthSquared;
|
||||
var dxSq = (map.CenterOfCell(c) - center).HorizontalLengthSquared;
|
||||
return dxSq >= innerSq && dxSq <= outerSq;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
destination = bestCell.Value;
|
||||
|
||||
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.Generation++;
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
}
|
||||
|
||||
// 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 AddedToWorld(Actor self)
|
||||
|
||||
@@ -223,7 +223,7 @@ namespace OpenRA.Mods.RA
|
||||
if (modifiers.HasModifier(TargetModifiers.ForceAttack))
|
||||
{
|
||||
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)
|
||||
cursor = ab.info.OutsideRangeCursor;
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
return footprint.Select(c => (IRenderable)(new SpriteRenderable(
|
||||
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;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
|
||||
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>())
|
||||
{
|
||||
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 )
|
||||
.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>();
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
self.World.ActorMap.RemoveInfluence(self, this);
|
||||
Location = cell;
|
||||
CenterPosition = cell.CenterPosition;
|
||||
CenterPosition = self.World.Map.CenterOfCell(cell);
|
||||
|
||||
if (self.IsInWorld)
|
||||
{
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
|
||||
var altitude = w.Map.Rules.Actors[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||
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 FacingInit(Util.GetFacing(p - startPos, 0))
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
if (!building.IsInWorld || !building.World.Selection.Actors.Contains(building))
|
||||
return SpriteRenderable.None;
|
||||
|
||||
var pos = cachedLocation.CenterPosition;
|
||||
var pos = wr.world.Map.CenterOfCell(cachedLocation);
|
||||
var palette = wr.Palette(palettePrefix+building.Owner.InternalName);
|
||||
return circles.Render(pos, palette).Concat(flag.Render(pos, palette));
|
||||
}
|
||||
|
||||
@@ -42,13 +42,14 @@ namespace OpenRA.Mods.RA
|
||||
this.self = init.self;
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
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); }
|
||||
@@ -69,8 +70,8 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
CenterPosition = pos;
|
||||
|
||||
@@ -23,11 +23,13 @@ namespace OpenRA.Mods.RA
|
||||
class Immobile : IOccupySpace, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||
{
|
||||
[Sync] readonly CPos location;
|
||||
[Sync] readonly WPos position;
|
||||
readonly IEnumerable<Pair<CPos, SubCell>> occupied;
|
||||
|
||||
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)
|
||||
occupied = new [] { Pair.New(TopLeft, SubCell.FullCell) };
|
||||
@@ -36,8 +38,8 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
|
||||
public CPos TopLeft { get { return location; } }
|
||||
public WPos CenterPosition { get { return position; } }
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupied; }
|
||||
public WPos CenterPosition { get { return location.CenterPosition; } }
|
||||
|
||||
public void AddedToWorld(Actor self)
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
// Set viewport
|
||||
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)
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
var pal = wr.Palette("terrain");
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace OpenRA.Mods.RA
|
||||
foreach (var c in minefield)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
if (init.Contains<LocationInit>())
|
||||
{
|
||||
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;
|
||||
@@ -260,7 +260,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
public void SetPosition(Actor self, CPos cell)
|
||||
{
|
||||
SetLocation(cell, fromSubCell, cell, fromSubCell);
|
||||
SetVisualPosition(self, fromCell.CenterPosition + MobileInfo.SubCellOffsets[fromSubCell]);
|
||||
SetVisualPosition(self, self.World.Map.CenterOfCell(fromCell) + MobileInfo.SubCellOffsets[fromSubCell]);
|
||||
FinishedMoving(self);
|
||||
}
|
||||
|
||||
@@ -611,7 +611,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
SetVisualPosition(self, pos);
|
||||
|
||||
// Animate transition
|
||||
var to = cell.CenterPosition;
|
||||
var to = self.World.Map.CenterOfCell(cell);
|
||||
var speed = MovementSpeedForCell(self, cell);
|
||||
var length = speed > 0 ? (to - pos).Length / speed : 0;
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||
var move = new MoveFirstHalf(
|
||||
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,
|
||||
mobile.Facing,
|
||||
mobile.Facing,
|
||||
@@ -375,7 +375,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
var ret2 = new MoveSecondHalf(
|
||||
move,
|
||||
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,
|
||||
moveFraction - moveFractionTotal);
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
// Select only the tiles that are within range from the requested SubCell
|
||||
// This assumes that the SubCell does not change during the path traversal
|
||||
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));
|
||||
|
||||
// See if there is any cell within range that does not involve a cross-domain request
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.RA.Orders
|
||||
|
||||
var actorInfo = rules.Actors[Building];
|
||||
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>();
|
||||
// Linebuild for walls.
|
||||
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA.Orders
|
||||
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)
|
||||
r.OffsetBy(offset).Render(wr);
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace OpenRA.Mods.RA.Orders
|
||||
foreach (var c in cells)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA
|
||||
if (order.OrderString != "PlaceBeacon")
|
||||
return;
|
||||
|
||||
var pos = order.TargetLocation.CenterPosition;
|
||||
var pos = self.World.Map.CenterOfCell(order.TargetLocation);
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
var exit = self.Location + exitinfo.ExitCell;
|
||||
var spawn = self.CenterPosition + exitinfo.SpawnOffset;
|
||||
var to = exit.CenterPosition;
|
||||
var to = self.World.Map.CenterOfCell(exit);
|
||||
|
||||
var fi = producee.Traits.Get<IFacingInfo>();
|
||||
var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi.GetInitialFacing()) : exitinfo.Facing;
|
||||
|
||||
@@ -22,8 +22,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
//TODO: Make palette for this customizable as well
|
||||
var bi = self.Info.Traits.Get<BuildingInfo>();
|
||||
FootprintUtils.UnpathableTiles(self.Info.Name, bi, self.Location).Do(
|
||||
t => self.World.AddFrameEndTask(
|
||||
w => w.Add(new Explosion(w, t.CenterPosition, "building", "effect"))));
|
||||
t => self.World.AddFrameEndTask(w => w.Add(new Explosion(w, w.Map.CenterOfCell(t), "building", "effect"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA.Scripting
|
||||
[Desc("Returns the center of a cell in world coordinates.")]
|
||||
public WPos CenterOfCell(CPos cell)
|
||||
{
|
||||
return cell.CenterPosition;
|
||||
return context.World.Map.CenterOfCell(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace OpenRA.Mods.RA
|
||||
// Initialize tile cache
|
||||
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);
|
||||
tiles[cell] = new ShroudTile(cell, screen, variant);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA
|
||||
var delta = new WVec(0, -1024, 0).Rotate(attackRotation);
|
||||
|
||||
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 finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Range * delta / 1024;
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
beacon = new Beacon(
|
||||
order.Player,
|
||||
order.TargetLocation.CenterPosition,
|
||||
self.World.Map.CenterOfCell(order.TargetLocation),
|
||||
Info.BeaconPalettePrefix,
|
||||
Info.BeaconPoster,
|
||||
Info.BeaconPosterPalette,
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.RA
|
||||
var tiles = world.Map.FindTilesInCircle(xy, range);
|
||||
var pal = wr.Palette("terrain");
|
||||
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)
|
||||
@@ -217,11 +217,11 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
// Source tiles
|
||||
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
|
||||
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
|
||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||
@@ -241,7 +241,7 @@ namespace OpenRA.Mods.RA
|
||||
var canEnter = manager.self.Owner.Shroud.IsExplored(targetCell) &&
|
||||
unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit, targetCell);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
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)
|
||||
.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 pal = wr.Palette("terrain");
|
||||
|
||||
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)
|
||||
|
||||
@@ -77,9 +77,10 @@ namespace OpenRA.Mods.RA
|
||||
var rb = self.Trait<RenderSimple>();
|
||||
rb.PlayCustomAnim(self, "active");
|
||||
|
||||
var targetPosition = self.World.Map.CenterOfCell(order.TargetLocation);
|
||||
var missile = new NukeLaunch(self.Owner, npi.MissileWeapon,
|
||||
self.CenterPosition + body.LocalToWorld(npi.SpawnOffset),
|
||||
order.TargetLocation.CenterPosition,
|
||||
targetPosition,
|
||||
npi.FlightVelocity, npi.FlightDelay, npi.SkipAscent);
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(missile));
|
||||
@@ -103,7 +104,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
var beacon = new Beacon(
|
||||
order.Player,
|
||||
order.TargetLocation.CenterPosition,
|
||||
targetPosition,
|
||||
Info.BeaconPalettePrefix,
|
||||
Info.BeaconPoster,
|
||||
Info.BeaconPosterPalette,
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA
|
||||
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||
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 FacingInit(Util.GetFacing(order.TargetLocation - startPos, 0))
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
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 FacingInit(Util.GetFacing(order.TargetLocation - enterCell, 0))
|
||||
});
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
ping = manager.RadarPings.Value.Add(
|
||||
() => order.Player.IsAlliedWith(self.World.RenderPlayer),
|
||||
order.TargetLocation.CenterPosition,
|
||||
self.World.Map.CenterOfCell(order.TargetLocation),
|
||||
order.Player.Color.RGB,
|
||||
Info.RadarPingDuration);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
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; } }
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
return null;
|
||||
|
||||
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
|
||||
{
|
||||
@@ -113,9 +113,9 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
return true;
|
||||
|
||||
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)
|
||||
worldRenderer.Viewport.Center(cell.CenterPosition);
|
||||
worldRenderer.Viewport.Center(world.Map.CenterOfCell(cell));
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right)
|
||||
{
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.RA
|
||||
if (wr.world.ShroudObscures(kv.Key))
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,9 @@ namespace OpenRA.Mods.RA
|
||||
layer[cell] = layer[cell] * 5 / 6;
|
||||
|
||||
// TODO: This doesn't make sense for isometric terrain
|
||||
var tl = wr.ScreenPxPosition(cell.TopLeft);
|
||||
var br = wr.ScreenPxPosition(cell.BottomRight);
|
||||
var pos = wr.world.Map.CenterOfCell(cell);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA
|
||||
public void AddSmudge(CPos loc)
|
||||
{
|
||||
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))
|
||||
{
|
||||
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.RA
|
||||
if (world.ShroudObscures(kv.Key))
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user