harvester empties; first stage of fixing BIM behavior

This commit is contained in:
Chris Forbes
2009-11-04 21:03:56 +13:00
parent 0d2b7eb855
commit 43170cc318
5 changed files with 26 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ namespace OpenRa.Game
{ {
class BuildingInfluenceMap class BuildingInfluenceMap
{ {
bool[,] blocked = new bool[128, 128];
Pair<Actor, float>[,] influence = new Pair<Actor, float>[128, 128]; Pair<Actor, float>[,] influence = new Pair<Actor, float>[128, 128];
readonly int maxDistance; /* clip limit for voronoi cells */ readonly int maxDistance; /* clip limit for voronoi cells */
static readonly Pair<Actor, float> NoClaim = Pair.New((Actor)null, float.MaxValue); static readonly Pair<Actor, float> NoClaim = Pair.New((Actor)null, float.MaxValue);
@@ -41,6 +42,10 @@ namespace OpenRa.Game
var initialTileCount = 0; 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) foreach (var t in tiles)
if (IsValid(t)) if (IsValid(t))
{ {
@@ -104,6 +109,10 @@ namespace OpenRa.Game
var max = int2.Min(new int2(128, 128), var max = int2.Min(new int2(128, 128),
tiles.Aggregate(int2.Max) + new int2(maxDistance, maxDistance)); 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 j = min.Y; j <= max.Y; j++)
for (var i = min.X; i <= max.X; i++) for (var i = min.X; i <= max.X; i++)
if (influence[i, j].First == a) if (influence[i, j].First == a)
@@ -149,6 +158,11 @@ namespace OpenRa.Game
return (int)influence[cell.X, cell.Y].Second; return (int)influence[cell.X, cell.Y].Second;
} }
public bool CanMoveHere(int2 cell)
{
return IsValid(cell) && !blocked[cell.X, cell.Y];
}
struct Cell : IComparable<Cell> struct Cell : IComparable<Cell>
{ {
public int2 location; public int2 location;

View File

@@ -52,7 +52,7 @@ namespace OpenRa.Game
for( int i = 0 ; i < path.Count ; i++ ) for( int i = 0 ; i < path.Count ; i++ )
{ {
var sl = path[ 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 ) ); queue.Add( new PathDistance( estimator( sl ), sl ) );
cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false ); cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false );
@@ -105,7 +105,7 @@ namespace OpenRa.Game
continue; continue;
if( passableCost[(int)umt][ newHere.X, newHere.Y ] == double.PositiveInfinity ) if( passableCost[(int)umt][ newHere.X, newHere.Y ] == double.PositiveInfinity )
continue; continue;
if (Game.BuildingInfluence.GetBuildingAt(newHere) != null) if (!Game.BuildingInfluence.CanMoveHere(newHere))
continue; continue;
if( checkForBlock && Game.UnitInfluence.GetUnitAt( newHere ) != null ) if( checkForBlock && Game.UnitInfluence.GetUnitAt( newHere ) != null )
continue; continue;

View File

@@ -15,6 +15,12 @@ namespace OpenRa.Game.Traits.Activities
{ {
if (isDone) if (isDone)
{ {
var harv = self.traits.Get<Harvester>();
/* todo: give cash */
harv.gemsCarried = 0;
harv.oreCarried = 0;
mobile.InternalSetActivity(NextActivity); mobile.InternalSetActivity(NextActivity);
/* todo: return to the ore patch */ /* todo: return to the ore patch */
return; return;

View File

@@ -33,9 +33,9 @@ namespace OpenRa.Game.Traits.Activities
static bool CanEnterCell( int2 c, Actor self ) static bool CanEnterCell( int2 c, Actor self )
{ {
if (!Game.BuildingInfluence.CanMoveHere(c)) return false;
var u = Game.UnitInfluence.GetUnitAt( c ); var u = Game.UnitInfluence.GetUnitAt( c );
var b = Game.BuildingInfluence.GetBuildingAt( c ); return (u == null || u == self);
return ( u == null || u == self ) && b == null;
} }
public void Tick( Actor self, Mobile mobile ) public void Tick( Actor self, Mobile mobile )

View File

@@ -8,8 +8,8 @@ namespace OpenRa.Game.Traits
class Harvester : IOrder class Harvester : IOrder
{ {
const int capacity = 28; const int capacity = 28;
int oreCarried = 0; /* sum of these must not exceed capacity */ public int oreCarried = 0; /* sum of these must not exceed capacity */
int gemsCarried = 0; public int gemsCarried = 0;
public bool IsFull { get { return oreCarried + gemsCarried == capacity; } } public bool IsFull { get { return oreCarried + gemsCarried == capacity; } }
public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } }