Advertisement
Guest User

simutrans depopulation

a guest
Dec 5th, 2011
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.42 KB | None | 0 0
  1. diff --git a/dataobj/einstellungen.cc b/dataobj/einstellungen.cc
  2. index 3f0d236..9bc02a9 100644
  3. --- a/dataobj/einstellungen.cc
  4. +++ b/dataobj/einstellungen.cc
  5. @@ -103,6 +103,8 @@ settings_t::settings_t() :
  6.     mail_multiplier = 20;
  7.     goods_multiplier = 20;
  8.     electricity_multiplier = 0;
  9. +   depopulation = 0;
  10. +   increased_depop = 101;
  11.  
  12.     // Also there are size dependen factors (0 causes crash !)
  13.     growthfactor_small = 400;
  14. @@ -956,6 +958,9 @@ void settings_t::parse_simuconf(tabfile_t& simuconf, sint16& disp_width, sint16&
  15.     goods_multiplier = contents.get_int("goods_multiplier", goods_multiplier );
  16.     electricity_multiplier = contents.get_int("electricity_multiplier", electricity_multiplier );
  17.  
  18. +   depopulation = contents.get_int("depopulation", depopulation);
  19. +   increased_depop = contents.get_int("increased_depop", increased_depop);
  20. +
  21.     growthfactor_small = contents.get_int("growthfactor_villages", growthfactor_small );
  22.     growthfactor_medium = contents.get_int("growthfactor_cities", growthfactor_medium );
  23.     growthfactor_large = contents.get_int("growthfactor_capitals", growthfactor_large );
  24. diff --git a/dataobj/einstellungen.h b/dataobj/einstellungen.h
  25. index c2c3ad2..bd76e2d 100644
  26. --- a/dataobj/einstellungen.h
  27. +++ b/dataobj/einstellungen.h
  28. @@ -74,6 +74,9 @@ private:
  29.     sint32 growthfactor_medium;
  30.     sint32 growthfactor_large;
  31.  
  32. +   sint32 depopulation;
  33. +   sint32 increased_depop;
  34. +
  35.     uint32 minimum_city_distance;
  36.     uint32 industry_increase;
  37.  
  38. @@ -464,6 +467,8 @@ public:
  39.     sint32 get_growthfactor_small() const { return growthfactor_small; }
  40.     sint32 get_growthfactor_medium() const { return growthfactor_medium; }
  41.     sint32 get_growthfactor_large() const { return growthfactor_large; }
  42. +   sint32 get_depopulation() const { return depopulation; }
  43. +   sint32 get_increased_depop() const {return increased_depop; }
  44.  
  45.     // percentage of passengers for different kinds of trips
  46.     sint16 get_factory_worker_percentage() const { return factory_worker_percentage; }
  47. diff --git a/simcity.cc b/simcity.cc
  48. index 8399c4c..04be1c7 100644
  49. --- a/simcity.cc
  50. +++ b/simcity.cc
  51. @@ -1053,6 +1053,8 @@ stadt_t::stadt_t(spieler_t* sp, koord pos, sint32 citizens) :
  52.     check_bau_rathaus(true);
  53.  
  54.     wachstum = 0;
  55. +   shrink = 0;
  56. +   shrink_is_increased = false;
  57.     allow_citygrowth = true;
  58.     change_size( citizens );
  59.  
  60. @@ -1095,6 +1097,8 @@ stadt_t::stadt_t(karte_t* wl, loadsave_t* file) :
  61.     has_low_density = false;
  62.  
  63.     wachstum = 0;
  64. +   shrink = 0;
  65. +   shrink_is_increased = false;
  66.     name = NULL;
  67.     stadtinfo_options = 3;
  68.  
  69. @@ -1438,6 +1442,7 @@ void stadt_t::step(long delta_t)
  70.     }
  71.  
  72.     while(stadt_t::step_bau_interval < next_bau_step) {
  73. +       step_depopulation();
  74.         calc_growth();
  75.         step_bau();
  76.         next_bau_step -= stadt_t::step_bau_interval;
  77. @@ -1461,7 +1466,42 @@ void stadt_t::step(long delta_t)
  78.     city_history_year[0][HIST_BUILDING] = buildings.get_count();
  79.  }
  80.  
  81. +/* performs depopulation */
  82. +void stadt_t::step_depopulation()
  83. +{
  84. +   settings_t const&  s                    = welt->get_settings();
  85. +   sint64     const(& h)[MAX_CITY_HISTORY] = city_history_month[1];
  86. +   sint32     const   population           = get_einwohner();
  87. +   sint32     const   not_transported      = (h[HIST_PAS_GENERATED] - h[HIST_PAS_TRANSPORTED]);
  88. +   sint32     const   depopulation         = s.get_depopulation();
  89. +   sint32     const   ratio_transported    = h[HIST_PAS_TRANSPORTED] / ((h[HIST_PAS_GENERATED] * s.get_increased_depop() / 100) + 1);
  90. +   int        const   jobless              = (bev - arb);
  91. +
  92. +    // maybe this town should stay static
  93. +   if(  !allow_citygrowth  ) {
  94. +       shrink = 0;
  95. +       return;
  96. +   }
  97.  
  98. +   // after get_increased_depop() per cent of the generated passengers are transported the city depopulation will be faster
  99. +   if ( !shrink_is_increased && (ratio_transported >= 1)) {
  100. +       shrink_is_increased = true;
  101. +   }
  102. +
  103. +   sint32 depop_factor = depopulation;
  104. +   if ( shrink_is_increased ) depop_factor += depopulation;
  105. +   // shrink is based on tatio of jobless and not transported passengers to city population
  106. +   shrink += (jobless + not_transported) * depop_factor / (population+1);
  107. +   const int shrink_step = (shrink>>4);
  108. +   DBG_DEBUG("stadt_t::step_depopulation()", "depop_factor %i, depopulation %i; not_transported %i; jobless %i; shrink %i; shrink_step %i; shrink_is_increased %s; ratio_transported %i; increased_depop %i; population %i", depop_factor, depopulation, not_transported, jobless, shrink, shrink_step, (shrink_is_increased)?"true":"false", ratio_transported, s.get_increased_depop(), population);
  109. +   shrink &= 0x0F;
  110. +   // max. depopulation is normally lower value of jobless and calculated shrink
  111. +   if ( (shrink_step <= jobless || shrink_is_increased) && bev > shrink_step ) bev -= shrink_step;
  112. +   else if ( bev > jobless ) bev -= jobless;
  113. +   // correct homeless, jobless < 0)
  114. +   if (bev < won) won = bev;
  115. +   if (bev < arb) arb = bev;
  116. +}
  117.  
  118.  /* updates the city history
  119.   * @author prissi
  120. diff --git a/simcity.h b/simcity.h
  121. index 5c9b1e5..47e18b4 100644
  122. --- a/simcity.h
  123. +++ b/simcity.h
  124. @@ -154,6 +154,10 @@ private:
  125.      */
  126.     sint32 wachstum;
  127.  
  128. +   // used for city depopulation
  129. +   sint32 shrink;
  130. +   bool shrink_is_increased;
  131. +
  132.     /**
  133.     * City history
  134.     * @author prissi
  135. @@ -259,6 +263,9 @@ private:
  136.     // calculates the growth rate for next step_bau using all the different indicators
  137.     void calc_growth();
  138.  
  139. +    /* performs depopulation */
  140. +    void step_depopulation();
  141. +
  142.     /**
  143.      * plant das bauen von Gebaeuden
  144.      * @author Hj. Malthaner
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement