diff --git a/OpenRa.Game/BuildingInfluenceMap.cs b/OpenRa.Game/BuildingInfluenceMap.cs index f207245468..c85b19840f 100644 --- a/OpenRa.Game/BuildingInfluenceMap.cs +++ b/OpenRa.Game/BuildingInfluenceMap.cs @@ -11,6 +11,7 @@ namespace OpenRa.Game { class BuildingInfluenceMap { + bool[,] blocked = new bool[128, 128]; Pair[,] influence = new Pair[128, 128]; readonly int maxDistance; /* clip limit for voronoi cells */ static readonly Pair NoClaim = Pair.New((Actor)null, float.MaxValue); @@ -41,6 +42,10 @@ namespace OpenRa.Game var initialTileCount = 0; + foreach (var u in Footprint.UnpathableTiles(a.unitInfo, a.Location)) + if (IsValid(u)) + blocked[u.X, u.Y] = true; + foreach (var t in tiles) if (IsValid(t)) { @@ -103,6 +108,10 @@ namespace OpenRa.Game tiles.Aggregate(int2.Min) - new int2(maxDistance, maxDistance)); var max = int2.Min(new int2(128, 128), tiles.Aggregate(int2.Max) + new int2(maxDistance, maxDistance)); + + foreach (var u in Footprint.UnpathableTiles(a.unitInfo, a.Location)) + if (IsValid(u)) + blocked[u.X, u.Y] = false; for (var j = min.Y; j <= max.Y; j++) for (var i = min.X; i <= max.X; i++) @@ -149,6 +158,11 @@ namespace OpenRa.Game return (int)influence[cell.X, cell.Y].Second; } + public bool CanMoveHere(int2 cell) + { + return IsValid(cell) && !blocked[cell.X, cell.Y]; + } + struct Cell : IComparable { public int2 location; diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index 395251755a..c2d443bffc 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -52,7 +52,7 @@ namespace OpenRa.Game for( int i = 0 ; i < path.Count ; i++ ) { var sl = path[ i ]; - if( i == 0 || Game.BuildingInfluence.GetBuildingAt( path[ i ] ) == null & Game.UnitInfluence.GetUnitAt( path[ i ] ) == null ) + if( i == 0 || (Game.BuildingInfluence.CanMoveHere(path[i]) && Game.UnitInfluence.GetUnitAt( path[ i ] ) == null) ) { queue.Add( new PathDistance( estimator( sl ), sl ) ); cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false ); @@ -105,7 +105,7 @@ namespace OpenRa.Game continue; if( passableCost[(int)umt][ newHere.X, newHere.Y ] == double.PositiveInfinity ) continue; - if (Game.BuildingInfluence.GetBuildingAt(newHere) != null) + if (!Game.BuildingInfluence.CanMoveHere(newHere)) continue; if( checkForBlock && Game.UnitInfluence.GetUnitAt( newHere ) != null ) continue; diff --git a/OpenRa.Game/Traits/Activities/DeliverOre.cs b/OpenRa.Game/Traits/Activities/DeliverOre.cs index 82b536aae4..7d5e2d0e5f 100644 --- a/OpenRa.Game/Traits/Activities/DeliverOre.cs +++ b/OpenRa.Game/Traits/Activities/DeliverOre.cs @@ -15,6 +15,12 @@ namespace OpenRa.Game.Traits.Activities { if (isDone) { + var harv = self.traits.Get(); + + /* todo: give cash */ + harv.gemsCarried = 0; + harv.oreCarried = 0; + mobile.InternalSetActivity(NextActivity); /* todo: return to the ore patch */ return; diff --git a/OpenRa.Game/Traits/Activities/Move.cs b/OpenRa.Game/Traits/Activities/Move.cs index 89fd565f2a..8a0b35c5ca 100755 --- a/OpenRa.Game/Traits/Activities/Move.cs +++ b/OpenRa.Game/Traits/Activities/Move.cs @@ -33,9 +33,9 @@ namespace OpenRa.Game.Traits.Activities static bool CanEnterCell( int2 c, Actor self ) { + if (!Game.BuildingInfluence.CanMoveHere(c)) return false; var u = Game.UnitInfluence.GetUnitAt( c ); - var b = Game.BuildingInfluence.GetBuildingAt( c ); - return ( u == null || u == self ) && b == null; + return (u == null || u == self); } public void Tick( Actor self, Mobile mobile ) diff --git a/OpenRa.Game/Traits/Harvester.cs b/OpenRa.Game/Traits/Harvester.cs index a9a2ca89f5..a7988556c3 100644 --- a/OpenRa.Game/Traits/Harvester.cs +++ b/OpenRa.Game/Traits/Harvester.cs @@ -8,8 +8,8 @@ namespace OpenRa.Game.Traits class Harvester : IOrder { const int capacity = 28; - int oreCarried = 0; /* sum of these must not exceed capacity */ - int gemsCarried = 0; + public int oreCarried = 0; /* sum of these must not exceed capacity */ + public int gemsCarried = 0; public bool IsFull { get { return oreCarried + gemsCarried == capacity; } } public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } }