# genworld_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: genworld_gui.cpp 15495 2009-02-14 23:17:32Z yexo $ */
    00002
    00005 #include "stdafx.h"
    00006 #include "openttd.h"
    00007 #include "heightmap.h"
    00008 #include "gui.h"
    00009 #include "variables.h"
    00010 #include "settings_func.h"
    00011 #include "debug.h"
    00012 #include "genworld.h"
    00013 #include "network/network.h"
    00014 #include "newgrf_config.h"
    00015 #include "strings_func.h"
    00016 #include "window_func.h"
    00017 #include "date_func.h"
    00018 #include "sound_func.h"
    00019 #include "fios.h"
    00020 #include "string_func.h"
    00021 #include "gfx_func.h"
    00022 #include "settings_type.h"
    00023 #include "widgets/dropdown_type.h"
    00024 #include "widgets/dropdown_func.h"
    00025 #include "core/random_func.hpp"
    00026 #include "landscape_type.h"
    00027 #include "querystring_gui.h"
    00028
    00029 #include "table/strings.h"
    00030 #include "table/sprites.h"
    00031
    00035 enum glwp_modes {
    00036   GLWP_GENERATE,
    00037   GLWP_HEIGHTMAP,
    00038   GLWP_SCENARIO,
    00039   GLWP_END
    00040 };
    00041
    00042 extern void SwitchMode(int new_mode);
    00043 extern void MakeNewgameSettingsLive();
    00044
    00045 static inline void SetNewLandscapeType(byte landscape)
    00046 {
    00047   _settings_newgame.game_creation.landscape = landscape;
    00048   InvalidateWindowClasses(WC_SELECT_GAME);
    00049   InvalidateWindowClasses(WC_GENERATE_LANDSCAPE);
    00050 }
    00051
    00052 enum GenerateLandscapeWindowWidgets {
    00053   GLAND_TEMPERATE = 3,
    00054   GLAND_ARCTIC,
    00055   GLAND_TROPICAL,
    00056   GLAND_TOYLAND,
    00057
    00058   GLAND_MAPSIZE_X_TEXT,
    00059   GLAND_MAPSIZE_X_PULLDOWN,
    00060   GLAND_MAPSIZE_Y_TEXT,
    00061   GLAND_MAPSIZE_Y_PULLDOWN,
    00062
    00063   GLAND_TOWN_TEXT,
    00064   GLAND_TOWN_PULLDOWN,
    00065   GLAND_INDUSTRY_TEXT,
    00066   GLAND_INDUSTRY_PULLDOWN,
    00067
    00068   GLAND_RANDOM_TEXT,
    00069   GLAND_RANDOM_EDITBOX,
    00070   GLAND_RANDOM_BUTTON,
    00071
    00072   GLAND_GENERATE_BUTTON,
    00073
    00074   GLAND_START_DATE_TEXT1,
    00075   GLAND_START_DATE_DOWN,
    00076   GLAND_START_DATE_TEXT,
    00077   GLAND_START_DATE_UP,
    00078
    00079   GLAND_SNOW_LEVEL_TEXT1,
    00080   GLAND_SNOW_LEVEL_DOWN,
    00081   GLAND_SNOW_LEVEL_TEXT,
    00082   GLAND_SNOW_LEVEL_UP,
    00083
    00084   GLAND_TREE_TEXT,
    00085   GLAND_TREE_PULLDOWN,
    00086   GLAND_LANDSCAPE_TEXT,
    00087   GLAND_LANDSCAPE_PULLDOWN,
    00088   GLAND_HEIGHTMAP_ROTATION_TEXT = GLAND_LANDSCAPE_TEXT,
    00089   GLAND_HEIGHTMAP_ROTATION_PULLDOWN = GLAND_LANDSCAPE_PULLDOWN,
    00090
    00091   GLAND_TERRAIN_TEXT,
    00092   GLAND_TERRAIN_PULLDOWN,
    00093   GLAND_WATER_TEXT,
    00094   GLAND_WATER_PULLDOWN,
    00095   GLAND_SMOOTHNESS_TEXT,
    00096   GLAND_SMOOTHNESS_PULLDOWN,
    00097
    00098   GLAND_BORDER_TYPES,
    00099   GLAND_BORDERS_RANDOM,
    00100   GLAND_WATER_NW_TEXT,
    00101   GLAND_WATER_NE_TEXT,
    00102   GLAND_WATER_SE_TEXT,
    00103   GLAND_WATER_SW_TEXT,
    00104   GLAND_WATER_NW,
    00105   GLAND_WATER_NE,
    00106   GLAND_WATER_SE,
    00107   GLAND_WATER_SW,
    00108 };
    00109
    00110 static const Widget _generate_landscape_widgets[] = {
    00111 {  WWT_CLOSEBOX,  RESIZE_NONE, COLOUR_BROWN,    0,  10,   0,  13, STR_00C5,                     STR_018B_CLOSE_WINDOW},
    00112 {    WWT_CAPTION, RESIZE_NONE, COLOUR_BROWN,   11, 337,   0,  13, STR_WORLD_GENERATION_CAPTION, STR_NULL},
    00113 {      WWT_PANEL, RESIZE_NONE, COLOUR_BROWN,    0, 337,  14, 313, 0x0,                          STR_NULL},
    00114
    00115 /* Landscape selection */
    00116 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE,  10,  86,  24,  78, SPR_SELECT_TEMPERATE,         STR_030E_SELECT_TEMPERATE_LANDSCAPE},    // GLAND_TEMPERATE
    00117 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE,  90, 166,  24,  78, SPR_SELECT_SUB_ARCTIC,        STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE},   // GLAND_ARCTIC
    00118 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE, 170, 246,  24,  78, SPR_SELECT_SUB_TROPICAL,      STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE}, // GLAND_TROPICAL
    00119 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE, 250, 326,  24,  78, SPR_SELECT_TOYLAND,           STR_0311_SELECT_TOYLAND_LANDSCAPE},      // GLAND_TOYLAND
    00120
    00121 /* Mapsize X */
    00122 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110,  91, 101, STR_MAPSIZE,                  STR_NULL},                               // GLAND_MAPSIZE_X_TEXT
    00123 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 161,  90, 101, STR_NUM_1,                    STR_NULL},                               // GLAND_MAPSIZE_X_PULLDOWN
    00124 /* Mapsize Y */
    00125 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 168, 176,  91, 101, STR_BY,                       STR_NULL},                               // GLAND_MAPSIZE_Y_TEXT
    00126 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 180, 227,  90, 101, STR_NUM_2,                    STR_NULL},                               // GLAND_MAPSIZE_Y_PULLDOWN
    00127
    00128 /*  Number of towns */
    00129 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 113, 123, STR_NUMBER_OF_TOWNS,          STR_NULL},                               // GLAND_TOWN_TEXT
    00130 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 175, 112, 123, 0x0,                          STR_NULL},                               // GLAND_TOWN_PULLDOWN
    00131
    00132 /* Number of industries */
    00133 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 131, 141, STR_NUMBER_OF_INDUSTRIES,     STR_NULL},                               // GLAND_INDUSTRY_TEXT
    00134 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 175, 130, 141, 0x0,                          STR_NULL},                               // GLAND_INDUSTRY_PULLDOWN
    00135
    00136 /* Edit box for seed */
    00137 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 153, 163, STR_RANDOM_SEED,              STR_NULL},                               // GLAND_RANDOM_TEXT
    00138 {    WWT_EDITBOX, RESIZE_NONE, COLOUR_WHITE,  114, 207, 152, 163, STR_RANDOM_SEED_OSKTITLE,     STR_RANDOM_SEED_HELP},                   // GLAND_RANDOM_EDITBOX
    00139 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_ORANGE, 216, 326, 152, 163, STR_RANDOM,                   STR_RANDOM_HELP},                        // GLAND_RANDOM_BUTTON
    00140
    00141 /* Generate button */
    00142 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREEN, 243, 326, 228, 257, STR_GENERATE,                 STR_NULL},                                // GLAND_GENERATE_BUTTON
    00143
    00144 /* Start date */
    00145 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 182, 212, 113, 123, STR_DATE,                     STR_NULL},                               // GLAND_START_DATE_TEXT1
    00146 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 216, 227, 112, 123, SPR_ARROW_DOWN,               STR_029E_MOVE_THE_STARTING_DATE},        // GLAND_START_DATE_DOWN
    00147 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_ORANGE, 228, 314, 112, 123, STR_GENERATE_DATE,            STR_NULL},                               // GLAND_START_DATE_TEXT
    00148 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 315, 326, 112, 123, SPR_ARROW_UP,                 STR_029F_MOVE_THE_STARTING_DATE},        // GLAND_START_DATE_UP
    00149
    00150 /* Snow line */
    00151 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 182, 278, 131, 141, STR_SNOW_LINE_HEIGHT,         STR_NULL},                               // GLAND_SNOW_LEVEL_TEXT1
    00152 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 282, 293, 130, 141, SPR_ARROW_DOWN,               STR_SNOW_LINE_DOWN},                     // GLAND_SNOW_LEVEL_DOWN
    00153 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_ORANGE, 294, 314, 130, 141, STR_NUM_3,                    STR_NULL},                               // GLAND_SNOW_LEVEL_TEXT
    00154 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 315, 326, 130, 141, SPR_ARROW_UP,                 STR_SNOW_LINE_UP},                       // GLAND_SNOW_LEVEL_UP
    00155
    00156 /* Tree placer */
    00157 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 193, 203, STR_TREE_PLACER,              STR_NULL},                               // GLAND_TREE_TEXT
    00158 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 231, 192, 203, 0x0,                          STR_NULL},                               // GLAND_TREE_PULLDOWN
    00159
    00160 /* Landscape generator */
    00161 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 175, 185, STR_LAND_GENERATOR,           STR_NULL},                               // GLAND_LANDSCAPE_TEXT
    00162 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 231, 174, 185, 0x0,                          STR_NULL},                               // GLAND_LANDSCAPE_PULLDOWN
    00163
    00164 /* Terrain type */
    00165 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 211, 221, STR_TERRAIN_TYPE,             STR_NULL},                               // GLAND_TERRAIN_TEXT
    00166 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 231, 210, 221, 0x0,                          STR_NULL},                               // GLAND_TERRAIN_PULLDOWN
    00167
    00168 /* Water quantity */
    00169 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 229, 239, STR_QUANTITY_OF_SEA_LAKES,    STR_NULL},                               // GLAND_WATER_TEXT
    00170 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 231, 228, 239, 0x0,                          STR_NULL},                               // GLAND_WATER_PULLDOWN
    00171
    00172 /* Map smoothness */
    00173 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 247, 257, STR_SMOOTHNESS,               STR_NULL},                               // GLAND_SMOOTHNESS_TEXT
    00174 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 231, 246, 257, 0x0,                          STR_NULL},                               // GLAND_SMOOTHNESS_PULLDOWN
    00175
    00176 /* Water borders */
    00177 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 265, 275, STR_BORDER_TYPE,             STR_NULL},                               // GLAND_BORDER_TYPES
    00178 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_ORANGE, 114, 231, 264, 275, STR_BORDER_RANDOMIZE,        STR_NULL},                               // GLAND_BORDERS_RANDOM
    00179 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12,  95, 282, 292, STR_NORTHWEST,               STR_NULL},                               // GLAND_WATER_NW_TEXT
    00180 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 250, 326, 282, 292, STR_NORTHEAST,               STR_NULL},                               // GLAND_WATER_NE_TEXT
    00181 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 250, 326, 294, 304, STR_SOUTHEAST,               STR_NULL},                               // GLAND_WATER_SE_TEXT
    00182 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12,  95, 294, 304, STR_SOUTHWEST,               STR_NULL},                               // GLAND_WATER_SW_TEXT
    00183 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_ORANGE, 100, 172, 280, 291, 0x0,                         STR_NORTHWEST},                          // GLAND_WATER_NW
    00184 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_ORANGE, 173, 245, 280, 291, 0x0,                         STR_NORTHEAST},                          // GLAND_WATER_NE
    00185 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_ORANGE, 173, 245, 292, 303, 0x0,                         STR_SOUTHEAST},                          // GLAND_WATER_SE
    00186 { WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_ORANGE, 100, 172, 292, 303, 0x0,                         STR_SOUTHWEST},                          // GLAND_WATER_SW
    00187 {   WIDGETS_END},
    00188 };
    00189
    00190 static const Widget _heightmap_load_widgets[] = {
    00191 {   WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN,    0,  10,   0,  13, STR_00C5,                     STR_018B_CLOSE_WINDOW},
    00192 {    WWT_CAPTION, RESIZE_NONE, COLOUR_BROWN,   11, 337,   0,  13, STR_WORLD_GENERATION_CAPTION, STR_NULL},
    00193 {      WWT_PANEL, RESIZE_NONE, COLOUR_BROWN,    0, 337,  14, 235, 0x0,                          STR_NULL},
    00194
    00195 /* Landscape selection */
    00196 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE,  10,  86,  24,  78, SPR_SELECT_TEMPERATE,        STR_030E_SELECT_TEMPERATE_LANDSCAPE},    // GLAND_TEMPERATE
    00197 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE,  90, 166,  24,  78, SPR_SELECT_SUB_ARCTIC,       STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE},   // GLAND_ARCTIC
    00198 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE, 170, 246,  24,  78, SPR_SELECT_SUB_TROPICAL,     STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE}, // GLAND_TROPICAL
    00199 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE, 250, 326,  24,  78, SPR_SELECT_TOYLAND,          STR_0311_SELECT_TOYLAND_LANDSCAPE},      // GLAND_TOYLAND
    00200
    00201 /* Mapsize X */
    00202 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 113, 123, STR_MAPSIZE,                  STR_NULL},                              // GLAND_MAPSIZE_X_TEXT
    00203 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 161, 112, 123, STR_NUM_1,                    STR_NULL},                              // GLAND_MAPSIZE_X_PULLDOWN
    00204 /* Mapsize Y */
    00205 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 168, 176, 113, 123, STR_BY,                       STR_NULL},                              // GLAND_MAPSIZE_Y_TEXT
    00206 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 180, 227, 112, 123, STR_NUM_2,                    STR_NULL},                              // GLAND_MAPSIZE_Y_PULLDOWN
    00207
    00208 /* Number of towns */
    00209 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 135, 145, STR_NUMBER_OF_TOWNS,          STR_NULL},                              // GLAND_TOWN_TEXT
    00210 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 175, 134, 145, 0x0,                          STR_NULL},                              // GLAND_TOWN_PULLDOWN
    00211
    00212 /* Number of industries */
    00213 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 153, 163, STR_NUMBER_OF_INDUSTRIES,     STR_NULL},                              // GLAND_INDUSTRY_TEXT
    00214 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 175, 152, 163, 0x0,                          STR_NULL},                              // GLAND_INDUSTRY_PULLDOWN
    00215
    00216 /* Edit box for seed */
    00217 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 175, 185, STR_RANDOM_SEED,              STR_NULL},                              // GLAND_RANDOM_TEXT
    00218 {    WWT_EDITBOX, RESIZE_NONE, COLOUR_WHITE,  114, 207, 174, 185, STR_RANDOM_SEED_OSKTITLE,     STR_RANDOM_SEED_HELP},                  // GLAND_RANDOM_EDITBOX
    00219 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_ORANGE, 216, 326, 174, 185, STR_RANDOM,                   STR_RANDOM_HELP},                       // GLAND_RANDOM_BUTTON
    00220
    00221 /* Generate button */
    00222 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREEN,  243, 326, 196, 225, STR_GENERATE,                 STR_NULL},                              // GLAND_GENERATE_BUTTON
    00223
    00224 /* Starting date */
    00225 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 182, 212, 135, 145, STR_DATE,                     STR_NULL},                              // GLAND_START_DATE_TEXT1
    00226 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 216, 227, 134, 145, SPR_ARROW_DOWN,               STR_029E_MOVE_THE_STARTING_DATE},       // GLAND_START_DATE_DOWN
    00227 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_ORANGE, 228, 314, 134, 145, STR_GENERATE_DATE,            STR_NULL},                              // GLAND_START_DATE_TEXT
    00228 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 315, 326, 134, 145, SPR_ARROW_UP,                 STR_029F_MOVE_THE_STARTING_DATE},       // GLAND_START_DATE_UP
    00229
    00230 /* Snow line */
    00231 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 182, 278, 153, 163, STR_SNOW_LINE_HEIGHT,         STR_NULL},                              // GLAND_SNOW_LEVEL_TEXT1
    00232 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 282, 293, 152, 163, SPR_ARROW_DOWN,               STR_SNOW_LINE_DOWN},                    // GLAND_SNOW_LEVEL_DOWN
    00233 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_ORANGE, 294, 314, 152, 163, STR_NUM_3,                    STR_NULL},                              // GLAND_SNOW_LEVEL_TEXT
    00234 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 315, 326, 152, 163, SPR_ARROW_UP,                 STR_SNOW_LINE_UP},                      // GLAND_SNOW_LEVEL_UP
    00235
    00236 /* Tree placer */
    00237 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 197, 207, STR_TREE_PLACER,              STR_NULL},                              // GLAND_TREE_TEXT
    00238 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 231, 196, 207, STR_0225,                     STR_NULL},                              // GLAND_TREE_PULLDOWN
    00239
    00240 /* Heightmap rotation */
    00241 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE,  12, 110, 215, 225, STR_HEIGHTMAP_ROTATION,       STR_NULL},                              // GLAND_HEIGHTMAP_ROTATION_TEXT
    00242 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 114, 231, 214, 225, STR_0225,                     STR_NULL},                              // GLAND_HEIGHTMAP_ROTATION_PULLDOWN
    00243
    00244 {   WIDGETS_END},
    00245 };
    00246
    00247 void StartGeneratingLandscape(glwp_modes mode)
    00248 {
    00249   DeleteAllNonVitalWindows();
    00250
    00251   /* Copy all XXX_newgame to XXX when coming from outside the editor */
    00252   MakeNewgameSettingsLive();
    00253   ResetGRFConfig(true);
    00254
    00255   SndPlayFx(SND_15_BEEP);
    00256   switch (mode) {
    00257     case GLWP_GENERATE:  _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND    : SM_NEWGAME;         break;
    00258     case GLWP_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
    00259     case GLWP_SCENARIO:  _switch_mode = SM_EDITOR; break;
    00260     default: NOT_REACHED();
    00261   }
    00262 }
    00263
    00264 static void LandscapeGenerationCallback(Window *w, bool confirmed)
    00265 {
    00266   if (confirmed) StartGeneratingLandscape((glwp_modes)w->window_number);
    00267 }
    00268
    00269 static DropDownList *BuildMapsizeDropDown()
    00270 {
    00271   DropDownList *list = new DropDownList();
    00272
    00273   for (uint i = 6; i <= 11; i++) {
    00274     DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
    00275     item->SetParam(0, 1 << i);
    00276     list->push_back(item);
    00277   }
    00278
    00279   return list;
    00280 }
    00281
    00282 static const StringID _elevations[]  = {STR_682A_VERY_FLAT, STR_682B_FLAT, STR_682C_HILLY, STR_682D_MOUNTAINOUS, INVALID_STRING_ID};
    00283 static const StringID _sea_lakes[]   = {STR_VERY_LOW, STR_6820_LOW, STR_6821_MEDIUM, STR_6822_HIGH, INVALID_STRING_ID};
    00284 static const StringID _smoothness[]  = {STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_ROUGH, INVALID_STRING_ID};
    00285 static const StringID _tree_placer[] = {STR_CONFIG_SETTING_TREE_PLACER_NONE, STR_CONFIG_SETTING_TREE_PLACER_ORIGINAL, STR_CONFIG_SETTING_TREE_PLACER_IMPROVED, INVALID_STRING_ID};
    00286 static const StringID _rotation[]    = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
    00287 static const StringID _landscape[]   = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
    00288 static const StringID _num_towns[]   = {STR_NUM_VERY_LOW, STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID};
    00289 static const StringID _num_inds[]    = {STR_NONE, STR_NUM_VERY_LOW, STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID};
    00290
    00291 struct GenerateLandscapeWindow : public QueryStringBaseWindow {
    00292   uint widget_id;
    00293   uint x;
    00294   uint y;
    00295   char name[64];
    00296   glwp_modes mode;
    00297
    00298   GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : QueryStringBaseWindow(11, desc, number)
    00299   {
    00300     this->LowerWidget(_settings_newgame.game_creation.landscape + GLAND_TEMPERATE);
    00301
    00302     /* snprintf() always outputs trailing '\0', so whole buffer can be used */
    00303     snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
    00304     InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 120);
    00305     this->SetFocusedWidget(GLAND_RANDOM_EDITBOX);
    00306     this->caption = STR_NULL;
    00307     this->afilter = CS_NUMERAL;
    00308
    00309     this->mode = (glwp_modes)this->window_number;
    00310
    00311     this->FindWindowPlacementAndResize(desc);
    00312   }
    00313
    00314   virtual void OnPaint()
    00315   {
    00316     /* You can't select smoothness / non-water borders if not terragenesis */
    00317     if (mode == GLWP_GENERATE) {
    00318       this->SetWidgetDisabledState(GLAND_SMOOTHNESS_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
    00319       this->SetWidgetDisabledState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges);
    00320       this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BORDERS_RANDOM,
    00321           GLAND_WATER_NW, GLAND_WATER_NE, GLAND_WATER_SE, GLAND_WATER_SW, WIDGET_LIST_END);
    00322
    00323       this->SetWidgetLoweredState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.water_borders == BORDERS_RANDOM);
    00324
    00325       this->SetWidgetLoweredState(GLAND_WATER_NW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW));
    00326       this->SetWidgetLoweredState(GLAND_WATER_NE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE));
    00327       this->SetWidgetLoweredState(GLAND_WATER_SE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE));
    00328       this->SetWidgetLoweredState(GLAND_WATER_SW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW));
    00329     }
    00330     /* Disable snowline if not hilly */
    00331     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_TEXT, _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00332     /* Disable town, industry and trees in SE */
    00333     this->SetWidgetDisabledState(GLAND_TOWN_PULLDOWN,     _game_mode == GM_EDITOR);
    00334     this->SetWidgetDisabledState(GLAND_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
    00335     this->SetWidgetDisabledState(GLAND_TREE_PULLDOWN,     _game_mode == GM_EDITOR);
    00336
    00337     this->SetWidgetDisabledState(GLAND_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
    00338     this->SetWidgetDisabledState(GLAND_START_DATE_UP,   _settings_newgame.game_creation.starting_year >= MAX_YEAR);
    00339     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_DOWN, _settings_newgame.game_creation.snow_line_height <= 2 || _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00340     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_UP,   _settings_newgame.game_creation.snow_line_height >= MAX_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00341
    00342     this->SetWidgetLoweredState(GLAND_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    00343     this->SetWidgetLoweredState(GLAND_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    00344     this->SetWidgetLoweredState(GLAND_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
    00345     this->SetWidgetLoweredState(GLAND_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    00346
    00347     if (_game_mode == GM_EDITOR) {
    00348       this->widget[GLAND_TOWN_PULLDOWN].data     = STR_6836_OFF;
    00349       this->widget[GLAND_INDUSTRY_PULLDOWN].data = STR_6836_OFF;
    00350     } else {
    00351       this->widget[GLAND_TOWN_PULLDOWN].data     = _num_towns[_settings_newgame.difficulty.number_towns];
    00352       this->widget[GLAND_INDUSTRY_PULLDOWN].data = _num_inds[_settings_newgame.difficulty.number_industries];
    00353     }
    00354
    00355     if (mode == GLWP_GENERATE) {
    00356       this->widget[GLAND_LANDSCAPE_PULLDOWN].data  = _landscape[_settings_newgame.game_creation.land_generator];
    00357       this->widget[GLAND_TREE_PULLDOWN].data       = _tree_placer[_settings_newgame.game_creation.tree_placer];
    00358       this->widget[GLAND_TERRAIN_PULLDOWN].data    = _elevations[_settings_newgame.difficulty.terrain_type];
    00359       this->widget[GLAND_WATER_PULLDOWN].data      = _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes];
    00360       this->widget[GLAND_SMOOTHNESS_PULLDOWN].data = _smoothness[_settings_newgame.game_creation.tgen_smoothness];
    00361       this->widget[GLAND_BORDERS_RANDOM].data      = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_BORDER_RANDOMIZE : STR_BORDER_MANUAL;
    00362
    00363       if (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) {
    00364         this->widget[GLAND_WATER_NE].data = STR_BORDER_RANDOM;
    00365         this->widget[GLAND_WATER_NW].data = STR_BORDER_RANDOM;
    00366         this->widget[GLAND_WATER_SE].data = STR_BORDER_RANDOM;
    00367         this->widget[GLAND_WATER_SW].data = STR_BORDER_RANDOM;
    00368       } else {
    00369         this->widget[GLAND_WATER_NE].data = HasBit(_settings_newgame.game_creation.water_borders,BORDER_NE) ? STR_BORDER_WATER : STR_BORDER_FREEFORM;
    00370         this->widget[GLAND_WATER_NW].data = HasBit(_settings_newgame.game_creation.water_borders,BORDER_NW) ? STR_BORDER_WATER : STR_BORDER_FREEFORM;
    00371         this->widget[GLAND_WATER_SE].data = HasBit(_settings_newgame.game_creation.water_borders,BORDER_SE) ? STR_BORDER_WATER : STR_BORDER_FREEFORM;
    00372         this->widget[GLAND_WATER_SW].data = HasBit(_settings_newgame.game_creation.water_borders,BORDER_SW) ? STR_BORDER_WATER : STR_BORDER_FREEFORM;
    00373       }
    00374     } else {
    00375       this->widget[GLAND_TREE_PULLDOWN].data               = _tree_placer[_settings_newgame.game_creation.tree_placer];
    00376       this->widget[GLAND_HEIGHTMAP_ROTATION_PULLDOWN].data = _rotation[_settings_newgame.game_creation.heightmap_rotation];
    00377     }
    00378
    00379     /* Set parameters for widget text that requires them. */
    00380     SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); // GLAND_START_DATE_TEXT
    00381     SetDParam(1, 1 << _settings_newgame.game_creation.map_x); // GLAND_MAPSIZE_X_PULLDOWN
    00382     SetDParam(2, 1 << _settings_newgame.game_creation.map_y); // GLAND_MAPSIZE_Y_PULLDOWN
    00383     SetDParam(3, _settings_newgame.game_creation.snow_line_height); // GLAND_SNOW_LEVEL_TEXT
    00384
    00385     this->DrawWidgets();
    00386
    00387     this->DrawEditBox(GLAND_RANDOM_EDITBOX);
    00388
    00389     if (mode != GLWP_GENERATE) {
    00390       char buffer[512];
    00391
    00392       if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
    00393         SetDParam(0, this->y);
    00394         SetDParam(1, this->x);
    00395       } else {
    00396         SetDParam(0, this->x);
    00397         SetDParam(1, this->y);
    00398       }
    00399       GetString(buffer, STR_HEIGHTMAP_SIZE, lastof(buffer));
    00400       DrawStringRightAligned(326, 91, STR_HEIGHTMAP_SIZE, TC_BLACK);
    00401
    00402       DrawString( 12,  91, STR_HEIGHTMAP_NAME, TC_BLACK);
    00403       SetDParamStr(0, this->name);
    00404       DrawStringTruncated(114,  91, STR_JUST_RAW_STRING, TC_ORANGE, 326 - 114 - GetStringBoundingBox(buffer).width - 5);
    00405     }
    00406   }
    00407
    00408   virtual void OnClick(Point pt, int widget)
    00409   {
    00410     switch (widget) {
    00411       case 0: delete this; break;
    00412
    00413       case GLAND_TEMPERATE:
    00414       case GLAND_ARCTIC:
    00415       case GLAND_TROPICAL:
    00416       case GLAND_TOYLAND:
    00417         this->RaiseWidget(_settings_newgame.game_creation.landscape + GLAND_TEMPERATE);
    00418         SetNewLandscapeType(widget - GLAND_TEMPERATE);
    00419         break;
    00420
    00421       case GLAND_MAPSIZE_X_PULLDOWN: // Mapsize X
    00422         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, GLAND_MAPSIZE_X_PULLDOWN);
    00423         break;
    00424
    00425       case GLAND_MAPSIZE_Y_PULLDOWN: // Mapsize Y
    00426         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, GLAND_MAPSIZE_Y_PULLDOWN);
    00427         break;
    00428
    00429       case GLAND_TOWN_PULLDOWN: // Number of towns
    00430         ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, GLAND_TOWN_PULLDOWN, 0, 0);
    00431         break;
    00432
    00433       case GLAND_INDUSTRY_PULLDOWN: // Number of industries
    00434         ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.number_industries, GLAND_INDUSTRY_PULLDOWN, 0, 0);
    00435         break;
    00436
    00437       case GLAND_RANDOM_BUTTON: // Random seed
    00438         _settings_newgame.game_creation.generation_seed = InteractiveRandom();
    00439         snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
    00440         UpdateTextBufferSize(&this->text);
    00441         this->SetDirty();
    00442         break;
    00443
    00444       case GLAND_GENERATE_BUTTON: // Generate
    00445         MakeNewgameSettingsLive();
    00446
    00447         if (mode == GLWP_HEIGHTMAP &&
    00448             (this->x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
    00449             this->x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
    00450             this->y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
    00451             this->y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
    00452           ShowQuery(
    00453             STR_HEIGHTMAP_SCALE_WARNING_CAPTION,
    00454             STR_HEIGHTMAP_SCALE_WARNING_MESSAGE,
    00455             this,
    00456             LandscapeGenerationCallback);
    00457         } else {
    00458           StartGeneratingLandscape(mode);
    00459         }
    00460         break;
    00461
    00462       case GLAND_START_DATE_DOWN:
    00463       case GLAND_START_DATE_UP: // Year buttons
    00464         /* Don't allow too fast scrolling */
    00465         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00466           this->HandleButtonClick(widget);
    00467           this->SetDirty();
    00468
    00469           _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
    00470         }
    00471         _left_button_clicked = false;
    00472         break;
    00473
    00474       case GLAND_START_DATE_TEXT: // Year text
    00475         this->widget_id = GLAND_START_DATE_TEXT;
    00476         SetDParam(0, _settings_newgame.game_creation.starting_year);
    00477         ShowQueryString(STR_CONFIG_SETTING_INT32, STR_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL, QSF_NONE);
    00478         break;
    00479
    00480       case GLAND_SNOW_LEVEL_DOWN:
    00481       case GLAND_SNOW_LEVEL_UP: // Snow line buttons
    00482         /* Don't allow too fast scrolling */
    00483         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00484           this->HandleButtonClick(widget);
    00485           this->SetDirty();
    00486
    00487           _settings_newgame.game_creation.snow_line_height = Clamp(_settings_newgame.game_creation.snow_line_height + widget - GLAND_SNOW_LEVEL_TEXT, 2, MAX_SNOWLINE_HEIGHT);
    00488         }
    00489         _left_button_clicked = false;
    00490         break;
    00491
    00492       case GLAND_SNOW_LEVEL_TEXT: // Snow line text
    00493         this->widget_id = GLAND_SNOW_LEVEL_TEXT;
    00494         SetDParam(0, _settings_newgame.game_creation.snow_line_height);
    00495         ShowQueryString(STR_CONFIG_SETTING_INT32, STR_SNOW_LINE_QUERY_CAPT, 3, 100, this, CS_NUMERAL, QSF_NONE);
    00496         break;
    00497
    00498       case GLAND_TREE_PULLDOWN: // Tree placer
    00499         ShowDropDownMenu(this, _tree_placer, _settings_newgame.game_creation.tree_placer, GLAND_TREE_PULLDOWN, 0, 0);
    00500         break;
    00501
    00502       case GLAND_LANDSCAPE_PULLDOWN: // Landscape generator OR Heightmap rotation
    00503       /* case GLAND_HEIGHTMAP_ROTATION_TEXT: case GLAND_HEIGHTMAP_ROTATION_PULLDOWN:*/
    00504         if (mode == GLWP_HEIGHTMAP) {
    00505           ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, GLAND_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
    00506         } else {
    00507           ShowDropDownMenu(this, _landscape, _settings_newgame.game_creation.land_generator, GLAND_LANDSCAPE_PULLDOWN, 0, 0);
    00508         }
    00509         break;
    00510
    00511       case GLAND_TERRAIN_PULLDOWN: // Terrain type
    00512         ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, GLAND_TERRAIN_PULLDOWN, 0, 0);
    00513         break;
    00514
    00515       case GLAND_WATER_PULLDOWN: // Water quantity
    00516         ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, GLAND_WATER_PULLDOWN, 0, 0);
    00517         break;
    00518
    00519       case GLAND_SMOOTHNESS_PULLDOWN: // Map smoothness
    00520         ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, GLAND_SMOOTHNESS_PULLDOWN, 0, 0);
    00521         break;
    00522
    00523       /* Freetype map borders */
    00524       case GLAND_WATER_NW:
    00525         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NW);
    00526         break;
    00527
    00528       case GLAND_WATER_NE:
    00529         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NE);
    00530         break;
    00531
    00532       case GLAND_WATER_SE:
    00533         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SE);
    00534         break;
    00535
    00536       case GLAND_WATER_SW:
    00537         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SW);
    00538         break;
    00539
    00540       case GLAND_BORDERS_RANDOM:
    00541         _settings_newgame.game_creation.water_borders = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? 0 : BORDERS_RANDOM;
    00542         this->SetDirty();
    00543         break;
    00544     }
    00545   }
    00546
    00547   virtual void OnMouseLoop()
    00548   {
    00549     this->HandleEditBox(GLAND_RANDOM_EDITBOX);
    00550   }
    00551
    00552   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00553   {
    00554     EventState state;
    00555     this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state);
    00556     /* the seed is unsigned, therefore atoi cannot be used.
    00557       * As 2^32 - 1 (UINT32_MAX) is a 'magic' value
    00558       * (use random seed) it should not be possible to be
    00559       * entered into the input field; the generate seed
    00560       * button can be used instead. */
    00561     _settings_newgame.game_creation.generation_seed = minu(strtoul(this->edit_str_buf, NULL, 10), UINT32_MAX - 1);
    00562     return state;
    00563   }
    00564
    00565   virtual void OnDropdownSelect(int widget, int index)
    00566   {
    00567     switch (widget) {
    00568       case GLAND_MAPSIZE_X_PULLDOWN:     _settings_newgame.game_creation.map_x = index; break;
    00569       case GLAND_MAPSIZE_Y_PULLDOWN:     _settings_newgame.game_creation.map_y = index; break;
    00570       case GLAND_TREE_PULLDOWN:          _settings_newgame.game_creation.tree_placer = index; break;
    00571       case GLAND_SMOOTHNESS_PULLDOWN:    _settings_newgame.game_creation.tgen_smoothness = index;  break;
    00572
    00573       case GLAND_TOWN_PULLDOWN:
    00574         _settings_newgame.difficulty.number_towns = index;
    00575         if (_settings_newgame.difficulty.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
    00576         IConsoleSetSetting("difficulty.number_towns", _settings_newgame.difficulty.number_towns);
    00577         break;
    00578
    00579       case GLAND_INDUSTRY_PULLDOWN:
    00580         _settings_newgame.difficulty.number_industries = index;
    00581         if (_settings_newgame.difficulty.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
    00582         IConsoleSetSetting("difficulty.number_industries", _settings_newgame.difficulty.number_industries);
    00583         break;
    00584
    00585       case GLAND_LANDSCAPE_PULLDOWN:
    00586       /* case GLAND_HEIGHTMAP_PULLDOWN: */
    00587         if (mode == GLWP_HEIGHTMAP) {
    00588           _settings_newgame.game_creation.heightmap_rotation = index;
    00589         } else {
    00590           _settings_newgame.game_creation.land_generator = index;
    00591         }
    00592         break;
    00593
    00594       case GLAND_TERRAIN_PULLDOWN:
    00595         _settings_newgame.difficulty.terrain_type = index;
    00596         if (_settings_newgame.difficulty.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
    00597         IConsoleSetSetting("difficulty.terrain_type", _settings_newgame.difficulty.terrain_type);
    00598         break;
    00599
    00600       case GLAND_WATER_PULLDOWN:
    00601         _settings_newgame.difficulty.quantity_sea_lakes = index;
    00602         if (_settings_newgame.difficulty.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
    00603         IConsoleSetSetting("difficulty.quantity_sea_lakes", _settings_newgame.difficulty.quantity_sea_lakes);
    00604         break;
    00605     }
    00606     this->SetDirty();
    00607   }
    00608
    00609   virtual void OnQueryTextFinished(char *str)
    00610   {
    00611     if (!StrEmpty(str)) {
    00612       int32 value = atoi(str);
    00613
    00614       switch (this->widget_id) {
    00615         case GLAND_START_DATE_TEXT:
    00616           this->InvalidateWidget(GLAND_START_DATE_TEXT);
    00617           _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
    00618           break;
    00619
    00620         case GLAND_SNOW_LEVEL_TEXT:
    00621           this->InvalidateWidget(GLAND_SNOW_LEVEL_TEXT);
    00622           _settings_newgame.game_creation.snow_line_height = Clamp(value, 2, MAX_SNOWLINE_HEIGHT);
    00623           break;
    00624       }
    00625
    00626       this->SetDirty();
    00627     }
    00628   }
    00629 };
    00630
    00631 static const WindowDesc _generate_landscape_desc = {
    00632   WDP_CENTER, WDP_CENTER, 338, 313, 338, 313,
    00633   WC_GENERATE_LANDSCAPE, WC_NONE,
    00634   WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
    00635   _generate_landscape_widgets,
    00636 };
    00637
    00638 static const WindowDesc _heightmap_load_desc = {
    00639   WDP_CENTER, WDP_CENTER, 338, 236, 338, 236,
    00640   WC_GENERATE_LANDSCAPE, WC_NONE,
    00641   WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
    00642   _heightmap_load_widgets,
    00643 };
    00644
    00645 static void _ShowGenerateLandscape(glwp_modes mode)
    00646 {
    00647   uint x = 0;
    00648   uint y = 0;
    00649
    00650   DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
    00651
    00652   /* Always give a new seed if not editor */
    00653   if (_game_mode != GM_EDITOR) _settings_newgame.game_creation.generation_seed = InteractiveRandom();
    00654
    00655   if (mode == GLWP_HEIGHTMAP) {
    00656     /* If the function returns negative, it means there was a problem loading the heightmap */
    00657     if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return;
    00658   }
    00659
    00660   GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>((mode == GLWP_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode);
    00661
    00662   if (mode == GLWP_HEIGHTMAP) {
    00663     w->x = x;
    00664     w->y = y;
    00665     strecpy(w->name, _file_to_saveload.title, lastof(w->name));
    00666   }
    00667
    00668   InvalidateWindow(WC_GENERATE_LANDSCAPE, mode);
    00669 }
    00670
    00671 void ShowGenerateLandscape()
    00672 {
    00673   _ShowGenerateLandscape(GLWP_GENERATE);
    00674 }
    00675
    00676 void ShowHeightmapLoad()
    00677 {
    00678   _ShowGenerateLandscape(GLWP_HEIGHTMAP);
    00679 }
    00680
    00681 void StartScenarioEditor()
    00682 {
    00683   StartGeneratingLandscape(GLWP_SCENARIO);
    00684 }
    00685
    00686 void StartNewGameWithoutGUI(uint seed)
    00687 {
    00688   /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
    00689   _settings_newgame.game_creation.generation_seed = seed;
    00690
    00691   StartGeneratingLandscape(GLWP_GENERATE);
    00692 }
    00693
    00694 enum CreateScenarioWindowWidgets {
    00695   CSCEN_TEMPERATE = 3,
    00696   CSCEN_ARCTIC,
    00697   CSCEN_TROPICAL,
    00698   CSCEN_TOYLAND,
    00699   CSCEN_EMPTY_WORLD,
    00700   CSCEN_RANDOM_WORLD,
    00701   CSCEN_MAPSIZE_X_TEXT,
    00702   CSCEN_MAPSIZE_X_PULLDOWN,
    00703   CSCEN_MAPSIZE_Y_TEXT,
    00704   CSCEN_MAPSIZE_Y_PULLDOWN,
    00705   CSCEN_START_DATE_LABEL,
    00706   CSCEN_START_DATE_DOWN,
    00707   CSCEN_START_DATE_TEXT,
    00708   CSCEN_START_DATE_UP,
    00709   CSCEN_FLAT_LAND_HEIGHT_LABEL,
    00710   CSCEN_FLAT_LAND_HEIGHT_DOWN,
    00711   CSCEN_FLAT_LAND_HEIGHT_TEXT,
    00712   CSCEN_FLAT_LAND_HEIGHT_UP
    00713 };
    00714
    00715
    00716 struct CreateScenarioWindow : public Window
    00717 {
    00718   uint widget_id;
    00719
    00720   CreateScenarioWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
    00721   {
    00722     this->LowerWidget(_settings_newgame.game_creation.landscape + CSCEN_TEMPERATE);
    00723     this->FindWindowPlacementAndResize(desc);
    00724   }
    00725
    00726   virtual void OnPaint()
    00727   {
    00728     this->SetWidgetDisabledState(CSCEN_START_DATE_DOWN,       _settings_newgame.game_creation.starting_year <= MIN_YEAR);
    00729     this->SetWidgetDisabledState(CSCEN_START_DATE_UP,         _settings_newgame.game_creation.starting_year >= MAX_YEAR);
    00730     this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
    00731     this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_UP,   _settings_newgame.game_creation.se_flat_world_height >= MAX_TILE_HEIGHT);
    00732
    00733     this->SetWidgetLoweredState(CSCEN_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    00734     this->SetWidgetLoweredState(CSCEN_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    00735     this->SetWidgetLoweredState(CSCEN_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
    00736     this->SetWidgetLoweredState(CSCEN_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    00737
    00738     /* Set parameters for widget text that requires them */
    00739     SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); // CSCEN_START_DATE_TEXT
    00740     SetDParam(1, 1 << _settings_newgame.game_creation.map_x); // CSCEN_MAPSIZE_X_PULLDOWN
    00741     SetDParam(2, 1 << _settings_newgame.game_creation.map_y); // CSCEN_MAPSIZE_Y_PULLDOWN
    00742     SetDParam(3, _settings_newgame.game_creation.se_flat_world_height); // CSCEN_FLAT_LAND_HEIGHT_TEXT
    00743
    00744     this->DrawWidgets();
    00745   }
    00746
    00747   virtual void OnClick(Point pt, int widget)
    00748   {
    00749     switch (widget) {
    00750       case CSCEN_TEMPERATE:
    00751       case CSCEN_ARCTIC:
    00752       case CSCEN_TROPICAL:
    00753       case CSCEN_TOYLAND:
    00754         this->RaiseWidget(_settings_newgame.game_creation.landscape + CSCEN_TEMPERATE);
    00755         SetNewLandscapeType(widget - CSCEN_TEMPERATE);
    00756         break;
    00757
    00758       case CSCEN_MAPSIZE_X_PULLDOWN: // Mapsize X
    00759         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, CSCEN_MAPSIZE_X_PULLDOWN);
    00760         break;
    00761
    00762       case CSCEN_MAPSIZE_Y_PULLDOWN: // Mapsize Y
    00763         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, CSCEN_MAPSIZE_Y_PULLDOWN);
    00764         break;
    00765
    00766       case CSCEN_EMPTY_WORLD: // Empty world / flat world
    00767         StartGeneratingLandscape(GLWP_SCENARIO);
    00768         break;
    00769
    00770       case CSCEN_RANDOM_WORLD: // Generate
    00771         ShowGenerateLandscape();
    00772         break;
    00773
    00774       case CSCEN_START_DATE_DOWN:
    00775       case CSCEN_START_DATE_UP: // Year buttons
    00776         /* Don't allow too fast scrolling */
    00777         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00778           this->HandleButtonClick(widget);
    00779           this->SetDirty();
    00780
    00781           _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
    00782         }
    00783         _left_button_clicked = false;
    00784         break;
    00785
    00786       case CSCEN_START_DATE_TEXT: // Year text
    00787         this->widget_id = CSCEN_START_DATE_TEXT;
    00788         SetDParam(0, _settings_newgame.game_creation.starting_year);
    00789         ShowQueryString(STR_CONFIG_SETTING_INT32, STR_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL, QSF_NONE);
    00790         break;
    00791
    00792       case CSCEN_FLAT_LAND_HEIGHT_DOWN:
    00793       case CSCEN_FLAT_LAND_HEIGHT_UP: // Height level buttons
    00794         /* Don't allow too fast scrolling */
    00795         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00796           this->HandleButtonClick(widget);
    00797           this->SetDirty();
    00798
    00799           _settings_newgame.game_creation.se_flat_world_height = Clamp(_settings_newgame.game_creation.se_flat_world_height + widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, MAX_TILE_HEIGHT);
    00800         }
    00801         _left_button_clicked = false;
    00802         break;
    00803
    00804       case CSCEN_FLAT_LAND_HEIGHT_TEXT: // Height level text
    00805         this->widget_id = CSCEN_FLAT_LAND_HEIGHT_TEXT;
    00806         SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
    00807         ShowQueryString(STR_CONFIG_SETTING_INT32, STR_FLAT_WORLD_HEIGHT_QUERY_CAPT, 3, 100, this, CS_NUMERAL, QSF_NONE);
    00808         break;
    00809     }
    00810   }
    00811
    00812   virtual void OnDropdownSelect(int widget, int index)
    00813   {
    00814     switch (widget) {
    00815       case CSCEN_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
    00816       case CSCEN_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
    00817     }
    00818     this->SetDirty();
    00819   }
    00820
    00821   virtual void OnQueryTextFinished(char *str)
    00822   {
    00823     if (!StrEmpty(str)) {
    00824       int32 value = atoi(str);
    00825
    00826       switch (this->widget_id) {
    00827         case CSCEN_START_DATE_TEXT:
    00828           this->InvalidateWidget(CSCEN_START_DATE_TEXT);
    00829           _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
    00830           break;
    00831
    00832         case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    00833           this->InvalidateWidget(CSCEN_FLAT_LAND_HEIGHT_TEXT);
    00834           _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, MAX_TILE_HEIGHT);
    00835           break;
    00836       }
    00837
    00838       this->SetDirty();
    00839     }
    00840   }
    00841 };
    00842
    00843 static const Widget _create_scenario_widgets[] = {
    00844 {   WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN,    0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW},
    00845 {    WWT_CAPTION, RESIZE_NONE, COLOUR_BROWN,   11, 337,   0,  13, STR_SE_CAPTION,          STR_NULL},
    00846 {      WWT_PANEL, RESIZE_NONE, COLOUR_BROWN,    0, 337,  14, 169, 0x0,                     STR_NULL},
    00847
    00848 /* Landscape selection */
    00849 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE,  10,  86,  24,  78, SPR_SELECT_TEMPERATE,    STR_030E_SELECT_TEMPERATE_LANDSCAPE},    // CSCEN_TEMPERATE
    00850 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE,  90, 166,  24,  78, SPR_SELECT_SUB_ARCTIC,   STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE},   // CSCEN_ARCTIC
    00851 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE, 170, 246,  24,  78, SPR_SELECT_SUB_TROPICAL, STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE}, // CSCEN_TROPICAL
    00852 {   WWT_IMGBTN_2, RESIZE_NONE, COLOUR_ORANGE, 250, 326,  24,  78, SPR_SELECT_TOYLAND,      STR_0311_SELECT_TOYLAND_LANDSCAPE},      // CSCEN_TOYLAND
    00853
    00854 /* Generation type */
    00855 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREEN,   12, 115,  95, 124, STR_SE_FLAT_WORLD,       STR_SE_FLAT_WORLD_TIP},                  // CSCEN_EMPTY_WORLD
    00856 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREEN,   12, 115, 131, 160, STR_SE_RANDOM_LAND,      STR_022A_GENERATE_RANDOM_LAND},          // CSCEN_RANDOM_WORLD
    00857
    00858 /* Mapsize X */
    00859 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 135, 212,  96, 106, STR_MAPSIZE,             STR_NULL},                               // CSCEN_MAPSIZE_X_TEXT
    00860 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 216, 263,  95, 106, STR_NUM_1,               STR_NULL},                               // CSCEN_MAPSIZE_X_PULLDOWN
    00861 /* Mapsize Y */
    00862 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 268, 276,  96, 106, STR_BY,                  STR_NULL},                               // CSCEN_MAPSIZE_Y_TEXT
    00863 {   WWT_DROPDOWN, RESIZE_NONE, COLOUR_ORANGE, 279, 326,  95, 106, STR_NUM_2,               STR_NULL},                               // CSCEN_MAPSIZE_Y_PULLDOWN
    00864
    00865 /* Start date */
    00866 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 135, 212, 114, 124, STR_DATE,                STR_NULL},                               // CSCEN_START_DATE_LABEL
    00867 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 216, 227, 113, 124, SPR_ARROW_DOWN,          STR_029E_MOVE_THE_STARTING_DATE},        // CSCEN_START_DATE_DOWN
    00868 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_ORANGE, 228, 314, 113, 124, STR_GENERATE_DATE,       STR_NULL},                               // CSCEN_START_DATE_TEXT
    00869 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 315, 326, 113, 124, SPR_ARROW_UP,            STR_029F_MOVE_THE_STARTING_DATE},        // CSCEN_START_DATE_UP
    00870
    00871 /* Flat map height */
    00872 {       WWT_TEXT, RESIZE_NONE, COLOUR_ORANGE, 135, 278, 132, 142, STR_FLAT_WORLD_HEIGHT,   STR_NULL},                               // CSCEN_FLAT_LAND_HEIGHT_LABEL
    00873 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 282, 293, 131, 142, SPR_ARROW_DOWN,          STR_FLAT_WORLD_HEIGHT_DOWN},             // CSCEN_FLAT_LAND_HEIGHT_DOWN
    00874 {    WWT_TEXTBTN, RESIZE_NONE, COLOUR_ORANGE, 294, 314, 131, 142, STR_NUM_3,               STR_NULL},                               // CSCEN_FLAT_LAND_HEIGHT_TEXT
    00875 {     WWT_IMGBTN, RESIZE_NONE, COLOUR_ORANGE, 315, 326, 131, 142, SPR_ARROW_UP,            STR_FLAT_WORLD_HEIGHT_UP},               // CSCEN_FLAT_LAND_HEIGHT_UP
    00876 {   WIDGETS_END},
    00877 };
    00878
    00879 static const WindowDesc _create_scenario_desc = {
    00880   WDP_CENTER, WDP_CENTER, 338, 170, 338, 170,
    00881   WC_GENERATE_LANDSCAPE, WC_NONE,
    00882   WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
    00883   _create_scenario_widgets,
    00884 };
    00885
    00886 void ShowCreateScenario()
    00887 {
    00888   DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
    00889   new CreateScenarioWindow(&_create_scenario_desc, GLWP_SCENARIO);
    00890 }
    00891
    00892
    00893 static const Widget _generate_progress_widgets[] = {
    00894 {    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    0,   180,     0,    13, STR_GENERATION_WORLD,   STR_018C_WINDOW_TITLE_DRAG_THIS}, // GPWW_CAPTION
    00895 {      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,    0,   180,    14,    96, 0x0,                    STR_NULL},                        // GPWW_BACKGROUND
    00896 {    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_WHITE,  20,   161,    74,    85, STR_GENERATION_ABORT,   STR_NULL},                        // GPWW_ABORT
    00897 {   WIDGETS_END},
    00898 };
    00899
    00900 static const WindowDesc _generate_progress_desc = {
    00901   WDP_CENTER, WDP_CENTER, 181, 97, 181, 97,
    00902   WC_GENERATE_PROGRESS_WINDOW, WC_NONE,
    00903   WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
    00904   _generate_progress_widgets,
    00905 };
    00906
    00907 struct tp_info {
    00908   uint percent;
    00909   StringID cls;
    00910   uint current;
    00911   uint total;
    00912   int timer;
    00913 };
    00914
    00915 static tp_info _tp;
    00916
    00917 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
    00918 {
    00919   if (confirmed) {
    00920     AbortGeneratingWorld();
    00921   } else if (IsGeneratingWorld() && !IsGeneratingWorldAborted()) {
    00922     SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
    00923   }
    00924 }
    00925
    00926 struct GenerateProgressWindow : public Window {
    00927 private:
    00928   enum GenerationProgressWindowWidgets {
    00929     GPWW_CAPTION,
    00930     GPWW_BACKGROUND,
    00931     GPWW_ABORT,
    00932   };
    00933
    00934 public:
    00935   GenerateProgressWindow() : Window(&_generate_progress_desc)
    00936   {
    00937     this->FindWindowPlacementAndResize(&_generate_progress_desc);
    00938   }
    00939
    00940   virtual void OnClick(Point pt, int widget)
    00941   {
    00942     switch (widget) {
    00943       case GPWW_ABORT:
    00944         if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
    00945         ShowQuery(
    00946           STR_GENERATION_ABORT_CAPTION,
    00947           STR_GENERATION_ABORT_MESSAGE,
    00948           this,
    00949           AbortGeneratingWorldCallback
    00950         );
    00951         break;
    00952     }
    00953   }
    00954
    00955   virtual void OnPaint()
    00956   {
    00957     this->DrawWidgets();
    00958
    00959     /* Draw the % complete with a bar and a text */
    00960     DrawFrameRect(19, 20, (this->width - 18), 37, COLOUR_GREY, FR_BORDERONLY);
    00961     DrawFrameRect(20, 21, (int)((this->width - 40) * _tp.percent / 100) + 20, 36, COLOUR_MAUVE, FR_NONE);
    00962     SetDParam(0, _tp.percent);
    00963     DrawStringCentered(90, 25, STR_PROGRESS, TC_FROMSTRING);
    00964
    00965     /* Tell which class we are generating */
    00966     DrawStringCentered(90, 46, _tp.cls, TC_FROMSTRING);
    00967
    00968     /* And say where we are in that class */
    00969     SetDParam(0, _tp.current);
    00970     SetDParam(1, _tp.total);
    00971     DrawStringCentered(90, 58, STR_GENERATION_PROGRESS, TC_FROMSTRING);
    00972
    00973     this->SetDirty();
    00974   }
    00975 };
    00976
    00980 void PrepareGenerateWorldProgress()
    00981 {
    00982   _tp.cls   = STR_WORLD_GENERATION;
    00983   _tp.current = 0;
    00984   _tp.total   = 0;
    00985   _tp.percent = 0;
    00986   _tp.timer   = 0; // Forces to paint the progress window immediatelly
    00987 }
    00988
    00992 void ShowGenerateWorldProgress()
    00993 {
    00994   if (BringWindowToFrontById(WC_GENERATE_PROGRESS_WINDOW, 0)) return;
    00995   new GenerateProgressWindow();
    00996 }
    00997
    00998 static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total)
    00999 {
    01000   static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 };
    01001   static const StringID class_table[GWP_CLASS_COUNT]  = {
    01002     STR_WORLD_GENERATION,
    01003     STR_022E_LANDSCAPE_GENERATION,
    01004     STR_CLEARING_TILES,
    01005     STR_022F_TOWN_GENERATION,
    01006     STR_0230_INDUSTRY_GENERATION,
    01007     STR_UNMOVABLE_GENERATION,
    01008     STR_TREE_GENERATION,
    01009     STR_SETTINGUP_GAME,
    01010     STR_PREPARING_TILELOOP,
    01011     STR_PREPARING_GAME
    01012   };
    01013
    01014   assert(cls < GWP_CLASS_COUNT);
    01015
    01016   /* Do not run this function if we aren't in a thread */
    01017   if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
    01018
    01019   if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
    01020
    01021   if (total == 0) {
    01022     assert(_tp.cls == class_table[cls]);
    01023     _tp.current += progress;
    01024   } else {
    01025     _tp.cls   = class_table[cls];
    01026     _tp.current = progress;
    01027     _tp.total   = total;
    01028     _tp.percent = percent_table[cls];
    01029   }
    01030
    01031   /* Don't update the screen too often. So update it once in every 200ms */
    01032   if (!_network_dedicated && _tp.timer != 0 && _realtime_tick - _tp.timer < 200) return;
    01033
    01034   /* Percentage is about the number of completed tasks, so 'current - 1' */
    01035   _tp.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total;
    01036
    01037   if (_network_dedicated) {
    01038     static uint last_percent = 0;
    01039
    01040     /* Never display 0% */
    01041     if (_tp.percent == 0) return;
    01042     /* Reset if percent is lower than the last recorded */
    01043     if (_tp.percent < last_percent) last_percent = 0;
    01044     /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
    01045     if (_tp.percent % 5 != 0 && _tp.percent <= last_percent + 5) return;
    01046     /* Never show steps smaller than 2%, even if it is a mod 5% */
    01047     if (_tp.percent <= last_percent + 2) return;
    01048
    01049     DEBUG(net, 1, "Map generation percentage complete: %d", _tp.percent);
    01050     last_percent = _tp.percent;
    01051
    01052     /* Don't continue as dedicated never has a thread running */
    01053     return;
    01054   }
    01055
    01056   InvalidateWindow(WC_GENERATE_PROGRESS_WINDOW, 0);
    01057   MarkWholeScreenDirty();
    01058   SetGeneratingWorldPaintStatus(true);
    01059
    01060   /* We wait here till the paint is done, so we don't read and write
    01061    *  on the same tile at the same moment. Nasty hack, but that happens
    01062    *  if you implement threading afterwards */
    01063   while (IsGeneratingWorldReadyForPaint()) { CSleep(10); }
    01064
    01065   _tp.timer = _realtime_tick;
    01066 }
    01067
    01076 void SetGeneratingWorldProgress(gwp_class cls, uint total)
    01077 {
    01078   if (total == 0) return;
    01079
    01080   _SetGeneratingWorldProgress(cls, 0, total);
    01081 }
    01082
    01090 void IncreaseGeneratingWorldProgress(gwp_class cls)
    01091 {
    01092   /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
    01093   _SetGeneratingWorldProgress(cls, 1, 0);
    01094 }