From 6c25c853630c8e09b47e91ab8bd15051d6ac78c6 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 24 Apr 2016 10:53:04 +0100 Subject: [PATCH] add variable pointers for park entrance position --- src/editor.c | 12 ++++++------ src/peep/peep.c | 39 ++++++++++++++++++++------------------- src/peep/staff.c | 12 ++++++------ src/rct1/S4Importer.cpp | 10 +++++----- src/scenario.c | 6 +++--- src/windows/park.c | 8 ++++---- src/world/map.c | 10 +++++----- src/world/park.c | 17 +++++++++++------ src/world/park.h | 5 +++++ 9 files changed, 65 insertions(+), 54 deletions(-) diff --git a/src/editor.c b/src/editor.c index 03e1dd041e..a6e01359f6 100644 --- a/src/editor.c +++ b/src/editor.c @@ -628,7 +628,7 @@ bool editor_check_park() } for (int i = 0; i < 4; i++) { - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i] != 0x8000) + if (gParkEntranceX[i] != 0x8000) break; if (i == 3) { @@ -638,13 +638,13 @@ bool editor_check_park() } for (int i = 0; i < 4; i++) { - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i] == 0x8000) + if (gParkEntranceX[i] == 0x8000) continue; - int x = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i]; - int y = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, uint16)[i]; - int z = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, uint16)[i] / 8; - int direction = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_DIRECTION, uint8)[i] ^ 2; + int x = gParkEntranceX[i]; + int y = gParkEntranceY[i]; + int z = gParkEntranceZ[i] / 8; + int direction = gParkEntranceDirection[i] ^ 2; switch (footpath_is_connected_to_map_edge(x, y, z, direction, 0)) { case FOOTPATH_SEARCH_NOT_FOUND: diff --git a/src/peep/peep.c b/src/peep/peep.c index 55fe45e831..3f8d3229f8 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -6969,14 +6969,14 @@ static int peep_interact_with_entrance(rct_peep* peep, sint16 x, sint16 y, rct_m uint8 entranceIndex = 0; while (1){ - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[entranceIndex] == (x & 0xFFE0) && - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[entranceIndex] == (y & 0xFFE0)) + if (gParkEntranceX[entranceIndex] == (x & 0xFFE0) && + gParkEntranceY[entranceIndex] == (y & 0xFFE0)) break; entranceIndex++; } - sint16 z = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, sint16)[entranceIndex] / 8; - entranceDirection = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_DIRECTION, uint8)[entranceIndex]; + sint16 z = gParkEntranceZ[entranceIndex] / 8; + entranceDirection = gParkEntranceDirection[entranceIndex]; sint16 next_x = (x & 0xFFE0) + TileDirectionDelta[entranceDirection].x; sint16 next_y = (y & 0xFFE0) + TileDirectionDelta[entranceDirection].y; @@ -7904,11 +7904,11 @@ static int guest_path_find_entering_park(rct_peep *peep, rct_map_element *map_el uint8 chosenEntrance = 0xFF; uint16 nearestDist = 0xFFFF; for (uint8 entranceNum = 0; entranceNum < 4; ++entranceNum){ - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[entranceNum] == (sint16)0x8000) + if (gParkEntranceX[entranceNum] == (sint16)0x8000) continue; - uint16 dist = abs(RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[entranceNum] - peep->next_x) + - abs(RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[entranceNum] - peep->next_y); + uint16 dist = abs(gParkEntranceX[entranceNum] - peep->next_x) + + abs(gParkEntranceY[entranceNum] - peep->next_y); if (dist >= nearestDist) continue; @@ -7920,9 +7920,9 @@ static int guest_path_find_entering_park(rct_peep *peep, rct_map_element *map_el if (chosenEntrance == 0xFF) return guest_path_find_aimless(peep, edges); - sint16 x = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[chosenEntrance]; - sint16 y = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[chosenEntrance]; - sint16 z = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, sint16)[chosenEntrance]; + sint16 x = gParkEntranceX[chosenEntrance]; + sint16 y = gParkEntranceY[chosenEntrance]; + sint16 z = gParkEntranceZ[chosenEntrance]; RCT2_GLOBAL(RCT2_ADDRESS_PEEP_PATHFINDING_GOAL_X, sint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_PEEP_PATHFINDING_GOAL_Y, sint16) = y; RCT2_GLOBAL(RCT2_ADDRESS_PEEP_PATHFINDING_GOAL_Z, uint8) = z / 8; @@ -7981,19 +7981,20 @@ static int guest_path_find_park_entrance(rct_peep* peep, rct_map_element *map_el // Resolves already-corrupt guests (e.g. loaded from save) if (peep->peep_flags & PEEP_FLAGS_PARK_ENTRANCE_CHOSEN && - (peep->current_ride >= 4 || - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[peep->current_ride] == (sint16)0x8000) - ) peep->peep_flags &= ~(PEEP_FLAGS_PARK_ENTRANCE_CHOSEN); + (peep->current_ride >= 4 || gParkEntranceX[peep->current_ride] == (sint16)0x8000) + ) { + peep->peep_flags &= ~(PEEP_FLAGS_PARK_ENTRANCE_CHOSEN); + } if (!(peep->peep_flags & PEEP_FLAGS_PARK_ENTRANCE_CHOSEN)){ uint8 chosenEntrance = 0xFF; uint16 nearestDist = 0xFFFF; for (entranceNum = 0; entranceNum < 4; ++entranceNum){ - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[entranceNum] == (sint16)0x8000) + if (gParkEntranceX[entranceNum] == (sint16)0x8000) continue; - uint16 dist = abs(RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[entranceNum] - peep->next_x) + - abs(RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[entranceNum] - peep->next_y); + uint16 dist = abs(gParkEntranceX[entranceNum] - peep->next_x) + + abs(gParkEntranceY[entranceNum] - peep->next_y); if (dist >= nearestDist) continue; @@ -8010,9 +8011,9 @@ static int guest_path_find_park_entrance(rct_peep* peep, rct_map_element *map_el } entranceNum = peep->current_ride; - sint16 x = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[entranceNum]; - sint16 y = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[entranceNum]; - sint16 z = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, sint16)[entranceNum]; + sint16 x = gParkEntranceX[entranceNum]; + sint16 y = gParkEntranceY[entranceNum]; + sint16 z = gParkEntranceZ[entranceNum]; RCT2_GLOBAL(RCT2_ADDRESS_PEEP_PATHFINDING_GOAL_X, sint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_PEEP_PATHFINDING_GOAL_Y, sint16) = y; RCT2_GLOBAL(RCT2_ADDRESS_PEEP_PATHFINDING_GOAL_Z, uint8) = z / 8; diff --git a/src/peep/staff.c b/src/peep/staff.c index 670edfab42..fa0f847009 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -205,22 +205,22 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx, count = 0; uint8 i; for (i = 0; i < 4; ++i) { - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[i] != SPRITE_LOCATION_NULL) ++count; + if (gParkEntranceX[i] != SPRITE_LOCATION_NULL) ++count; } if (count > 0) { uint32 rand = scenario_rand_max(count); for (i = 0; i < 4; ++i) { - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[i] != SPRITE_LOCATION_NULL) { + if (gParkEntranceX[i] != SPRITE_LOCATION_NULL) { if (rand == 0) break; --rand; } } - uint8 dir = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_DIRECTION, uint8)[i]; - x = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[i]; - y = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[i]; - z = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, sint16)[i]; + uint8 dir = gParkEntranceDirection[i]; + x = gParkEntranceX[i]; + y = gParkEntranceY[i]; + z = gParkEntranceZ[i]; x += 16 + ((dir & 1) == 0 ? ((dir & 2) ? 32 : -32) : 0); y += 16 + ((dir & 1) == 1 ? ((dir & 2) ? -32 : 32) : 0); } else { diff --git a/src/rct1/S4Importer.cpp b/src/rct1/S4Importer.cpp index 2fdbe6cc3a..98e7439042 100644 --- a/src/rct1/S4Importer.cpp +++ b/src/rct1/S4Importer.cpp @@ -1398,7 +1398,7 @@ void S4Importer::FixEntrancePositions() { for (int i = 0; i < 4; i++) { - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i] = 0x8000; + gParkEntranceX[i] = (sint16)0x8000; } uint8 entranceIndex = 0; @@ -1413,10 +1413,10 @@ void S4Importer::FixEntrancePositions() if (element->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE) continue; if ((element->properties.entrance.index & 0x0F) != 0) continue; - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[entranceIndex] = it.x * 32; - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, uint16)[entranceIndex] = it.y * 32; - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, uint16)[entranceIndex] = element->base_height * 8; - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_DIRECTION, uint8)[entranceIndex] = element->type & 3; + gParkEntranceX[entranceIndex] = it.x * 32; + gParkEntranceY[entranceIndex] = it.y * 32; + gParkEntranceZ[entranceIndex] = element->base_height * 8; + gParkEntranceDirection[entranceIndex] = element->type & 3; entranceIndex++; } } diff --git a/src/scenario.c b/src/scenario.c index 03be9ef10c..c9b6333d0d 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -470,9 +470,9 @@ void scenario_entrance_fee_too_high_check() uint32 game_flags = gParkFlags, packed_xy; if ((game_flags & PARK_FLAGS_PARK_OPEN) && !(game_flags & PARK_FLAGS_NO_MONEY) && park_entrance_fee > max_fee) { - for (int i = 0; RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[i] != SPRITE_LOCATION_NULL; i++) { - x = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[i] + 16; - y = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[i] + 16; + for (int i = 0; gParkEntranceX[i] != SPRITE_LOCATION_NULL; i++) { + x = gParkEntranceX[i] + 16; + y = gParkEntranceY[i] + 16; } packed_xy = (y << 16) | x; diff --git a/src/windows/park.c b/src/windows/park.c index bc588a073c..8e990d8f0d 100644 --- a/src/windows/park.c +++ b/src/windows/park.c @@ -1062,10 +1062,10 @@ static void window_park_init_viewport(rct_window *w) return; for (i = 0; i < 4; i++) { - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[i] != SPRITE_LOCATION_NULL) { - x = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[i] + 16; - y = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[i] + 16; - z = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, sint16)[i] + 32; + if (gParkEntranceX[i] != SPRITE_LOCATION_NULL) { + x = gParkEntranceX[i] + 16; + y = gParkEntranceY[i] + 16; + z = gParkEntranceZ[i] + 32; r = get_current_rotation(); xy = 0x40000000 | (y << 16) | x; diff --git a/src/world/map.c b/src/world/map.c index 2e4c98c53b..0e1c29d5d4 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -4926,7 +4926,7 @@ money32 place_park_entrance(int flags, sint16 x, sint16 y, sint16 z, uint8 direc sint8 entranceNum = -1; for (uint8 i = 0; i < 4; ++i) { - if (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[i] == (sint16)0x8000) { + if (gParkEntranceX[i] == (sint16)0x8000) { entranceNum = i; break; } @@ -4938,10 +4938,10 @@ money32 place_park_entrance(int flags, sint16 x, sint16 y, sint16 z, uint8 direc } if (flags & GAME_COMMAND_FLAG_APPLY) { - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16)[entranceNum] = x; - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16)[entranceNum] = y; - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, sint16)[entranceNum] = (z & 0xFF) << 4; - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_DIRECTION, uint8)[entranceNum] = direction; + gParkEntranceX[entranceNum] = x; + gParkEntranceY[entranceNum] = y; + gParkEntranceZ[entranceNum] = (z & 0xFF) << 4; + gParkEntranceDirection[entranceNum] = direction; } sint8 zLow = (z & 0xFF) * 2; diff --git a/src/world/park.c b/src/world/park.c index ed2de70ca7..52543d529f 100644 --- a/src/world/park.c +++ b/src/world/park.c @@ -57,6 +57,11 @@ int _suggestedGuestMaximum; */ int _guestGenerationProbability; +sint16 *gParkEntranceX = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, sint16); +sint16 *gParkEntranceY = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, sint16); +sint16 *gParkEntranceZ = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, sint16); +uint8 *gParkEntranceDirection = RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_DIRECTION, uint8); + bool gParkEntranceGhostExists; rct_xyz16 gParkEntranceGhostPosition; uint8 gParkEntranceGhostDirection; @@ -341,7 +346,7 @@ void reset_park_entrances() gParkName = 0; for (short i = 0; i < 4; i++) { - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i] = 0x8000; + gParkEntranceX[i] = 0x8000; } RCT2_GLOBAL(RCT2_ADDRESS_PEEP_SPAWNS, uint16) = 0xFFFF; @@ -706,9 +711,9 @@ int park_get_entrance_index(int x, int y, int z) for (i = 0; i < 4; i++) { if ( - x == RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[i] && - y == RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Y, uint16)[i] && - z == RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_Z, uint16)[i] + x == gParkEntranceX[i] && + y == gParkEntranceY[i] && + z == gParkEntranceZ[i] ) { return i; } @@ -840,8 +845,8 @@ void game_command_remove_park_entrance(int *eax, int *ebx, int *ecx, int *edx, i return; } - RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_X, uint16)[entranceIndex] = 0x8000; - direction = (RCT2_ADDRESS(RCT2_ADDRESS_PARK_ENTRANCE_DIRECTION, uint8)[entranceIndex] - 1) & 3; + gParkEntranceX[entranceIndex] = 0x8000; + direction = (gParkEntranceDirection[entranceIndex] - 1) & 3; z = (*edx & 0xFF) * 2; // Centre (sign) diff --git a/src/world/park.h b/src/world/park.h index 224567fb0c..2e78302ebf 100644 --- a/src/world/park.h +++ b/src/world/park.h @@ -66,6 +66,11 @@ extern uint8 *gGuestsInParkHistory; extern int _guestGenerationProbability; extern int _suggestedGuestMaximum; +extern sint16 *gParkEntranceX; +extern sint16 *gParkEntranceY; +extern sint16 *gParkEntranceZ; +extern uint8 *gParkEntranceDirection; + extern bool gParkEntranceGhostExists; extern rct_xyz16 gParkEntranceGhostPosition; extern uint8 gParkEntranceGhostDirection;