Ejemplo n.º 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##" );
      }
    }
  }
}
Ejemplo n.º 2
0
HousePtr Immigrant::_findBlankHouse()
{
    CityHelper hlp( _getCity() );
    HouseList houses = hlp.find< House >( building::house );
    HousePtr blankHouse;
    _d->destination = TilePos( -1, -1 );

    HouseList::iterator itHouse = houses.begin();
    while( itHouse != houses.end() )
    {
        if( (*itHouse)->getAccessRoads().size() > 0 &&
                ( (*itHouse)->getHabitants().count() < (*itHouse)->getMaxHabitants() ) )
        {
            itHouse++;
        }
        else
        {
            itHouse = houses.erase( itHouse );
        }
    }

    if( houses.size() > 0 )
    {
        itHouse = houses.begin();
        std::advance(itHouse, rand() % houses.size() );
        blankHouse = *itHouse;
        _d->destination = blankHouse->getTilePos();
    }

    return blankHouse;
}
Ejemplo n.º 3
0
HouseList Statistic::_Houses::habitable() const
{
  HouseList houses = find();

  for( auto it=houses.begin(); it != houses.end(); )
  {
    if( (*it)->habitants().count() > 0 ) ++it;
    else it = houses.erase( it );
  }

  return houses;
}
Ejemplo n.º 4
0
HouseList Statistic::_Houses::ready4evolve(const object::TypeSet& checkTypes ) const
{
  HouseList houses = find();

  for( auto it=houses.begin(); it != houses.end(); )
  {
    object::Type btype;
    (*it)->spec().next().checkHouse( *it, nullptr, &btype );
    if( checkTypes.count( btype ) ) it = houses.erase( it );
    else ++it;
  }

  return houses;
}