From 464fdc8efe49bae2383804b83b2ec24d030cdbba Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Wed, 18 May 2016 23:14:41 +0200 Subject: [PATCH] Paint ferris wheel (#3657) --- src/ride/gentle/ferris_wheel.c | 182 +++++++++++++++++++++++++++++++++ src/ride/track_data.c | 4 +- src/ride/track_paint.c | 20 ++-- src/ride/track_paint.h | 1 + 4 files changed, 195 insertions(+), 12 deletions(-) diff --git a/src/ride/gentle/ferris_wheel.c b/src/ride/gentle/ferris_wheel.c index 846fd9695d..6b1df5b7b0 100644 --- a/src/ride/gentle/ferris_wheel.c +++ b/src/ride/gentle/ferris_wheel.c @@ -13,3 +13,185 @@ * A full copy of the GNU General Public License can be found in licence.txt *****************************************************************************/ #pragma endregion + +#include "../../interface/viewport.h" +#include "../../paint/paint.h" +#include "../../paint/supports.h" +#include "../track_paint.h" + +static const uint8 track_map_1x4[][4] = { + {0, 1, 2, 3}, + {2, 3, 0, 1}, + {2, 3, 0, 1}, + {0, 1, 2, 3}, +}; + +static const uint8 edges_1x4_ne_sw[] = { + EDGE_NW | EDGE_SE, + EDGE_NW | EDGE_SE | EDGE_NE, + EDGE_NW | EDGE_SE, + EDGE_NW | EDGE_SE | EDGE_SW, +}; + +static const uint8 edges_1x4_nw_se[] = { + EDGE_NE | EDGE_SW, + EDGE_NE | EDGE_SW | EDGE_NW, + EDGE_NE | EDGE_SW, + EDGE_NE | EDGE_SW | EDGE_SE, +}; + +typedef struct ferris_wheel_bound_box +{ + sint16 length_x; + sint16 length_y; + sint16 offset_x; + sint16 offset_y; +} ferris_wheel_bound_box; + +/** rct2: 0x008A8CA8 */ +static ferris_wheel_bound_box ferris_wheel_data[] = { + {31, 16, 1, 8}, + {16, 31, 8, 1}, + {31, 16, 1, 8}, + {16, 31, 8, 1}, +}; + + +/** + * rct2: 0x004C3874 + */ +static void paint_ferris_wheel_structure(uint8 rideIndex, uint8 direction, sint8 axisOffset, uint16 height) +{ + uint32 imageId, baseImageId; + + rct_map_element * savedMapElement = RCT2_GLOBAL(0x009DE578, rct_map_element*); + + rct_ride * ride = get_ride(rideIndex); + rct_ride_entry * rideType = get_ride_entry(ride->subtype); + rct_vehicle * vehicle = NULL; + + sint8 xOffset = !(direction & 1) ? axisOffset : 0; + sint8 yOffset = (direction & 1) ? axisOffset : 0; + + height += 7; + + baseImageId = rideType->vehicles[0].base_image_id; + + if (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK + && ride->vehicles[0] != SPRITE_INDEX_NULL) { + vehicle = GET_VEHICLE(ride->vehicles[0]); + + RCT2_GLOBAL(RCT2_ADDRESS_PAINT_SETUP_CURRENT_TYPE, uint8) = VIEWPORT_INTERACTION_ITEM_SPRITE; + RCT2_GLOBAL(0x009DE578, rct_vehicle*) = vehicle; + } + + uint32 imageOffset = 0; + if (vehicle != NULL) { + imageOffset = vehicle->vehicle_sprite_type % 8; + } + + uint32 imageColourFlags = RCT2_GLOBAL(0x00F441A0, uint32); + if (imageColourFlags == 0x20000000) { + imageColourFlags = ride->vehicle_colours[0].body_colour << 19 | ride->vehicle_colours[0].trim_colour << 24 | 0xA0000000; + } + + ferris_wheel_bound_box boundBox = ferris_wheel_data[direction]; + + imageId = (22150 + (direction & 1) * 2) | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x, boundBox.offset_y, height, get_current_rotation()); + + imageId = (baseImageId + direction * 8 + imageOffset) | imageColourFlags; + sub_98199C(imageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x, boundBox.offset_y, height, get_current_rotation()); + + if (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK + && ride->vehicles[0] != SPRITE_INDEX_NULL) { + vehicle = GET_VEHICLE(ride->vehicles[0]); + for (int i = 0; i < 32; i += 2) { + if (vehicle->peep[i] == SPRITE_INDEX_NULL) { + continue; + } + + rct_peep * peep = GET_PEEP(vehicle->peep[i]); + if (peep->state != PEEP_STATE_ON_RIDE) { + continue; + } + + int frameNum = (vehicle->vehicle_sprite_type + i * 4) % 128; + imageColourFlags = vehicle->peep_tshirt_colours[i] << 19 | vehicle->peep_tshirt_colours[i + 1] << 24 | 0xA0000000; + imageId = (baseImageId + 32 + direction * 128 + frameNum) | imageColourFlags; + sub_98199C(imageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x, boundBox.offset_y, height, get_current_rotation()); + } + } + + imageId = (22150 + (direction & 1) * 2 + 1) | RCT2_GLOBAL(0x00F44198, uint32); + sub_98199C(imageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x, boundBox.offset_y, height, get_current_rotation()); + + RCT2_GLOBAL(0x009DE578, rct_map_element*) = savedMapElement; + RCT2_GLOBAL(RCT2_ADDRESS_PAINT_SETUP_CURRENT_TYPE, uint8) = VIEWPORT_INTERACTION_ITEM_RIDE; +} + + +/** + * rct2: 0x008A8EC4 + */ +static void paint_ferris_wheel(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + uint8 relativeTrackSequence = track_map_1x4[direction][trackSequence]; + + int edges; + if (direction & 1) { + edges = edges_1x4_nw_se[relativeTrackSequence]; + } else { + edges = edges_1x4_ne_sw[relativeTrackSequence]; + } + + 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), NULL); + + track_paint_util_paint_floor(edges, RCT2_GLOBAL(0x00F44198, uint32), height, floorSpritesCork, get_current_rotation()); + + uint32 imageId; + uint8 rotation = get_current_rotation(); + uint32 colourFlags = RCT2_GLOBAL(0x00F441A0, uint32); + if (edges & EDGE_NW && track_paint_util_has_fence(EDGE_NW, position, mapElement, ride, rotation)) { + imageId = SPR_FENCE_ROPE_NW | colourFlags; + sub_98199C(imageId, 0, 0, 32, 1, 7, height, 0, 2, height + 2, rotation); + } + if (edges & EDGE_NE && track_paint_util_has_fence(EDGE_NE, position, mapElement, ride, rotation)) { + imageId = SPR_FENCE_ROPE_NE | colourFlags; + sub_98199C(imageId, 0, 0, 1, 32, 7, height, 2, 0, height + 2, rotation); + } + if (edges & EDGE_SE && track_paint_util_has_fence(EDGE_SE, position, mapElement, ride, rotation)) { + // Bound box is slightly different from track_paint_util_paint_fences + imageId = SPR_FENCE_ROPE_SE | colourFlags; + sub_98197C(imageId, 0, 0, 28, 1, 7, height, 0, 29, height + 3, rotation); + } + if (edges & EDGE_SW && track_paint_util_has_fence(EDGE_SW, position, mapElement, ride, rotation)) { + imageId = SPR_FENCE_ROPE_SW | colourFlags; + sub_98197C(imageId, 0, 0, 1, 32, 7, height, 30, 0, height + 2, rotation); + } + + switch (relativeTrackSequence) { + case 1: paint_ferris_wheel_structure(rideIndex, rotation, 48, height); break; + case 2: paint_ferris_wheel_structure(rideIndex, rotation, 16, height); break; + case 0: paint_ferris_wheel_structure(rideIndex, rotation, -16, height); break; + case 3: paint_ferris_wheel_structure(rideIndex, rotation, -48, height); break; + } + + paint_util_set_segment_support_height(SEGMENTS_ALL, 0xFFFF, 0); + paint_util_set_general_support_height(height + 176, 0x20); +} + +/** + * rct2: 0x008A8CC8 + */ +TRACK_PAINT_FUNCTION get_track_paint_function_ferris_wheel(int trackType, int direction) +{ + if (trackType != 122) { + return NULL; + } + + return paint_ferris_wheel; +} \ No newline at end of file diff --git a/src/ride/track_data.c b/src/ride/track_data.c index 50f5d7f03f..d36aca2b93 100644 --- a/src/ride/track_data.c +++ b/src/ride/track_data.c @@ -5504,7 +5504,7 @@ const uint32 RideTypeTrackPaintFunctionsOld[91] = { 0, // RIDE_TYPE_22 0, // RIDE_TYPE_INFORMATION_KIOSK 0, // RIDE_TYPE_TOILETS - 0x008A8CC8, // RIDE_TYPE_FERRIS_WHEEL + 0, // RIDE_TYPE_FERRIS_WHEEL 0x00763520, // RIDE_TYPE_MOTION_SIMULATOR 0, // RIDE_TYPE_3D_CINEMA 0, // RIDE_TYPE_TOP_SPIN @@ -5599,7 +5599,7 @@ const TRACK_PAINT_FUNCTION_GETTER RideTypeTrackPaintFunctions[91] = { get_track_paint_function_shop, // RIDE_TYPE_22 get_track_paint_function_shop, // RIDE_TYPE_INFORMATION_KIOSK get_track_paint_function_facility, // RIDE_TYPE_TOILETS - 0, // RIDE_TYPE_FERRIS_WHEEL + get_track_paint_function_ferris_wheel, // RIDE_TYPE_FERRIS_WHEEL 0, // RIDE_TYPE_MOTION_SIMULATOR get_track_paint_function_3d_cinema, // RIDE_TYPE_3D_CINEMA get_track_paint_function_topspin, // RIDE_TYPE_TOP_SPIN diff --git a/src/ride/track_paint.c b/src/ride/track_paint.c index 5e5d46ab4c..019f967de0 100644 --- a/src/ride/track_paint.c +++ b/src/ride/track_paint.c @@ -178,21 +178,21 @@ void track_paint_util_paint_fences(uint8 edges, rct_xy16 position, rct_map_eleme { uint32 imageId; - if (edges & EDGE_NW && track_paint_util_has_fence(EDGE_NW, position, mapElement, ride, get_current_rotation())) { + if (edges & EDGE_NW && track_paint_util_has_fence(EDGE_NW, position, mapElement, ride, rotation)) { imageId = fenceSprites[3] | colourFlags; - sub_98199C(imageId, 0, 0, 32, 1, 7, height, 0, 2, height + 2, get_current_rotation()); + sub_98199C(imageId, 0, 0, 32, 1, 7, height, 0, 2, height + 2, rotation); } - if (edges & EDGE_NE && track_paint_util_has_fence(EDGE_NE, position, mapElement, ride, get_current_rotation())) { + if (edges & EDGE_NE && track_paint_util_has_fence(EDGE_NE, position, mapElement, ride, rotation)) { imageId = fenceSprites[0] | colourFlags; - sub_98199C(imageId, 0, 0, 1, 32, 7, height, 2, 0, height + 2, get_current_rotation()); + sub_98199C(imageId, 0, 0, 1, 32, 7, height, 2, 0, height + 2, rotation); } - if (edges & EDGE_SW && track_paint_util_has_fence(EDGE_SW, position, mapElement, ride, get_current_rotation())) { - imageId = fenceSprites[2] | colourFlags; - sub_98197C(imageId, 0, 0, 1, 32, 7, height, 30, 0, height + 2, get_current_rotation()); - } - if (edges & EDGE_SE && track_paint_util_has_fence(EDGE_SE, position, mapElement, ride, get_current_rotation())) { + if (edges & EDGE_SE && track_paint_util_has_fence(EDGE_SE, position, mapElement, ride, rotation)) { imageId = fenceSprites[1] | colourFlags; - sub_98197C(imageId, 0, 0, 32, 1, 7, height, 0, 30, height + 2, get_current_rotation()); + sub_98197C(imageId, 0, 0, 32, 1, 7, height, 0, 30, height + 2, rotation); + } + if (edges & EDGE_SW && track_paint_util_has_fence(EDGE_SW, position, mapElement, ride, rotation)) { + imageId = fenceSprites[2] | colourFlags; + sub_98197C(imageId, 0, 0, 1, 32, 7, height, 30, 0, height + 2, rotation); } } diff --git a/src/ride/track_paint.h b/src/ride/track_paint.h index a85bf455b0..43bc974a80 100644 --- a/src/ride/track_paint.h +++ b/src/ride/track_paint.h @@ -67,6 +67,7 @@ typedef TRACK_PAINT_FUNCTION (*TRACK_PAINT_FUNCTION_GETTER)(int trackType, int d TRACK_PAINT_FUNCTION get_track_paint_function_maze(int trackType, int direction); TRACK_PAINT_FUNCTION get_track_paint_function_spiral_slide(int trackType, int direction); TRACK_PAINT_FUNCTION get_track_paint_function_dodgems(int trackType, int direction); +TRACK_PAINT_FUNCTION get_track_paint_function_ferris_wheel(int trackType, int direction); TRACK_PAINT_FUNCTION get_track_paint_function_3d_cinema(int trackType, int direction); TRACK_PAINT_FUNCTION get_track_paint_function_topspin(int trackType, int direction); TRACK_PAINT_FUNCTION get_track_paint_function_shop(int trackType, int direction);