Advertisement
Guest User

simutrans depopulation

a guest
Dec 7th, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. diff --git a/dataobj/einstellungen.cc b/dataobj/einstellungen.cc
  2. index 3393bfc..b2be4bf 100644
  3. --- a/dataobj/einstellungen.cc
  4. +++ b/dataobj/einstellungen.cc
  5. @@ -103,6 +103,9 @@ settings_t::settings_t() :
  6. mail_multiplier = 20;
  7. goods_multiplier = 20;
  8. electricity_multiplier = 0;
  9. + depopulation_low = 101;
  10. + depopulation_med = 101;
  11. + depopulation_hig = 101;
  12.  
  13. // Also there are size dependen factors (0 causes crash !)
  14. growthfactor_small = 400;
  15. @@ -954,6 +957,10 @@ void settings_t::parse_simuconf(tabfile_t& simuconf, sint16& disp_width, sint16&
  16. goods_multiplier = contents.get_int("goods_multiplier", goods_multiplier );
  17. electricity_multiplier = contents.get_int("electricity_multiplier", electricity_multiplier );
  18.  
  19. + depopulation_low = contents.get_int("depopulation_low", depopulation_low);
  20. + depopulation_med = contents.get_int("depopulation_med", depopulation_med);
  21. + depopulation_hig = contents.get_int("depopulation_hig", depopulation_hig);
  22. +
  23. growthfactor_small = contents.get_int("growthfactor_villages", growthfactor_small );
  24. growthfactor_medium = contents.get_int("growthfactor_cities", growthfactor_medium );
  25. growthfactor_large = contents.get_int("growthfactor_capitals", growthfactor_large );
  26. diff --git a/dataobj/einstellungen.h b/dataobj/einstellungen.h
  27. index c2c3ad2..602f9d5 100644
  28. --- a/dataobj/einstellungen.h
  29. +++ b/dataobj/einstellungen.h
  30. @@ -74,6 +74,10 @@ private:
  31. sint32 growthfactor_medium;
  32. sint32 growthfactor_large;
  33.  
  34. + sint32 depopulation_low;
  35. + sint32 depopulation_med;
  36. + sint32 depopulation_hig;
  37. +
  38. uint32 minimum_city_distance;
  39. uint32 industry_increase;
  40.  
  41. @@ -464,6 +468,9 @@ public:
  42. sint32 get_growthfactor_small() const { return growthfactor_small; }
  43. sint32 get_growthfactor_medium() const { return growthfactor_medium; }
  44. sint32 get_growthfactor_large() const { return growthfactor_large; }
  45. + sint32 get_depopopulation_low() const { return depopulation_low; }
  46. + sint32 get_depopopulation_med() const { return depopulation_med; }
  47. + sint32 get_depopopulation_hig() const { return depopulation_hig; }
  48.  
  49. // percentage of passengers for different kinds of trips
  50. sint16 get_factory_worker_percentage() const { return factory_worker_percentage; }
  51. diff --git a/simcity.cc b/simcity.cc
  52. index ce2b183..47758d4 100644
  53. --- a/simcity.cc
  54. +++ b/simcity.cc
  55. @@ -1056,6 +1056,8 @@ stadt_t::stadt_t(spieler_t* sp, koord pos, sint32 citizens) :
  56. check_bau_rathaus(true);
  57.  
  58. wachstum = 0;
  59. + shrink = 0;
  60. + shrink_level = 0;
  61. allow_citygrowth = true;
  62. change_size( citizens );
  63.  
  64. @@ -1098,6 +1100,9 @@ stadt_t::stadt_t(karte_t* wl, loadsave_t* file) :
  65. has_low_density = false;
  66.  
  67. wachstum = 0;
  68. + shrink = 0;
  69. + shrink_level = 0;
  70. +
  71. stadtinfo_options = 3;
  72.  
  73. rdwr(file);
  74. @@ -1437,6 +1442,7 @@ void stadt_t::step(long delta_t)
  75. }
  76.  
  77. while(stadt_t::step_bau_interval < next_bau_step) {
  78. + step_depopulation();
  79. calc_growth();
  80. step_bau();
  81. next_bau_step -= stadt_t::step_bau_interval;
  82. @@ -1460,7 +1466,51 @@ void stadt_t::step(long delta_t)
  83. city_history_year[0][HIST_BUILDING] = buildings.get_count();
  84. }
  85.  
  86. +/* performs depopulation */
  87. +void stadt_t::step_depopulation()
  88. +{
  89. + settings_t const& s = welt->get_settings();
  90. + sint64 const(& h1)[MAX_CITY_HISTORY] = city_history_month[1];
  91. + sint64 const(& h0)[MAX_CITY_HISTORY] = city_history_month[0];
  92. + sint32 const ratio_transported_low = ((h0[HIST_PAS_TRANSPORTED] + h1[HIST_PAS_TRANSPORTED]) / (((h0[HIST_PAS_GENERATED] + h1[HIST_PAS_GENERATED]) * s.get_depopopulation_low() / 100) + 1))?1:0;
  93. + sint32 const ratio_transported_med = ((h0[HIST_PAS_TRANSPORTED] + h1[HIST_PAS_TRANSPORTED]) / (((h0[HIST_PAS_GENERATED] + h1[HIST_PAS_GENERATED]) * s.get_depopopulation_med() / 100) + 1))?1:0;
  94. + sint32 const ratio_transported_hig = ((h0[HIST_PAS_TRANSPORTED] + h1[HIST_PAS_TRANSPORTED]) / (((h0[HIST_PAS_GENERATED] + h1[HIST_PAS_GENERATED]) * s.get_depopopulation_hig() / 100) + 1))?1:0;
  95. + bool const is_shrink_too_high = (get_wachstum() * -10 >= get_einwohner())?true:false;
  96. +
  97. + // maybe this town should stay static, also skip depopulation when previous month had no passengers
  98. + if( !allow_citygrowth || h1[HIST_PAS_GENERATED] == 0 ) {
  99. + shrink = 0;
  100. + return;
  101. + }
  102.  
  103. + // highest level of transported passengers
  104. + if ( shrink_level < (ratio_transported_low+ratio_transported_med+ratio_transported_hig) ) {
  105. + shrink_level = ratio_transported_low+ratio_transported_med+ratio_transported_hig;
  106. + }
  107. +
  108. + // shrink is based on tatio of jobless and not transported passengers to city population
  109. + shrink += shrink_level - (ratio_transported_low+ratio_transported_med+ratio_transported_hig);
  110. + const int shrink_step = (shrink>>4);
  111. + DBG_DEBUG("stadt_t::step_depopulation()", "%s: shrink %i; shrink_step %i; shrink_level %i; ratio_transported_low %i; ratio_transported_med %i; ratio_transported_hig %i; depopulation_low %i; depopulation_med %i; depopulation_hig %i; is_shrink_too_high %s", get_name(), shrink, shrink_step, shrink_level, ratio_transported_low, ratio_transported_med, ratio_transported_hig, s.get_depopopulation_low(), s.get_depopopulation_med(), s.get_depopopulation_hig(), is_shrink_too_high?"true":"false");
  112. + shrink &= 0x0F;
  113. + // every shrink_step lowers shrink_level
  114. + if ( shrink_step > 0 ) {
  115. + shrink_level -= 1;
  116. + // small chance to bulldoze a public owned building
  117. + gebaeude_t* const gb = pick_any(buildings);
  118. + gebaeude_t::typ const typ = gb->get_haustyp();
  119. + if ( spieler_t::check_owner(gb->get_besitzer(),NULL) && (typ == gebaeude_t::wohnung || typ == gebaeude_t::gewerbe) && !is_shrink_too_high ) {
  120. + sint32 population_before = get_einwohner();
  121. + koord gb_koord = gb->get_pos().get_2d();
  122. + DBG_DEBUG("stadt_t::step_depopulation()", "%s: bulldozed building %s at %i %i %i", get_name(), gb->get_tile()->get_besch()->get_name(), gb->get_pos().x, gb->get_pos().y, gb->get_pos().z);
  123. + remove_gebaeude_from_stadt(gb);
  124. + hausbauer_t::remove(welt,welt->get_spieler(1),gb);
  125. + cbuffer_t buf;
  126. + buf.printf(translator::translate("The citizens of %s\nare displeased with\nthe public transport.\n%i inhabitants\nemigrated to Mars."), get_name(), population_before - get_einwohner());
  127. + welt->get_message()->add_message(buf, gb_koord, message_t::city, CITY_KI, IMG_LEER);
  128. + }
  129. + }
  130. +}
  131.  
  132. /* updates the city history
  133. * @author prissi
  134. diff --git a/simcity.h b/simcity.h
  135. index 98a9742..8d3e01e 100644
  136. --- a/simcity.h
  137. +++ b/simcity.h
  138. @@ -155,6 +155,10 @@ private:
  139. */
  140. sint32 wachstum;
  141.  
  142. + // used for city depopulation
  143. + sint32 shrink;
  144. + sint32 shrink_level;
  145. +
  146. /**
  147. * City history
  148. * @author prissi
  149. @@ -260,6 +264,9 @@ private:
  150. // calculates the growth rate for next step_bau using all the different indicators
  151. void calc_growth();
  152.  
  153. + /* performs depopulation */
  154. + void step_depopulation();
  155. +
  156. /**
  157. * plant das bauen von Gebaeuden
  158. * @author Hj. Malthaner
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement