Advertisement
Guest User

depopulation for ST

a guest
Dec 9th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.99 KB | None | 0 0
  1. diff --git a/gui/citylist_stats_t.cc b/gui/citylist_stats_t.cc
  2. index 35438b9..2419b6a 100644
  3. --- a/gui/citylist_stats_t.cc
  4. +++ b/gui/citylist_stats_t.cc
  5. @@ -134,7 +134,7 @@ void citylist_stats_t::zeichnen(koord offset)
  6.         sint32 growth = stadt->get_wachstum();
  7.  
  8.         buf.clear();
  9. -       buf.printf( "%s: ", stadt->get_name() );
  10. +       buf.printf( "%s%s: ", stadt->get_name(), stadt->get_transport_status()?"":" (!)" );
  11.         buf.append( bev, 0 );
  12.         buf.append( " (" );
  13.         buf.append( growth/10.0, 1 );
  14. diff --git a/simcity.cc b/simcity.cc
  15. index ce2b183..1eb7783 100644
  16. --- a/simcity.cc
  17. +++ b/simcity.cc
  18. @@ -1056,6 +1056,9 @@ stadt_t::stadt_t(spieler_t* sp, koord pos, sint32 citizens) :
  19.     check_bau_rathaus(true);
  20.  
  21.     wachstum = 0;
  22. +   shrink = 0;
  23. +   transport_level = 0;
  24. +   ratio_transported = 0;
  25.     allow_citygrowth = true;
  26.     change_size( citizens );
  27.  
  28. @@ -1098,6 +1101,10 @@ stadt_t::stadt_t(karte_t* wl, loadsave_t* file) :
  29.     has_low_density = false;
  30.  
  31.     wachstum = 0;
  32. +   shrink = 0;
  33. +   transport_level = 0;
  34. +   ratio_transported = 0;
  35. +
  36.     stadtinfo_options = 3;
  37.  
  38.     rdwr(file);
  39. @@ -1437,6 +1444,7 @@ void stadt_t::step(long delta_t)
  40.     }
  41.  
  42.     while(stadt_t::step_bau_interval < next_bau_step) {
  43. +       step_depopulation();
  44.         calc_growth();
  45.         step_bau();
  46.         next_bau_step -= stadt_t::step_bau_interval;
  47. @@ -1460,7 +1468,51 @@ void stadt_t::step(long delta_t)
  48.     city_history_year[0][HIST_BUILDING] = buildings.get_count();
  49.  }
  50.  
  51. +/* performs depopulation */
  52. +void stadt_t::step_depopulation()
  53. +{
  54. +   sint64     const(& h1)[MAX_CITY_HISTORY] = city_history_month[1];
  55. +   sint64     const(& h0)[MAX_CITY_HISTORY] = city_history_month[0];
  56. +   ratio_transported                        = (h0[HIST_PAS_TRANSPORTED] + h1[HIST_PAS_TRANSPORTED]) * 10 / ((h0[HIST_PAS_GENERATED] + h1[HIST_PAS_GENERATED]) + 1 ); // transported passengers in 10% steps
  57. +   bool       const   is_shrink_too_high    = (get_wachstum() * -10 >= get_einwohner())?true:false;
  58. +
  59. +   // maybe this town should stay static, also skip depopulation when previous month had no passengers
  60. +   if(  !allow_citygrowth || h1[HIST_PAS_GENERATED] == 0 ) {
  61. +       shrink = 0;
  62. +       return;
  63. +   }
  64.  
  65. +    // population rewards rising transport level
  66. +    shrink -= (ratio_transported > transport_level && shrink > 0)?1:0;
  67. +
  68. +   // highest level of transported passengers
  69. +   transport_level = (transport_level >= ratio_transported)?transport_level:ratio_transported;
  70. +
  71. +   // city shrinks when expected passenger transport level is higher than reached transport level
  72. +   if ( (transport_level - 1) > ratio_transported ) { // population accepts an underachievement margin
  73. +       shrink += transport_level - ratio_transported - 1;
  74. +   }
  75. +   const int shrink_step = (shrink>>4);
  76. +   DBG_DEBUG("stadt_t::step_depopulation()", "%s: shrink %i; shrink_step %i; transport_level %i; ratio_transported %i; is_shrink_too_high %s", get_name(), shrink, shrink_step, transport_level, ratio_transported, is_shrink_too_high?"true":"false");
  77. +   shrink &= 0x0F;
  78. +   // every shrink_step lowers expected transport level
  79. +   if ( shrink_step > 0 ) {
  80. +       transport_level -= 1;
  81. +       // small chance to bulldoze a public owned building
  82. +       gebaeude_t* const gb = pick_any(buildings);
  83. +       gebaeude_t::typ const typ = gb->get_haustyp();
  84. +       if ( spieler_t::check_owner(gb->get_besitzer(),NULL) && (typ == gebaeude_t::wohnung || typ == gebaeude_t::gewerbe) && !is_shrink_too_high ) {
  85. +           sint32 population_before = get_einwohner();
  86. +           koord gb_koord = gb->get_pos().get_2d();
  87. +           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);
  88. +           remove_gebaeude_from_stadt(gb);
  89. +           hausbauer_t::remove(welt,welt->get_spieler(1),gb);
  90. +           cbuffer_t buf;
  91. +           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());
  92. +           welt->get_message()->add_message(buf, gb_koord, message_t::city, CITY_KI, IMG_LEER);
  93. +       }
  94. +   }
  95. +}
  96.  
  97.  /* updates the city history
  98.   * @author prissi
  99. diff --git a/simcity.h b/simcity.h
  100. index 98a9742..a729c48 100644
  101. --- a/simcity.h
  102. +++ b/simcity.h
  103. @@ -155,6 +155,11 @@ private:
  104.      */
  105.     sint32 wachstum;
  106.  
  107. +   // used for city depopulation
  108. +   sint32 shrink;
  109. +   sint32 transport_level;
  110. +   sint32 ratio_transported;
  111. +
  112.     /**
  113.     * City history
  114.     * @author prissi
  115. @@ -260,6 +265,9 @@ private:
  116.     // calculates the growth rate for next step_bau using all the different indicators
  117.     void calc_growth();
  118.  
  119. +    /* performs depopulation */
  120. +    void step_depopulation();
  121. +
  122.     /**
  123.      * plant das bauen von Gebaeuden
  124.      * @author Hj. Malthaner
  125. @@ -400,6 +408,9 @@ public:
  126.      */
  127.     void set_name( const char *name );
  128.  
  129. +   // returns status of transport level (used for depopulation)
  130. +   bool get_transport_status() const { return ((transport_level - 1) < ratio_transported); }
  131. +
  132.     /**
  133.      * gibt einen zufällingen gleichverteilten Punkt innerhalb der
  134.      * Stadtgrenzen zurück
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement