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
{
bool[,] blocked = new bool[128, 128];
Pair<Actor, float>[,] influence = new Pair<Actor, float>[128, 128];
readonly int maxDistance; /* clip limit for voronoi cells */
static readonly Pair<Actor, float> 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))
{
@@ -104,6 +109,10 @@ namespace OpenRa.Game
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++)
if (influence[i, j].First == a)
@@ -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<Cell>
{
public int2 location;

View File

@@ -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;

View File

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

View File

@@ -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 )

View File

@@ -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; } }