예제 #1
0
void TraineeWalker::computeWalkerPath()
{
  _maxNeed = 0;  // need of this trainee in buildings
  Propagator pathPropagator;
  pathPropagator.init( *_originBuilding.object() );
  pathPropagator.propagate(_maxDistance);

  for (std::list<BuildingType>::iterator itType = _buildingNeed.begin(); itType != _buildingNeed.end(); ++itType)
  {
    BuildingType buildingType = *itType;
    checkDestination(buildingType, pathPropagator);
  }

  if( _destinationBuilding != NULL )
  {
    // some building needs that trainee!
    // std::cout << "trainee sent!" << std::endl;
    PathWay pathWay;
    pathPropagator.getPath( _destinationBuilding, pathWay);
    setPathWay( pathWay );
    setIJ( _pathWay.getOrigin().getIJ() );
  }
  else
  {
    // nobody needs him...
    // std::cout << "trainee suicide!" << std::endl;
    deleteLater();
  }
}
예제 #2
0
void TraineeWalker::computeWalkerPath()
{
   _maxNeed = 0;  // need of this trainee in buildings
   Propagator pathPropagator;
   pathPropagator.init(*_originBuilding);
   pathPropagator.propagate(_maxDistance);

   for (std::list<BuildingType>::iterator itType = _buildingNeed.begin(); itType != _buildingNeed.end(); ++itType)
   {
      BuildingType buildingType = *itType;
      checkDestination(buildingType, pathPropagator);
   }

   if (_destinationBuilding != NULL)
   {
      // some building needs that trainee!
      // std::cout << "trainee sent!" << std::endl;
      PathWay pathWay;
      pathPropagator.getPath(*_destinationBuilding, pathWay);
      setPathWay(pathWay);
      setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ());
      Scenario::instance().getCity().getWalkerList().push_back(this);
      _destinationBuilding->reserveTrainee(_traineeType);
   }
   else
   {
      // nobody needs him...
      // std::cout << "trainee suicide!" << std::endl;
      _isDeleted = true;
   }

}
예제 #3
0
void Emigrant::assignPath( const Road& startPoint )
{
	std::list<PathWay> pathWayList;

	std::list<LandOverlay*> houses = Scenario::instance().getCity().getBuildingList(B_HOUSE);
	House* blankHouse = 0;
	for( std::list<LandOverlay*>::iterator itHouse = houses.begin(); itHouse != houses.end(); ++itHouse )
	{
		if( House* house = dynamic_cast<House*>(*itHouse) )
		{
			if( house->getNbHabitants() < house->getMaxHabitants() )
			{
				blankHouse = house;
				_d->destination = house->getTile().getIJ();
				break;
			}
		}
	}

	Propagator pathfinder;
	PathWay pathWay;
	pathfinder.init( const_cast< Road& >( startPoint ) );
	bool findPath = pathfinder.getPath( *blankHouse, pathWay );
	if( findPath )
	{
		setPathWay( pathWay );
		setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ());   
	}
}
예제 #4
0
void Immigrant::assignPath( const Building& home )
{
    City& city = Scenario::instance().getCity();
    Tile& exitTile = city.getTilemap().at( city.getRoadExitI(), city.getRoadExitJ() );

    Road* exitRoad = dynamic_cast< Road* >( exitTile.get_terrain().getOverlay() );
    if( exitRoad )
    {
        Propagator pathfinder;
	    PathWay pathWay;
        pathfinder.init( const_cast< Building& >( home ) );
        bool findPath = pathfinder.getPath( *exitRoad, pathWay );
	    if( findPath )
	    {
		    setPathWay( pathWay );
		    setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ());   
	    }
    }
    else
        _isDeleted = true;
}