Beispiel #1
0
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##" );
      }
    }
  }
}
Beispiel #2
0
void Migration::Impl::createMigrationToCity( PlayerCityPtr city )
{
  unsigned int vh = calcVacantHouse( city );
  if( vh == 0 )
  {
    return;
  }

  EmigrantList migrants;
  migrants << city->walkers();

  if( vh <= migrants.size() * 5 )
  {
    return;
  }

  Tile& roadTile = city->tilemap().at( city->borderInfo().roadEntry );

  ImmigrantPtr emigrant = Immigrant::create( city );

  if( emigrant.isValid() )
  {
    bool success = emigrant->send2city( roadTile );
    emigrant->setSpeedMultiplier( 0.8f + math::random( 40 ) / 100.f );

    if( success )
      lastMonthComing += emigrant->peoples().count();
  }
}