BuildingPtr CartPusher::getWalkerDestination_warehouse(Propagator &pathPropagator, PathWay &oPathWay)
{
   BuildingPtr res;

   Propagator::ReachedBuldings pathWayList;
   pathPropagator.getReachedBuildings(B_WAREHOUSE, pathWayList);

   for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt)
   {
      // for every warehouse within range
      BuildingPtr building= pathWayIt->first;
      PathWay& pathWay= pathWayIt->second;

      SmartPtr<Warehouse> warehouse= building.as<Warehouse>();
      _d->reservationID = warehouse->getGoodStore().reserveStorage(_d->stock);
      if (_d->reservationID != 0)
      {
         res = warehouse.as<Building>();
         oPathWay = pathWay;
         break;
      }
   }

   return res;
}
BuildingPtr CartPusher::getWalkerDestination_granary(Propagator &pathPropagator, PathWay &oPathWay)
{
   BuildingPtr res;

   GoodType goodType = _d->stock._goodType;
   if (!(goodType == G_WHEAT || goodType == G_FISH || goodType == G_MEAT || goodType == G_FRUIT || goodType == G_VEGETABLE))
   {
      // this good cannot be stored in a granary
      return NULL;
   }

   Propagator::ReachedBuldings pathWayList;
   pathPropagator.getReachedBuildings( B_GRANARY, pathWayList);

   // find a granary with enough storage
   for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt)
   {
      // for every granary within range
      BuildingPtr building= pathWayIt->first;
      PathWay& pathWay= pathWayIt->second;

      SmartPtr<Granary> granary= building.as<Granary>();
      _d->reservationID = granary->getGoodStore().reserveStorage(_d->stock);
      if (_d->reservationID != 0)
      {
         res = granary.as<Building>();
         oPathWay = pathWay;
         break;
      }
   }

   return res;
}
BuildingPtr CartPusher::getWalkerDestination_factory(Propagator &pathPropagator, PathWay &oPathWay)
{
   BuildingPtr res;
   GoodType goodType = _d->stock._goodType;
   BuildingType buildingType = BuildingDataHolder::instance().getBuildingTypeByInGood(goodType);

   if (buildingType == B_NONE)
   {
      // no factory can use this good
      return NULL;
   }

   Propagator::ReachedBuldings pathWayList;
   pathPropagator.getReachedBuildings(buildingType, pathWayList);

   for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt)
   {
      // for every factory within range
      BuildingPtr building= pathWayIt->first;
      PathWay& pathWay= pathWayIt->second;

      SmartPtr<Factory> factory = building.as<Factory>();
      _d->reservationID = factory->getGoodStore().reserveStorage(_d->stock);
      if (_d->reservationID != 0)
      {
         res = factory.as<Building>();
         oPathWay = pathWay;
         break;
      }
   }

   return res;
}
Beispiel #4
0
void TraineeWalker::checkDestination(const BuildingType buildingType, Propagator &pathPropagator)
{
  Propagator::ReachedBuldings pathWayList;
  pathPropagator.getReachedBuildings(buildingType, pathWayList);

  for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); 
    pathWayIt != pathWayList.end(); ++pathWayIt)
  {
    // for every building within range
    BuildingPtr building = pathWayIt->first;

    float need = building->evaluateTrainee(_traineeType);
    if (need > _maxNeed)
    {
      _maxNeed = need;
      _destinationBuilding = building;
    }
  }
}
TilePos getSupplierDestination2( Propagator &pathPropagator, const BuildingType type, 
                                 const GoodType what, const int needQty,
                                 PathWay &oPathWay, long& reservId )
{
  SmartPtr< T > res;

  Propagator::ReachedBuldings pathWayList;
  pathPropagator.getReachedBuildings(type, pathWayList);

  int max_qty = 0;

  // select the warehouse with the max quantity of requested goods
  for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); 
       pathWayIt != pathWayList.end(); ++pathWayIt)
  {
    // for every warehouse within range
    BuildingPtr building= pathWayIt->first;
    PathWay& pathWay= pathWayIt->second;

    SmartPtr< T > destBuilding = building.as< T >();
    int qty = destBuilding->getGoodStore().getMaxRetrieve( what );
    if( qty > max_qty )
    {
      res = destBuilding;
      oPathWay = pathWay;
      max_qty = qty;
    }
  }

  if( res.isValid() )
  {
    // a warehouse/granary has been found!
    // reserve some goods from that warehouse/granary
    int qty = math::clamp( needQty, 0, max_qty );
    GoodStock tmpStock( what, qty, qty);
    reservId = res->getGoodStore().reserveRetrieval( tmpStock );
    return res->getTilePos();
  }
  else
  {
    return TilePos( -1, -1 );
  }
}