# genworld_gui.cpp

Go to the documentation of this file.

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