Пример #1
0
float ServiceWalker::evaluatePath(PathWay &pathWay)
{
   // evaluate all buildings along the path
   std::set<Building*> doneBuildings;  // list of evaluated building: don't do them again
   std::list<Tile*>& pathTileList = pathWay.getAllTiles();

   int distance = 0;
   float res = 0.0;
   for (std::list<Tile*>::iterator itTile = pathTileList.begin(); itTile != pathTileList.end(); ++itTile)
   {
      Tile &tile = **itTile;
      std::set<Building*> reachedBuildings = getReachedBuildings(tile.getI(), tile.getJ());
      for (std::set<Building*>::iterator itBuilding = reachedBuildings.begin(); itBuilding != reachedBuildings.end(); ++itBuilding)
      {
         Building& building = **itBuilding;
         std::pair<std::set<Building*>::iterator, bool> rc = doneBuildings.insert(&building);
         if (rc.second == true)
         {
            // the building has not been evaluated yet
            res = res + building.evaluateService(*this);
         }
      }
      distance++;
   }

   // std::cout << "evaluate path ";
   // pathWay.prettyPrint();
   // std::cout << " = " << res << std::endl;

   return res;
}
Пример #2
0
void ServiceWalker::reservePath(PathWay &pathWay)
{
   // reserve all buildings along the path
   std::set<Building*> doneBuildings;  // list of evaluated building: don't do them again
   std::list<Tile*>& pathTileList = pathWay.getAllTiles();

   for (std::list<Tile*>::iterator itTile = pathTileList.begin(); itTile != pathTileList.end(); ++itTile)
   {
      Tile &tile = **itTile;
      std::set<Building*> reachedBuildings = getReachedBuildings(tile.getI(), tile.getJ());
      for (std::set<Building*>::iterator itBuilding = reachedBuildings.begin(); itBuilding != reachedBuildings.end(); ++itBuilding)
      {
         Building &building = **itBuilding;
         std::pair<std::set<Building*>::iterator, bool> rc = doneBuildings.insert(&building);
         if (rc.second == true)
         {
            // the building has not been reserved yet
            building.reserveService(_service);
         }
      }
   }
}