Advertisement
Guest User

simutrans depopulation

a guest
Dec 6th, 2011
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.97 KB | None | 0 0
  1. diff --git a/dataobj/einstellungen.cc b/dataobj/einstellungen.cc
  2. index 3393bfc..97f64d9 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. @@ -954,6 +956,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 ce2b183..21b5513 100644
  49. --- a/simcity.cc
  50. +++ b/simcity.cc
  51. @@ -1056,6 +1056,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. @@ -1098,6 +1100,9 @@ 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. +
  67.     stadtinfo_options = 3;
  68.  
  69.     rdwr(file);
  70. @@ -1437,6 +1442,7 @@ void stadt_t::step(long delta_t)
  71.     }
  72.  
  73.     while(stadt_t::step_bau_interval < next_bau_step) {
  74. +       step_depopulation();
  75.         calc_growth();
  76.         step_bau();
  77.         next_bau_step -= stadt_t::step_bau_interval;
  78. @@ -1460,7 +1466,49 @@ void stadt_t::step(long delta_t)
  79.     city_history_year[0][HIST_BUILDING] = buildings.get_count();
  80.  }
  81.  
  82. +/* performs depopulation */
  83. +void stadt_t::step_depopulation()
  84. +{
  85. +   settings_t const&  s                    = welt->get_settings();
  86. +   sint64     const(& h)[MAX_CITY_HISTORY] = city_history_month[1];
  87. +   sint32     const   population           = get_einwohner();
  88. +   sint32     const   not_transported      = (h[HIST_PAS_GENERATED] - h[HIST_PAS_TRANSPORTED]);
  89. +   sint32     const   depopulation         = s.get_depopulation();
  90. +   sint32     const   ratio_transported    = h[HIST_PAS_TRANSPORTED] / ((h[HIST_PAS_GENERATED] * s.get_increased_depop() / 100) + 1);
  91. +   int        const   jobless              = (bev - arb);
  92.  
  93. +   // maybe this town should stay static
  94. +   if(  !allow_citygrowth  ) {
  95. +       shrink = 0;
  96. +       return;
  97. +   }
  98. +
  99. +   // after get_increased_depop() per cent of the generated passengers are transported the city depopulation will be faster
  100. +   if ( !shrink_is_increased && (ratio_transported >= 1)) {
  101. +       shrink_is_increased = true;
  102. +   }
  103. +
  104. +   sint32 depop_factor = depopulation;
  105. +   if ( shrink_is_increased ) depop_factor += depopulation;
  106. +   // shrink is based on tatio of jobless and not transported passengers to city population
  107. +   shrink += (jobless + not_transported) * depop_factor / (population+1);
  108. +   const int shrink_step = (shrink>>4);
  109. +   DBG_DEBUG("stadt_t::step_depopulation()", "%s: 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", get_name(), depop_factor, depopulation, not_transported, jobless, shrink, shrink_step, (shrink_is_increased)?"true":"false", ratio_transported, s.get_increased_depop(), population);
  110. +   shrink &= 0x0F;
  111. +   // max. depopulation is normally lower value of jobless and calculated shrink
  112. +   if ( (shrink_step <= jobless || shrink_is_increased) && bev > shrink_step ) bev -= shrink_step;
  113. +   else if ( bev > jobless ) bev -= jobless;
  114. +   // correct homeless, jobless < 0)
  115. +   if (bev < won) won = bev;
  116. +   if (bev < arb) arb = bev;
  117. +   // small chance to bulldoze a public owned building
  118. +   gebaeude_t* const gb = pick_any(buildings);
  119. +   gebaeude_t::typ const typ = gb->get_haustyp();
  120. +   if ( shrink_is_increased && spieler_t::check_owner(gb->get_besitzer(),NULL) && shrink_step > 0 && (typ == gebaeude_t::wohnung || typ == gebaeude_t::gewerbe) ) {
  121. +       remove_gebaeude_from_stadt(gb);
  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. +   }
  124. +}
  125.  
  126.  /* updates the city history
  127.   * @author prissi
  128. diff --git a/simcity.h b/simcity.h
  129. index 98a9742..c1e84c1 100644
  130. --- a/simcity.h
  131. +++ b/simcity.h
  132. @@ -155,6 +155,10 @@ private:
  133.      */
  134.     sint32 wachstum;
  135.  
  136. +   // used for city depopulation
  137. +   sint32 shrink;
  138. +   bool shrink_is_increased;
  139. +
  140.     /**
  141.     * City history
  142.     * @author prissi
  143. @@ -260,6 +264,9 @@ private:
  144.     // calculates the growth rate for next step_bau using all the different indicators
  145.     void calc_growth();
  146.  
  147. +    /* performs depopulation */
  148. +    void step_depopulation();
  149. +
  150.     /**
  151.      * plant das bauen von Gebaeuden
  152.      * @author Hj. Malthaner
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement