void House::timeStep(const unsigned long time) { // _goodStockList[G_WHEAT]._currentQty -= _d->currentHabitants; // to do once every month! if( time % 16 == 0 ) { // consume services for (int i = 0; i < S_MAX; ++i) { ServiceType service = (ServiceType) i; _d->serviceAccessMap[service] = std::max(_d->serviceAccessMap[service] - 1, 0); } cancelService( S_WORKERS_HUNTER ); // consume goods for (int i = 0; i < G_MAX; ++i) { GoodType goodType = (GoodType) i; int qty = std::max(_d->goodStore.getCurrentQty(goodType) - 1, 0); _d->goodStore.setCurrentQty(goodType, qty); } } if( time % 64 == 0 ) { bool validate = _d->houseLevelSpec.checkHouse(*this); if (!validate) { levelDown(); } else { validate = _d->nextHouseLevelSpec.checkHouse(*this); if( validate && _d->currentHabitants > 0 ) { levelUp(); } } int homeless = math::clamp( _d->currentHabitants - _d->maxHabitants, 0, 0xff ); if( homeless > 0 ) { _d->currentHabitants = math::clamp( _d->currentHabitants, 0, _d->maxHabitants ); CityPtr city = Scenario::instance().getCity(); ImmigrantPtr im = Immigrant::create( city ); im->setCapacity( homeless ); im->send2City( getTile() ); } } if( _d->currentHabitants > 0 ) { Building::timeStep( time ); } }
void House::timeStep(const unsigned long time) { if( _d->currentHabitants > 0 ) { if( time % 16 == 0 ) { // consume services for (int i = 0; i < Service::S_MAX; ++i) { Service::Type service = (Service::Type) i; _d->serviceAccess[service] = std::max(_d->serviceAccess[service] - 1, 0); } cancelService( Service::S_WORKERS_HUNTER ); _d->updateHealthLevel(); // consume goods for (int i = 0; i < Good::goodCount; ++i) { Good::Type goodType = (Good::Type) i; _d->goodStore.setCurrentQty( goodType, std::max( _d->goodStore.getCurrentQty(goodType) - 1, 0) ); } } if( time % 64 == 0 ) { bool validate = _d->houseLevelSpec.checkHouse( this ); if (!validate) { levelDown(); } else { _d->condition4Up = ""; validate = _d->nextHouseLevelSpec.checkHouse( this, &_d->condition4Up ); if( validate && _d->currentHabitants > 0 ) { levelUp(); } } int homeless = math::clamp( _d->currentHabitants - _d->maxHabitants, 0, 0xff ); if( homeless > 0 ) { _d->currentHabitants = math::clamp( _d->currentHabitants, 0, _d->maxHabitants ); ImmigrantPtr im = Immigrant::create( _getCity() ); im->setCapacity( homeless ); im->send2City( getTile() ); } } Building::timeStep( time ); } }
void House::destroy() { int homeless = _d->currentHabitants; _d->currentHabitants = _d->maxHabitants; if( homeless > 0 ) { CityPtr city = Scenario::instance().getCity(); ImmigrantPtr im = Immigrant::create( city ); im->setCapacity( homeless ); im->send2City( getTile() ); } Building::destroy(); }