Changed IsCloseEnoughToBase to take top-left position.

This commit is contained in:
Bob
2010-01-18 14:22:38 +13:00
parent 7913fcf75b
commit 738d293b48
4 changed files with 7 additions and 6 deletions

View File

@@ -7,7 +7,7 @@ namespace OpenRa.GameRules
{
static class Footprint
{
public static IEnumerable<int2> Tiles( string name, BuildingInfo buildingInfo, int2 position )
public static IEnumerable<int2> 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<int2> Tiles(Actor a, Traits.Building building)

View File

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

View File

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

View File

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