diff --git a/src/ride/gentle/crooked_house.c b/src/ride/gentle/crooked_house.c index 71f242725a..ba67072a2e 100644 --- a/src/ride/gentle/crooked_house.c +++ b/src/ride/gentle/crooked_house.c @@ -19,81 +19,6 @@ #include "../../paint/supports.h" #include "../track_paint.h" -/* rct2: 0x007667AE */ -static rct_xy16 loc_7667AE[] = { - { .x = 0, .y = -1 }, - { .x = 1, .y = 0 }, - { .x = 0, .y = 1}, - { .x = -1, .y = 0 }, -}; - -/* rct2: 0x007667AC */ -static rct_xy16 loc_7667AC[] = { - { .x = -1, .y = 0 }, - { .x = 0, .y = -1 }, - { .x = 1, .y = 0 }, - { .x = 0, .y = 1 }, -}; - -static void crooked_house_paint_supports(uint8 direction, int height) { - wooden_a_supports_paint_setup((direction & 1), 0, height, RCT2_GLOBAL(0x00F441A0, uint32), NULL); -} - -static void crooked_house_paint_floor(int height, int floor_sprite_id) { - uint32 image_id = floor_sprite_id | RCT2_GLOBAL(0x00F44198, uint32); - sub_98197C(image_id, 0, 0, 31, 31, 1, height, 0, 0, height, get_current_rotation()); -} - -static void crooked_house_paint_support_heights() { - RCT2_GLOBAL(0x0141E9D0, uint16) = 0xFFFF; - RCT2_GLOBAL(0x0141E9C4, uint16) = 0xFFFF; - RCT2_GLOBAL(0x0141E9CC, uint16) = 0xFFFF; - RCT2_GLOBAL(0x0141E9B8, uint16) = 0xFFFF; - RCT2_GLOBAL(0x0141E9BC, uint16) = 0xFFFF; - RCT2_GLOBAL(0x0141E9B4, uint16) = 0xFFFF; - RCT2_GLOBAL(0x0141E9C0, uint16) = 0xFFFF; - RCT2_GLOBAL(0x0141E9C8, uint16) = 0xFFFF; - RCT2_GLOBAL(0x0141E9D4, uint16) = 0xFFFF; -} - -static void crooked_house_fence_top_left(rct_ride *ride, int height, rct_map_element *mapElement) { - sint16 x = RCT2_GLOBAL(0x009DE56A, sint16), y = RCT2_GLOBAL(0x009DE56E, sint16); - uint8 entranceId = (mapElement->properties.entrance.index & 0x70) >> 4; - - uint16 entranceLoc = - ((x / 32) + loc_7667AE[get_current_rotation()].x) | - (((y / 32) + loc_7667AE[get_current_rotation()].y) << 8); - - if (ride->entrances[entranceId] != entranceLoc && ride->exits[entranceId] != entranceLoc) { - uint32 image_id = 22141 | RCT2_GLOBAL(0x00F441A0, uint32); - sub_98199C(image_id, 0, 0, 32, 1, 7, height, 0, 2, height + 2, get_current_rotation()); - } -} - -static void crooked_house_fence_top_right(rct_ride *ride, int height, rct_map_element *mapElement) { - sint16 x = RCT2_GLOBAL(0x009DE56A, sint16), y = RCT2_GLOBAL(0x009DE56E, sint16); - uint8 entranceId = (mapElement->properties.entrance.index & 0x70) >> 4; - - uint16 entranceLoc = - ((x / 32) + loc_7667AC[get_current_rotation()].x) | - (((y / 32) + loc_7667AC[get_current_rotation()].y) << 8); - - if (ride->entrances[entranceId] != entranceLoc && ride->exits[entranceId] != entranceLoc) { - uint32 image_id = 22138 | RCT2_GLOBAL(0x00F441A0, uint32); - sub_98199C(image_id, 0, 0, 1, 32, 7, height, 0, 2, height + 2, get_current_rotation()); - } -} - -static void crooked_house_fence_bottom_right(rct_ride *ride, int height, rct_map_element *mapElement) { - uint32 image_id = 22139 | RCT2_GLOBAL(0x00F441A0, uint32); - sub_98199C(image_id, 0, 0, 32, 1, 7, height, 0, 30, height + 2, get_current_rotation()); -} - -static void crooked_house_fence_bottom_left(rct_ride *ride, int height, rct_map_element *mapElement) { - uint32 image_id = 22140 | RCT2_GLOBAL(0x00F441A0, uint32); - sub_98199C(image_id, 0, 0, 1, 32, 7, height, 30, 0, height + 2, get_current_rotation()); -} - typedef struct rct_crooked_house_bound_box { sint16 offset_x; sint16 offset_y; @@ -148,183 +73,58 @@ static void sub_88ABA4(uint8 direction, uint8 x_offset, uint8 y_offset, uint32 s sub_98197C(image_id, x_offset, y_offset, boundBox.length_x, boundBox.length_y, 127, height + 3, boundBox.offset_x, boundBox.offset_y, height + 3, get_current_rotation()); } -static void crooked_house_paint_setup_889F08(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22137); - crooked_house_paint_support_heights(); +static void paint_crooked_house(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + trackSequence = track_map_3x3[direction][trackSequence]; + uint32 imageId; + + int edges = edges_3x3[trackSequence]; + rct_ride * ride = get_ride(rideIndex); + rct_xy16 position = {RCT2_GLOBAL(0x009DE56A, sint16), RCT2_GLOBAL(0x009DE56E, sint16)}; + + wooden_a_supports_paint_setup((direction & 1), 0, height, RCT2_GLOBAL(0x00F441A0, uint32_t), NULL); + + track_paint_util_paint_floor(edges, RCT2_GLOBAL(0x00F44198, uint32), height, floorSpritesCork, get_current_rotation()); + + track_paint_util_paint_fences(edges, position, mapElement, ride, RCT2_GLOBAL(0x00F441A0, uint32), height, fenceSpritesRope, get_current_rotation()); + + switch(trackSequence) { + case 3: sub_88ABA4(direction, 32, 224, 0, height); break; + case 5: sub_88ABA4(direction, 0, 224, 1, height); break; + case 6: sub_88ABA4(direction, 224, 32, 4, height); break; + case 7: sub_88ABA4(direction, 224, 224, 2, height); break; + //case 8: sub_88ABA4(rideIndex, 224, 0, 3, height); break; + } + + int cornerSegments = 0; + switch (trackSequence) { + case 1: + // top + cornerSegments = SEGMENT_B4 | SEGMENT_C8 | SEGMENT_CC; + break; + case 3: + // right + cornerSegments = SEGMENT_CC | SEGMENT_BC | SEGMENT_D4; + break; + case 6: + // left + cornerSegments = SEGMENT_C8 | SEGMENT_B8 | SEGMENT_D0; + break; + case 7: + // bottom + cornerSegments = SEGMENT_D0 | SEGMENT_C0 | SEGMENT_D4; + break; + } + + paint_util_set_segment_support_height(cornerSegments, height + 2, 0x20); + paint_util_set_segment_support_height(SEGMENTS_ALL & ~cornerSegments, 0xFFFF, 0); paint_util_set_general_support_height(height + 128, 0x20); } -static void crooked_house_paint_setup_889FCC(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22137); - - rct_ride *ride = get_ride(rideIndex); - crooked_house_fence_top_left(ride, height, mapElement); - crooked_house_fence_top_right(ride, height, mapElement); - - height += 2; - crooked_house_paint_support_heights(); - paint_util_set_segment_support_height(SEGMENT_B4 | SEGMENT_C8 | SEGMENT_CC, height, 0x20); - - paint_util_set_general_support_height(height + 126, 0x20); -} - -static void crooked_house_paint_setup_88A1D0(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22136); - - rct_ride *ride = get_ride(rideIndex); - crooked_house_fence_top_right(ride, height, mapElement); - crooked_house_fence_bottom_right(ride, height, mapElement); - - sub_88ABA4(direction, 32, 224, 0, height); - - height += 2; - crooked_house_paint_support_heights(); - paint_util_set_segment_support_height(SEGMENT_CC | SEGMENT_BC | SEGMENT_D4, height, 0x20); - - paint_util_set_general_support_height(height + 126, 0x20); -} - -static void crooked_house_paint_setup_88A392(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22135); - - rct_ride *ride = get_ride(rideIndex); - crooked_house_fence_top_left(ride, height, mapElement); - crooked_house_fence_bottom_left(ride, height, mapElement); - - sub_88ABA4(direction, 224, 32, 4, height); - - height += 2; - crooked_house_paint_support_heights(); - paint_util_set_segment_support_height(SEGMENT_C8 | SEGMENT_B8 | SEGMENT_D0, height, 0x20); - - paint_util_set_general_support_height(height + 126, 0x20); -} - -static void crooked_house_paint_setup_88A554(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22134); - - rct_ride *ride = get_ride(rideIndex); - crooked_house_fence_bottom_left(ride, height, mapElement); - crooked_house_fence_bottom_right(ride, height, mapElement); - - sub_88ABA4(direction, 224, 224, 2, height); - - height += 2; - crooked_house_paint_support_heights(); - paint_util_set_segment_support_height(SEGMENT_D0 | SEGMENT_C0 | SEGMENT_D4, height, 0x20); - - paint_util_set_general_support_height(height + 126, 0x20); -} - - -static void crooked_house_paint_setup_88A97C(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22136); - - rct_ride *ride = get_ride(rideIndex); - crooked_house_fence_bottom_right(ride, height, mapElement); - - sub_88ABA4(direction, 0, 224, 1, height); - - crooked_house_paint_support_heights(); - paint_util_set_general_support_height(height + 128, 0x20); -} - -static void crooked_house_paint_setup_88A821(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22137); - - rct_ride *ride = get_ride(rideIndex); - crooked_house_fence_top_left(ride, height, mapElement); - - crooked_house_paint_support_heights(); - paint_util_set_general_support_height(height + 128, 0x20); -} - -static void crooked_house_paint_setup_88A6C6(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22137); - - rct_ride *ride = get_ride(rideIndex); - crooked_house_fence_top_right(ride, height, mapElement); - crooked_house_paint_support_heights(); - paint_util_set_general_support_height(height + 128, 0x20); -} - -// bottom center -static void crooked_house_paint_setup_88AA90(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_supports(direction, height); - crooked_house_paint_floor(height, 22135); - - rct_ride *ride = get_ride(rideIndex); - crooked_house_fence_bottom_left(ride, height, mapElement); - - //sub_88ABA4(rideIndex, 224, 0, 3, height); - - crooked_house_paint_support_heights(); - paint_util_set_general_support_height(height + 128, 0x20); -} - -TRACK_PAINT_FUNCTION crooked_house_paint_setup_functions[][9] = { - { - crooked_house_paint_setup_889F08, - crooked_house_paint_setup_889FCC, - crooked_house_paint_setup_88A6C6, - crooked_house_paint_setup_88A1D0, - crooked_house_paint_setup_88A821, - crooked_house_paint_setup_88A97C, - crooked_house_paint_setup_88A392, - crooked_house_paint_setup_88A554, - crooked_house_paint_setup_88AA90, - }, - { - crooked_house_paint_setup_889F08, - crooked_house_paint_setup_88A1D0, - crooked_house_paint_setup_88A97C, - crooked_house_paint_setup_88A554, - crooked_house_paint_setup_88A6C6, - crooked_house_paint_setup_88AA90, - crooked_house_paint_setup_889FCC, - crooked_house_paint_setup_88A392, - crooked_house_paint_setup_88A821, - }, - { - crooked_house_paint_setup_889F08, - crooked_house_paint_setup_88A554, - crooked_house_paint_setup_88AA90, - crooked_house_paint_setup_88A392, - crooked_house_paint_setup_88A97C, - crooked_house_paint_setup_88A821, - crooked_house_paint_setup_88A1D0, - crooked_house_paint_setup_889FCC, - crooked_house_paint_setup_88A6C6, - }, - { - crooked_house_paint_setup_889F08, - crooked_house_paint_setup_88A392, - crooked_house_paint_setup_88A821, - crooked_house_paint_setup_889FCC, - crooked_house_paint_setup_88AA90, - crooked_house_paint_setup_88A6C6, - crooked_house_paint_setup_88A554, - crooked_house_paint_setup_88A1D0, - crooked_house_paint_setup_88A97C, - }, -}; - -static void crooked_house_paint_setup(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element *mapElement) { - crooked_house_paint_setup_functions[direction][trackSequence](rideIndex, trackSequence, direction, height, mapElement); -} - TRACK_PAINT_FUNCTION get_track_paint_function_crooked_house(int trackType, int direction) { if (trackType != 123) { return NULL; } - return crooked_house_paint_setup; + return paint_crooked_house; } diff --git a/src/ride/thrill/top_spin.c b/src/ride/thrill/top_spin.c index ba2e2cb552..87ebb54edc 100644 --- a/src/ride/thrill/top_spin.c +++ b/src/ride/thrill/top_spin.c @@ -251,36 +251,6 @@ static void top_spin_paint_vehicle(sint8 al, sint8 cl, uint8 rideIndex, uint8 di RCT2_GLOBAL(RCT2_ADDRESS_PAINT_SETUP_CURRENT_TYPE, uint8) = VIEWPORT_INTERACTION_ITEM_RIDE; } -const uint8 track_map_3x3[][9] = { - {0, 1, 2, 3, 4, 5, 6, 7, 8}, - {0, 3, 5, 7, 2, 8, 1, 6, 4}, - {0, 7, 8, 6, 5, 4, 3, 1, 2}, - {0, 6, 4, 1, 8, 2, 7, 3, 5} -}; - -const uint8 edges_3x3[] = { - 0, - EDGE_NE | EDGE_NW, - EDGE_NE, - EDGE_NE | EDGE_SE, - EDGE_NW, - EDGE_SE, - EDGE_SW | EDGE_NW, - EDGE_SW | EDGE_SE, - EDGE_SW, -}; - -enum { - SPR_FLOOR_CORK_SE_SW = 22134, - SPR_FLOOR_CORK_SW = 22135, - SPR_FLOOR_CORK_SE = 22136, - SPR_FLOOR_CORK = 22137, - SPR_FENCE_ROPE_NE = 22138, - SPR_FENCE_ROPE_SE = 22139, - SPR_FENCE_ROPE_SW = 22140, - SPR_FENCE_ROPE_NW = 22141, -}; - /** * rct2: 0x0076679C */ @@ -294,36 +264,12 @@ static void paint_top_spin(uint8 rideIndex, uint8 trackSequence, uint8 direction rct_ride *ride = get_ride(rideIndex); rct_xy16 position = {RCT2_GLOBAL(0x009DE56A, sint16), RCT2_GLOBAL(0x009DE56E, sint16)}; - if (edges & EDGE_SW && edges & EDGE_SE) { - imageId = SPR_FLOOR_CORK_SE_SW | RCT2_GLOBAL(0x00F44198, uint32); - } else if (edges & EDGE_SW) { - imageId = SPR_FLOOR_CORK_SW | RCT2_GLOBAL(0x00F44198, uint32); - } else if (edges & EDGE_SE) { - imageId = SPR_FLOOR_CORK_SE | RCT2_GLOBAL(0x00F44198, uint32); - } else { - imageId = SPR_FLOOR_CORK | RCT2_GLOBAL(0x00F44198, uint32); - } - sub_98197C(imageId, 0, 0, 32, 32, 1, height, 0, 0, height, get_current_rotation()); + track_paint_util_paint_floor(edges, RCT2_GLOBAL(0x00F44198, uint32), height, floorSpritesCork, get_current_rotation()); - if (edges & EDGE_NW && track_paint_util_has_fence(EDGE_NW, position, mapElement, ride, get_current_rotation())) { - imageId = SPR_FENCE_ROPE_NW | RCT2_GLOBAL(0x00F441A0, uint32); - sub_98199C(imageId, 0, 0, 32, 1, 7, height, 0, 2, height + 2, get_current_rotation()); - } - if (edges & EDGE_SW && track_paint_util_has_fence(EDGE_SW, position, mapElement, ride, get_current_rotation())) { - imageId = SPR_FENCE_ROPE_SW | RCT2_GLOBAL(0x00F441A0, uint32); - sub_98197C(imageId, 0, 0, 1, 32, 7, height, 30, 0, height + 2, get_current_rotation()); - } - if (edges & EDGE_NE && track_paint_util_has_fence(EDGE_NE, position, mapElement, ride, get_current_rotation())) { - imageId = SPR_FENCE_ROPE_NE | RCT2_GLOBAL(0x00F441A0, uint32); - sub_98199C(imageId, 0, 0, 1, 32, 7, height, 0, 2, height + 2, get_current_rotation()); - } - if (edges & EDGE_SE && track_paint_util_has_fence(EDGE_SE, position, mapElement, ride, get_current_rotation())) { - imageId = SPR_FENCE_ROPE_SE | RCT2_GLOBAL(0x00F441A0, uint32); - sub_98197C(imageId, 0, 0, 32, 1, 7, height, 0, 30, height + 2, get_current_rotation()); - } + track_paint_util_paint_fences(edges, position, mapElement, ride, RCT2_GLOBAL(0x00F441A0, uint32), height, fenceSpritesRope, get_current_rotation()); switch (trackSequence) { - case 0: top_spin_paint_vehicle(32, 32, rideIndex, direction, height, mapElement); break; + case 1: top_spin_paint_vehicle(32, 32, rideIndex, direction, height, mapElement); break; case 3: top_spin_paint_vehicle(32, -32, rideIndex, direction, height, mapElement); break; case 5: top_spin_paint_vehicle(0, -32, rideIndex, direction, height, mapElement); break; case 6: top_spin_paint_vehicle(-32, 32, rideIndex, direction, height, mapElement); break; diff --git a/src/ride/track_paint.c b/src/ride/track_paint.c index 0e2b6db0a3..ee565963d7 100644 --- a/src/ride/track_paint.c +++ b/src/ride/track_paint.c @@ -73,6 +73,46 @@ bool track_paint_util_has_fence(enum edge edge, rct_xy16 position, rct_map_eleme return (ride->entrances[entranceId] != entranceLoc && ride->exits[entranceId] != entranceLoc); } +void track_paint_util_paint_floor(uint edges, uint32 colourFlags, uint16 height, const uint floorSprites[4], uint8 rotation) +{ + uint32 imageId; + + if (edges & EDGE_SW && edges & EDGE_SE) { + imageId = floorSprites[0]; + } else if (edges & EDGE_SW) { + imageId = floorSprites[1]; + } else if (edges & EDGE_SE) { + imageId = floorSprites[2]; + } else { + imageId = floorSprites[3]; + } + + sub_98197C(imageId | colourFlags, 0, 0, 32, 32, 1, height, 0, 0, height, rotation); +} + +void track_paint_util_paint_fences(uint edges, rct_xy16 position, rct_map_element * mapElement, rct_ride * ride, uint32 colourFlags, uint16 height, const uint fenceSprites[4], uint8 rotation) +{ + uint32 imageId; + + if (edges & EDGE_NW && track_paint_util_has_fence(EDGE_NW, position, mapElement, ride, get_current_rotation())) { + imageId = SPR_FENCE_ROPE_NW | colourFlags; + sub_98199C(imageId, 0, 0, 32, 1, 7, height, 0, 2, height + 2, get_current_rotation()); + } + if (edges & EDGE_SW && track_paint_util_has_fence(EDGE_SW, position, mapElement, ride, get_current_rotation())) { + imageId = SPR_FENCE_ROPE_SW | colourFlags; + sub_98197C(imageId, 0, 0, 1, 32, 7, height, 30, 0, height + 2, get_current_rotation()); + } + if (edges & EDGE_NE && track_paint_util_has_fence(EDGE_NE, position, mapElement, ride, get_current_rotation())) { + imageId = SPR_FENCE_ROPE_NE | colourFlags; + sub_98199C(imageId, 0, 0, 1, 32, 7, height, 0, 2, height + 2, get_current_rotation()); + } + if (edges & EDGE_SE && track_paint_util_has_fence(EDGE_SE, position, mapElement, ride, get_current_rotation())) { + imageId = SPR_FENCE_ROPE_SE | colourFlags; + sub_98197C(imageId, 0, 0, 32, 1, 7, height, 0, 30, height + 2, get_current_rotation()); + } +} + + /** * * rct2: 0x006C4794 diff --git a/src/ride/track_paint.h b/src/ride/track_paint.h index 126bcac94e..fc2ed8054c 100644 --- a/src/ride/track_paint.h +++ b/src/ride/track_paint.h @@ -21,7 +21,53 @@ #include "../world/map.h" #include "../paint/map_element/map_element.h" +static const uint8 track_map_3x3[][9] = { + {0, 1, 2, 3, 4, 5, 6, 7, 8}, + {0, 3, 5, 7, 2, 8, 1, 6, 4}, + {0, 7, 8, 6, 5, 4, 3, 1, 2}, + {0, 6, 4, 1, 8, 2, 7, 3, 5} +}; + +static const uint8 edges_3x3[] = { + 0, + EDGE_NE | EDGE_NW, + EDGE_NE, + EDGE_NE | EDGE_SE, + EDGE_NW, + EDGE_SE, + EDGE_SW | EDGE_NW, + EDGE_SW | EDGE_SE, + EDGE_SW, +}; + +enum { + SPR_FLOOR_CORK_SE_SW = 22134, + SPR_FLOOR_CORK_SW = 22135, + SPR_FLOOR_CORK_SE = 22136, + SPR_FLOOR_CORK = 22137, + SPR_FENCE_ROPE_NE = 22138, + SPR_FENCE_ROPE_SE = 22139, + SPR_FENCE_ROPE_SW = 22140, + SPR_FENCE_ROPE_NW = 22141, +}; + +static const uint floorSpritesCork[] = { + SPR_FLOOR_CORK_SE_SW, + SPR_FLOOR_CORK_SW, + SPR_FLOOR_CORK_SE, + SPR_FLOOR_CORK +}; + +static const uint fenceSpritesRope[] = { + SPR_FENCE_ROPE_NE, + SPR_FENCE_ROPE_SE, + SPR_FENCE_ROPE_SW, + SPR_FENCE_ROPE_NW +}; + bool track_paint_util_has_fence(enum edge edge, rct_xy16 position, rct_map_element * mapElement, rct_ride * ride, uint8 rotation); +void track_paint_util_paint_floor(uint edges, uint32 colourFlags, uint16 height, const uint floorSprites[4], uint8 rotation); +void track_paint_util_paint_fences(uint edges, rct_xy16 position, rct_map_element * mapElement, rct_ride * ride, uint32 colourFlags, uint16 height, const uint fenceSprites[4], uint8 rotation); typedef void (*TRACK_PAINT_FUNCTION)(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element* mapElement); typedef TRACK_PAINT_FUNCTION (*TRACK_PAINT_FUNCTION_GETTER)(int trackType, int direction);