void House::_makeOldHabitants() { CitizenGroup newHabitants = _d->habitants; newHabitants.makeOld(); unsigned int houseHealth = state( House::health ); newHabitants[ CitizenGroup::longliver ] = 0; //death-health function from oldest habitants count unsigned int agedPeoples = newHabitants.count( CitizenGroup::aged ); unsigned int peoples2remove = math::random( agedPeoples * ( 100 - houseHealth ) / 100 ); newHabitants.retrieve( CitizenGroup::aged, peoples2remove+1 ); unsigned int studentNumber = newHabitants.count( 10, 19 ); unsigned int youngNumber = newHabitants.count( 20, 29); unsigned int matureNumber = newHabitants.count( 30, 39 ); unsigned int oldNumber = newHabitants.count( 40, 49 ); unsigned int newBorn = studentNumber * math::random( 3 ) / 100 + //at 3% of student add newborn youngNumber * math::random( 16 ) / 100 + //at 16% of young people add newborn matureNumber * math::random( 9 ) / 100 + //at 9% of matures add newborn oldNumber * math::random( 2 ) / 100; //at 2% of aged peoples add newborn newBorn = newBorn * houseHealth / 100 ; //house health add compensation for newborn citizens unsigned int vacantRoom = maxHabitants() - newHabitants.count(); newBorn = math::clamp( newBorn, 0u, vacantRoom ); newHabitants[ CitizenGroup::newborn ] = newBorn; //birth+health function from mature habitants count _updateHabitants( newHabitants ); }
bool Immigrant::send2City( CityPtr city, const CitizenGroup& peoples, Tile& startTile ) { if( peoples.count() > 0 ) { ImmigrantPtr im = Immigrant::create( city ); im->setPeoples( peoples ); im->send2City( startTile ); return true; } return false; }
void House::_updateHabitants( const CitizenGroup& group ) { int deltaWorkersNumber = group.count( CitizenGroup::mature ) - _d->habitants.count( CitizenGroup::mature ); _d->habitants = group; _d->services[ Service::recruter ].setMax( _d->habitants.count( CitizenGroup::mature ) ); int firedWorkersNumber = _d->services[ Service::recruter ] + deltaWorkersNumber; _d->services[ Service::recruter ] += deltaWorkersNumber; if( firedWorkersNumber < 0 ) { GameEventPtr e = FireWorkers::create( pos(), abs( firedWorkersNumber ) ); e->dispatch(); } }