From 2cfb2908dee1412726e2bd704f3e7c6e4fefe10e Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 31 Aug 2014 15:40:08 +0100 Subject: [PATCH] add ride track functions, for window ride branch --- src/map.c | 3 -- src/map.h | 2 ++ src/ride.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ride.h | 4 +++ 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/src/map.c b/src/map.c index c82fd6dc48..ac086487e4 100644 --- a/src/map.c +++ b/src/map.c @@ -23,9 +23,6 @@ #include "date.h" #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(); void map_element_set_terrain(rct_map_element *element, int terrain) diff --git a/src/map.h b/src/map.h index 8aa4e171fd..6c2cbf8b32 100644 --- a/src/map.h +++ b/src/map.h @@ -199,5 +199,7 @@ int map_element_height(int x, int y); void sub_68B089(); int map_coord_is_connected(uint16 coordinate, uint8 height, uint8 face_direction); +#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]) #endif diff --git a/src/ride.c b/src/ride.c index bc5ae32544..546817e186 100644 --- a/src/ride.c +++ b/src/ride.c @@ -344,3 +344,91 @@ void ride_check_all_reachable() } } +/** + * + * rct2: 0x006CAF80 + * ax result x + * bx result y + * dl ride index + * esi result map element + */ +rct_map_element *sub_6CAF80(int rideIndex, int *outX, int *outY) +{ + rct_map_element *resultMapElement, *mapElement; + int foundSpecialTrackPiece; + + resultMapElement = (rct_map_element*)-1; + foundSpecialTrackPiece = 0; + + uint16 x, y; + for (x = 0; x < 256; x++) { + for (y = 0; y < 256; y++) { + // Iterate through map elements on tile + int tileIndex = (y << 8) | x; + mapElement = TILE_MAP_ELEMENT_POINTER(tileIndex); + do { + if ((mapElement->type & MAP_ELEMENT_TYPE_MASK) != MAP_ELEMENT_TYPE_TRACK) + continue; + if (rideIndex != mapElement->properties.track.ride_index) + continue; + + // Found a track piece for target ride + + // Check if its a ??? + int specialTrackPiece = ( + (mapElement->properties.track.type != 2 && mapElement->properties.track.type != 3) && + (RCT2_ADDRESS(0x0099BA64, uint8)[mapElement->properties.track.type * 16] & 0x10) + ); + + // Set result tile to this track piece if first found track or a ??? + if (resultMapElement == (rct_map_element*)-1 || specialTrackPiece) { + resultMapElement = mapElement; + + if (outX != NULL) *outX = x * 32; + if (outY != NULL) *outY = y * 32; + } + + if (specialTrackPiece) { + foundSpecialTrackPiece = 1; + return resultMapElement; + } + } while (!(mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE) && mapElement++); + } + } + return resultMapElement; +} + +/** + * + * rct2: 0x006CB02F + * ax result x + * bx result y + * esi input / output map element + */ +rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *outX, int *outY) +{ + int eax, ebx, ecx, edx, esi, edi, ebp; + esi = (int)startTrackElement; + eax = *outX; + ebx = 0; + ecx = *outY; + edx = 0; + edi = 0; + ebp = 0; + RCT2_CALLFUNC_X(0x006CB02F, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + + if (outX != NULL) *outX = eax & 0xFFFF; + if (outY != NULL) *outY = ecx & 0xFFFF; + return (rct_map_element*)esi; +} + +/** + * + * rct2: 0x006CC056 + */ +int ride_try_construct(rct_map_element *trackMapElement) +{ + // Success stored in carry flag which can't be accessed after call using is macro + RCT2_CALLPROC_X(0x006CC056, 0, 0, 0, (int)trackMapElement, 0, 0, 0); + return 1; +} \ No newline at end of file diff --git a/src/ride.h b/src/ride.h index 77f4013831..dca498d637 100644 --- a/src/ride.h +++ b/src/ride.h @@ -21,6 +21,7 @@ #ifndef _RIDE_H_ #define _RIDE_H_ +#include "map.h" #include "rct2.h" #include "string_ids.h" @@ -381,5 +382,8 @@ void ride_init_all(); void reset_all_ride_build_dates(); void ride_update_favourited_stat(); void ride_check_all_reachable(); +rct_map_element *sub_6CAF80(int rideIndex, int *outX, int *outY); +rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *outX, int *outY); +int ride_try_construct(rct_map_element *trackMapElement); #endif