truelight@4300: /* $Id$ */ truelight@4300: truelight@4300: #include "stdafx.h" truelight@4300: #include "openttd.h" truelight@4300: #include "heightmap.h" truelight@4300: #include "functions.h" truelight@4300: #include "table/strings.h" belugas@4366: #include "table/sprites.h" truelight@4300: #include "window.h" truelight@4300: #include "gui.h" truelight@4300: #include "gfx.h" truelight@4300: #include "strings.h" truelight@4300: #include "gfxinit.h" truelight@4300: #include "player.h" truelight@4300: #include "command.h" truelight@4300: #include "sound.h" truelight@4300: #include "variables.h" truelight@4300: #include "string.h" truelight@4300: #include "settings.h" truelight@4300: #include "debug.h" truelight@4300: #include "genworld.h" truelight@4300: #include "network.h" truelight@4300: #include "thread.h" truelight@4300: #include "date.h" peter1138@5228: #include "newgrf_config.h" truelight@4300: truelight@4300: enum { truelight@4300: START_DATE_QUERY, truelight@4300: SNOW_LINE_QUERY, truelight@4300: FLAT_WORLD_HEIGHT_QUERY, truelight@4300: truelight@4300: LEN_RND_SEED = 11, truelight@4300: SEED_EDIT = 15, truelight@4300: }; truelight@4300: truelight@4300: /** truelight@4300: * In what 'mode' the GenerateLandscapeWindowProc is. truelight@4300: */ truelight@4300: typedef enum glwp_modes { truelight@4300: GLWP_GENERATE, truelight@4300: GLWP_HEIGHTMAP, truelight@4300: GLWP_SCENARIO, truelight@4300: GLWP_END truelight@4300: } glwp_modes; truelight@4300: truelight@4300: static char _edit_str_buf[LEN_RND_SEED]; truelight@4300: static uint _heightmap_x = 0; truelight@4300: static uint _heightmap_y = 0; truelight@4300: static StringID _heightmap_str = STR_NULL; truelight@4300: static bool _goto_editor = false; truelight@4300: truelight@4300: extern void SwitchMode(int new_mode); truelight@4300: truelight@4300: static inline void SetNewLandscapeType(byte landscape) truelight@4300: { truelight@4300: _opt_newgame.landscape = landscape; truelight@4300: InvalidateWindowClasses(WC_SELECT_GAME); truelight@4300: InvalidateWindowClasses(WC_GENERATE_LANDSCAPE); truelight@4300: } truelight@4300: truelight@4300: // no longer static to allow calling from outside module truelight@4300: const Widget _generate_landscape_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 13, 11, 337, 0, 13, STR_WORLD_GENERATION_CAPTION, STR_NULL}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 13, 0, 337, 14, 267, 0x0, STR_NULL}, truelight@4300: Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 10, 86, 24, 78, SPR_SELECT_TEMPERATE, STR_030E_SELECT_TEMPERATE_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 90, 166, 24, 78, SPR_SELECT_SUB_ARCTIC, STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 170, 246, 24, 78, SPR_SELECT_SUB_TROPICAL, STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 250, 326, 24, 78, SPR_SELECT_TOYLAND, STR_0311_SELECT_TOYLAND_LANDSCAPE}, truelight@4300: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 149, 90, 101, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 150, 161, 90, 101, STR_0225, STR_NULL}, // Mapsize X Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 180, 215, 90, 101, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 216, 227, 90, 101, STR_0225, STR_NULL}, // Mapsize Y truelight@4300: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 163, 112, 123, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 164, 175, 112, 123, STR_0225, STR_NULL}, // Number of towns Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 163, 130, 141, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 164, 175, 130, 141, STR_0225, STR_NULL}, // Number of industries rubidium@4344: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 15, 114, 207, 152, 163, 0x0, STR_RANDOM_SEED_HELP}, // Edit box for seed glx@4364: { WWT_TEXTBTN, RESIZE_NONE, 12, 216, 326, 152, 163, STR_RANDOM, STR_RANDOM_HELP}, rubidium@4344: rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 6, 243, 326, 228, 257, STR_GENERATE, STR_NULL}, // Generate button rubidium@4344: rubidium@4344: { WWT_IMGBTN, RESIZE_NONE, 12, 216, 227, 112, 123, SPR_ARROW_DOWN, STR_029E_MOVE_THE_STARTING_DATE}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 12, 228, 314, 112, 123, 0x0, STR_NULL}, rubidium@4344: { WWT_IMGBTN, RESIZE_NONE, 12, 315, 326, 112, 123, SPR_ARROW_UP, STR_029F_MOVE_THE_STARTING_DATE}, rubidium@4344: rubidium@4344: { WWT_IMGBTN, RESIZE_NONE, 12, 282, 293, 130, 141, SPR_ARROW_DOWN, STR_SNOW_LINE_DOWN}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 12, 294, 314, 130, 141, 0x0, STR_NULL}, rubidium@4344: { WWT_IMGBTN, RESIZE_NONE, 12, 315, 326, 130, 141, SPR_ARROW_UP, STR_SNOW_LINE_UP}, rubidium@4344: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 219, 192, 203, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 220, 231, 192, 203, STR_0225, STR_NULL}, // Tree placer rubidium@4344: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 219, 174, 185, 0x0, STR_NULL}, belugas@4750: { WWT_TEXTBTN, RESIZE_NONE, 12, 220, 231, 174, 185, STR_0225, STR_NULL}, // Landscape generator Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 219, 210, 221, 0x0, STR_NULL}, belugas@4750: { WWT_TEXTBTN, RESIZE_NONE, 12, 220, 231, 210, 221, STR_0225, STR_NULL}, // Terrain type Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 113, 219, 228, 239, 0x0, STR_NULL}, belugas@4750: { WWT_TEXTBTN, RESIZE_NONE, 12, 220, 231, 228, 239, STR_0225, STR_NULL}, // Water quantity Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 113, 219, 246, 257, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 220, 231, 246, 257, STR_0225, STR_NULL}, // Map smoothness truelight@4300: { WIDGETS_END}, truelight@4300: }; truelight@4300: truelight@4300: const Widget _heightmap_load_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 13, 11, 337, 0, 13, STR_WORLD_GENERATION_CAPTION, STR_NULL}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 13, 0, 337, 14, 235, 0x0, STR_NULL}, truelight@4300: Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 10, 86, 24, 78, SPR_SELECT_TEMPERATE, STR_030E_SELECT_TEMPERATE_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 90, 166, 24, 78, SPR_SELECT_SUB_ARCTIC, STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 170, 246, 24, 78, SPR_SELECT_SUB_TROPICAL, STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 250, 326, 24, 78, SPR_SELECT_TOYLAND, STR_0311_SELECT_TOYLAND_LANDSCAPE}, truelight@4300: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 149, 112, 123, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 150, 161, 112, 123, STR_0225, STR_NULL}, // Mapsize X Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 180, 215, 112, 123, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 216, 227, 112, 123, STR_0225, STR_NULL}, // Mapsize Y truelight@4300: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 163, 134, 145, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 164, 175, 134, 145, STR_0225, STR_NULL}, // Number of towns Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 163, 152, 163, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 164, 175, 152, 163, STR_0225, STR_NULL}, // Number of industries truelight@4300: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 15, 114, 194, 174, 185, 0x0, STR_RANDOM_SEED_HELP}, // Edit box for seed rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 203, 285, 174, 185, STR_RANDOM, STR_RANDOM_HELP}, truelight@4300: rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 6, 243, 326, 196, 225, STR_GENERATE, STR_NULL}, // Generate button rubidium@4344: rubidium@4344: { WWT_IMGBTN, RESIZE_NONE, 12, 216, 227, 134, 145, SPR_ARROW_DOWN, STR_029E_MOVE_THE_STARTING_DATE}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 12, 228, 314, 134, 145, 0x0, STR_NULL}, rubidium@4344: { WWT_IMGBTN, RESIZE_NONE, 12, 315, 326, 134, 145, SPR_ARROW_UP, STR_029F_MOVE_THE_STARTING_DATE}, rubidium@4344: rubidium@4344: { WWT_IMGBTN, RESIZE_NONE, 12, 282, 293, 152, 163, SPR_ARROW_DOWN, STR_SNOW_LINE_DOWN}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 12, 294, 314, 152, 163, 0x0, STR_NULL}, rubidium@4344: { WWT_IMGBTN, RESIZE_NONE, 12, 315, 326, 152, 163, SPR_ARROW_UP, STR_SNOW_LINE_UP}, rubidium@4344: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 219, 196, 207, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 220, 231, 196, 207, STR_0225, STR_NULL}, // Tree placer rubidium@4344: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 114, 219, 214, 225, 0x0, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 12, 220, 231, 214, 225, STR_0225, STR_NULL}, // Heightmap rotation truelight@4300: { WIDGETS_END}, truelight@4300: }; truelight@4300: truelight@4300: static void StartGeneratingLandscape(glwp_modes mode) truelight@4300: { truelight@4300: /* If we want to go to the editor, and aren't yet, we need to delay truelight@4300: * it as long as possible, else it gives nasty side-effects (aborting truelight@4300: * results in ending up in the SE, which you don't want. Therefor we truelight@4300: * use this switch to do it at the very end. truelight@4300: */ truelight@4300: if (_goto_editor) _game_mode = GM_EDITOR; truelight@4300: truelight@4300: DeleteWindowByClass(WC_GENERATE_LANDSCAPE); truelight@4300: DeleteWindowByClass(WC_INDUSTRY_VIEW); truelight@4300: DeleteWindowByClass(WC_TOWN_VIEW); truelight@4300: DeleteWindowByClass(WC_LAND_INFO); truelight@4300: truelight@4300: /* Copy all XXX_newgame to XXX */ truelight@4300: UpdatePatches(); truelight@4300: _opt_ptr = &_opt; tron@5024: *_opt_ptr = _opt_newgame; peter1138@5228: ResetGRFConfig(true); truelight@4300: truelight@4300: SndPlayFx(SND_15_BEEP); truelight@4300: switch (mode) { truelight@4300: case GLWP_GENERATE: _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND : SM_NEWGAME; break; truelight@4300: case GLWP_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break; truelight@4300: case GLWP_SCENARIO: _switch_mode = SM_EDITOR; break; truelight@4300: default: NOT_REACHED(); return; truelight@4300: } truelight@4300: } truelight@4300: truelight@4300: static void HeightmapScaledTooMuchCallback(bool ok_clicked) truelight@4300: { truelight@4300: if (ok_clicked) { truelight@4300: Window *w; truelight@4300: glwp_modes mode = 0; truelight@4300: for (mode = 0; mode < GLWP_END; mode++) { truelight@4300: w = FindWindowById(WC_GENERATE_LANDSCAPE, mode); truelight@4300: if (w != NULL) StartGeneratingLandscape(mode); truelight@4300: } truelight@4300: } truelight@4300: } truelight@4300: truelight@4300: void GenerateLandscapeWndProc(Window *w, WindowEvent *e) truelight@4300: { truelight@4300: static const StringID mapsizes[] = {STR_64, STR_128, STR_256, STR_512, STR_1024, STR_2048, INVALID_STRING_ID}; truelight@4300: static const StringID elevations[] = {STR_682A_VERY_FLAT, STR_682B_FLAT, STR_682C_HILLY, STR_682D_MOUNTAINOUS, INVALID_STRING_ID}; truelight@4300: static const StringID sea_lakes[] = {STR_VERY_LOW, STR_6820_LOW, STR_6821_MEDIUM, STR_6822_HIGH, INVALID_STRING_ID}; truelight@4300: static const StringID smoothness[] = {STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_VERY_ROUGH, INVALID_STRING_ID}; truelight@4300: static const StringID tree_placer[] = {STR_CONFIG_PATCHES_TREE_PLACER_NONE, STR_CONFIG_PATCHES_TREE_PLACER_ORIGINAL, STR_CONFIG_PATCHES_TREE_PLACER_IMPROVED, INVALID_STRING_ID}; truelight@4300: static const StringID rotation[] = {STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID}; truelight@4300: static const StringID landscape[] = {STR_CONFIG_PATCHES_LAND_GENERATOR_ORIGINAL, STR_CONFIG_PATCHES_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID}; truelight@4300: static const StringID num_towns[] = {STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID}; truelight@4300: static const StringID num_inds[] = {STR_26816_NONE, STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID}; truelight@4300: truelight@4300: uint mode = w->window_number; truelight@4300: uint y; truelight@4300: truelight@4300: switch (e->event) { belugas@4719: case WE_CREATE: LowerWindowWidget(w, _opt_newgame.landscape + 3); break; belugas@4719: truelight@4300: case WE_PAINT: truelight@4300: /* You can't select smoothness if not terragenesis */ rubidium@5213: if (mode == GLWP_GENERATE) { rubidium@5213: SetWindowWidgetDisabledState(w, 32, _patches_newgame.land_generator == 0); rubidium@5213: SetWindowWidgetDisabledState(w, 33, _patches_newgame.land_generator == 0); rubidium@5213: } truelight@4300: /* Disable snowline if not hilly */ belugas@4709: SetWindowWidgetDisabledState(w, 22, _opt_newgame.landscape != LT_HILLY); truelight@4300: /* Disable town and industry in SE */ belugas@4709: SetWindowWidgetDisabledState(w, 11, _game_mode == GM_EDITOR); belugas@4709: SetWindowWidgetDisabledState(w, 12, _game_mode == GM_EDITOR); belugas@4709: SetWindowWidgetDisabledState(w, 13, _game_mode == GM_EDITOR); belugas@4709: SetWindowWidgetDisabledState(w, 14, _game_mode == GM_EDITOR); belugas@4709: SetWindowWidgetDisabledState(w, 24, _game_mode == GM_EDITOR); belugas@4709: SetWindowWidgetDisabledState(w, 25, _game_mode == GM_EDITOR); truelight@4300: belugas@4709: SetWindowWidgetDisabledState(w, 18, _patches_newgame.starting_year <= MIN_YEAR); belugas@4709: SetWindowWidgetDisabledState(w, 20, _patches_newgame.starting_year >= MAX_YEAR); belugas@4709: SetWindowWidgetDisabledState(w, 21, _patches_newgame.snow_line_height <= 2 || _opt_newgame.landscape != LT_HILLY); belugas@4709: SetWindowWidgetDisabledState(w, 23, _patches_newgame.snow_line_height >= 13 || _opt_newgame.landscape != LT_HILLY); truelight@4300: belugas@4727: SetWindowWidgetLoweredState(w, 3, _opt_newgame.landscape == LT_NORMAL); belugas@4727: SetWindowWidgetLoweredState(w, 4, _opt_newgame.landscape == LT_HILLY); belugas@4729: SetWindowWidgetLoweredState(w, 5, _opt_newgame.landscape == LT_DESERT); belugas@4727: SetWindowWidgetLoweredState(w, 6, _opt_newgame.landscape == LT_CANDY); truelight@4300: DrawWindowWidgets(w); truelight@4300: truelight@4300: y = (mode == GLWP_HEIGHTMAP) ? 22 : 0; truelight@4300: truelight@4300: DrawString( 12, 91 + y, STR_MAPSIZE, 0); truelight@4300: DrawString(119, 91 + y, mapsizes[_patches_newgame.map_x - 6], 0x10); truelight@4300: DrawString(168, 91 + y, STR_BY, 0); truelight@4300: DrawString(182, 91 + y, mapsizes[_patches_newgame.map_y - 6], 0x10); truelight@4300: truelight@4300: DrawString( 12, 113 + y, STR_NUMBER_OF_TOWNS, 0); truelight@4300: DrawString( 12, 131 + y, STR_NUMBER_OF_INDUSTRIES, 0); truelight@4300: if (_game_mode == GM_EDITOR) { truelight@4300: DrawString(118, 113 + y, STR_6836_OFF, 0x10); truelight@4300: DrawString(118, 131 + y, STR_6836_OFF, 0x10); truelight@4300: } else { truelight@4300: DrawString(118, 113 + y, num_towns[_opt_newgame.diff.number_towns], 0x10); truelight@4300: DrawString(118, 131 + y, num_inds[_opt_newgame.diff.number_industries], 0x10); truelight@4300: } truelight@4300: truelight@4300: DrawString( 12, 153 + y, STR_RANDOM_SEED, 0); truelight@4300: DrawEditBox(w, &WP(w, querystr_d), SEED_EDIT); truelight@4300: truelight@4300: DrawString(182, 113 + y, STR_DATE, 0); truelight@4300: SetDParam(0, ConvertYMDToDate(_patches_newgame.starting_year, 0, 1)); truelight@4300: DrawStringCentered(271, 113 + y, STR_GENERATE_DATE, 0); truelight@4300: truelight@4300: DrawString(182, 131 + y, STR_SNOW_LINE_HEIGHT, 0); truelight@4300: SetDParam(0, _patches_newgame.snow_line_height); truelight@4300: DrawStringCentered(303, 131 + y, STR_SNOW_LINE_HEIGHT_NUM, 0x10); truelight@4300: truelight@4300: if (mode == GLWP_GENERATE) { truelight@4300: DrawString( 12, 175, STR_LAND_GENERATOR, 0); truelight@4300: DrawString(118, 175, landscape[_patches_newgame.land_generator], 0x10); truelight@4300: truelight@4300: DrawString( 12, 193, STR_TREE_PLACER, 0); truelight@4300: DrawString(118, 193, tree_placer[_patches_newgame.tree_placer], 0x10); truelight@4300: truelight@4300: DrawString( 12, 211, STR_TERRAIN_TYPE, 0); truelight@4300: DrawString(118, 211, elevations[_opt_newgame.diff.terrain_type], 0x10); truelight@4300: truelight@4300: DrawString( 12, 229, STR_QUANTITY_OF_SEA_LAKES, 0); truelight@4300: DrawString(118, 229, sea_lakes[_opt_newgame.diff.quantity_sea_lakes], 0x10); truelight@4300: truelight@4300: DrawString( 12, 247, STR_SMOOTHNESS, 0); truelight@4300: DrawString(118, 247, smoothness[_patches_newgame.tgen_smoothness], 0x10); truelight@4300: } else { truelight@4300: char buffer[512]; truelight@4300: truelight@4300: if (_patches_newgame.heightmap_rotation == HM_CLOCKWISE) { truelight@4300: SetDParam(0, _heightmap_y); truelight@4300: SetDParam(1, _heightmap_x); truelight@4300: } else { truelight@4300: SetDParam(0, _heightmap_x); truelight@4300: SetDParam(1, _heightmap_y); truelight@4300: } Darkvater@4912: GetString(buffer, STR_HEIGHTMAP_SIZE, lastof(buffer)); truelight@4300: DrawStringRightAligned(326, 91, STR_HEIGHTMAP_SIZE, 0x10); truelight@4300: truelight@4300: DrawString( 12, 91, STR_HEIGHTMAP_NAME, 0x10); truelight@4300: SetDParam(0, _heightmap_str); Darkvater@4609: DrawStringTruncated(114, 91, STR_ORANGE, 0x10, 326 - 114 - GetStringBoundingBox(buffer).width - 5); truelight@4300: truelight@4300: DrawString( 12, 197, STR_TREE_PLACER, 0); truelight@4300: DrawString(118, 197, tree_placer[_patches_newgame.tree_placer], 0x10); truelight@4300: truelight@4300: DrawString( 12, 215, STR_HEIGHTMAP_ROTATION, 0); truelight@4300: DrawString(118, 215, rotation[_patches_newgame.heightmap_rotation], 0x10); truelight@4300: } truelight@4300: truelight@4300: break; truelight@4300: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { truelight@4300: case 0: DeleteWindow(w); break; truelight@4300: case 3: case 4: case 5: case 6: belugas@4719: RaiseWindowWidget(w, _opt_newgame.landscape + 3); belugas@4634: SetNewLandscapeType(e->we.click.widget - 3); truelight@4300: break; truelight@4300: case 7: case 8: // Mapsize X truelight@4300: ShowDropDownMenu(w, mapsizes, _patches_newgame.map_x - 6, 8, 0, 0); truelight@4300: break; truelight@4300: case 9: case 10: // Mapsize Y truelight@4300: ShowDropDownMenu(w, mapsizes, _patches_newgame.map_y - 6, 10, 0, 0); truelight@4300: break; truelight@4300: case 11: case 12: // Number of towns truelight@4300: ShowDropDownMenu(w, num_towns, _opt_newgame.diff.number_towns, 12, 0, 0); truelight@4300: break; truelight@4300: case 13: case 14: // Number of industries truelight@4300: ShowDropDownMenu(w, num_inds, _opt_newgame.diff.number_industries, 14, 0, 0); truelight@4300: break; truelight@4300: case 16: // Random seed truelight@4300: _patches_newgame.generation_seed = InteractiveRandom(); tron@5042: snprintf(_edit_str_buf, lengthof(_edit_str_buf), "%u", _patches_newgame.generation_seed); Darkvater@4909: UpdateTextBufferSize(&WP(w, querystr_d).text); truelight@4300: SetWindowDirty(w); truelight@4300: break; truelight@4300: case 17: // Generate truelight@4300: if (mode == GLWP_HEIGHTMAP && ( truelight@4300: _heightmap_x * 2 < (1U << _patches_newgame.map_x) || _heightmap_x / 2 > (1U << _patches_newgame.map_x) || truelight@4300: _heightmap_y * 2 < (1U << _patches_newgame.map_y) || _heightmap_y / 2 > (1U << _patches_newgame.map_y))) { truelight@4300: ShowQuery(STR_HEIGHTMAP_SCALE_WARNING_CAPTION, STR_HEIGHTMAP_SCALE_WARNING_MESSAGE, HeightmapScaledTooMuchCallback, WC_GENERATE_LANDSCAPE, mode); truelight@4300: } else { truelight@4300: StartGeneratingLandscape(mode); truelight@4300: } truelight@4300: break; truelight@4300: case 18: case 20: // Year buttons truelight@4300: /* Don't allow too fast scrolling */ truelight@4300: if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { belugas@4634: HandleButtonClick(w, e->we.click.widget); truelight@4300: SetWindowDirty(w); truelight@4300: belugas@4634: _patches_newgame.starting_year = clamp(_patches_newgame.starting_year + e->we.click.widget - 19, MIN_YEAR, MAX_YEAR); truelight@4300: } truelight@4300: _left_button_clicked = false; truelight@4300: break; truelight@4300: case 19: // Year text truelight@4300: WP(w, def_d).data_3 = START_DATE_QUERY; truelight@4300: SetDParam(0, _patches_newgame.starting_year); rubidium@4326: ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_START_DATE_QUERY_CAPT, 8, 100, WC_GENERATE_LANDSCAPE, mode, CS_NUMERAL); truelight@4300: break; truelight@4300: case 21: case 23: // Snow line buttons truelight@4300: /* Don't allow too fast scrolling */ truelight@4300: if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { belugas@4634: HandleButtonClick(w, e->we.click.widget); truelight@4300: SetWindowDirty(w); truelight@4300: belugas@4634: _patches_newgame.snow_line_height = clamp(_patches_newgame.snow_line_height + e->we.click.widget - 22, 2, 13); truelight@4300: } truelight@4300: _left_button_clicked = false; truelight@4300: break; truelight@4300: case 22: // Snow line text truelight@4300: WP(w, def_d).data_3 = SNOW_LINE_QUERY; truelight@4300: SetDParam(0, _patches_newgame.snow_line_height); truelight@4300: ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_SNOW_LINE_QUERY_CAPT, 3, 100, WC_GENERATE_LANDSCAPE, mode, CS_NUMERAL); truelight@4300: break; truelight@4300: case 24: case 25: // Tree placer truelight@4300: ShowDropDownMenu(w, tree_placer, _patches_newgame.tree_placer, 25, 0, 0); truelight@4300: break; belugas@4750: case 26: case 27: // Landscape generator OR Heightmap rotation truelight@4300: if (mode == GLWP_HEIGHTMAP) { truelight@4300: ShowDropDownMenu(w, rotation, _patches_newgame.heightmap_rotation, 27, 0, 0); truelight@4300: } else { truelight@4300: ShowDropDownMenu(w, landscape, _patches_newgame.land_generator, 27, 0, 0); truelight@4300: } truelight@4300: break; belugas@4750: case 28: case 29: // Terrain type belugas@4750: ShowDropDownMenu(w, elevations, _opt_newgame.diff.terrain_type, 29, 0, 0); truelight@4300: break; belugas@4750: case 30: case 31: // Water quantity belugas@4750: ShowDropDownMenu(w, sea_lakes, _opt_newgame.diff.quantity_sea_lakes, 31, 0, 0); truelight@4300: break; belugas@4750: case 32: case 33: // Map smoothness belugas@4750: ShowDropDownMenu(w, smoothness, _patches_newgame.tgen_smoothness, 33, 0, 0); truelight@4300: break; truelight@4300: } truelight@4300: break; truelight@4300: truelight@4300: case WE_MOUSELOOP: truelight@4300: HandleEditBox(w, &WP(w, querystr_d), SEED_EDIT); truelight@4300: break; truelight@4300: truelight@4300: case WE_KEYPRESS: Darkvater@4909: HandleEditBoxKey(w, &WP(w, querystr_d), SEED_EDIT, e); rubidium@4453: /* the seed is unsigned, therefore atoi cannot be used. rubidium@4453: * As 2^32 - 1 (MAX_UVALUE(uint32)) is a 'magic' value rubidium@4453: * (use random seed) it should not be possible to be rubidium@4453: * entered into the input field; the generate seed rubidium@4453: * button can be used instead. */ rubidium@4453: _patches_newgame.generation_seed = minu(strtoul(_edit_str_buf, NULL, 10), MAX_UVALUE(uint32) - 1); truelight@4300: break; truelight@4300: truelight@4300: case WE_DROPDOWN_SELECT: belugas@4634: switch (e->we.dropdown.button) { belugas@4634: case 8: _patches_newgame.map_x = e->we.dropdown.index + 6; break; belugas@4634: case 10: _patches_newgame.map_y = e->we.dropdown.index + 6; break; truelight@4300: case 12: belugas@4634: _opt_newgame.diff.number_towns = e->we.dropdown.index; truelight@4300: if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0); truelight@4300: DoCommandP(0, 2, _opt_newgame.diff.number_towns, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); truelight@4300: break; truelight@4300: case 14: belugas@4634: _opt_newgame.diff.number_industries = e->we.dropdown.index; truelight@4300: if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0); truelight@4300: DoCommandP(0, 3, _opt_newgame.diff.number_industries, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); truelight@4300: break; truelight@4300: case 25: belugas@4634: _patches_newgame.tree_placer = e->we.dropdown.index; truelight@4300: break; truelight@4300: case 27: truelight@4300: if (mode == GLWP_HEIGHTMAP) { belugas@4634: _patches_newgame.heightmap_rotation = e->we.dropdown.index; truelight@4300: } else { belugas@4634: _patches_newgame.land_generator = e->we.dropdown.index; truelight@4300: } truelight@4300: break; belugas@4750: case 29: belugas@4634: _opt_newgame.diff.terrain_type = e->we.dropdown.index; truelight@4300: if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0); truelight@4300: DoCommandP(0, 12, _opt_newgame.diff.terrain_type, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); truelight@4300: break; belugas@4750: case 31: belugas@4634: _opt_newgame.diff.quantity_sea_lakes = e->we.dropdown.index; truelight@4300: if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0); truelight@4300: DoCommandP(0, 13, _opt_newgame.diff.quantity_sea_lakes, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); truelight@4300: break; belugas@4750: case 33: belugas@4634: _patches_newgame.tgen_smoothness = e->we.dropdown.index; truelight@4300: break; truelight@4300: } truelight@4300: SetWindowDirty(w); truelight@4300: break; truelight@4300: truelight@4300: case WE_ON_EDIT_TEXT: { belugas@4634: if (e->we.edittext.str != NULL) { belugas@4634: int32 value = atoi(e->we.edittext.str); truelight@4300: truelight@4300: switch (WP(w, def_d).data_3) { truelight@4300: case START_DATE_QUERY: truelight@4300: InvalidateWidget(w, 19); truelight@4300: _patches_newgame.starting_year = clamp(value, MIN_YEAR, MAX_YEAR); truelight@4300: break; truelight@4300: case SNOW_LINE_QUERY: truelight@4300: InvalidateWidget(w, 22); truelight@4300: _patches_newgame.snow_line_height = clamp(value, 2, 13); truelight@4300: break; truelight@4300: } truelight@4300: truelight@4300: SetWindowDirty(w); truelight@4300: } truelight@4300: break; truelight@4300: } truelight@4300: } truelight@4300: } truelight@4300: truelight@4300: const WindowDesc _generate_landscape_desc = { truelight@4300: WDP_CENTER, WDP_CENTER, 338, 268, truelight@4300: WC_GENERATE_LANDSCAPE, 0, truelight@4300: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@4300: _generate_landscape_widgets, truelight@4300: GenerateLandscapeWndProc, truelight@4300: }; truelight@4300: truelight@4300: const WindowDesc _heightmap_load_desc = { truelight@4300: WDP_CENTER, WDP_CENTER, 338, 236, truelight@4300: WC_GENERATE_LANDSCAPE, 0, truelight@4300: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@4300: _heightmap_load_widgets, truelight@4300: GenerateLandscapeWndProc, truelight@4300: }; truelight@4300: truelight@4300: static void _ShowGenerateLandscape(glwp_modes mode) truelight@4300: { truelight@4300: Window *w; truelight@4300: truelight@4300: /* Don't kill WC_GENERATE_LANDSCAPE:GLWP_SCENARIO, because it resets truelight@4300: * _goto_editor, which we maybe need later on. */ truelight@4300: DeleteWindowById(WC_GENERATE_LANDSCAPE, GLWP_GENERATE); truelight@4300: DeleteWindowById(WC_GENERATE_LANDSCAPE, GLWP_HEIGHTMAP); truelight@4300: truelight@4300: /* Always give a new seed if not editor */ truelight@4300: if (_game_mode != GM_EDITOR) _patches_newgame.generation_seed = InteractiveRandom(); truelight@4300: truelight@4300: if (mode == GLWP_HEIGHTMAP) { truelight@4300: if (_heightmap_str != STR_NULL) DeleteName(_heightmap_str); truelight@4300: truelight@4300: _heightmap_x = 0; truelight@4300: _heightmap_y = 0; truelight@4300: _heightmap_str = AllocateName(_file_to_saveload.title, 0); truelight@4300: /* If the function returns negative, it means there was a problem loading the heightmap */ truelight@4300: if (!GetHeightmapDimensions(_file_to_saveload.name, &_heightmap_x, &_heightmap_y)) truelight@4300: return; truelight@4300: } truelight@4300: truelight@4300: w = AllocateWindowDescFront((mode == GLWP_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode); truelight@4300: truelight@4300: if (w != NULL) { truelight@4300: querystr_d *querystr = &WP(w, querystr_d); truelight@4300: tron@5042: snprintf(_edit_str_buf, lengthof(_edit_str_buf), "%u", _patches_newgame.generation_seed); truelight@4300: Darkvater@4948: InitializeTextBuffer(&querystr->text, _edit_str_buf, lengthof(_edit_str_buf), 120); truelight@4300: querystr->caption = STR_NULL; Darkvater@4909: querystr->afilter = CS_NUMERAL; truelight@4300: truelight@4300: InvalidateWindow(WC_GENERATE_LANDSCAPE, mode); truelight@4300: } truelight@4300: } truelight@4300: truelight@4300: void ShowGenerateLandscape(void) truelight@4300: { truelight@4300: _ShowGenerateLandscape(GLWP_GENERATE); truelight@4300: } truelight@4300: truelight@4300: void ShowHeightmapLoad(void) truelight@4300: { truelight@4300: _ShowGenerateLandscape(GLWP_HEIGHTMAP); truelight@4300: } truelight@4300: truelight@4300: void StartNewGameWithoutGUI(uint seed) truelight@4300: { truelight@4300: /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */ truelight@4300: _patches_newgame.generation_seed = seed; truelight@4300: truelight@4300: StartGeneratingLandscape(GLWP_GENERATE); truelight@4300: } truelight@4300: truelight@4300: truelight@4300: void CreateScenarioWndProc(Window *w, WindowEvent *e) truelight@4300: { truelight@4300: static const StringID mapsizes[] = {STR_64, STR_128, STR_256, STR_512, STR_1024, STR_2048, INVALID_STRING_ID}; truelight@4300: truelight@4300: switch (e->event) { belugas@4719: case WE_CREATE: LowerWindowWidget(w, _opt_newgame.landscape + 3); break; belugas@4719: truelight@4300: case WE_PAINT: belugas@4709: SetWindowWidgetDisabledState(w, 14, _patches_newgame.starting_year <= MIN_YEAR); belugas@4709: SetWindowWidgetDisabledState(w, 16, _patches_newgame.starting_year >= MAX_YEAR); belugas@4709: SetWindowWidgetDisabledState(w, 17, _patches_newgame.se_flat_world_height <= 0); belugas@4709: SetWindowWidgetDisabledState(w, 19, _patches_newgame.se_flat_world_height >= 15); truelight@4300: belugas@4727: SetWindowWidgetLoweredState(w, 3, _opt_newgame.landscape == LT_NORMAL); belugas@4727: SetWindowWidgetLoweredState(w, 4, _opt_newgame.landscape == LT_HILLY); belugas@4727: SetWindowWidgetLoweredState(w, 5, _opt_newgame.landscape == LT_DESERT); belugas@4727: SetWindowWidgetLoweredState(w, 6, _opt_newgame.landscape == LT_CANDY); truelight@4300: DrawWindowWidgets(w); truelight@4300: truelight@4300: DrawString( 12, 96, STR_MAPSIZE, 0); glx@4309: DrawString(167, 96, mapsizes[_patches_newgame.map_x - 6], 0x10); glx@4309: DrawString(216, 96, STR_BY, 0); glx@4309: DrawString(230, 96, mapsizes[_patches_newgame.map_y - 6], 0x10); truelight@4300: truelight@4300: DrawString(162, 118, STR_DATE, 0); truelight@4300: SetDParam(0, ConvertYMDToDate(_patches_newgame.starting_year, 0, 1)); truelight@4300: DrawStringCentered(271, 118, STR_GENERATE_DATE, 0); truelight@4300: truelight@4300: DrawString(162, 136, STR_FLAT_WORLD_HEIGHT, 0); truelight@4300: SetDParam(0, _patches_newgame.se_flat_world_height); truelight@4300: DrawStringCentered(303, 136, STR_FLAT_WORLD_HEIGHT_NUM, 0x10); truelight@4300: truelight@4300: break; truelight@4300: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { truelight@4300: case 0: DeleteWindow(w); break; truelight@4300: case 3: case 4: case 5: case 6: belugas@4719: RaiseWindowWidget(w, _opt_newgame.landscape + 3); belugas@4634: SetNewLandscapeType(e->we.click.widget - 3); truelight@4300: break; truelight@4300: case 7: case 8: // Mapsize X truelight@4300: ShowDropDownMenu(w, mapsizes, _patches_newgame.map_x - 6, 8, 0, 0); truelight@4300: break; truelight@4300: case 9: case 10: // Mapsize Y truelight@4300: ShowDropDownMenu(w, mapsizes, _patches_newgame.map_y - 6, 10, 0, 0); truelight@4300: break; truelight@4300: case 11: // Empty world / flat world truelight@4300: StartGeneratingLandscape(GLWP_SCENARIO); truelight@4300: break; truelight@4300: case 12: // Generate truelight@4300: _goto_editor = true; truelight@4300: ShowGenerateLandscape(); truelight@4300: break; truelight@4300: case 13: // Heightmap truelight@4300: _goto_editor = true; truelight@4300: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); truelight@4300: break; truelight@4300: case 14: case 16: // Year buttons truelight@4300: /* Don't allow too fast scrolling */ truelight@4300: if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { belugas@4634: HandleButtonClick(w, e->we.click.widget); truelight@4300: SetWindowDirty(w); truelight@4300: belugas@4634: _patches_newgame.starting_year = clamp(_patches_newgame.starting_year + e->we.click.widget - 15, MIN_YEAR, MAX_YEAR); truelight@4300: } truelight@4300: _left_button_clicked = false; truelight@4300: break; truelight@4300: case 15: // Year text truelight@4300: WP(w, def_d).data_3 = START_DATE_QUERY; truelight@4300: SetDParam(0, _patches_newgame.starting_year); rubidium@4326: ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_START_DATE_QUERY_CAPT, 8, 100, WC_GENERATE_LANDSCAPE, GLWP_SCENARIO, CS_NUMERAL); truelight@4300: break; truelight@4300: case 17: case 19: // Height level buttons truelight@4300: /* Don't allow too fast scrolling */ truelight@4300: if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { belugas@4634: HandleButtonClick(w, e->we.click.widget); truelight@4300: SetWindowDirty(w); truelight@4300: belugas@4634: _patches_newgame.se_flat_world_height = clamp(_patches_newgame.se_flat_world_height + e->we.click.widget - 18, 0, 15); truelight@4300: } truelight@4300: _left_button_clicked = false; truelight@4300: break; truelight@4300: case 18: // Height level text truelight@4300: WP(w, def_d).data_3 = FLAT_WORLD_HEIGHT_QUERY; truelight@4300: SetDParam(0, _patches_newgame.se_flat_world_height); truelight@4300: ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_FLAT_WORLD_HEIGHT_QUERY_CAPT, 3, 100, WC_GENERATE_LANDSCAPE, GLWP_SCENARIO, CS_NUMERAL); truelight@4300: break; truelight@4300: } truelight@4300: break; truelight@4300: truelight@4300: case WE_DROPDOWN_SELECT: belugas@4634: switch (e->we.dropdown.button) { belugas@4634: case 8: _patches_newgame.map_x = e->we.dropdown.index + 6; break; belugas@4634: case 10: _patches_newgame.map_y = e->we.dropdown.index + 6; break; truelight@4300: } truelight@4300: SetWindowDirty(w); truelight@4300: break; truelight@4300: truelight@4300: case WE_DESTROY: truelight@4300: _goto_editor = false; truelight@4300: break; truelight@4300: truelight@4300: case WE_ON_EDIT_TEXT: { belugas@4634: if (e->we.edittext.str != NULL) { belugas@4634: int32 value = atoi(e->we.edittext.str); truelight@4300: truelight@4300: switch (WP(w, def_d).data_3) { truelight@4300: case START_DATE_QUERY: truelight@4300: InvalidateWidget(w, 15); truelight@4300: _patches_newgame.starting_year = clamp(value, MIN_YEAR, MAX_YEAR); truelight@4300: break; truelight@4300: case FLAT_WORLD_HEIGHT_QUERY: truelight@4300: InvalidateWidget(w, 18); truelight@4300: _patches_newgame.se_flat_world_height = clamp(value, 0, 15); truelight@4300: break; truelight@4300: } truelight@4300: truelight@4300: SetWindowDirty(w); truelight@4300: } truelight@4300: break; truelight@4300: } truelight@4300: } truelight@4300: } truelight@4300: truelight@4300: const Widget _create_scenario_widgets[] = { truelight@4300: { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@4300: { WWT_CAPTION, RESIZE_NONE, 13, 11, 337, 0, 13, STR_SE_CAPTION, STR_NULL}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 13, 0, 337, 14, 179, 0x0, STR_NULL}, truelight@4300: Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 10, 86, 24, 78, SPR_SELECT_TEMPERATE, STR_030E_SELECT_TEMPERATE_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 90, 166, 24, 78, SPR_SELECT_SUB_ARCTIC, STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 170, 246, 24, 78, SPR_SELECT_SUB_TROPICAL, STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE}, Darkvater@4938: { WWT_IMGBTN_2, RESIZE_NONE, 12, 250, 326, 24, 78, SPR_SELECT_TOYLAND, STR_0311_SELECT_TOYLAND_LANDSCAPE}, truelight@4300: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 162, 197, 95, 106, 0x0, STR_NULL}, glx@4309: { WWT_TEXTBTN, RESIZE_NONE, 12, 198, 209, 95, 106, STR_0225, STR_NULL}, // Mapsize X Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 12, 228, 263, 95, 106, 0x0, STR_NULL}, glx@4309: { WWT_TEXTBTN, RESIZE_NONE, 12, 264, 275, 95, 106, STR_0225, STR_NULL}, // Mapsize Y truelight@4300: truelight@4306: { WWT_TEXTBTN, RESIZE_NONE, 6, 12, 145, 117, 128, STR_SE_FLAT_WORLD, STR_SE_FLAT_WORLD_TIP}, // Empty (sea-level) map truelight@4300: { WWT_TEXTBTN, RESIZE_NONE, 6, 12, 145, 135, 146, STR_SE_RANDOM_LAND, STR_022A_GENERATE_RANDOM_LAND}, // Generate truelight@4300: { WWT_TEXTBTN, RESIZE_NONE, 6, 12, 145, 153, 164, STR_LOAD_GAME_HEIGHTMAP, STR_LOAD_SCEN_HEIGHTMAP}, // Heightmap truelight@4300: truelight@4300: { WWT_IMGBTN, RESIZE_NONE, 12, 216, 227, 117, 128, SPR_ARROW_DOWN, STR_029E_MOVE_THE_STARTING_DATE}, truelight@4300: { WWT_PANEL, RESIZE_NONE, 12, 228, 314, 117, 128, 0x0, STR_NULL}, truelight@4300: { WWT_IMGBTN, RESIZE_NONE, 12, 315, 326, 117, 128, SPR_ARROW_UP, STR_029F_MOVE_THE_STARTING_DATE}, truelight@4300: truelight@4300: { WWT_IMGBTN, RESIZE_NONE, 12, 282, 293, 135, 146, SPR_ARROW_DOWN, STR_FLAT_WORLD_HEIGHT_DOWN}, truelight@4300: { WWT_PANEL, RESIZE_NONE, 12, 294, 314, 135, 146, 0x0, STR_NULL}, truelight@4300: { WWT_IMGBTN, RESIZE_NONE, 12, 315, 326, 135, 146, SPR_ARROW_UP, STR_FLAT_WORLD_HEIGHT_UP}, truelight@4300: { WIDGETS_END}, truelight@4300: }; truelight@4300: truelight@4300: const WindowDesc _create_scenario_desc = { truelight@4300: WDP_CENTER, WDP_CENTER, 338, 180, truelight@4300: WC_GENERATE_LANDSCAPE, 0, truelight@4300: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@4300: _create_scenario_widgets, truelight@4300: CreateScenarioWndProc, truelight@4300: }; truelight@4300: truelight@4300: void ShowCreateScenario(void) truelight@4300: { truelight@4300: DeleteWindowByClass(WC_GENERATE_LANDSCAPE); truelight@4300: AllocateWindowDescFront(&_create_scenario_desc, GLWP_SCENARIO); truelight@4300: } truelight@4300: truelight@4300: truelight@4300: static const Widget _show_terrain_progress_widgets[] = { truelight@4300: { WWT_CAPTION, RESIZE_NONE, 14, 0, 180, 0, 13, STR_GENERATION_WORLD, STR_018C_WINDOW_TITLE_DRAG_THIS}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 180, 14, 96, 0x0, STR_NULL}, truelight@4300: { WWT_TEXTBTN, RESIZE_NONE, 15, 20, 161, 74, 85, STR_GENERATION_ABORT, STR_NULL}, // Abort button truelight@4300: { WIDGETS_END}, truelight@4300: }; truelight@4300: truelight@4300: typedef struct tp_info { truelight@4300: uint percent; truelight@4300: StringID class; truelight@4300: uint current; truelight@4300: uint total; truelight@4300: int timer; truelight@4300: } tp_info; truelight@4300: truelight@4300: static tp_info _tp; truelight@4300: truelight@4300: static void AbortGeneratingWorldCallback(bool ok_clicked) truelight@4300: { truelight@4300: if (ok_clicked) AbortGeneratingWorld(); truelight@4300: else if (IsGeneratingWorld() && !IsGeneratingWorldAborted()) SetMouseCursor(SPR_CURSOR_ZZZ); truelight@4300: } truelight@4300: truelight@4300: static void ShowTerrainProgressProc(Window* w, WindowEvent* e) truelight@4300: { truelight@4300: switch (e->event) { truelight@4300: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { truelight@4300: case 2: truelight@4300: if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE); truelight@4300: ShowQuery(STR_GENERATION_ABORT_CAPTION, STR_GENERATION_ABORT_MESSAGE, AbortGeneratingWorldCallback, WC_GENERATE_PROGRESS_WINDOW, 0); truelight@4300: break; truelight@4300: } truelight@4300: break; truelight@4300: truelight@4300: case WE_PAINT: truelight@4300: DrawWindowWidgets(w); truelight@4300: truelight@4300: /* Draw the % complete with a bar and a text */ truelight@4300: DrawFrameRect(19, 20, (w->width - 18), 37, 14, FR_BORDERONLY); truelight@4300: DrawFrameRect(20, 21, (int)((w->width - 40) * _tp.percent / 100) + 20, 36, 10, 0); truelight@4300: SetDParam(0, _tp.percent); truelight@4300: DrawStringCentered(90, 25, STR_PROGRESS, 0); truelight@4300: truelight@4300: /* Tell which class we are generating */ truelight@4300: DrawStringCentered(90, 46, _tp.class, 0); truelight@4300: truelight@4300: /* And say where we are in that class */ truelight@4300: SetDParam(0, _tp.current); truelight@4300: SetDParam(1, _tp.total); truelight@4300: DrawStringCentered(90, 58, STR_GENERATION_PROGRESS, 0); truelight@4300: truelight@4300: SetWindowDirty(w); truelight@4300: break; truelight@4300: } truelight@4300: } truelight@4300: truelight@4300: static const WindowDesc _show_terrain_progress_desc = { truelight@4300: WDP_CENTER, WDP_CENTER, 181, 97, truelight@4300: WC_GENERATE_PROGRESS_WINDOW, 0, truelight@4300: WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@4300: _show_terrain_progress_widgets, truelight@4300: ShowTerrainProgressProc truelight@4300: }; truelight@4300: truelight@4300: /** truelight@4300: * Initializes the progress counters to the starting point. truelight@4300: */ truelight@4300: void PrepareGenerateWorldProgress(void) truelight@4300: { truelight@4300: _tp.class = STR_WORLD_GENERATION; truelight@4300: _tp.current = 0; truelight@4300: _tp.total = 0; truelight@4300: _tp.percent = 0; truelight@4300: _tp.timer = 0; // Forces to paint the progress window immediatelly truelight@4300: } truelight@4300: truelight@4300: /** truelight@4300: * Show the window where a user can follow the process of the map generation. truelight@4300: */ truelight@4300: void ShowGenerateWorldProgress(void) truelight@4300: { truelight@4300: AllocateWindowDescFront(&_show_terrain_progress_desc, 0); truelight@4300: } truelight@4300: truelight@4300: static void _SetGeneratingWorldProgress(gwp_class class, uint progress, uint total) truelight@4300: { truelight@4300: static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 }; truelight@4300: static const StringID class_table[GWP_CLASS_COUNT] = { truelight@4300: STR_WORLD_GENERATION, truelight@4300: STR_022E_LANDSCAPE_GENERATION, truelight@4300: STR_CLEARING_TILES, truelight@4300: STR_022F_TOWN_GENERATION, truelight@4300: STR_0230_INDUSTRY_GENERATION, truelight@4300: STR_UNMOVABLE_GENERATION, truelight@4300: STR_TREE_GENERATION, truelight@4300: STR_SETTINGUP_GAME, truelight@4300: STR_PREPARING_TILELOOP, truelight@4300: STR_PREPARING_GAME truelight@4300: }; truelight@4300: truelight@4300: assert(class < GWP_CLASS_COUNT); truelight@4300: truelight@4300: /* Do not run this function if we aren't in a thread */ truelight@4300: if (!IsGenerateWorldThreaded() && !_network_dedicated) return; truelight@4300: truelight@4300: if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion(); truelight@4300: truelight@4300: if (total == 0) { truelight@4300: assert(_tp.class == class_table[class]); truelight@4300: _tp.current += progress; truelight@4300: } else { truelight@4300: _tp.class = class_table[class]; truelight@4300: _tp.current = progress; truelight@4300: _tp.total = total; truelight@4300: _tp.percent = percent_table[class]; truelight@4300: } truelight@4300: peter1138@5052: /* Don't update the screen too often. So update it once in every 200ms. peter1138@5052: * However, the _tick_counter increases by 8 every 30ms, so compensate peter1138@5052: * for that. */ peter1138@5052: if (!_network_dedicated && _tp.timer != 0 && _timer_counter - _tp.timer < (200 * 8 / 30)) return; truelight@4300: truelight@4300: /* Percentage is about the number of completed tasks, so 'current - 1' */ truelight@4300: _tp.percent = percent_table[class] + (percent_table[class + 1] - percent_table[class]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total; truelight@4300: _tp.timer = _timer_counter; truelight@4300: truelight@4300: if (_network_dedicated) { truelight@4300: static uint last_percent = 0; truelight@4300: truelight@4300: /* Never display 0% */ truelight@4300: if (_tp.percent == 0) return; truelight@4300: /* Reset if percent is lower then the last recorded */ truelight@4300: if (_tp.percent < last_percent) last_percent = 0; truelight@4300: /* Display every 5%, but 6% is also very valid.. just not smaller steps then 5% */ truelight@4300: if (_tp.percent % 5 != 0 && _tp.percent <= last_percent + 5) return; truelight@4300: /* Never show steps smaller then 2%, even if it is a mod 5% */ truelight@4300: if (_tp.percent <= last_percent + 2) return; truelight@4300: Darkvater@5568: DEBUG(net, 1, "Map generation percentage complete: %d", _tp.percent); truelight@4300: last_percent = _tp.percent; truelight@4300: truelight@4300: /* Don't continue as dedicated never has a thread running */ truelight@4300: return; truelight@4300: } truelight@4300: truelight@4300: InvalidateWindow(WC_GENERATE_PROGRESS_WINDOW, 0); truelight@4300: MarkWholeScreenDirty(); truelight@4300: SetGeneratingWorldPaintStatus(true); truelight@4300: truelight@4300: /* We wait here till the paint is done, so we don't read and write truelight@4300: * on the same tile at the same moment. Nasty hack, but that happens truelight@4300: * if you implement threading afterwards */ truelight@4300: while (IsGeneratingWorldReadyForPaint()) { CSleep(10); } truelight@4300: } truelight@4300: truelight@4300: /** truelight@4300: * Set the total of a stage of the world generation. truelight@4300: * @param class the current class we are in. truelight@4300: * @param total Set the total expected items for this class. truelight@4300: * truelight@4300: * Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always. truelight@4300: * Also, progress works if total is zero, total works if progress is zero. truelight@4300: */ truelight@4300: void SetGeneratingWorldProgress(gwp_class class, uint total) truelight@4300: { truelight@4300: if (total == 0) return; truelight@4300: truelight@4300: _SetGeneratingWorldProgress(class, 0, total); truelight@4300: } truelight@4300: truelight@4300: /** truelight@4300: * Increases the current stage of the world generation with one. truelight@4300: * @param class the current class we are in. truelight@4300: * truelight@4300: * Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always. truelight@4300: * Also, progress works if total is zero, total works if progress is zero. truelight@4300: */ truelight@4300: void IncreaseGeneratingWorldProgress(gwp_class class) truelight@4300: { truelight@4300: /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */ truelight@4300: _SetGeneratingWorldProgress(class, 1, 0); truelight@4300: }