当前位置: 首页>>代码示例>>C++>>正文


C++ Propagator::getRoutes方法代码示例

本文整理汇总了C++中Propagator::getRoutes方法的典型用法代码示例。如果您正苦于以下问题:C++ Propagator::getRoutes方法的具体用法?C++ Propagator::getRoutes怎么用?C++ Propagator::getRoutes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Propagator的用法示例。


在下文中一共展示了Propagator::getRoutes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

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();
}
开发者ID:BlackFoks,项目名称:opencaesar3,代码行数:32,代码来源:merchant.cpp

示例2: reserveShortestPath

BuildingPtr reserveShortestPath( const BuildingType buildingType, 
                                 GoodStock& stock, long& reservationID,
                                 Propagator &pathPropagator, PathWay &oPathWay )
{
  BuildingPtr res;
  Propagator::Routes pathWayList;
  pathPropagator.getRoutes(buildingType, pathWayList);

  //remove factories with improrer storage
  Propagator::Routes::iterator pathWayIt= pathWayList.begin();
  while( pathWayIt != pathWayList.end() )
  {
    // for every factory within range
    SmartPtr<T> building = pathWayIt->first.as<T>();

    if( stock._currentQty >  building->getGoodStore().getMaxStore( stock.type() ) )
    {
      pathWayList.erase( pathWayIt++ );
    }
    else
    {
      pathWayIt++;
    }
  }

  //find shortest path
  int maxLength = 999;
  PathWay* shortestPath = 0;
  for( Propagator::Routes::iterator pathIt = pathWayList.begin(); 
    pathIt != pathWayList.end(); pathIt++ )
  {
    if( pathIt->second.getLength() < maxLength )
    {
      shortestPath = &pathIt->second;
      maxLength = pathIt->second.getLength();
      res = pathIt->first;
    }
  }

  if( res.isValid() )
  {
    reservationID = res.as<T>()->getGoodStore().reserveStorage( stock );
    if (reservationID != 0)
    {
      oPathWay = *shortestPath;
    }
    else
    {
      res = BuildingPtr();
    }
  }


  return res;
}
开发者ID:mjgsklea,项目名称:opencaesar3,代码行数:55,代码来源:oc3_walker_cart_pusher.cpp

示例3: _checkDestination

void TraineeWalker::_checkDestination(const object::Type buildingType, Propagator &pathPropagator)
{
  DirectPRoutes pathWayList = pathPropagator.getRoutes( buildingType );

  for( auto item : pathWayList )
  {
    // for every building within range
    BuildingPtr building = item.first.as<Building>();

    float need = building->evaluateTrainee( type() );
    if (need > _d->maxNeed)
    {
      _d->maxNeed = need;
      _d->destLocation = building->pos();
    }
  }
}
开发者ID:binakot,项目名称:caesaria-game,代码行数:17,代码来源:trainee.cpp

示例4: getWalkerDestination2

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);
}
开发者ID:brobits,项目名称:opencaesar3,代码行数:43,代码来源:market_lady.cpp

示例5: getSupplierDestination2

TilePos getSupplierDestination2( Propagator &pathPropagator, const TileOverlayType type, 
                                 const Good::Type what, const int needQty,
                                 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 = math::clamp( needQty, 0, max_qty );
    GoodStock tmpStock( what, qty, qty);
    reservId = res->getGoodStore().reserveRetrieval( tmpStock );
    return res->getTilePos();
  }
  else
  {
    return TilePos( -1, -1 );
  }
}
开发者ID:brobits,项目名称:opencaesar3,代码行数:43,代码来源:cart_supplier.cpp


注:本文中的Propagator::getRoutes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。