void Migration::Impl::createMigrationFromCity( PlayerCityPtr city ) { HouseList houses = city->statistic().houses.find(); const int minWorkersNumber = 4; for( HouseList::iterator i=houses.begin(); i != houses.end(); ) { int houseWorkless = (*i)->unemployed(); if( !(*i)->enterArea().empty() && houseWorkless > minWorkersNumber ) { ++i; } else { i = houses.erase( i ); } } if( !houses.empty() ) { int number = math::random( houses.size() ); HouseList randHouses = houses.random( number ); for( auto house : randHouses ) { ImmigrantPtr emigrant = Immigrant::create( city ); if( emigrant.isValid() ) { house->removeHabitants( minWorkersNumber ); emigrant->leaveCity( *(house->enterArea().front()) ); emigrant->setThinks( "##immigrant_no_work_for_me##" ); } } } }
void RandomPlague::_exec( Game& game, unsigned int time) { int population = game.city()->states().population; if( _d->popRange.contain( population ) ) { Logger::info( "Execute random plague event" ); _d->isDeleted = true; HouseList houses = game.city()->statistic().houses.habitable(); unsigned int number4burn = math::clamp<unsigned int>( (houses.size() * _d->strong / 100), 1u, 100u ); for( unsigned int k=0; k < number4burn; k++ ) { HousePtr house = houses.random(); house->setState( pr::health, 0.f ); } } }
HousePtr Emigrant::_findBlankHouse() { city::Helper hlp( _city() ); HousePtr blankHouse; TilePos offset( 5, 5 ); HouseList houses = hlp.find<House>( building::house, pos() - offset, pos() + offset ); _checkHouses( houses ); if( houses.empty() ) { houses = hlp.find<House>( building::house ); _checkHouses( houses ); } if( houses.size() > 0 ) { blankHouse = houses.random(); } return blankHouse; }
void Disorder::Impl::weekUpdate( unsigned int time, PlayerCityPtr rcity ) { HouseList houses = rcity->statistic().houses.find(); const WalkerList& walkers = rcity->statistic().walkers.find( walker::protestor ); HouseList criminalizedHouse; crime.level.current = 0; crime.level.maximum = 0; for( auto house : houses ) { int currentValue = house->getServiceValue( Service::crime )+1; if( currentValue >= crime.level.minimum ) { criminalizedHouse.push_back( house ); } crime.level.current += currentValue; crime.level.maximum = std::max<int>( crime.level.maximum, currentValue ); } if( houses.size() > 0 ) crime.level.current /= houses.size(); if( criminalizedHouse.size() > walkers.size() ) { HousePtr house = criminalizedHouse.random(); int hCrimeLevel = house->getServiceValue( Service::crime ); int sentiment = rcity->sentiment(); int randomValue = math::random( crime::maxValue ); if (sentiment >= minSentiment4protest ) { if ( randomValue >= sentiment + 20 ) { if ( hCrimeLevel > crime::level4protestor ) { generateProtestor( rcity, house ); } } } else if ( sentiment >= minSentiment4mugger ) { if ( randomValue >= sentiment + 40 ) { if ( hCrimeLevel >= crime::level4mugger ) { generateMugger( rcity, house ); } else if ( hCrimeLevel > crime::level4protestor ) { generateProtestor( rcity, house ); } } } else if( sentiment < minSentiment4mugger ) { if ( randomValue >= sentiment + 50 ) { if ( hCrimeLevel >= crime::level4rioter ) { generateRioter( rcity, house ); } else if ( hCrimeLevel >= crime::level4mugger ) { generateMugger( rcity, house ); } else if ( hCrimeLevel > crime::level4protestor ) { generateProtestor( rcity, house ); } } } } }