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 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 MarketLady::computeWalkerDestination( MarketPtr market ) { _d->market = market; std::list<Good::Type> 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( _getCity() ); pathPropagator.init( _d->market.as<Construction>() ); pathPropagator.propagate( _d->maxDistance); // try to find the most needed good foreach( Good::Type goodType, priorityGoods ) { _d->priorityGood = goodType; if( _d->priorityGood == Good::wheat || _d->priorityGood == Good::fish || _d->priorityGood == Good::meat || _d->priorityGood == Good::fruit || _d->priorityGood == Good::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; } }
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() ); }