Ejemplo n.º 1
0
void CartSupplier::computeWalkerDestination(BuildingPtr building, const Good::Type type, const int qty )
{
  _d->baseBuildingPos = building->getTilePos();
  _d->storageBuildingPos = TilePos( -1, -1 );  // no destination yet

  // we have something to buy!
  // get the list of buildings within reach
  PathWay pathWay;
  Propagator pathPropagator( _d->city );
  pathPropagator.init( building.as<Construction>() );
  pathPropagator.propagate( _d->maxDistance);

  // try get that good from a granary
  _d->storageBuildingPos = getSupplierDestination2<Granary>( pathPropagator, B_GRANARY,
                                                             type, qty, pathWay, _d->reservationID );

  if( _d->storageBuildingPos.getI() < 0 )
  {
    // try get that good from a warehouse
    _d->storageBuildingPos = getSupplierDestination2<Warehouse>( pathPropagator, B_WAREHOUSE,
                                                                 type, qty, pathWay, _d->reservationID );
  }

  if( _d->storageBuildingPos.getI() >= 0 )
  {
    // we found a destination!
    setPathWay(pathWay);    
  }
  else
  {
    // we have nothing to buy, or cannot find what we need to buy
    deleteLater();
    return;
  }

  setIJ( _getPathway().getOrigin().getIJ() );
}