Beispiel #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;
}
Beispiel #2
0
void ServiceWalker::onNewTile()
{
   Walker::onNewTile();

   std::set<Building*> reachedBuildings = getReachedBuildings(getI(), getJ());
   for (std::set<Building*>::iterator itBuilding = reachedBuildings.begin(); itBuilding != reachedBuildings.end(); ++itBuilding)
   {
      Building &building = **itBuilding;
      building.applyService(*this);
   }
}
bool WalkerPrefect::_looks4Fire( ServiceWalker::ReachedBuildings& buildings, TilePos& pos )
{
  buildings = getReachedBuildings( getIJ() );

  foreach( BuildingPtr building, buildings )
  {
    if( building->getType() == B_BURNING_RUINS )
    {
      pos = building->getTilePos();
      return true;
    }
  }

  return false;
}
void TaxCollector::onMidTile()
{
  ServiceWalker::onMidTile();

  ReachedBuildings buildings = getReachedBuildings( getIJ() );
  for( ReachedBuildings::iterator it=buildings.begin(); it != buildings.end(); it++ )
  {
    HousePtr house = (*it).as<House>();
    if( house.isValid() )
    {
      int money = house->collectTaxes();
      _d->money += money;
      _d->peoplesReached += money > 0 ? house->getNbHabitants() : 0;
    }
  }
}
Beispiel #5
0
bool WalkerPrefect::_looks4Fire( ServiceWalker::ReachedBuildings& buildings, TilePos& pos )
{
  buildings = getReachedBuildings( getIJ() );

  for( ServiceWalker::ReachedBuildings::const_iterator itBuilding = buildings.begin(); 
    itBuilding != buildings.end(); ++itBuilding)
  {
    SmartPtr< BurningRuins > bruins = ( *itBuilding ).as<BurningRuins>();
    if( bruins.isValid() )
    {
      pos = bruins->getTile().getIJ();
      return true;
    }
  }

  return false;
}
Beispiel #6
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);
         }
      }
   }
}