# genworld_gui.cpp

Go to the documentation of this file.

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