diff --git a/OpenRA.Game/CVec.cs b/OpenRA.Game/CVec.cs index f9db67b1ee..97f677bde9 100644 --- a/OpenRA.Game/CVec.cs +++ b/OpenRA.Game/CVec.cs @@ -44,8 +44,6 @@ namespace OpenRA public int LengthSquared { get { return X * X + Y * Y; } } public int Length { get { return (int)Math.Sqrt(LengthSquared); } } - public WVec ToWVec() { return new WVec(X*1024, Y*1024, 0); } - public CVec Clamp(Rectangle r) { return new CVec( @@ -115,7 +113,6 @@ namespace OpenRA { case "X": return X; case "Y": return Y; - case "Facing": return Traits.Util.GetFacing(this, 0); default: throw new LuaException("CVec does not define a member '{0}'".F(key)); } } diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 613c0ca986..512362fad2 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -476,6 +476,11 @@ namespace OpenRA return new CPos(pos.X / 1024, pos.Y / 1024); } + public int FacingBetween(CPos cell, CPos towards, int fallbackfacing) + { + return Traits.Util.GetFacing(CenterOfCell(towards) - CenterOfCell(cell), fallbackfacing); + } + public void Resize(int width, int height) // editor magic. { var oldMapTiles = MapTiles.Value; diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index e7888cab6b..6268bcf1d5 100644 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -42,11 +42,6 @@ namespace OpenRA.Traits return (angle / 4 - 0x40) & 0xFF; } - public static int GetFacing(CVec d, int currentFacing) - { - return GetFacing(d.ToWVec(), currentFacing); - } - public static int GetNearestFacing(int facing, int desiredFacing) { var turn = desiredFacing - facing; diff --git a/OpenRA.Mods.RA/BelowUnits.cs b/OpenRA.Mods.RA/BelowUnits.cs index 5605d09876..04393c931a 100644 --- a/OpenRA.Mods.RA/BelowUnits.cs +++ b/OpenRA.Mods.RA/BelowUnits.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA { // Offset effective position to the top of the northernmost occupied cell var bi = self.Info.Traits.GetOrDefault(); - offset = ((bi != null) ? -FootprintUtils.CenterOffset(bi).Y : 0) - 512; + offset = ((bi != null) ? -FootprintUtils.CenterOffset(self.World, bi).Y : 0) - 512; } public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) diff --git a/OpenRA.Mods.RA/Buildings/Bib.cs b/OpenRA.Mods.RA/Buildings/Bib.cs index 6d93fa3dff..9a67f8ac5d 100755 --- a/OpenRA.Mods.RA/Buildings/Bib.cs +++ b/OpenRA.Mods.RA/Buildings/Bib.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Buildings { var width = bi.Dimensions.X; var bibOffset = bi.Dimensions.Y - 1; - var centerOffset = FootprintUtils.CenterOffset(bi); + var centerOffset = FootprintUtils.CenterOffset(self.World, bi); var location = self.Location; var rows = info.HasMinibib ? 1 : 2; var map = self.World.Map; @@ -49,16 +49,17 @@ namespace OpenRA.Mods.RA.Buildings var index = i; var anim = new Animation(self.World, rs.GetImage(self)); var cellOffset = new CVec(i % width, i / width + bibOffset); + var cell = location + cellOffset; // Some mods may define terrain-specific bibs - var terrain = map.GetTerrainInfo(location + cellOffset).Type; + var terrain = map.GetTerrainInfo(cell).Type; var testSequence = info.Sequence + "-" + terrain; var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence; anim.PlayFetchIndex(sequence, () => index); anim.IsDecoration = true; // Z-order is one set to the top of the footprint - var offset = cellOffset.ToWVec() - centerOffset; + var offset = self.World.Map.CenterOfCell(cell) - self.World.Map.CenterOfCell(location) - centerOffset; var awo = new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512)); rs.Add("bib_{0}".F(i), awo, info.Palette); } diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index 53c64d6dbc..0167f7b20f 100644 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Buildings public Actor FindBaseProvider(World world, Player p, CPos topLeft) { - var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(this); + var center = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, this); foreach (var bp in world.ActorsWithTrait()) { 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 = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(Info); + CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info); BuildComplete = init.Contains(); } diff --git a/OpenRA.Mods.RA/Buildings/FootprintUtils.cs b/OpenRA.Mods.RA/Buildings/FootprintUtils.cs index f6c20667c6..0d288dfd97 100644 --- a/OpenRA.Mods.RA/Buildings/FootprintUtils.cs +++ b/OpenRA.Mods.RA/Buildings/FootprintUtils.cs @@ -62,11 +62,10 @@ namespace OpenRA.Mods.RA.Buildings return new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0); } - public static WVec CenterOffset(BuildingInfo buildingInfo) + public static WVec CenterOffset(World w, BuildingInfo buildingInfo) { var dim = buildingInfo.Dimensions; - // Offset is measured relative to the center of the cell, so need to subtract an additional half cell. - return new CVec(dim.X, dim.Y).ToWVec() / 2 - new WVec(512, 512, 0); + return (w.Map.CenterOfCell(CPos.Zero + new CVec(dim.X, dim.Y)) - w.Map.CenterOfCell(new CPos(1, 1))) / 2; } } } diff --git a/OpenRA.Mods.RA/CrateSpawner.cs b/OpenRA.Mods.RA/CrateSpawner.cs index 5fdad6ed9c..938c089f40 100644 --- a/OpenRA.Mods.RA/CrateSpawner.cs +++ b/OpenRA.Mods.RA/CrateSpawner.cs @@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA { 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)) + new FacingInit(w.Map.FacingBetween(startPos, p, 0)) }); plane.CancelActivity(); diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index 1af21831fb..265fdb3076 100755 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -139,8 +139,7 @@ namespace OpenRA.Mods.RA.Move if (nextCell == null) return this; - var dir = nextCell.Value.First - mobile.fromCell; - var firstFacing = Util.GetFacing(dir, mobile.Facing); + var firstFacing = self.World.Map.FacingBetween(mobile.fromCell, nextCell.Value.First, mobile.Facing); if (firstFacing != mobile.Facing) { path.Add(nextCell.Value.First); @@ -362,7 +361,7 @@ namespace OpenRA.Mods.RA.Move Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2, Util.BetweenCells(self.World, mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2, mobile.Facing, - Util.GetNearestFacing(mobile.Facing, Util.GetFacing(nextCell.Value.First - mobile.toCell, mobile.Facing)), + Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.toCell, nextCell.Value.First, mobile.Facing)), moveFraction - moveFractionTotal); mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second); diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 25a99409cb..59bf4aed1a 100644 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA.Orders initialized = true; } - var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(BuildingInfo) - WPos.Zero; + var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, BuildingInfo) - WPos.Zero; foreach (var r in preview) r.OffsetBy(offset).Render(wr); diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index cd444a92a2..029d14f98f 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Render var bi = init.self.Info.Traits.Get(); // Additional 512 units move from center -> top of cell - var offset = FootprintUtils.CenterOffset(bi).Y + 512; + var offset = FootprintUtils.CenterOffset(init.world, bi).Y + 512; Add("roof", new AnimationWithOffset(roof, null, () => !buildComplete, offset)); } diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs index 5605449ea1..7c7373d3f1 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs @@ -229,7 +229,7 @@ namespace OpenRA.Mods.RA.Scripting public int GetFacing(object vec, double currentFacing) { if (vec is CVec) - return Util.GetFacing((CVec)vec, (int)currentFacing); + return world.Map.FacingBetween(CPos.Zero, CPos.Zero + (CVec)vec, (int)currentFacing); if (vec is WVec) return Util.GetFacing((WVec)vec, (int)currentFacing); throw new ArgumentException("Unsupported vector type: {0}".F(vec.GetType())); diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index b07666206a..37e2f4f21c 100644 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -226,7 +226,7 @@ namespace OpenRA.Mods.RA // Unit previews foreach (var unit in power.UnitsInRange(sourceLocation)) { - var offset = (xy - sourceLocation).ToWVec(); + var offset = world.Map.CenterOfCell(xy) - world.Map.CenterOfCell(sourceLocation); if (manager.self.Owner.Shroud.IsTargetable(unit)) foreach (var r in unit.Render(wr)) yield return r.OffsetBy(offset); diff --git a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs index 24bbf0f0ed..24bb609e82 100644 --- a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs @@ -60,7 +60,7 @@ namespace OpenRA.Mods.RA { 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)) + new FacingInit(w.Map.FacingBetween(startPos, order.TargetLocation, 0)) }); a.CancelActivity(); diff --git a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs index d4ec13acbc..a858b73279 100644 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA { 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)) + new FacingInit(self.World.Map.FacingBetween(enterCell, order.TargetLocation, 0)) }); plane.CancelActivity();