diff --git a/OpenRa.Game/BuildingInfluenceMap.cs b/OpenRa.Game/BuildingInfluenceMap.cs index 1d7bc89bad..bd2ab8cea7 100644 --- a/OpenRa.Game/BuildingInfluenceMap.cs +++ b/OpenRa.Game/BuildingInfluenceMap.cs @@ -40,18 +40,6 @@ namespace OpenRa return influence[cell.X, cell.Y]; } - public Actor GetNearestBuilding(int2 cell) - { - if (!IsValid(cell)) return null; - return influence[cell.X, cell.Y]; - } - - public int GetDistanceToBuilding(int2 cell) - { - if (!IsValid(cell)) return int.MaxValue; - return influence[cell.X, cell.Y] == null ? int.MaxValue : 0; - } - public bool CanMoveHere(int2 cell) { return IsValid(cell) && !blocked[cell.X, cell.Y]; diff --git a/OpenRa.Game/Traits/Building.cs b/OpenRa.Game/Traits/Building.cs index 07a0b00007..2c61fa4d68 100644 --- a/OpenRa.Game/Traits/Building.cs +++ b/OpenRa.Game/Traits/Building.cs @@ -19,7 +19,7 @@ namespace OpenRa.Traits public readonly int Power = 0; public readonly bool RequiresPower = false; public readonly bool BaseNormal = true; - public readonly int Adjacent = 1; + public readonly int Adjacent = 2; public readonly bool Bib = false; public readonly bool Capturable = false; public readonly bool Repairable = true; diff --git a/OpenRa.Game/WorldUtils.cs b/OpenRa.Game/WorldUtils.cs index 4e734c875f..3453d74864 100755 --- a/OpenRa.Game/WorldUtils.cs +++ b/OpenRa.Game/WorldUtils.cs @@ -109,26 +109,46 @@ namespace OpenRa 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 buildingMaxBounds = bi.Dimensions; + if( bi.Bib ) + buildingMaxBounds.Y += 1; - var search = new PathSearch() + var scanStart = world.ClampToWorld( topLeft - new int2( bi.Adjacent, bi.Adjacent ) ); + var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( bi.Adjacent, bi.Adjacent ) ); + + var nearnessCandidates = new List(); + + for( int y = scanStart.Y ; y < scanEnd.Y ; y++ ) { - heuristic = loc => + for( int x = scanStart.X ; x < scanEnd.X ; x++ ) { - var b = world.BuildingInfluence.GetBuildingAt(loc); - if (b != null && b.Owner == p && b.Info.Traits.Get().BaseNormal) return 0; - if ((loc - position).Length > maxDistance) - return float.PositiveInfinity; /* not quite right */ - return 1; - }, - checkForBlocked = false, - ignoreTerrain = true, - }; + var at = world.BuildingInfluence.GetBuildingAt( new int2( x, y ) ); + if( at != null && at.Owner == p ) + nearnessCandidates.Add( new int2( x, y ) ); + } + } + var buildingTiles = Footprint.Tiles( buildingName, bi, topLeft ).ToList(); + return nearnessCandidates + .Any( a => buildingTiles + .Any( b => Math.Abs( a.X - b.X ) <= bi.Adjacent + && Math.Abs( a.Y - b.Y ) <= bi.Adjacent ) ); + } - foreach (var t in Footprint.Tiles(buildingName, bi, topLeft)) search.AddInitialCell(t); + static int2 ClampToWorld( this World world, int2 xy ) + { + var mapStart = world.Map.Offset; + var mapEnd = world.Map.Offset + world.Map.Size; + if( xy.X < mapStart.X ) + xy.X = mapStart.X; + if( xy.X > mapEnd.X ) + xy.X = mapEnd.X; - return world.PathFinder.FindPath(search).Count != 0; + if( xy.Y < mapStart.Y ) + xy.Y = mapStart.Y; + if( xy.Y > mapEnd.Y ) + xy.Y = mapEnd.Y; + + return xy; } } }