Exemple #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##" );
      }
    }
  }
}
Exemple #2
0
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;
}