void CartPusher::computeWalkerDestination() { // get the list of buildings within reach PathWay pathWay; Propagator pathPropagator( _getCity() ); _d->consumerBuilding = 0; if( _d->producerBuilding.isNull() ) { StringHelper::debug( 0xff, "CartPusher destroyed: producerBuilding can't be NULL" ); deleteLater(); return; } pathPropagator.init( _d->producerBuilding.as<Construction>() ); pathPropagator.propagate(_d->maxDistance); BuildingPtr destBuilding; if (destBuilding == NULL) { // try send that good to a factory destBuilding = _d->getWalkerDestination_factory(pathPropagator, pathWay); } if (destBuilding == NULL) { // try send that good to a granary destBuilding = _d->getWalkerDestination_granary(pathPropagator, pathWay); } if (destBuilding == NULL) { // try send that good to a warehouse destBuilding = _d->getWalkerDestination_warehouse( pathPropagator, pathWay ); } if( destBuilding != NULL) { //_isDeleted = true; // no destination! setConsumerBuilding( destBuilding ); setPathWay( pathWay ); setIJ( _getPathway().getOrigin().getIJ() ); setSpeed( 1 ); } else { _setDirection( D_NORTH ); setSpeed( 0 ); setIJ( _d->producerBuilding->getAccessRoads().front()->getIJ() ); walk(); } }
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 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 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 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 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 MarketLady::computeWalkerDestination( MarketPtr market ) { _d->market = market; std::list<GoodType> priorityGoods = _d->market->getMostNeededGoods(); _d->destBuildingPos = TilePos( -1, -1 ); // no destination yet if( priorityGoods.size() > 0 ) { // we have something to buy! // get the list of buildings within reach PathWay pathWay; Propagator pathPropagator( _d->city ); pathPropagator.init( _d->market.as<Construction>() ); pathPropagator.propagate( _d->maxDistance); // try to find the most needed good for (std::list<GoodType>::iterator itGood = priorityGoods.begin(); itGood != priorityGoods.end(); ++itGood) { _d->priorityGood = *itGood; if( _d->priorityGood == G_WHEAT || _d->priorityGood == G_FISH || _d->priorityGood == G_MEAT || _d->priorityGood == G_FRUIT || _d->priorityGood == G_VEGETABLE) { // try get that good from a granary _d->destBuildingPos = getWalkerDestination2<Granary>( pathPropagator, B_GRANARY, _d->market, _d->basket, _d->priorityGood, pathWay, _d->reservationID ); } else { // try get that good from a warehouse _d->destBuildingPos = getWalkerDestination2<Warehouse>( pathPropagator, B_WAREHOUSE, _d->market, _d->basket, _d->priorityGood, pathWay, _d->reservationID ); } if( _d->destBuildingPos.getI() >= 0 ) { // we found a destination! setPathWay(pathWay); break; } } } if( _d->destBuildingPos.getI() < 0) { // we have nothing to buy, or cannot find what we need to buy deleteLater(); return; } setIJ( _getPathway().getOrigin().getIJ() ); }
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; }
void CartSupplier::computeWalkerDestination(BuildingPtr building, const Good::Type type, const int qty ) { _d->baseBuildingPos = building->getTilePos(); _d->storageBuildingPos = TilePos( -1, -1 ); // no destination yet // we have something to buy! // get the list of buildings within reach PathWay pathWay; Propagator pathPropagator( _d->city ); pathPropagator.init( building.as<Construction>() ); pathPropagator.propagate( _d->maxDistance); // try get that good from a granary _d->storageBuildingPos = getSupplierDestination2<Granary>( pathPropagator, B_GRANARY, type, qty, pathWay, _d->reservationID ); if( _d->storageBuildingPos.getI() < 0 ) { // try get that good from a warehouse _d->storageBuildingPos = getSupplierDestination2<Warehouse>( pathPropagator, B_WAREHOUSE, type, qty, pathWay, _d->reservationID ); } if( _d->storageBuildingPos.getI() >= 0 ) { // we found a destination! setPathWay(pathWay); } else { // we have nothing to buy, or cannot find what we need to buy deleteLater(); return; } setIJ( _getPathway().getOrigin().getIJ() ); }