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(); } }
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; } }
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()); } }
void ServiceWalker::computeWalkerPath() { std::list<PathWay> pathWayList; Propagator pathPropagator; pathPropagator.init(*_building); pathPropagator.getAllPaths(_maxDistance, pathWayList); float maxPathValue = 0.0; PathWay* bestPath = NULL; for (std::list<PathWay>::iterator itPath = pathWayList.begin(); itPath != pathWayList.end(); ++itPath) { PathWay &path = *itPath; float pathValue = evaluatePath(path); if (pathValue > maxPathValue) { bestPath = &path; maxPathValue = pathValue; } } if (bestPath == NULL) { // no good path _isDeleted = true; return; } reservePath(*bestPath); setPathWay(*bestPath); setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ()); Scenario::instance().getCity().getWalkerList().push_back(this); }
void Roads::Impl::updateRoadsAround( Propagator& propagator, UpdateInfo info ) { propagator.init( info.first ); PathwayList pathWayList = propagator.getWays( info.second ); for( auto& path : pathWayList ) { RoadList roads = path->allTiles().overlays<Road>(); for( auto road : roads ) road->appendPaved( paved.increase ); } }
void Roads::Impl::updateRoadsAround( Propagator& propagator, UpdateInfo info ) { propagator.init( info.first ); PathwayList pathWayList = propagator.getWays( info.second ); for( auto&& path : pathWayList ) { const TilesArray& tiles = path->allTiles(); for( auto tile : tiles ) { RoadPtr road = tile->overlay().as<Road>(); if( road.isValid() ) { road->appendPaved( defaultIncreasePaved ); } } } }
void CartPusher::computeWalkerDestination() { // get the list of buildings within reach PathWay pathWay; Propagator pathPropagator; _d->consumerBuilding = 0; pathPropagator.init( *_d->producerBuilding.object() ); pathPropagator.propagate(_d->maxDistance); BuildingPtr destBuilding; if (destBuilding == NULL) { // try send that good to a factory destBuilding = getWalkerDestination_factory(pathPropagator, pathWay); } if (destBuilding == NULL) { // try send that good to a granary destBuilding = getWalkerDestination_granary(pathPropagator, pathWay); } if (destBuilding == NULL) { // try send that good to a warehouse destBuilding = getWalkerDestination_warehouse( pathPropagator, pathWay ); } if( destBuilding != NULL) { //_isDeleted = true; // no destination! setConsumerBuilding( destBuilding ); setPathWay( pathWay ); setIJ( _pathWay.getOrigin().getIJ() ); setSpeed( 1 ); } else { _action._direction = D_NORTH; setSpeed( 0 ); setIJ( _d->producerBuilding->getAccessRoads().front()->getIJ() ); walk(); } }
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; }