Пример #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##" );
      }
    }
  }
}
Пример #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();
  }
}
Пример #3
0
void House::timeStep(const unsigned long time)
{
   // _goodStockList[G_WHEAT]._currentQty -= _d->currentHabitants;  // to do once every month!
   if( time % 16 == 0 )
   {
      // consume services
      for (int i = 0; i < S_MAX; ++i)
      {
         ServiceType service = (ServiceType) i;
         _d->serviceAccessMap[service] = std::max(_d->serviceAccessMap[service] - 1, 0);
      }

      cancelService( S_WORKERS_HUNTER );

      // consume goods
      for (int i = 0; i < G_MAX; ++i)
      {
         GoodType goodType = (GoodType) i;
         int qty = std::max(_d->goodStore.getCurrentQty(goodType) - 1, 0);
         _d->goodStore.setCurrentQty(goodType, qty);
      }
   }

   if( time % 64 == 0 )
   {
     bool validate = _d->houseLevelSpec.checkHouse(*this);
     if (!validate)
     {
       levelDown();
     }
     else
     {
       validate = _d->nextHouseLevelSpec.checkHouse(*this);
       if( validate && _d->currentHabitants > 0 )
       {
          levelUp();
       }
     }

     int homeless = math::clamp( _d->currentHabitants - _d->maxHabitants, 0, 0xff );

     if( homeless > 0 )
     {
       _d->currentHabitants = math::clamp( _d->currentHabitants, 0, _d->maxHabitants );

       CityPtr city = Scenario::instance().getCity();
       ImmigrantPtr im = Immigrant::create( city );
       im->setCapacity( homeless );
       im->send2City( getTile() );
     }
   }

   if( _d->currentHabitants > 0 )
   {
     Building::timeStep( time );
   }
}
Пример #4
0
void House::timeStep(const unsigned long time)
{
   if( _d->currentHabitants > 0 )
   {
     if( time % 16 == 0 )
     {
        // consume services
        for (int i = 0; i < Service::S_MAX; ++i)
        {
           Service::Type service = (Service::Type) i;
           _d->serviceAccess[service] = std::max(_d->serviceAccess[service] - 1, 0);
        }

        cancelService( Service::S_WORKERS_HUNTER );
        _d->updateHealthLevel();

        // consume goods
        for (int i = 0; i < Good::goodCount; ++i)
        {
           Good::Type goodType = (Good::Type) i;
           _d->goodStore.setCurrentQty( goodType, std::max( _d->goodStore.getCurrentQty(goodType) - 1, 0) );
        }
     }

     if( time % 64 == 0 )
     {
       bool validate = _d->houseLevelSpec.checkHouse( this );
       if (!validate)
       {
         levelDown();
       }
       else
       {
         _d->condition4Up = "";
         validate = _d->nextHouseLevelSpec.checkHouse( this, &_d->condition4Up );
         if( validate && _d->currentHabitants > 0 )
         {
            levelUp();
         }
       }

       int homeless = math::clamp( _d->currentHabitants - _d->maxHabitants, 0, 0xff );

       if( homeless > 0 )
       {
         _d->currentHabitants = math::clamp( _d->currentHabitants, 0, _d->maxHabitants );

         ImmigrantPtr im = Immigrant::create( _getCity() );
         im->setCapacity( homeless );
         im->send2City( getTile() );
       }
     }

     Building::timeStep( time );
   }
}
Пример #5
0
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;
}
Пример #6
0
void House::destroy()
{
  int homeless = _d->currentHabitants;
  _d->currentHabitants = _d->maxHabitants;

  if( homeless > 0 )
  {
    CityPtr city = Scenario::instance().getCity();
    ImmigrantPtr im = Immigrant::create( city );
    im->setCapacity( homeless );
    im->send2City( getTile() );
  }

  Building::destroy();
}