From d18ea8570dd764f261dd323d58a09245e8bae548 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 24 Apr 2016 14:30:21 +0100 Subject: [PATCH] add global macro: gNextFreeMapElement --- src/addresses.h | 3 ++- src/rct1/S4Importer.cpp | 8 ++++---- src/ride/track.c | 10 ++++++---- src/world/map.c | 22 ++++++++++++---------- src/world/map.h | 3 +++ 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index f6b8c00e1c..30d5721139 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -433,7 +433,6 @@ #define RCT2_ADDRESS_CURRENT_FONT_FLAGS 0x013CE9A2 #define RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS 0x013CE9A4 -#define RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT 0x0140E9A4 #define RCT2_ADDRESS_CURRENT_ROTATION 0x0141E9E0 @@ -611,6 +610,8 @@ #define RCT2_ADDRESS_CONSTRUCT_PATH_VALID_DIRECTIONS 0x00F3EF9E #define RCT2_ADDRESS_TRACK_PREVIEW_ROTATION 0x00F440AE +#define RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT 0x0140E9A4 + #define RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT 0x0141E9AC #define RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE 0x0141E9AE diff --git a/src/rct1/S4Importer.cpp b/src/rct1/S4Importer.cpp index 701a189251..feb8768dd4 100644 --- a/src/rct1/S4Importer.cpp +++ b/src/rct1/S4Importer.cpp @@ -1095,7 +1095,7 @@ void S4Importer::ClearExtraTileEntries() *tilePointer++ = nextFreeMapElement++; } - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*) = nextFreeMapElement; + gNextFreeMapElement = nextFreeMapElement; } void S4Importer::FixColours() @@ -1128,7 +1128,7 @@ void S4Importer::FixColours() // } rct_map_element * mapElement = gMapElements; - while (mapElement < RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*)) + while (mapElement < gNextFreeMapElement) { if (mapElement->base_height != 255) { @@ -1188,7 +1188,7 @@ void S4Importer::FixZ() // } rct_map_element * mapElement = gMapElements; - while (mapElement < RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*)) + while (mapElement < gNextFreeMapElement) { if (mapElement->base_height != 255) { @@ -1203,7 +1203,7 @@ void S4Importer::FixZ() void S4Importer::FixPaths() { rct_map_element * mapElement = gMapElements; - while (mapElement < RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*)) + while (mapElement < gNextFreeMapElement) { switch (map_element_get_type(mapElement)) { case MAP_ELEMENT_TYPE_PATH: diff --git a/src/ride/track.c b/src/ride/track.c index c1a4d0adb2..c4b3a91305 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -694,7 +694,8 @@ void reset_track_list_cache(){ * * rct2: 0x006D1C68 */ -int backup_map(){ +int backup_map() +{ RCT2_GLOBAL(0xF440ED, uint8*) = malloc(0xED600); if (RCT2_GLOBAL(0xF440ED, uint32) == 0) return 0; @@ -718,7 +719,7 @@ int backup_map(){ memcpy(RCT2_GLOBAL(0xF440F1, uint32*), tile_map_pointers, 0x40000); uint8* backup_info = RCT2_GLOBAL(0xF440F5, uint8*); - *(uint32*)backup_info = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, uint32); + *(uint32*)backup_info = (uint32)gNextFreeMapElement; *(uint16*)(backup_info + 4) = gMapSizeUnits; *(uint16*)(backup_info + 6) = gMapSizeMinus2; *(uint16*)(backup_info + 8) = gMapSize; @@ -730,7 +731,8 @@ int backup_map(){ * * rct2: 0x006D2378 */ -void reload_map_backup(){ +void reload_map_backup() +{ uint32* map_elements = RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, uint32); memcpy(map_elements, RCT2_GLOBAL(0xF440ED, uint32*), 0xED600); @@ -738,7 +740,7 @@ void reload_map_backup(){ memcpy(tile_map_pointers, RCT2_GLOBAL(0xF440F1, uint32*), 0x40000); uint8* backup_info = RCT2_GLOBAL(0xF440F5, uint8*); - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, uint32) = *(uint32*)backup_info; + gNextFreeMapElement = (rct_map_element*)backup_info; gMapSizeUnits = *(uint16*)(backup_info + 4); gMapSizeMinus2 = *(uint16*)(backup_info + 6); gMapSize = *(uint16*)(backup_info + 8); diff --git a/src/world/map.c b/src/world/map.c index 400b1cd418..2721e1c6b2 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -61,6 +61,8 @@ rct_map_element **gMapElementTilePointers = (rct_map_element**)RCT2_ADDRESS_TILE rct_xy16 *gMapSelectionTiles = (rct_xy16*)0x009DE596; rct2_peep_spawn *gPeepSpawns = (rct2_peep_spawn*)RCT2_ADDRESS_PEEP_SPAWNS; +rct_map_element *gNextFreeMapElement; + bool gLandMountainMode; bool gLandPaintMode; bool LandRightsMode; @@ -357,7 +359,7 @@ void map_update_tile_pointers() } } - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*) = mapElement; + gNextFreeMapElement = mapElement; } /** @@ -543,12 +545,12 @@ void sub_68B089() mapElementFirst++; } while (!map_element_is_last_for_tile(mapElement++)); - mapElement = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*); + mapElement = gNextFreeMapElement; do { mapElement--; } while (mapElement->base_height == 255); mapElement++; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*) = mapElement; + gNextFreeMapElement = mapElement; } @@ -3776,8 +3778,8 @@ void map_element_remove(rct_map_element *mapElement) (mapElement - 1)->flags |= MAP_ELEMENT_FLAG_LAST_TILE; mapElement->base_height = 0xFF; - if ((mapElement + 1) == RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*)){ - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*)--; + if ((mapElement + 1) == gNextFreeMapElement){ + gNextFreeMapElement--; } } @@ -3935,18 +3937,18 @@ void map_reorganise_elements() */ int sub_68B044() { - if (RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*) <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) + if (gNextFreeMapElement <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) return 1; for (int i = 1000; i != 0; --i) sub_68B089(); - if (RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*) <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) + if (gNextFreeMapElement <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) return 1; map_reorganise_elements(); - if (RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*) <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) + if (gNextFreeMapElement <= RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS_END, rct_map_element)) return 1; else{ gGameCommandErrorText = 894; @@ -3967,7 +3969,7 @@ rct_map_element *map_element_insert(int x, int y, int z, int flags) return NULL; } - newMapElement = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*); + newMapElement = gNextFreeMapElement; originalMapElement = TILE_MAP_ELEMENT_POINTER(y * 256 + x); // Set tile index pointer to point to new element block @@ -4008,7 +4010,7 @@ rct_map_element *map_element_insert(int x, int y, int z, int flags) } while (!((newMapElement - 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE)); } - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_FREE_MAP_ELEMENT, rct_map_element*) = newMapElement; + gNextFreeMapElement = newMapElement; return insertedElement; } diff --git a/src/world/map.h b/src/world/map.h index 6751f61894..81388267ce 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -280,6 +280,9 @@ extern rct_map_element **gMapElementTilePointers; extern rct_xy16 *gMapSelectionTiles; extern rct2_peep_spawn *gPeepSpawns; + +extern rct_map_element *gNextFreeMapElement; + // Used in the land tool window to enable mountain tool / land smoothing extern bool gLandMountainMode; // Used in the land tool window to allow dragging and changing land styles