can build again
This commit is contained in:
@@ -311,6 +311,29 @@ namespace OpenRa.Game
|
|||||||
return CanPlaceBuilding(building, xy, null, adjust);
|
return CanPlaceBuilding(building, xy, null, adjust);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsCloseEnoughToBase(Player p, UnitInfo.BuildingInfo bi, int2 position)
|
||||||
|
{
|
||||||
|
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
|
||||||
|
|
||||||
|
var search = new PathSearch()
|
||||||
|
{
|
||||||
|
heuristic = loc =>
|
||||||
|
{
|
||||||
|
var b = Game.BuildingInfluence.GetBuildingAt(loc);
|
||||||
|
if (b != null && b.Owner == p) return 0;
|
||||||
|
if ((loc - position).Length > maxDistance)
|
||||||
|
return float.PositiveInfinity; /* not quite right */
|
||||||
|
return 1;
|
||||||
|
},
|
||||||
|
checkForBlocked = false,
|
||||||
|
ignoreTerrain = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var t in Footprint.Tiles(bi, position)) search.AddInitialCell(t);
|
||||||
|
|
||||||
|
return Game.PathFinder.FindPath(search).Count != 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static void BuildUnit(Player player, string name)
|
public static void BuildUnit(Player player, string name)
|
||||||
{
|
{
|
||||||
var producerTypes = Rules.TechTree.UnitBuiltAt( Rules.UnitInfo[ name ] );
|
var producerTypes = Rules.TechTree.UnitBuiltAt( Rules.UnitInfo[ name ] );
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace OpenRa.Game
|
|||||||
public UnitMovementType umt;
|
public UnitMovementType umt;
|
||||||
Func<int2, bool> customBlock;
|
Func<int2, bool> customBlock;
|
||||||
public bool checkForBlocked;
|
public bool checkForBlocked;
|
||||||
|
public bool ignoreTerrain;
|
||||||
|
|
||||||
public PathSearch()
|
public PathSearch()
|
||||||
{
|
{
|
||||||
@@ -39,22 +40,31 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
||||||
continue;
|
continue;
|
||||||
if( passableCost[ (int)umt ][ newHere.X, newHere.Y ] == float.PositiveInfinity )
|
if (ignoreTerrain)
|
||||||
continue;
|
{
|
||||||
if( !Game.BuildingInfluence.CanMoveHere( newHere ) )
|
if (!Game.map.IsInMap(newHere.X, newHere.Y)) continue;
|
||||||
continue;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (passableCost[(int)umt][newHere.X, newHere.Y] == float.PositiveInfinity)
|
||||||
|
continue;
|
||||||
|
if (!Game.BuildingInfluence.CanMoveHere(newHere))
|
||||||
|
continue;
|
||||||
|
if (Game.map.IsOverlaySolid(newHere))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if( checkForBlocked && Game.UnitInfluence.GetUnitAt( newHere ) != null )
|
if( checkForBlocked && Game.UnitInfluence.GetUnitAt( newHere ) != null )
|
||||||
continue;
|
continue;
|
||||||
if (customBlock != null && customBlock(newHere))
|
if (customBlock != null && customBlock(newHere))
|
||||||
continue;
|
continue;
|
||||||
if (Game.map.IsOverlaySolid(newHere))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var est = heuristic( newHere );
|
var est = heuristic( newHere );
|
||||||
if( est == float.PositiveInfinity )
|
if( est == float.PositiveInfinity )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float cellCost = ( ( d.X * d.Y != 0 ) ? 1.414213563f : 1.0f ) * passableCost[ (int)umt ][ newHere.X, newHere.Y ];
|
float cellCost = ( ( d.X * d.Y != 0 ) ? 1.414213563f : 1.0f ) *
|
||||||
|
(ignoreTerrain ? 1 : passableCost[ (int)umt ][ newHere.X, newHere.Y ]);
|
||||||
float newCost = cellInfo[ p.Location.X, p.Location.Y ].MinCost + cellCost;
|
float newCost = cellInfo[ p.Location.X, p.Location.Y ].MinCost + cellCost;
|
||||||
|
|
||||||
if( newCost >= cellInfo[ newHere.X, newHere.Y ].MinCost )
|
if( newCost >= cellInfo[ newHere.X, newHere.Y ].MinCost )
|
||||||
|
|||||||
@@ -24,11 +24,9 @@ namespace OpenRa.Game
|
|||||||
if( !Game.CanPlaceBuilding( Building, xy, true ) )
|
if( !Game.CanPlaceBuilding( Building, xy, true ) )
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var maxDistance = Building.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
|
if (!Game.IsCloseEnoughToBase(Owner, Building, xy))
|
||||||
if( !Footprint.Tiles( Building, xy ).Any(
|
|
||||||
t => Game.GetDistanceToBase( t, Owner ) < maxDistance ) )
|
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
yield return OpenRa.Game.Order.PlaceBuilding( Owner, xy, Building.Name );
|
yield return OpenRa.Game.Order.PlaceBuilding( Owner, xy, Building.Name );
|
||||||
}
|
}
|
||||||
else // rmb
|
else // rmb
|
||||||
|
|||||||
@@ -46,22 +46,10 @@ namespace OpenRa.Game
|
|||||||
public void DrawBuildingGrid( UnitInfo.BuildingInfo bi )
|
public void DrawBuildingGrid( UnitInfo.BuildingInfo bi )
|
||||||
{
|
{
|
||||||
var position = Game.controller.MousePosition.ToInt2();
|
var position = Game.controller.MousePosition.ToInt2();
|
||||||
|
var isCloseEnough = Game.IsCloseEnoughToBase(Game.LocalPlayer, bi, position);
|
||||||
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
|
|
||||||
|
|
||||||
//if( ShowBuildDebug )
|
|
||||||
// for( var j = 0 ; j < 128 ; j++ )
|
|
||||||
// for( var i = 0 ; i < 128 ; i++ )
|
|
||||||
// if( Game.GetDistanceToBase( new int2( i, j ), Game.LocalPlayer ) < maxDistance )
|
|
||||||
// if( Game.IsCellBuildable( new int2( i, j ), bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel ) )
|
|
||||||
// if( !Game.map.ContainsResource( new int2( i, j ) ) )
|
|
||||||
// spriteRenderer.DrawSprite( unitDebug, Game.CellSize * new float2( i, j ), 0 );
|
|
||||||
|
|
||||||
var tooFarFromBase = !Footprint.Tiles( bi, position ).Any(
|
|
||||||
t => Game.GetDistanceToBase( t, Game.LocalPlayer ) < maxDistance );
|
|
||||||
|
|
||||||
foreach( var t in Footprint.Tiles( bi, position ) )
|
foreach( var t in Footprint.Tiles( bi, position ) )
|
||||||
spriteRenderer.DrawSprite( ( !tooFarFromBase && Game.IsCellBuildable( t, bi.WaterBound
|
spriteRenderer.DrawSprite( ( isCloseEnough && Game.IsCellBuildable( t, bi.WaterBound
|
||||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.map.ContainsResource( t ) )
|
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.map.ContainsResource( t ) )
|
||||||
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user