From 0f6e64ac7697a505c6240ddc6fec259f0df136a0 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 24 Apr 2016 14:00:26 +0100 Subject: [PATCH] add global macros for map size and tile loop --- src/editor.c | 2 +- src/interface/screenshot.c | 4 +- src/interface/viewport.c | 18 +++---- src/network/network.cpp | 2 +- src/peep/peep.c | 2 +- src/ride/track.c | 20 ++++---- src/scenario.h | 4 +- src/windows/map.c | 28 +++++----- src/windows/ride_construction.c | 19 ++++--- src/world/footpath.c | 12 ++--- src/world/map.c | 90 ++++++++++++++++----------------- src/world/map.h | 8 +++ src/world/mapgen.c | 6 +-- src/world/park.c | 6 +-- 14 files changed, 117 insertions(+), 104 deletions(-) diff --git a/src/editor.c b/src/editor.c index a6e01359f6..cf7ecf9072 100644 --- a/src/editor.c +++ b/src/editor.c @@ -229,7 +229,7 @@ void trackmanager_load() */ static void set_all_land_owned() { - int mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16); + int mapSize = gMapSize; game_do_command(64, 1, 64, 2, GAME_COMMAND_SET_LAND_OWNERSHIP, (mapSize - 2) * 32, (mapSize - 2) * 32); } diff --git a/src/interface/screenshot.c b/src/interface/screenshot.c index 1a68cd48b6..ff292df40e 100644 --- a/src/interface/screenshot.c +++ b/src/interface/screenshot.c @@ -173,7 +173,7 @@ void screenshot_giant() int rotation = originalRotation; int zoom = originalZoom; - int mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16); + int mapSize = gMapSize; int resolutionWidth = (mapSize * 32 * 2) >> zoom; int resolutionHeight = (mapSize * 32 * 1) >> zoom; @@ -309,7 +309,7 @@ int cmdline_for_screenshot(const char **argv, int argc) RCT2_GLOBAL(RCT2_ADDRESS_RUN_INTRO_TICK_PART, uint8) = 0; gScreenFlags = SCREEN_FLAGS_PLAYING; - int mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16); + int mapSize = gMapSize; if (resolutionWidth == 0 || resolutionHeight == 0) { resolutionWidth = (mapSize * 32 * 2) >> customZoom; resolutionHeight = (mapSize * 32 * 1) >> customZoom; diff --git a/src/interface/viewport.c b/src/interface/viewport.c index a5f3fdeb2c..d6bc3fc90f 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -245,7 +245,7 @@ void sub_689174(sint16* x, sint16* y, sint16 *z) // HACK: This is to prevent the x and y values being set to values outside // of the map. This can happen when the height is larger than the map size. - sint16 max = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, sint16); + sint16 max = gMapSizeMinus2; if (pos.x > max && pos.y > max) { int x_corr[] = { -1, 1, 1, -1 }; int y_corr[] = { -1, -1, 1, 1 }; @@ -600,12 +600,12 @@ void viewport_update_position(rct_window *window) } //Clamp to the map maximum value (scenario specific) - if (x > RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, sint16)){ - x = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, sint16); + if (x > gMapSizeMinus2){ + x = gMapSizeMinus2; at_map_edge = 1; } - if (y > RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, sint16)){ - y = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, sint16); + if (y > gMapSizeMinus2){ + y = gMapSizeMinus2; at_map_edge = 1; } @@ -2016,8 +2016,8 @@ static void viewport_blank_tiles_paint_setup(int x, int y) void sub_68B2B7(int x, int y) { if ( - x < RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) && - y < RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) && + x < gMapSizeUnits && + y < gMapSizeUnits && x >= 32 && y >= 32 ) { @@ -2049,8 +2049,8 @@ void map_element_paint_setup(int x, int y) { rct_drawpixelinfo *dpi = RCT2_GLOBAL(0x0140E9A8, rct_drawpixelinfo*); if ( - x < RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) && - y < RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) && + x < gMapSizeUnits && + y < gMapSizeUnits && x >= 32 && y >= 32 ) { diff --git a/src/network/network.cpp b/src/network/network.cpp index 77706d6dce..c598898d9a 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1125,7 +1125,7 @@ void Network::AdvertiseHeartbeat() json_object_set_new(body, "players", json_integer(network_get_num_players())); json_t *gameInfo = json_object(); - json_object_set_new(gameInfo, "mapSize", json_integer(RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, sint16))); + json_object_set_new(gameInfo, "mapSize", json_integer(gMapSizeMinus2)); json_object_set_new(gameInfo, "day", json_integer(gDateMonthTicks)); json_object_set_new(gameInfo, "month", json_integer(gDateMonthsElapsed)); json_object_set_new(gameInfo, "guests", json_integer(gNumGuestsInPark)); diff --git a/src/peep/peep.c b/src/peep/peep.c index 3f8d3229f8..439a3fd091 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -8380,7 +8380,7 @@ static int sub_693C9E(rct_peep *peep) return 1; } - if (x < 32 || y < 32 || x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) || y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16)){ + if (x < 32 || y < 32 || x >= gMapSizeUnits || y >= gMapSizeUnits){ if (peep->outside_of_park == 1){ RCT2_GLOBAL(0x00F1EE18, uint16) |= (1 << 1); } diff --git a/src/ride/track.c b/src/ride/track.c index 4423c4ec2a..c1a4d0adb2 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -719,9 +719,9 @@ int backup_map(){ uint8* backup_info = RCT2_GLOBAL(0xF440F5, uint8*); *(uint32*)backup_info = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, uint32); - *(uint16*)(backup_info + 4) = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16); - *(uint16*)(backup_info + 6) = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, uint16); - *(uint16*)(backup_info + 8) = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16); + *(uint16*)(backup_info + 4) = gMapSizeUnits; + *(uint16*)(backup_info + 6) = gMapSizeMinus2; + *(uint16*)(backup_info + 8) = gMapSize; *(uint32*)(backup_info + 10) = get_current_rotation(); return 1; } @@ -739,9 +739,9 @@ void reload_map_backup(){ uint8* backup_info = RCT2_GLOBAL(0xF440F5, uint8*); RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, uint32) = *(uint32*)backup_info; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) = *(uint16*)(backup_info + 4); - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, uint16) = *(uint16*)(backup_info + 6); - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) = *(uint16*)(backup_info + 8); + gMapSizeUnits = *(uint16*)(backup_info + 4); + gMapSizeMinus2 = *(uint16*)(backup_info + 6); + gMapSize = *(uint16*)(backup_info + 8); RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32) = *(uint32*)(backup_info + 10); free(RCT2_GLOBAL(0xF440ED, uint8*)); @@ -757,9 +757,9 @@ void blank_map(){ // These values were previously allocated in backup map but // it seems more fitting to place in this function - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) = 0x1FE0; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, uint16) = 0x20FE; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) = 0x100; + gMapSizeUnits = 0x1FE0; + gMapSizeMinus2 = 0x20FE; + gMapSize = 0x100; rct_map_element* map_element; for (int i = 0; i < MAX_TILE_MAP_ELEMENT_POINTERS; i++) { @@ -2044,7 +2044,7 @@ int sub_6D2189(int* cost, uint8* ride_id){ uint8 backup_rotation = _currentTrackPieceDirection; uint32 backup_park_flags = gParkFlags; gParkFlags &= ~PARK_FLAGS_FORBID_HIGH_CONSTRUCTION; - int map_size = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) << 4; + int map_size = gMapSize << 4; _currentTrackPieceDirection = 0; int z = sub_6D01B3(3, 0, map_size, map_size, 16); diff --git a/src/scenario.h b/src/scenario.h index 4667a3fb3d..efebf862fe 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -374,8 +374,8 @@ typedef struct { rct_news_item news_items[61]; uint8 byte_13CE730[64]; uint32 dword_13CE770; - uint16 word_13CE774; - uint16 word_13CE776; + uint16 wide_path_tile_loop_x; + uint16 wide_path_tile_loop_y; uint8 pad_13CE778[434]; } rct_s6_data; diff --git a/src/windows/map.c b/src/windows/map.c index e6658a2149..3c7e2050b3 100644 --- a/src/windows/map.c +++ b/src/windows/map.c @@ -622,7 +622,7 @@ static void window_map_textinput(rct_window *w, int widgetIndex, char *text) size += 2; size=clamp(MINIMUM_MAP_SIZE_TECHNICAL, size, MAXIMUM_MAP_SIZE_TECHNICAL); - int currentSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16); + int currentSize = gMapSize; while (size < currentSize) { map_window_decrease_map_size(); currentSize--; @@ -931,7 +931,7 @@ static void window_map_show_default_scenario_editor_buttons(rct_window *w) { w->widgets[WIDX_MAP_SIZE_SPINNER].type = WWT_SPINNER; w->widgets[WIDX_MAP_SIZE_SPINNER_UP].type = WWT_DROPDOWN_BUTTON; w->widgets[WIDX_MAP_SIZE_SPINNER_DOWN].type = WWT_DROPDOWN_BUTTON; - RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 2, uint16) = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) - 2; + RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 2, uint16) = gMapSize - 2; } static void window_map_inputsize_land(rct_window *w) @@ -1338,15 +1338,15 @@ static void window_map_set_peep_spawn_tool_down(int x, int y) */ static void map_window_increase_map_size() { - if (RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) >= 256) { + if (gMapSize >= 256) { window_error_open(STR_CANT_INCREASE_MAP_SIZE_ANY_FURTHER, STR_NONE); return; } - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16)++; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) = (RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) - 1) * 32; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, uint16) = (RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) * 32) + 254; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16) = ((RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) - 1) * 32) - 1; + gMapSize++; + gMapSizeUnits = (gMapSize - 1) * 32; + gMapSizeMinus2 = (gMapSize * 32) + 254; + gMapSizeMaxXY = ((gMapSize - 1) * 32) - 1; map_extend_boundary_surface(); window_map_init_map(); window_map_center_on_view_point(); @@ -1359,15 +1359,15 @@ static void map_window_increase_map_size() */ static void map_window_decrease_map_size() { - if (RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) < 16) { + if (gMapSize < 16) { window_error_open(STR_CANT_DECREASE_MAP_SIZE_ANY_FURTHER, STR_NONE); return; } - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16)--; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) = (RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) - 1) * 32; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, uint16) = (RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) * 32) + 254; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16) = ((RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) - 1) * 32) - 1; + gMapSize--; + gMapSizeUnits = (gMapSize - 1) * 32; + gMapSizeMinus2 = (gMapSize * 32) + 254; + gMapSizeMaxXY = ((gMapSize - 1) * 32) - 1; map_remove_out_of_range_elements(); window_map_init_map(); window_map_center_on_view_point(); @@ -1638,8 +1638,8 @@ static void map_window_set_pixels(rct_window *w) if ( x > 0 && y > 0 && - x < RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) && - y < RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) + x < gMapSizeUnits && + y < gMapSizeUnits ) { switch (w->selected_tab) { case PAGE_PEEPS: diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index a9e6ae96d0..e9f2b260e2 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -2276,7 +2276,6 @@ static void sub_6CBCE2( const rct_preview_track *trackBlock; int preserve_current_viewport_flags; int x, y, baseZ, clearanceZ, offsetX, offsetY; - uint64 preserve_map_size_vars; preserve_current_viewport_flags = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16); RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) = 0; @@ -2287,12 +2286,15 @@ static void sub_6CBCE2( ride = get_ride(rideIndex); - preserve_map_size_vars = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint64); + sint16 preserveMapSizeUnits = gMapSizeUnits; + sint16 preserveMapSizeMinus2 = gMapSizeMinus2; + sint16 preserveMapSize = gMapSize; + sint16 preserveMapSizeMaxXY = gMapSizeMaxXY; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) = 255 * 32; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, uint16) = (255 * 32) + 286; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) = 256; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16) = (256 * 32) - 1; + gMapSizeUnits = 255 * 32; + gMapSizeMinus2 = (255 * 32) + 286; + gMapSize = 256; + gMapSizeMaxXY = (256 * 32) - 1; trackBlock = get_track_def_from_ride(ride, trackType); while (trackBlock->index != 255) { @@ -2377,7 +2379,10 @@ static void sub_6CBCE2( trackBlock++; } - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint64) = preserve_map_size_vars; + gMapSizeUnits = preserveMapSizeUnits; + gMapSizeMinus2 = preserveMapSizeMinus2; + gMapSize = preserveMapSize; + gMapSizeMaxXY = preserveMapSizeMaxXY; sub_688217(); sub_688485(); diff --git a/src/world/footpath.c b/src/world/footpath.c index ef41e02a2b..44536455e6 100644 --- a/src/world/footpath.c +++ b/src/world/footpath.c @@ -80,9 +80,9 @@ static void automatically_set_peep_spawn(int x, int y, int z) int direction = 0; if (x != 32) { direction++; - if (y != RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) - 32) { + if (y != gMapSizeUnits - 32) { direction++; - if (x != RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) - 32) { + if (x != gMapSizeUnits - 32) { direction++; if (y != 32) return; @@ -329,7 +329,7 @@ static money32 footpath_place_real(int type, int x, int y, int z, int slope, int RCT2_GLOBAL(0x00F3EFD9, money32) = 0; RCT2_GLOBAL(0x00F3EFA4, uint8) = 0; - if (x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) || y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16)) { + if (x >= gMapSizeUnits || y >= gMapSizeUnits) { gGameCommandErrorText = STR_OFF_EDGE_OF_MAP; return MONEY32_UNDEFINED; } @@ -860,8 +860,8 @@ bool map_is_edge(int x, int y) return ( x < 32 || y < 32 || - x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) || - y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) + x >= gMapSizeUnits || + y >= gMapSizeUnits ); } @@ -1506,7 +1506,7 @@ int footpath_is_connected_to_map_edge_recurse( // Check if we are at edge of map if (x < 32 || y < 32) return FOOTPATH_SEARCH_SUCCESS; - if (x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) || y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16)) + if (x >= gMapSizeUnits || y >= gMapSizeUnits) return FOOTPATH_SEARCH_SUCCESS; mapElement = map_get_first_element_at(x >> 5, y >> 5); diff --git a/src/world/map.c b/src/world/map.c index 2a0a3f9a99..400b1cd418 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -325,12 +325,12 @@ void map_init(int size) } RCT2_GLOBAL(RCT2_ADDRESS_GRASS_SCENERY_TILEPOS, sint16) = 0; - RCT2_GLOBAL(0x013CE774, sint16) = 0; - RCT2_GLOBAL(0x013CE776, sint16) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) = size * 32 - 32; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, sint16) = size * 32 - 2; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16) = size; - RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, sint16) = size * 32 - 33; + gWidePathTileLoopX = 0; + gWidePathTileLoopY = 0; + gMapSizeUnits = size * 32 - 32; + gMapSizeMinus2 = size * 32 - 2; + gMapSize = size; + gMapSizeMaxXY = size * 32 - 33; RCT2_GLOBAL(0x01359208, sint16) = 7; map_update_tile_pointers(); map_remove_out_of_range_elements(); @@ -590,17 +590,16 @@ int map_coord_is_connected(int x, int y, int z, uint8 faceDirection) */ void map_update_path_wide_flags() { - int i, x, y; - - if (gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)) + if (gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)) { return; + } // Presumebly update_path_wide_flags is too computationally expensive to call for every - // tile every update, so word_13CE774 and word_13CE776 store the x and y + // tile every update, so gWidePathTileLoopX and gWidePathTileLoopY store the x and y // progress. A maximum of 128 calls is done per update. - x = RCT2_GLOBAL(0x013CE774, sint16); - y = RCT2_GLOBAL(0x013CE776, sint16); - for (i = 0; i < 128; i++) { + uint16 x = gWidePathTileLoopX; + uint16 y = gWidePathTileLoopY; + for (int i = 0; i < 128; i++) { footpath_update_path_wide_flags(x, y); // Next x, y tile @@ -608,12 +607,13 @@ void map_update_path_wide_flags() if (x >= 8192) { x = 0; y += 32; - if (y >= 8192) + if (y >= 8192) { y = 0; + } } } - RCT2_GLOBAL(0x013CE774, sint16) = x; - RCT2_GLOBAL(0x013CE776, sint16) = y; + gWidePathTileLoopX = x; + gWidePathTileLoopY = y; } /** @@ -1378,8 +1378,8 @@ money32 map_clear_scenery(int x0, int y0, int x1, int y1, int clear, int flags) x0 = max(x0, 32); y0 = max(y0, 32); - x1 = min(x1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); - y1 = min(y1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); + x1 = min(x1, gMapSizeMaxXY); + y1 = min(y1, gMapSizeMaxXY); noValidTiles = true; totalCost = 0; @@ -1438,8 +1438,8 @@ money32 map_change_surface_style(int x0, int y0, int x1, int y1, uint8 surfaceSt x0 = max(x0, 32); y0 = max(y0, 32); - x1 = min(x1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); - y1 = min(y1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); + x1 = min(x1, gMapSizeMaxXY); + y1 = min(y1, gMapSizeMaxXY); int xMid, yMid; @@ -1612,7 +1612,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl } } - if (x > RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16) || y > RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)) { + if (x > gMapSizeMaxXY || y > gMapSizeMaxXY) { gGameCommandErrorText = STR_OFF_EDGE_OF_MAP; return MONEY32_UNDEFINED; } @@ -1808,15 +1808,15 @@ money32 map_set_land_ownership(uint8 flags, sint16 x1, sint16 y1, sint16 x2, sin RCT2_GLOBAL(0x009E2E28, uint8) = 0; // Clamp to maximum addressable element to prevent long loop spamming the log - x1 = clamp(0, x1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)); - y1 = clamp(0, y1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)); - x2 = min(x2, RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)); - y2 = min(y2, RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)); + x1 = clamp(0, x1, gMapSizeUnits); + y1 = clamp(0, y1, gMapSizeUnits); + x2 = min(x2, gMapSizeUnits); + y2 = min(y2, gMapSizeUnits); for (sint16 y = y1; y <= y2; y += 32) { for (sint16 x = x1; x <= x2; x += 32) { - if (x > RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)) + if (x > gMapSizeUnits) continue; - if (y > RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)) + if (y > gMapSizeUnits) continue; map_buy_land_rights(x, y, x2, y2, 6, flags | (newOwnership << 8)); @@ -1827,8 +1827,8 @@ money32 map_set_land_ownership(uint8 flags, sint16 x1, sint16 y1, sint16 x2, sin return 0; } - sint16 x = clamp(0, x1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)); - sint16 y = clamp(0, y1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)); + sint16 x = clamp(0, x1, gMapSizeUnits); + sint16 y = clamp(0, y1, gMapSizeUnits); x += 16; y += 16; @@ -1873,8 +1873,8 @@ money32 raise_land(int flags, int x, int y, int z, int ax, int ay, int bx, int b ax = max(ax, 32); ay = max(ay, 32); - bx = min(bx, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); - by = min(by, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); + bx = min(bx, gMapSizeMaxXY); + by = min(by, gMapSizeMaxXY); // find lowest map element in selection for (int yi = ay; yi <= by; yi += 32) { @@ -1935,8 +1935,8 @@ money32 lower_land(int flags, int x, int y, int z, int ax, int ay, int bx, int b ax = max(ax, 32); ay = max(ay, 32); - bx = min(bx, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); - by = min(by, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); + bx = min(bx, gMapSizeMaxXY); + by = min(by, gMapSizeMaxXY); // find highest map element in selection for (int yi = ay; yi <= by; yi += 32) { @@ -1999,8 +1999,8 @@ money32 raise_water(sint16 x0, sint16 y0, sint16 x1, sint16 y1, uint8 flags) x0 = max(x0, 32); y0 = max(y0, 32); - x1 = min(x1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); - y1 = min(y1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); + x1 = min(x1, gMapSizeMaxXY); + y1 = min(y1, gMapSizeMaxXY); for (int yi = y0; yi <= y1; yi += 32) { for (int xi = x0; xi <= x1; xi += 32) { @@ -2080,8 +2080,8 @@ money32 lower_water(sint16 x0, sint16 y0, sint16 x1, sint16 y1, uint8 flags) x0 = max(x0, 32); y0 = max(y0, 32); - x1 = min(x1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); - y1 = min(y1, RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16)); + x1 = min(x1, gMapSizeMaxXY); + y1 = min(y1, gMapSizeMaxXY); for (int yi = y0; yi <= y1; yi += 32){ for (int xi = x0; xi <= x1; xi += 32){ @@ -2592,7 +2592,7 @@ void game_command_set_water_height(int* eax, int* ebx, int* ecx, int* edx, int* return; } - if(x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) || y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16)){ + if(x >= gMapSizeUnits || y >= gMapSizeUnits){ gGameCommandErrorText = STR_OFF_EDGE_OF_MAP; *ebx = MONEY32_UNDEFINED; return; @@ -2918,7 +2918,7 @@ void game_command_place_scenery(int* eax, int* ebx, int* ecx, int* edx, int* esi RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16) += 16; if(game_is_not_paused() || gCheatsBuildInPauseMode){ if(sub_68B044()){ - if(RCT2_GLOBAL(0x009D8150, uint8) & 1 || (x <= RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16) && y <= RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16))){ + if(RCT2_GLOBAL(0x009D8150, uint8) & 1 || (x <= gMapSizeMaxXY && y <= gMapSizeMaxXY)){ rct_scenery_entry* scenery_entry = (rct_scenery_entry*)object_entry_groups[OBJECT_TYPE_SMALL_SCENERY].chunks[scenery_type]; if(scenery_entry->small_scenery.flags & SMALL_SCENERY_FLAG_FULL_TILE || !(scenery_entry->small_scenery.flags & SMALL_SCENERY_FLAG9)){ if(scenery_entry->small_scenery.flags & (SMALL_SCENERY_FLAG9 | SMALL_SCENERY_FLAG24 | SMALL_SCENERY_FLAG25)){ @@ -3689,7 +3689,7 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in } RCT2_GLOBAL(0x00F64F14, uint8) = b; - if (curTile.x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) || curTile.y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16)) { + if (curTile.x >= gMapSizeUnits || curTile.y >= gMapSizeUnits) { gGameCommandErrorText = STR_OFF_EDGE_OF_MAP; *ebx = MONEY32_UNDEFINED; return; @@ -4082,7 +4082,7 @@ static void map_obstruction_set_error_text(rct_map_element *mapElement) int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, CLEAR_FUNC *clearFunc, uint8 bl, uint8 flags, money32 *price) { RCT2_GLOBAL(RCT2_ADDRESS_ELEMENT_LOCATION_COMPARED_TO_GROUND_AND_WATER, uint8) = 1; - if (x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) || y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) || x < 32 || y < 32) { + if (x >= gMapSizeUnits || y >= gMapSizeUnits || x < 32 || y < 32) { gGameCommandErrorText = STR_OFF_EDGE_OF_MAP; return false; } @@ -4379,7 +4379,7 @@ void map_element_remove_banner_entry(rct_map_element *mapElement) */ void map_remove_out_of_range_elements() { - int mapMaxXY = RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, uint16); + int mapMaxXY = gMapSizeMaxXY; for (int y = 0; y < (256 * 32); y += 32) { for (int x = 0; x < (256 * 32); x += 32) { @@ -4400,7 +4400,7 @@ void map_extend_boundary_surface() rct_map_element *existingMapElement, *newMapElement; int x, y, z, slope; - y = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) - 2; + y = gMapSize - 2; for (x = 0; x < 256; x++) { existingMapElement = map_get_surface_element_at(x, y - 1); newMapElement = map_get_surface_element_at(x, y); @@ -4436,7 +4436,7 @@ void map_extend_boundary_surface() update_park_fences(x << 5, y << 5); } - x = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16) - 2; + x = gMapSize - 2; for (y = 0; y < 256; y++) { existingMapElement = map_get_surface_element_at(x - 1, y); newMapElement = map_get_surface_element_at(x, y); @@ -4919,7 +4919,7 @@ money32 place_park_entrance(int flags, sint16 x, sint16 y, sint16 z, uint8 direc return MONEY32_UNDEFINED; } - if (x <= 32 || y <= 32 || x >= (RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) - 32) || y >= (RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) - 32)) { + if (x <= 32 || y <= 32 || x >= (gMapSizeUnits - 32) || y >= (gMapSizeUnits - 32)) { gGameCommandErrorText = 3215; return MONEY32_UNDEFINED; } diff --git a/src/world/map.h b/src/world/map.h index 32cb69f6a4..6751f61894 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -267,6 +267,14 @@ typedef struct { extern const rct_xy16 TileDirectionDelta[]; +#define gWidePathTileLoopX RCT2_GLOBAL(0x013CE774, uint16) +#define gWidePathTileLoopY RCT2_GLOBAL(0x013CE776, uint16) + +#define gMapSizeUnits RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, sint16) +#define gMapSizeMinus2 RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_MINUS_2, sint16) +#define gMapSize RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16) +#define gMapSizeMaxXY RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAX_XY, sint16) + extern rct_map_element *gMapElements; extern rct_map_element **gMapElementTilePointers; diff --git a/src/world/mapgen.c b/src/world/mapgen.c index 8c80801779..0468526eab 100644 --- a/src/world/mapgen.c +++ b/src/world/mapgen.c @@ -289,7 +289,7 @@ static void mapgen_place_trees() } } - mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16); + mapSize = gMapSize; int availablePositionsCount = 0; struct { int x; int y; } tmp, *pos, *availablePositions; @@ -325,7 +325,7 @@ static void mapgen_place_trees() float treeToLandRatio = (10 + (util_rand() % 30)) / 100.0f; int numTrees = max(4, (int)(availablePositionsCount * treeToLandRatio)); - mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16); + mapSize = gMapSize; for (i = 0; i < numTrees; i++) { pos = &availablePositions[i]; @@ -377,7 +377,7 @@ static void mapgen_set_water_level(int waterLevel) int x, y, mapSize; rct_map_element *mapElement; - mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, sint16); + mapSize = gMapSize; for (y = 1; y < mapSize - 1; y++) { for (x = 1; x < mapSize - 1; x++) { diff --git a/src/world/park.c b/src/world/park.c index 2cc88efdce..8fc740eebb 100644 --- a/src/world/park.c +++ b/src/world/park.c @@ -735,9 +735,9 @@ void update_park_fences(int x, int y) return; // When setting the ownership of map edges - if (x <= 0 || x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16)) + if (x <= 0 || x >= gMapSizeUnits) return; - if (y <= 0 || y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16)) + if (y <= 0 || y >= gMapSizeUnits) return; rct_map_element* sufaceElement = map_get_surface_element_at(x / 32, y / 32); @@ -1020,7 +1020,7 @@ money32 map_buy_land_rights_for_tile(int x, int y, int setting, int flags) { return MONEY32_UNDEFINED; } - if (x >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16) || y >= RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE_UNITS, uint16)) { + if (x >= gMapSizeUnits || y >= gMapSizeUnits) { gGameCommandErrorText = STR_TOO_CLOSE_TO_EDGE_OF_MAP; return MONEY32_UNDEFINED; }