Ejemplo n.º 1
0
  void updateLists()
  {
    for( int i=G_WHEAT; i < G_MAX; i++ )
    {
      GoodType gtype = (GoodType)i;
      const GoodInfo& info = goods[ gtype ];

      switch( info.order )
      {
      case CityTradeOptions::importing:
        buys.setMaxQty( gtype, 9999 );
        sells.setMaxQty( gtype, 0 );
      break;

      case CityTradeOptions::exporting:
        buys.setMaxQty( gtype, 0 );
        sells.setMaxQty( gtype, 9999 );
      break;

      case CityTradeOptions::noTrade:
        buys.setMaxQty( gtype, 0 );
        buys.setMaxQty( gtype, 0 );
      break;

      default: break;
      }
    }
  }
Ejemplo n.º 2
0
Propagator::DirectRoute getWarehouse4Buys( Propagator &pathPropagator,
                                           SimpleGoodStore& basket )
{
  Propagator::Routes pathWayList = pathPropagator.getRoutes( building::warehouse );

  std::map< int, Propagator::DirectRoute > warehouseRating;

  // select the warehouse with the max quantity of requested goods
  Propagator::Routes::iterator pathWayIt = pathWayList.begin(); 
  while( pathWayIt != pathWayList.end() )
  {
    // for every warehouse within range
    WarehousePtr warehouse= pathWayIt->first.as< Warehouse >();

    int rating = 0;
    for( int i=Good::wheat; i<Good::goodCount; i++ )
    {
      Good::Type gtype = Good::Type(i);
      int qty = warehouse->getGoodStore().getMaxRetrieve( gtype );
      int need = basket.getFreeQty( gtype );
      rating = need > 0 ? ( qty ) : 0;
    }

    rating = math::clamp( rating - pathWayIt->second.getLength(), 0, 999 );
    warehouseRating[ rating ] = *pathWayIt; 

    pathWayIt++;
  }

  //have only available warehouses, find nearest of it
  return warehouseRating.size() > 0 ? warehouseRating.rbegin()->second : Propagator::DirectRoute();
}
Ejemplo n.º 3
0
  Impl()
  {
    buys.setMaxQty( 9999 );
    sells.setMaxQty( 9999 );
    for( int i=G_WHEAT; i < G_MAX; i++ )
    {
      GoodType gtype = (GoodType)i;
      goods[ gtype ].stacking = false;
      goods[ gtype ].order = CityTradeOptions::noTrade;
      goods[ gtype ].vendor = true;
      goods[ gtype ].exportLimit = 0;
    }

    goods[ G_FISH ].order = CityTradeOptions::disabled;
    goods[ G_DENARIES ].order = CityTradeOptions::disabled;
  }
Ejemplo n.º 4
0
TilePos getWalkerDestination2( Propagator &pathPropagator, const TileOverlayType type, 
                               MarketPtr market, SimpleGoodStore& basket, const Good::Type what,
                               PathWay &oPathWay, long& reservId )
{
  SmartPtr< T > res;

  Propagator::Routes pathWayList;
  pathPropagator.getRoutes(type, pathWayList);

  int max_qty = 0;

  // select the warehouse with the max quantity of requested goods
  for( Propagator::Routes::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 = std::min( max_qty, market->getGoodDemand( what ) );
    qty = std::min(qty, basket.getMaxQty( what ) - basket.getCurrentQty( what ));
    // std::cout << "MarketLady reserves from warehouse, qty=" << qty << std::endl;
    GoodStock stock( what, qty, qty);
    reservId = res->getGoodStore().reserveRetrieval( stock );
    return res->getTilePos();
  }

  return TilePos(-1, -1);
}
Ejemplo n.º 5
0
  bool isAnyGoodStored()
  {
    bool anyGoodStored = false;
    for( int i = 0; i < G_MAX; ++i)
    {
      anyGoodStored |= ( goodStore.getCurrentQty( GoodType(i) ) >= 100 );
    }

    return anyGoodStored;
  }