Changed IsCloseEnoughToBase to take top-left position.
This commit is contained in:
@@ -7,7 +7,7 @@ namespace OpenRa.GameRules
|
|||||||
{
|
{
|
||||||
static class Footprint
|
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;
|
var dim = buildingInfo.Dimensions;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ namespace OpenRa.GameRules
|
|||||||
footprint = footprint.Concat(new char[dim.X]);
|
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)
|
public static IEnumerable<int2> Tiles(Actor a, Traits.Building building)
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ namespace OpenRa.Orders
|
|||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
|
var topLeft = xy - Footprint.AdjustForBuildingSize( BuildingInfo );
|
||||||
if (!Game.world.CanPlaceBuilding( Building, BuildingInfo, xy, null, true)
|
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");
|
Sound.Play("nodeply1.aud");
|
||||||
yield break;
|
yield break;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
var position = Game.controller.MousePosition.ToInt2();
|
var position = Game.controller.MousePosition.ToInt2();
|
||||||
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
|
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 ) )
|
foreach( var t in Footprint.Tiles( name, bi, topLeft ) )
|
||||||
spriteRenderer.DrawSprite( ( isCloseEnough && Game.world.IsCellBuildable( t, bi.WaterBound
|
spriteRenderer.DrawSprite( ( isCloseEnough && Game.world.IsCellBuildable( t, bi.WaterBound
|
||||||
|
|||||||
@@ -108,9 +108,10 @@ namespace OpenRa
|
|||||||
toIgnore));
|
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 maxDistance = bi.Adjacent + 1;
|
||||||
|
var position = topLeft + Footprint.AdjustForBuildingSize( bi );
|
||||||
|
|
||||||
var search = new PathSearch()
|
var search = new PathSearch()
|
||||||
{
|
{
|
||||||
@@ -126,7 +127,6 @@ namespace OpenRa
|
|||||||
ignoreTerrain = true,
|
ignoreTerrain = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
|
|
||||||
foreach (var t in Footprint.Tiles(buildingName, bi, topLeft)) search.AddInitialCell(t);
|
foreach (var t in Footprint.Tiles(buildingName, bi, topLeft)) search.AddInitialCell(t);
|
||||||
|
|
||||||
return world.PathFinder.FindPath(search).Count != 0;
|
return world.PathFinder.FindPath(search).Count != 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user