From 481b8e23c08b4d559f71889269b17880b0a939b6 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 9 Apr 2014 17:06:47 +0100 Subject: [PATCH] add editor loading --- src/addresses.h | 2 + src/editor.c | 117 ++++++++++++++++++++++++++++++++++++++++-- src/game.c | 13 ++++- src/map.c | 34 +++++++++++- src/map.h | 5 +- src/park.c | 9 ++++ src/park.h | 2 + src/rct2.c | 5 ++ src/rct2.h | 1 + src/window.c | 15 ++++++ src/window.h | 2 + src/window_dropdown.c | 2 +- 12 files changed, 199 insertions(+), 8 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 1aa5613b20..fe411534fb 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -113,6 +113,8 @@ #define RCT2_ADDRESS_NEWS_ITEM_LIST 0x013CA754 +#define RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS 0x013CE9A4 + #define RCT2_ADDRESS_SCENARIO_NAME 0x0141F5B8 #define RCT2_ADDRESS_SCENARIO_DETAILS 0x0141F5F8 diff --git a/src/editor.c b/src/editor.c index b0855f3560..7d0c59e9d0 100644 --- a/src/editor.c +++ b/src/editor.c @@ -19,7 +19,17 @@ *****************************************************************************/ #include "addresses.h" +#include "date.h" #include "editor.h" +#include "gfx.h" +#include "map.h" +#include "news_item.h" +#include "park.h" +#include "ride.h" +#include "window.h" +#include "viewport.h" + +static void set_all_land_owned(); /** * @@ -27,7 +37,39 @@ */ void editor_load() { - RCT2_CALLPROC_EBPSAFE(0x0066FFE1); + rct_window *mainWindow; + + RCT2_CALLPROC_EBPSAFE(0x006BABB4); + RCT2_CALLPROC_EBPSAFE(0x006BABD8); + RCT2_CALLPROC_EBPSAFE(0x006A9CE8); + map_init(); + RCT2_CALLPROC_EBPSAFE(0x006B9CB0); + RCT2_CALLPROC_EBPSAFE(0x00667104); + RCT2_CALLPROC_EBPSAFE(0x006C4209); + RCT2_CALLPROC_EBPSAFE(0x0069EB13); + ride_init_all(); + RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a + RCT2_CALLPROC_EBPSAFE(0x006BD3A4); + park_init(); + RCT2_CALLPROC_EBPSAFE(0x0069DEFB); + date_reset(); + RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b + RCT2_CALLPROC_EBPSAFE(0x006BD39C); + RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_SCENARIO_EDITOR; + RCT2_GLOBAL(0x0141F570, uint8) = 0; + RCT2_GLOBAL(0x013573E4, uint32) |= 16; + RCT2_CALLPROC_EBPSAFE(0x006ACA58); + RCT2_GLOBAL(0x0141F571, uint8) = 4; + viewport_init_all(); + news_item_init_queue(); + RCT2_CALLPROC_EBPSAFE(0x0066EF38); // window_main_editor_create + mainWindow = window_get_main(); + RCT2_CALLPROC_X(0x006E7C9C, 0x960, 0, 0x960, 0x70, mainWindow, 0, 0); + mainWindow->flags &= ~0x08; + RCT2_CALLPROC_EBPSAFE(0x006837E3); + gfx_invalidate_screen(); + RCT2_GLOBAL(0x009DEA66, sint16) = 0; + rct2_endupdate(); } /** @@ -45,7 +87,36 @@ void editor_convert_save_to_scenario() */ void trackdesigner_load() { - RCT2_CALLPROC_EBPSAFE(0x00672957); + rct_window *mainWindow; + + RCT2_CALLPROC_EBPSAFE(0x006A9CE8); + map_init(); + set_all_land_owned(); + RCT2_CALLPROC_EBPSAFE(0x006B9CB0); + RCT2_CALLPROC_EBPSAFE(0x00667104); + RCT2_CALLPROC_EBPSAFE(0x006C4209); + RCT2_CALLPROC_EBPSAFE(0x0069EB13); + ride_init_all(); + RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a + RCT2_CALLPROC_EBPSAFE(0x006BD3A4); + park_init(); + RCT2_CALLPROC_EBPSAFE(0x0069DEFB); + date_reset(); + RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b + RCT2_CALLPROC_EBPSAFE(0x006BD39C); + RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_TRACK_DESIGNER; + RCT2_GLOBAL(0x0141F570, uint8) = 0; + RCT2_CALLPROC_EBPSAFE(0x006ACA58); + viewport_init_all(); + news_item_init_queue(); + RCT2_CALLPROC_EBPSAFE(0x0066EF38); // window_main_editor_create + mainWindow = window_get_main(); + RCT2_CALLPROC_X(0x006E7C9C, 0x960, 0, 0x960, 0x70, mainWindow, 0, 0); + mainWindow->flags &= ~0x08; + RCT2_CALLPROC_EBPSAFE(0x006837E3); + gfx_invalidate_screen(); + RCT2_GLOBAL(0x009DEA66, sint16) = 0; + rct2_endupdate(); } /** @@ -54,5 +125,45 @@ void trackdesigner_load() */ void trackmanager_load() { - RCT2_CALLPROC_EBPSAFE(0x006729FD); + rct_window *mainWindow; + + RCT2_CALLPROC_EBPSAFE(0x006A9CE8); + map_init(); + set_all_land_owned(); + RCT2_CALLPROC_EBPSAFE(0x006B9CB0); + RCT2_CALLPROC_EBPSAFE(0x00667104); + RCT2_CALLPROC_EBPSAFE(0x006C4209); + RCT2_CALLPROC_EBPSAFE(0x0069EB13); + ride_init_all(); + RCT2_CALLPROC_EBPSAFE(0x0068F083); // window_guest_list_init_vars_a + RCT2_CALLPROC_EBPSAFE(0x006BD3A4); + park_init(); + RCT2_CALLPROC_EBPSAFE(0x0069DEFB); + date_reset(); + RCT2_CALLPROC_EBPSAFE(0x0068F050); // window_guest_list_init_vars_b + RCT2_CALLPROC_EBPSAFE(0x006BD39C); + RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_TRACK_MANAGER; + RCT2_GLOBAL(0x0141F570, uint8) = 0; + RCT2_CALLPROC_EBPSAFE(0x006ACA58); + viewport_init_all(); + news_item_init_queue(); + RCT2_CALLPROC_EBPSAFE(0x0066EF38); // window_main_editor_create + mainWindow = window_get_main(); + RCT2_CALLPROC_X(0x006E7C9C, 0x960, 0, 0x960, 0x70, mainWindow, 0, 0); + mainWindow->flags &= ~0x08; + RCT2_CALLPROC_EBPSAFE(0x006837E3); + gfx_invalidate_screen(); + RCT2_GLOBAL(0x009DEA66, sint16) = 0; + rct2_endupdate(); +} + +/** + * + * rct2: 0x0068ABEC + */ +static void set_all_land_owned() +{ + int mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16); + + RCT2_CALLPROC_X(0x006677F2, 64, 1, 64, 2, 56, (mapSize - 2) * 32, (mapSize - 2) * 32); } \ No newline at end of file diff --git a/src/game.c b/src/game.c index 4e9f8e78b7..29e0f372a6 100644 --- a/src/game.c +++ b/src/game.c @@ -97,7 +97,7 @@ void game_update() } } } - +#include "map.h" void game_logic_update() { short _bx, _dx; @@ -108,6 +108,17 @@ void game_logic_update() if (RCT2_GLOBAL(0x009DEA66, sint16) == 0) RCT2_GLOBAL(0x009DEA66, sint16)--; + { + int i; + rct_map_element *mapElement = RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element); + for (i = 0; i < MAX_MAP_ELEMENTS; i++) { + if (mapElement->var_0 == 0) { + // mapElement->var_0 = 2; + } + mapElement++; + } + } + RCT2_CALLPROC_EBPSAFE(0x0068B089); RCT2_CALLPROC_EBPSAFE(0x006C44B1); // update_objective RCT2_CALLPROC_EBPSAFE(0x006C46B1); // update_climate diff --git a/src/map.c b/src/map.c index 276a770162..ba4809d1de 100644 --- a/src/map.c +++ b/src/map.c @@ -24,6 +24,9 @@ #include "map.h" #define GET_MAP_ELEMENT(x) (&(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element)[x])) +#define TILE_MAP_ELEMENT_POINTER(x) (RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*)[x]) + +static void tiles_init(); /** * @@ -38,7 +41,7 @@ void map_init() RCT2_GLOBAL(0x0138B580, sint16) = 0; RCT2_GLOBAL(0x010E63B8, sint32) = 0; - for (i = 0; i < MAX_MAP_ELEMENTS; i++) { + for (i = 0; i < MAX_TILE_MAP_ELEMENT_POINTERS; i++) { map_element = GET_MAP_ELEMENT(i); map_element->var_0 = 0; map_element->var_1 = 128; @@ -58,8 +61,35 @@ void map_init() RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16) = 150; RCT2_GLOBAL(0x01358836, sint16) = 4767; RCT2_GLOBAL(0x01359208, sint16) = 7; - RCT2_CALLPROC_EBPSAFE(0x0068AFFD); + tiles_init(); RCT2_CALLPROC_EBPSAFE(0x0068ADBC); climate_reset(CLIMATE_WARM); +} + +/** + * + * rct2: 0x0068AFFD + */ +static void tiles_init() +{ + int i, x, y, lastTile; + + for (i = 0; i < MAX_TILE_MAP_ELEMENT_POINTERS; i++) + TILE_MAP_ELEMENT_POINTER(i) = TILE_UNDEFINED_MAP_ELEMENT; + + rct_map_element *mapElement = RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element); + rct_map_element **tile = RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*); + for (y = 0; y < 256; y++) { + for (x = 0; x < 256; x++) { + *tile++ = mapElement; + do { + lastTile = (mapElement->var_1 & 128); + mapElement++; + } while (!lastTile); + } + } + + // Possible next free map element + RCT2_GLOBAL(0x0140E9A4, rct_map_element*) = mapElement; } \ No newline at end of file diff --git a/src/map.h b/src/map.h index 1ff28b1147..3fc25bd670 100644 --- a/src/map.h +++ b/src/map.h @@ -50,7 +50,10 @@ enum { }; #define MAP_ELEMENT_TYPE_MASK 0x3C -#define MAX_MAP_ELEMENTS 65536 +#define MAX_MAP_ELEMENTS 196608 +#define MAX_TILE_MAP_ELEMENT_POINTERS (256 * 256) + +#define TILE_UNDEFINED_MAP_ELEMENT -1 void map_init(); diff --git a/src/park.c b/src/park.c index e4adc1627c..186036fc38 100644 --- a/src/park.c +++ b/src/park.c @@ -24,6 +24,15 @@ #include "ride.h" #include "sprite.h" +/** + * + * rct2: 0x00667132 + */ +void park_init() +{ + RCT2_CALLPROC_EBPSAFE(0x00667132); +} + /** * * rct2: 0x00669EAA diff --git a/src/park.h b/src/park.h index 9510f687ce..85b2a64fd6 100644 --- a/src/park.h +++ b/src/park.h @@ -26,6 +26,8 @@ #define DECRYPT_MONEY(money) rol32((money) ^ 0xF4EC9621, 13) #define ENCRYPT_MONEY(money) (ror32((money), 13) ^ 0xF4EC9621) +void park_init(); + int calculate_park_rating(); int calculate_park_value(); int calculate_company_value(); diff --git a/src/rct2.c b/src/rct2.c index c5fe265296..5edd450a0a 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -215,6 +215,11 @@ void rct2_update_2() game_update(); } +void rct2_endupdate() +{ + longjmp(_end_update_jump, 0); +} + /** * * rct2: 0x00674E6C diff --git a/src/rct2.h b/src/rct2.h index 0ffc2af9fc..4a2c86aa4a 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -114,6 +114,7 @@ enum { }; +void rct2_endupdate(); char *get_file_path(int pathId); void get_system_time(); void *rct2_malloc(size_t numBytes); diff --git a/src/window.c b/src/window.c index 2496c1c2e2..95d9169ca2 100644 --- a/src/window.c +++ b/src/window.c @@ -424,6 +424,21 @@ rct_window *window_bring_to_front(rct_window *w) return w; } +/** + * + * rct2: 0x006EE2E4 + */ +rct_window *window_get_main() +{ + rct_window* w; + + for (w = RCT2_FIRST_WINDOW; w < RCT2_NEW_WINDOW; w++) + if (w->classification == WC_MAIN_WINDOW) + return w; + + return NULL; +} + /** * Draws a window that is in the specified region. * rct2: 0x006E756C diff --git a/src/window.h b/src/window.h index 1bcf7eb1a0..704c4fc04b 100644 --- a/src/window.h +++ b/src/window.h @@ -281,6 +281,8 @@ int window_get_scroll_data_index(rct_window *w, int widget_index); rct_window *window_bring_to_front_by_id(rct_windowclass cls, rct_windownumber number); rct_window *window_bring_to_front(rct_window *w); +rct_window *window_get_main(); + void window_draw(rct_window *w, int left, int top, int right, int bottom); void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi); diff --git a/src/window_dropdown.c b/src/window_dropdown.c index 6a7deec8a7..45d0abc229 100644 --- a/src/window_dropdown.c +++ b/src/window_dropdown.c @@ -146,7 +146,7 @@ void window_dropdown_show_text(int x, int y, int extray, uint8 colour, uint8 fla _dropdown_highlighted_index = -1; RCT2_GLOBAL(0x009DED34, sint32) = 0; RCT2_GLOBAL(0x009DED38, sint32) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) = 5; + RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) = INPUT_STATE_DROPDOWN_ACTIVE; // Copy the following properties until all use of it is decompiled RCT2_GLOBAL(0x009DEBA0, sint16) = _dropdown_num_items;