From 738d293b489902f8c8473f29e0875b43e96fa755 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 18 Jan 2010 14:22:38 +1300 Subject: [PATCH] Changed IsCloseEnoughToBase to take top-left position. --- OpenRa.Game/GameRules/Footprint.cs | 4 ++-- OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs | 3 ++- OpenRa.Game/UiOverlay.cs | 2 +- OpenRa.Game/WorldUtils.cs | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/OpenRa.Game/GameRules/Footprint.cs b/OpenRa.Game/GameRules/Footprint.cs index fa113453a9..055f5abd1f 100644 --- a/OpenRa.Game/GameRules/Footprint.cs +++ b/OpenRa.Game/GameRules/Footprint.cs @@ -7,7 +7,7 @@ namespace OpenRa.GameRules { static class Footprint { - public static IEnumerable Tiles( string name, BuildingInfo buildingInfo, int2 position ) + public static IEnumerable Tiles( string name, BuildingInfo buildingInfo, int2 topLeft ) { var dim = buildingInfo.Dimensions; @@ -18,7 +18,7 @@ namespace OpenRa.GameRules footprint = footprint.Concat(new char[dim.X]); } - return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + position ); + return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + topLeft ); } public static IEnumerable Tiles(Actor a, Traits.Building building) diff --git a/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs b/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs index ebcdcd994c..c047266d95 100644 --- a/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs @@ -28,8 +28,9 @@ namespace OpenRa.Orders { if (mi.Button == MouseButton.Left) { + var topLeft = xy - Footprint.AdjustForBuildingSize( BuildingInfo ); if (!Game.world.CanPlaceBuilding( Building, BuildingInfo, xy, null, true) - || !Game.world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, xy)) + || !Game.world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, topLeft)) { Sound.Play("nodeply1.aud"); yield break; diff --git a/OpenRa.Game/UiOverlay.cs b/OpenRa.Game/UiOverlay.cs index 3042179706..55a6dbb667 100644 --- a/OpenRa.Game/UiOverlay.cs +++ b/OpenRa.Game/UiOverlay.cs @@ -47,7 +47,7 @@ namespace OpenRa { var position = Game.controller.MousePosition.ToInt2(); var topLeft = position - Footprint.AdjustForBuildingSize( bi ); - var isCloseEnough = Game.world.IsCloseEnoughToBase(Game.LocalPlayer, name, bi, position); + var isCloseEnough = Game.world.IsCloseEnoughToBase(Game.LocalPlayer, name, bi, topLeft); foreach( var t in Footprint.Tiles( name, bi, topLeft ) ) spriteRenderer.DrawSprite( ( isCloseEnough && Game.world.IsCellBuildable( t, bi.WaterBound diff --git a/OpenRa.Game/WorldUtils.cs b/OpenRa.Game/WorldUtils.cs index 13d82a8833..f661d94ec0 100755 --- a/OpenRa.Game/WorldUtils.cs +++ b/OpenRa.Game/WorldUtils.cs @@ -108,9 +108,10 @@ namespace OpenRa toIgnore)); } - public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 position) + public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft) { var maxDistance = bi.Adjacent + 1; + var position = topLeft + Footprint.AdjustForBuildingSize( bi ); var search = new PathSearch() { @@ -126,7 +127,6 @@ namespace OpenRa ignoreTerrain = true, }; - var topLeft = position - Footprint.AdjustForBuildingSize( bi ); foreach (var t in Footprint.Tiles(buildingName, bi, topLeft)) search.AddInitialCell(t); return world.PathFinder.FindPath(search).Count != 0;