diff --git a/src/drawing/drawing.h b/src/drawing/drawing.h index 69d8c85c3a..f4a6f885f7 100644 --- a/src/drawing/drawing.h +++ b/src/drawing/drawing.h @@ -69,6 +69,8 @@ typedef struct { void *data; } rct_gx; +#define SPRITE_ID_PALETTE_COLOUR_1(colourId) ((IMAGE_TYPE_USE_PALETTE << 28) | ((colourId) << 19)) + extern const uint16 palette_to_g1_offset[]; extern const uint8 peep_palette[]; extern uint8 text_palette[]; diff --git a/src/drawing/supports.c b/src/drawing/supports.c index 4ab328d6e3..f242877c07 100644 --- a/src/drawing/supports.c +++ b/src/drawing/supports.c @@ -6,7 +6,7 @@ typedef struct { uint16 full; uint16 half; uint16 flat; - uint16 unk; + uint16 slope; } supports_id_desc; /* 0x0097B1C4 */ @@ -142,23 +142,16 @@ const uint16 word_97B3C4[] = { }; /** - * + * Adds paint structs for wooden supports. * rct2: 0x006629BC - * dx: height - * ax: unknown - * ebp: imageColourFlags - * edi: unknown - * @returns true if any supports have been drawn. + * @param supportType (edi) Type and direction of supports. + * @param special (ax) Used for curved supports. + * @param height (dx) The height of the supports. + * @param imageColourFlags (ebp) The colour and palette flags for the support sprites. + * @returns true if any supports have been drawn, otherwise false. */ -bool wooden_a_supports_paint_setup(int height, uint16 ax, uint32 imageColourFlags, int supportType) +bool wooden_a_supports_paint_setup(int supportType, int special, int height, uint32 imageColourFlags) { - // { - // int eax = ax, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; - // RCT2_CALLFUNC_X(0x006629BC, &eax, &ebx, &ecx, &edx, &esi, &_edi, &ebp); - // return eax & 0xFF; - // } - - RCT2_GLOBAL(0x009E32B1, uint8) = 0; if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) { return false; } @@ -174,116 +167,131 @@ bool wooden_a_supports_paint_setup(int height, uint16 ax, uint32 imageColourFlag } height /= 16; + bool hasSupports = false; bool drawFlatPiece = false; - int ecx = RCT2_GLOBAL(0x0141E9DA, uint8); - if (ecx & (1 << 5)) { + int rotation = get_current_rotation(); + + // Draw base support (usually shaped to the slope) + int slope = RCT2_GLOBAL(0x0141E9DA, uint8); + if (slope & (1 << 5)) { + // Above scenery (just put a base piece above it) drawFlatPiece = true; - } else if (ecx & (1 << 4)) { + } else if (slope & (1 << 4)) { + // Steep diagonal (place the correct shaped support for the slope) height -= 2; if (height < 0) { return true; } - int imageId = WoodenSupportImageIds[supportType].unk; - if (imageId != 0) { - ecx &= 0x1F; - imageId += word_97B3C4[ecx]; + int imageId = WoodenSupportImageIds[supportType].slope; + if (imageId == 0) { + drawFlatPiece = true; + } else { + imageId += word_97B3C4[slope & 0x1F]; imageId |= imageColourFlags; RCT2_GLOBAL(0x009DEA52, uint16) = 0; RCT2_GLOBAL(0x009DEA54, uint16) = 0; RCT2_GLOBAL(0x009DEA56, uint16) = z + 2; - sub_98197C(0, 11, imageId, 0, z, 32, 32, get_current_rotation()); + sub_98197C(0, 11, imageId, 0, z, 32, 32, rotation); - RCT2_GLOBAL(0x009E32B1, uint8) = 1; - z += 32; - } else { - z += 32; - drawFlatPiece = true; + RCT2_GLOBAL(0x009DEA52, uint16) = 0; + RCT2_GLOBAL(0x009DEA54, uint16) = 0; + RCT2_GLOBAL(0x009DEA56, uint16) = z + 16 + 2; + sub_98197C(0, 11, imageId + 4, 0, z + 16, 32, 32, rotation); + + hasSupports = true; } - } else if (ecx & 0x0F) { + z += 32; + } else if ((slope & 0x0F) != 0) { + // 1 to 3 quarters up height--; if (height < 0) { return true; } - int imageId = WoodenSupportImageIds[supportType].unk; + + int imageId = WoodenSupportImageIds[supportType].slope; if (imageId == 0) { - z += 16; drawFlatPiece = true; } else { - ecx &= 0x1F; - imageId += word_97B3C4[ecx]; + imageId += word_97B3C4[slope & 0x1F]; imageId |= imageColourFlags; RCT2_GLOBAL(0x009DEA52, uint16) = 0; RCT2_GLOBAL(0x009DEA54, uint16) = 0; RCT2_GLOBAL(0x009DEA56, uint16) = z + 2; - sub_98196C(0, 11, imageId, 0, z, 32, 32, get_current_rotation()); - z += 16; - RCT2_GLOBAL(0x009E32B1, uint8) = 1; + sub_98196C(0, 11, imageId, 0, z, 32, 32, rotation); + hasSupports = true; } + z += 16; } + // Draw flat base support if (drawFlatPiece) { int imageId = WoodenSupportImageIds[supportType].flat | imageColourFlags; - sub_98197C(0, 0, imageId, 0, z - 2, 32, 32, get_current_rotation()); - RCT2_GLOBAL(0x009E32B1, uint8) = 1; + sub_98196C(0, 0, imageId, 0, z - 2, 32, 32, rotation); + hasSupports = true; } + // Draw repeated supports for left over space while (height != 0) { if ((z & 16) == 0 && height >= 2 && z + 16 != RCT2_GLOBAL(0x00141E9DC, uint16)) { // Full support int imageId = WoodenSupportImageIds[supportType].full | imageColourFlags; - uint8 ah = ax == 2 ? 23 : 28; - sub_98196C(0, ah, imageId, 0, z, 32, 32, get_current_rotation()); - RCT2_GLOBAL(0x009E32B1, uint8) = 1; + uint8 ah = special == 2 ? 23 : 28; + sub_98196C(0, ah, imageId, 0, z, 32, 32, rotation); + hasSupports = true; z += 32; height -= 2; } else { // Half support int imageId = WoodenSupportImageIds[supportType].half | imageColourFlags; - uint8 ah = ax == 1 ? 7 : 12; - sub_98196C(0, ah, imageId, 0, z, 32, 32, get_current_rotation()); + uint8 ah = special == 1 ? 7 : 12; + sub_98196C(0, ah, imageId, 0, z, 32, 32, rotation); + hasSupports = true; z += 16; - RCT2_GLOBAL(0x009E32B1, uint8) = 1; height -= 1; } } - if (ax != 0) { - int eax = (ax - 1) & 0xFFFF; + // Draw special pieces, e.g. curved supports + if (special != 0) { + special = (special - 1) & 0xFFFF; + int imageId = WoodenCurveSupportImageIds[supportType]; - if (imageId != 0 && byte_97B23C[eax].var_7 != 0) { - imageId += eax; + if (imageId != 0 && byte_97B23C[special].var_7 != 0) { + imageId += special; imageId |= imageColourFlags; - RCT2_GLOBAL(0x009DEA52, uint16) = byte_97B23C[eax].var_0; - RCT2_GLOBAL(0x009DEA54, uint16) = byte_97B23C[eax].var_1; - RCT2_GLOBAL(0x009DEA56, uint16) = byte_97B23C[eax].var_2 + z; - uint16 lengthY = byte_97B23C[eax].var_3; - uint16 lengthX = byte_97B23C[eax].var_4; - uint8 ah = byte_97B23C[eax].var_5; - if (byte_97B23C[eax].var_6 == 0 || RCT2_GLOBAL(0x009DEA58, uint32) == 0) { - sub_98197C(0, ah, imageId, 0, z, lengthY, lengthX, get_current_rotation()); - RCT2_GLOBAL(0x009E32B1, uint8) = 1; + + RCT2_GLOBAL(0x009DEA52, uint16) = byte_97B23C[special].var_0; + RCT2_GLOBAL(0x009DEA54, uint16) = byte_97B23C[special].var_1; + RCT2_GLOBAL(0x009DEA56, uint16) = byte_97B23C[special].var_2 + z; + uint16 lengthY = byte_97B23C[special].var_3; + uint16 lengthX = byte_97B23C[special].var_4; + uint8 ah = byte_97B23C[special].var_5; + if (byte_97B23C[special].var_6 == 0 || RCT2_GLOBAL(0x009DEA58, uint32) == 0) { + sub_98197C(0, ah, imageId, 0, z, lengthY, lengthX, rotation); + hasSupports = true; } else { - RCT2_GLOBAL(0x009E32B1, uint8) = 1; - if (!sub_98198C(0, ah, imageId, 0, z, lengthY, lengthX, get_current_rotation())) { + hasSupports = true; + if (!sub_98198C(0, ah, imageId, 0, z, lengthY, lengthX, rotation)) { int edi = RCT2_GLOBAL(0x009DEA58, uint32); RCT2_GLOBAL(edi + 0x20, uint32) = imageColourFlags; } } } } - return false; + + return hasSupports; } /** * Wooden supports * rct2: 0x00662D5C */ -bool wooden_b_supports_paint_setup(int height, uint16 ax, uint32 imageColourFlags, int supportType) +bool wooden_b_supports_paint_setup(int supportType, int special, int height, uint32 imageColourFlags) { - int eax = ax, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; + int eax = special, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; RCT2_CALLFUNC_X(0x00662D5C, &eax, &ebx, &ecx, &edx, &esi, &_edi, &ebp); return eax & 0xFF; } @@ -292,9 +300,9 @@ bool wooden_b_supports_paint_setup(int height, uint16 ax, uint32 imageColourFlag * Metal pole supports * rct2: 0x00663105 */ -bool metal_a_wooden_a_supports_paint_setup(int height, uint16 ax, uint32 imageColourFlags, int supportType) +bool metal_a_wooden_a_supports_paint_setup(int supportType, int special, int height, uint32 imageColourFlags) { - int eax = ax, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; + int eax = special, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; RCT2_CALLFUNC_X(0x00663105, &eax, &ebx, &ecx, &edx, &esi, &_edi, &ebp); return eax & 0xFF; } @@ -303,9 +311,9 @@ bool metal_a_wooden_a_supports_paint_setup(int height, uint16 ax, uint32 imageCo * Metal pole supports * rct2: 0x00663584 */ -bool metal_b_wooden_a_supports_paint_setup(int height, uint16 ax, uint32 imageColourFlags, int supportType) +bool metal_b_wooden_a_supports_paint_setup(int supportType, int special, int height, uint32 imageColourFlags) { - int eax = ax, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; + int eax = special, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; RCT2_CALLFUNC_X(0x00663584, &eax, &ebx, &ecx, &edx, &esi, &_edi, &ebp); return eax & 0xFF; } @@ -314,9 +322,9 @@ bool metal_b_wooden_a_supports_paint_setup(int height, uint16 ax, uint32 imageCo * Some kind of supports * rct2: 0x006A2ECC */ -bool sub_6A2ECC(int height, uint16 ax, uint32 imageColourFlags, int supportType) +bool sub_6A2ECC(int supportType, int special, int height, uint32 imageColourFlags) { - int eax = ax, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; + int eax = special, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; RCT2_CALLFUNC_X(0x006A2ECC, &eax, &ebx, &ecx, &edx, &esi, &_edi, &ebp); return eax & 0xFF; } @@ -325,9 +333,9 @@ bool sub_6A2ECC(int height, uint16 ax, uint32 imageColourFlags, int supportType) * * rct2: 0x006A326B */ -bool path_wooden_a_supports_paint_setup(int height, uint16 ax, uint32 imageColourFlags, int supportType) +bool path_wooden_a_supports_paint_setup(int supportType, int special, int height, uint32 imageColourFlags) { - int eax = ax, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; + int eax = special, ebx = 0, ecx = 0, edx = height, esi = 0, _edi = supportType, ebp = imageColourFlags; RCT2_CALLFUNC_X(0x006A326B, &eax, &ebx, &ecx, &edx, &esi, &_edi, &ebp); return eax & 0xFF; } diff --git a/src/drawing/supports.h b/src/drawing/supports.h index 97a4ef9ec8..f5e71b9854 100644 --- a/src/drawing/supports.h +++ b/src/drawing/supports.h @@ -3,6 +3,6 @@ #include "../common.h" -bool wooden_a_supports_paint_setup(int height, uint16 ax, uint32 image_id, int supportType); +bool wooden_a_supports_paint_setup(int supportType, int special, int height, uint32 imageColourFlags); #endif \ No newline at end of file diff --git a/src/interface/viewport.c b/src/interface/viewport.c index 19dc1aafa8..0c77c432c6 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -1381,15 +1381,10 @@ void viewport_ride_entrance_exit_paint_setup(uint8 direction, int height, rct_ma } image_id = RCT2_GLOBAL(0x009E32BC, uint32); - if (!image_id){ - image_id = 0x20B80000; - } - - if (direction & 1) { - wooden_a_supports_paint_setup(height, 0, image_id, 1); - } else { - wooden_a_supports_paint_setup(height, 0, image_id, 0); + if (image_id == 0) { + image_id = SPRITE_ID_PALETTE_COLOUR_1(COLOUR_SATURATED_BROWN); } + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); RCT2_GLOBAL(0x141E9B4, uint16) = 0xFFFF; RCT2_GLOBAL(0x141E9B8, uint16) = 0xFFFF; @@ -1501,15 +1496,10 @@ void viewport_park_entrance_paint_setup(uint8 direction, int height, rct_map_ele } image_id = ghost_id; - if (!image_id){ - image_id = 0x20B80000; - } - - if (direction & 1) { - wooden_a_supports_paint_setup(height, 0, image_id, 1); - } else { - wooden_a_supports_paint_setup(height, 0, image_id, 0); + if (image_id == 0) { + image_id = SPRITE_ID_PALETTE_COLOUR_1(COLOUR_SATURATED_BROWN); } + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); RCT2_GLOBAL(0x141E9B4, uint16) = 0xFFFF; RCT2_GLOBAL(0x141E9B8, uint16) = 0xFFFF; diff --git a/src/ride/track_paint.c b/src/ride/track_paint.c index 796e445b67..26f762edd9 100644 --- a/src/ride/track_paint.c +++ b/src/ride/track_paint.c @@ -38,7 +38,7 @@ */ static void top_spin_paint_tile_0(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22137 | RCT2_GLOBAL(0x00F44198, uint32); @@ -342,7 +342,7 @@ static void top_spin_paint_vehicle(sint8 al, sint8 cl, uint8 rideIndex, uint8 di */ static void top_spin_paint_tile_1(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22137 | RCT2_GLOBAL(0x00F44198, uint32); @@ -411,7 +411,7 @@ static void top_spin_paint_tile_1(uint8 rideIndex, uint8 trackSequence, uint8 di */ static void top_spin_paint_tile_2(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22137 | RCT2_GLOBAL(0x00F44198, uint32); @@ -461,7 +461,7 @@ static void top_spin_paint_tile_2(uint8 rideIndex, uint8 trackSequence, uint8 di */ static void top_spin_paint_tile_4(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22137 | RCT2_GLOBAL(0x00F44198, uint32); @@ -511,7 +511,7 @@ static void top_spin_paint_tile_4(uint8 rideIndex, uint8 trackSequence, uint8 di */ static void top_spin_paint_tile_3(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22136 | RCT2_GLOBAL(0x00F44198, uint32); @@ -580,7 +580,7 @@ static void top_spin_paint_tile_3(uint8 rideIndex, uint8 trackSequence, uint8 di */ static void top_spin_paint_tile_5(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22136 | RCT2_GLOBAL(0x00F44198, uint32); @@ -631,7 +631,7 @@ static void top_spin_paint_tile_5(uint8 rideIndex, uint8 trackSequence, uint8 di */ static void top_spin_paint_tile_6(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22135 | RCT2_GLOBAL(0x00F44198, uint32); @@ -700,7 +700,7 @@ static void top_spin_paint_tile_6(uint8 rideIndex, uint8 trackSequence, uint8 di */ static void top_spin_paint_tile_7(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22134 | RCT2_GLOBAL(0x00F44198, uint32); @@ -769,7 +769,7 @@ static void top_spin_paint_tile_7(uint8 rideIndex, uint8 trackSequence, uint8 di */ static void top_spin_paint_tile_8(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { uint32 image_id = RCT2_GLOBAL(0x00F441A0, uint32); - wooden_a_supports_paint_setup(height, 0, image_id, direction & 1); + wooden_a_supports_paint_setup(direction & 1, 0, height, image_id); image_id = 22135 | RCT2_GLOBAL(0x00F44198, uint32); @@ -991,7 +991,7 @@ TRACK_PAINT_FUNCTION get_track_paint_function_topspin(int trackType, int directi */ static void shop_paint_setup(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { - bool hasSupports = wooden_a_supports_paint_setup(height, 0, RCT2_GLOBAL(0x00F441A4, uint32), direction & 1); + bool hasSupports = wooden_a_supports_paint_setup(direction & 1, 0, height, RCT2_GLOBAL(0x00F441A4, uint32)); RCT2_GLOBAL(0x0141E9D0, sint16) = -1; RCT2_GLOBAL(0x0141E9C4, sint16) = -1; @@ -1053,8 +1053,6 @@ TRACK_PAINT_FUNCTION get_track_paint_function_shop(int trackType, int direction) return NULL; } -static int tempi = 0; - /** * * rct2: 0x00763234 @@ -1064,7 +1062,7 @@ static int tempi = 0; */ static void facility_paint_setup(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement) { - bool hasSupports = wooden_a_supports_paint_setup(height, 0, RCT2_GLOBAL(0x00F441A4, uint32), direction & 1); + bool hasSupports = wooden_a_supports_paint_setup(direction & 1, 0, height, RCT2_GLOBAL(0x00F441A4, uint32)); RCT2_GLOBAL(0x0141E9D0, sint16) = -1; RCT2_GLOBAL(0x0141E9C4, sint16) = -1;