From 98e3eb059a8d28daf05111e59b6f8ea318432f1b Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Mon, 9 May 2016 08:44:07 +0200 Subject: [PATCH 1/6] Draw submarine ride track --- src/ride/track_data.c | 4 +- src/ride/track_paint.h | 1 + src/ride/water/submarine_ride.c | 427 +++++++++++++++++++++++++++++++- 3 files changed, 425 insertions(+), 7 deletions(-) diff --git a/src/ride/track_data.c b/src/ride/track_data.c index b64102aae5..68ed96fcbb 100644 --- a/src/ride/track_data.c +++ b/src/ride/track_data.c @@ -5545,7 +5545,7 @@ const uint32 RideTypeTrackPaintFunctionsOld[91] = { 0x008AF764, // RIDE_TYPE_AIR_POWERED_VERTICAL_COASTER 0x00890940, // RIDE_TYPE_INVERTED_HAIRPIN_COASTER 0x00898384, // RIDE_TYPE_MAGIC_CARPET - 0x008995D4, // RIDE_TYPE_SUBMARINE_RIDE + 0/*x008995D4*/, // RIDE_TYPE_SUBMARINE_RIDE 0x0089B0C0, // RIDE_TYPE_RIVER_RAFTS 0, // RIDE_TYPE_50 0x008A13B4, // RIDE_TYPE_ENTERPRISE @@ -5640,7 +5640,7 @@ const TRACK_PAINT_FUNCTION_GETTER RideTypeTrackPaintFunctions[91] = { 0, // RIDE_TYPE_AIR_POWERED_VERTICAL_COASTER 0, // RIDE_TYPE_INVERTED_HAIRPIN_COASTER 0, // RIDE_TYPE_MAGIC_CARPET - 0, // RIDE_TYPE_SUBMARINE_RIDE + get_track_paint_function_submarine_ride, // RIDE_TYPE_SUBMARINE_RIDE 0, // RIDE_TYPE_RIVER_RAFTS get_track_paint_function_shop, // RIDE_TYPE_50 0, // RIDE_TYPE_ENTERPRISE diff --git a/src/ride/track_paint.h b/src/ride/track_paint.h index d0a456b621..3744260c13 100644 --- a/src/ride/track_paint.h +++ b/src/ride/track_paint.h @@ -63,5 +63,6 @@ TRACK_PAINT_FUNCTION get_track_paint_function_facility(int trackType, int direct TRACK_PAINT_FUNCTION get_track_paint_function_circus_show(int trackType, int direction); TRACK_PAINT_FUNCTION get_track_paint_function_flying_saucers(int trackType, int direction); TRACK_PAINT_FUNCTION get_track_paint_function_crooked_house(int trackType, int direction); +TRACK_PAINT_FUNCTION get_track_paint_function_submarine_ride(int trackType, int direction); #endif diff --git a/src/ride/water/submarine_ride.c b/src/ride/water/submarine_ride.c index 0eb50a4f2f..3bec769823 100644 --- a/src/ride/water/submarine_ride.c +++ b/src/ride/water/submarine_ride.c @@ -14,12 +14,134 @@ *****************************************************************************/ #pragma endregion -#include "../../addresses.h" -#include "../../config.h" -#include "../../interface/viewport.h" -#include "../../world/sprite.h" -#include "../../paint/paint.h" +#include "../track_paint.h" +#include "../track.h" #include "../vehicle_paint.h" +#include "../../interface/viewport.h" +#include "../../paint/paint.h" +#include "../../paint/supports.h" + +enum +{ + SPR_MONORAIL_ELEM_FLAT_NE_SW = 23231, + SPR_MONORAIL_ELEM_FLAT_SE_NW = 23232, +} SPR_MONORAIL; + +enum +{ + SEGMENT_B4 = (1 << 0), + SEGMENT_0 = SEGMENT_B4, + SEGMENT_B8 = (1 << 1), + SEGMENT_1 = SEGMENT_B8, + SEGMENT_BC = (1 << 2), + SEGMENT_2 = SEGMENT_BC, + SEGMENT_C0 = (1 << 3), + SEGMENT_3 = SEGMENT_C0, + SEGMENT_C4 = (1 << 4), + SEGMENT_4 = SEGMENT_C4, + SEGMENT_C8 = (1 << 5), + SEGMENT_5 = SEGMENT_C8, + SEGMENT_CC = (1 << 6), + SEGMENT_6 = SEGMENT_CC, + SEGMENT_D0 = (1 << 7), + SEGMENT_7 = SEGMENT_D0, + SEGMENT_D4 = (1 << 8), + SEGMENT_8 = SEGMENT_D4, +}; + +const int SEGMENTS_ALL = SEGMENT_B4 | SEGMENT_B8 | SEGMENT_BC | SEGMENT_C0 | SEGMENT_C4 | SEGMENT_C8 | SEGMENT_CC | SEGMENT_D0 | SEGMENT_D4; + +const int segmentOffsets[9] = { + 1 << 0, // 0 -> 0 + 1 << 6, // 1 -> 6 + 1 << 2, // 2 -> 2 + 1 << 4, // 3 -> 4 + 0, // center is skipped + 1 << 7, + 1 << 1, + 1 << 5, + 1 << 3 +}; + +static uint16 segments_rotate(uint16 segments, uint8 rotation) +{ + uint8 temp = 0; + + for (int s = 0; s < 9; s++) { + if (segments & (1 << s)) { + temp |= segmentOffsets[s]; + } + } + + temp = ror8(temp, rotation * 2); + + uint16 out = 0; + + for (int s = 0; s < 9; s++) { + if (temp & segmentOffsets[s]) { + out |= (1 << s); + } + } + + if (segments & SEGMENT_4) { + out |= SEGMENT_4; + } + + return out; +} + +static void paint_util_set_segment_support_height(int flags, uint16 height, uint8 segment_flags) +{ + for (int s = 0; s < 9; s++) { + if (flags & (1 << s)) { + RCT2_GLOBAL(0x0141E9B4 + s * 4, uint16) = height; + RCT2_GLOBAL(0x0141E9B6 + s * 4, uint8) = segment_flags; + } + } +} + +static void paint_util_set_support_height(uint16 height, uint8 flags) +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PAINT_TILE_MAX_HEIGHT, sint16) < height) { + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PAINT_TILE_MAX_HEIGHT, sint16) = height; + RCT2_GLOBAL(0x141E9DA, uint8) = flags; + } +} + +enum +{ + TUNNEL_0, + TUNNEL_FLAT = 6, + TUNNEL_7 = 7, + TUNNEL_UP = 8, + TUNNEL_14 = 0x0E +}; + +static void paint_util_push_tunnel_left(uint16 height, uint8 type) +{ + uint32 eax = 0xFFFF0000 | ((height / 16) & 0xFF) | type << 8; + RCT2_ADDRESS(0x009E3138, uint32)[RCT2_GLOBAL(0x141F56A, uint8) / 2] = eax; + RCT2_GLOBAL(0x141F56A, uint8)++; +} + +static void paint_util_push_tunnel_right(uint16 height, uint8 type) +{ + uint32 eax = 0xFFFF0000 | ((height / 16) & 0xFF) | type << 8; + RCT2_ADDRESS(0x009E30B6, uint32)[RCT2_GLOBAL(0x141F56B, uint8) / 2] = eax; + RCT2_GLOBAL(0x141F56B, uint8)++; +} + +/* Supports are only placed every 2 tiles for flat pieces*/ +bool paint_util_should_paint_supports(rct_xy16 position) +{ + if ((position.x & (1 << 5)) == (position.y & (1 << 5))) + return true; + + if ((!(position.x & (1 << 5))) && (!(position.y & (1 << 5)))) + return true; + + return false; +} /** * @@ -64,3 +186,298 @@ void vehicle_visual_submarine(int x, int imageDirection, int y, int z, rct_vehic assert(vehicleEntry->effect_visual == 1); } + +enum +{ + SPR_SUBMARINE_RIDE_FLAT_NE_SW = 16870, + SPR_SUBMARINE_RIDE_FLAT_SE_NW = 16871, + + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SW_SE_PART_0 = 16872, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SW_SE_PART_1 = 16873, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SW_SE_PART_2 = 16874, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NW_SW_PART_0 = 16875, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NW_SW_PART_1 = 16876, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NW_SW_PART_2 = 16877, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NE_NW_PART_0 = 16878, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NE_NW_PART_1 = 16879, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NE_NW_PART_2 = 16880, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SE_NE_PART_0 = 16881, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SE_NE_PART_1 = 16882, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SE_NE_PART_2 = 16883, + + SPR_SUBMARINE_RIDE_FLAT_TO_25_DEG_UP_SW_NE, + SPR_SUBMARINE_RIDE_FLAT_TO_25_DEG_UP_NW_SE, + SPR_SUBMARINE_RIDE_FLAT_TO_25_DEG_UP_NE_SW, + SPR_SUBMARINE_RIDE_FLAT_TO_25_DEG_UP_SE_NW, + + SPR_SUBMARINE_RIDE_25_DEG_UP_TO_FLAT_SW_NE, + SPR_SUBMARINE_RIDE_25_DEG_UP_TO_FLAT_NW_SE, + SPR_SUBMARINE_RIDE_25_DEG_UP_TO_FLAT_NE_SW, + SPR_SUBMARINE_RIDE_25_DEG_UP_TO_FLAT_SE_NW, + + SPR_SUBMARINE_RIDE_25_DEG_UP_SW_NE, + SPR_SUBMARINE_RIDE_25_DEG_UP_NW_SE, + SPR_SUBMARINE_RIDE_25_DEG_UP_NE_SW, + SPR_SUBMARINE_RIDE_25_DEG_UP_SE_NW, + + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_SW_NW = 16896, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_NW_NE = 16897, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_NE_SE = 16898, + SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_SE_SW = 16899, +}; + +static void submarine_ride_paint_track_station(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + rct_xy16 position = {RCT2_GLOBAL(0x009DE56A, sint16), RCT2_GLOBAL(0x009DE56E, sint16)}; + int heightLower = height - 16; + uint32 imageId; +} + +static void submarine_ride_paint_track_flat(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + rct_xy16 position = {RCT2_GLOBAL(0x009DE56A, sint16), RCT2_GLOBAL(0x009DE56E, sint16)}; + int heightLower = height - 16; + uint32 imageId; + + if (direction & 1) { + imageId = SPR_SUBMARINE_RIDE_FLAT_SE_NW | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 20, 32, 3, heightLower, 6, 0, heightLower, get_current_rotation()); + paint_util_push_tunnel_right(heightLower, TUNNEL_0); + } else { + imageId = SPR_SUBMARINE_RIDE_FLAT_NE_SW | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 32, 20, 3, heightLower, 0, 6, heightLower, get_current_rotation()); + paint_util_push_tunnel_left(heightLower, TUNNEL_0); + } + + if (paint_util_should_paint_supports(position)) { + metal_a_supports_paint_setup((direction & 1) ? 4 : 5, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + } + + paint_util_set_segment_support_height(segments_rotate(SEGMENT_D0 | SEGMENT_C4 | SEGMENT_CC, direction), 0xFFFF, 0); + paint_util_set_support_height(height + 16, 0x20); +} + +static void submarine_ride_paint_track_quarter_turn_3_tiles_nw_sw(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + int heightLower = height - 16; + uint32 imageId; + + switch (trackSequence) { + case 0: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NW_SW_PART_2 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 32, 20, 3, heightLower, 0, 6, heightLower, get_current_rotation()); + + paint_util_push_tunnel_right(heightLower, TUNNEL_0); + metal_a_supports_paint_setup(4, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + paint_util_set_segment_support_height(SEGMENT_D0 | SEGMENT_C4 | SEGMENT_CC | SEGMENT_B4, 0xFFFF, 0); + break; + case 1: + break; + case 2: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NW_SW_PART_1 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 16, 16, 3, heightLower, 16, 0, heightLower, get_current_rotation()); + + paint_util_set_segment_support_height(SEGMENT_C8 | SEGMENT_C4 | SEGMENT_D0 | SEGMENT_B8, 0xFFFF, 0); + break; + case 3: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NW_SW_PART_0 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 20, 32, 3, heightLower, 6, 0, heightLower, get_current_rotation()); + + metal_a_supports_paint_setup(4, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + paint_util_set_segment_support_height(SEGMENT_C8 | SEGMENT_C4 | SEGMENT_D4 | SEGMENT_C0, 0xFFFF, 0); + break; + } + + paint_util_set_support_height(height + 16, 0x20); +} + +static void submarine_ride_paint_track_quarter_turn_3_tiles_ne_nw(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + int heightLower = height - 16; + uint32 imageId; + + switch (trackSequence) { + case 0: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NE_NW_PART_2 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 20, 32, 3, heightLower, 6, 0, heightLower, get_current_rotation()); + + metal_a_supports_paint_setup(4, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + paint_util_set_segment_support_height(SEGMENT_C8 | SEGMENT_C4 | SEGMENT_D4 | SEGMENT_BC, 0xFFFF, 0); + break; + case 1: + break; + case 2: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NE_NW_PART_1 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 16, 16, 3, heightLower, 0, 0, heightLower, get_current_rotation()); + + paint_util_set_segment_support_height(SEGMENT_B4 | SEGMENT_C4 | SEGMENT_CC | SEGMENT_C8, 0xFFFF, 0); + break; + case 3: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_NE_NW_PART_0 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 32, 20, 3, heightLower, 0, 6, heightLower, get_current_rotation()); + + metal_a_supports_paint_setup(4, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + paint_util_set_segment_support_height(SEGMENT_D0 | SEGMENT_C4 | SEGMENT_CC | SEGMENT_B8, 0xFFFF, 0); + break; + } + + paint_util_set_support_height(height + 16, 0x20); +} + +static void submarine_ride_paint_track_quarter_turn_3_tiles_se_ne(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + int heightLower = height - 16; + uint32 imageId; + + switch (trackSequence) { + case 0: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SE_NE_PART_2 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 32, 20, 3, heightLower, 0, 6, heightLower, get_current_rotation()); + + metal_a_supports_paint_setup(4, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + paint_util_set_segment_support_height(SEGMENT_CC | SEGMENT_C4 | SEGMENT_D0 | SEGMENT_C0, 0xFFFF, 0); + break; + case 1: + break; + case 2: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SE_NE_PART_1 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 16, 16, 3, heightLower, 0, 16, heightLower, get_current_rotation()); + + paint_util_set_segment_support_height(SEGMENT_CC | SEGMENT_C4 | SEGMENT_D4 | SEGMENT_BC, 0xFFFF, 0); + break; + case 3: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SE_NE_PART_0 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 20, 32, 3, heightLower, 6, 0, heightLower, get_current_rotation()); + + metal_a_supports_paint_setup(4, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + paint_util_set_segment_support_height(SEGMENT_D0 | SEGMENT_C4 | SEGMENT_CC | SEGMENT_BC, 0xFFFF, 0); + paint_util_push_tunnel_left(heightLower, TUNNEL_0); + break; + } + + paint_util_set_support_height(height + 16, 0x20); +} + +static void submarine_ride_paint_track_quarter_turn_3_tiles_sw_se(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + int heightLower = height - 16; + uint32 imageId; + + switch (trackSequence) { + case 0: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SW_SE_PART_2 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 20, 32, 3, heightLower, 6, 0, heightLower, get_current_rotation()); + + metal_a_supports_paint_setup(4, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + paint_util_set_segment_support_height(SEGMENT_D4 | SEGMENT_C4 | SEGMENT_C8 | SEGMENT_B8, 0xFFFF, 0); + paint_util_push_tunnel_right(heightLower, TUNNEL_0); + break; + case 1: + break; + case 2: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SW_SE_PART_1 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 16, 16, 3, heightLower, 16, 16, heightLower, get_current_rotation()); + + paint_util_set_segment_support_height(SEGMENT_D0 | SEGMENT_C4 | SEGMENT_D4 | SEGMENT_C0, 0xFFFF, 0); + break; + case 3: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_3_TILES_SW_SE_PART_0 | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 32, 20, 3, heightLower, 0, 6, heightLower, get_current_rotation()); + + metal_a_supports_paint_setup(4, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); + paint_util_set_segment_support_height(SEGMENT_D0 | SEGMENT_C4 | SEGMENT_D4 | SEGMENT_B4, 0xFFFF, 0); + break; + } + + paint_util_set_support_height(height + 16, 0x20); +} + +static void submarine_ride_paint_track_left_quarter_turn_3_tiles(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + switch (direction) { + case 0: + submarine_ride_paint_track_quarter_turn_3_tiles_nw_sw(rideIndex, trackSequence, direction, height, mapElement); + break; + case 1: + submarine_ride_paint_track_quarter_turn_3_tiles_ne_nw(rideIndex, trackSequence, direction, height, mapElement); + break; + case 2: + submarine_ride_paint_track_quarter_turn_3_tiles_se_ne(rideIndex, trackSequence, direction, height, mapElement); + break; + case 3: + submarine_ride_paint_track_quarter_turn_3_tiles_sw_se(rideIndex, trackSequence, direction, height, mapElement); + break; + } +} + +uint8 right_quarter_turn_3_tiles_to_left_turn_map[] = {3, 1, 2, 0}; +static void submarine_ride_paint_track_right_quarter_turn_3_tiles(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + trackSequence = right_quarter_turn_3_tiles_to_left_turn_map[trackSequence]; + return submarine_ride_paint_track_left_quarter_turn_3_tiles(rideIndex, trackSequence, (direction + 3) % 4, height, mapElement); +} + +static void submarine_ride_paint_track_left_quarter_turn_1_tile(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + int heightLower = height - 16; + uint32 imageId; + + switch (direction) { + case 0: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_SW_NW | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 26, 24, 1, heightLower, 6, 2, heightLower, get_current_rotation()); + paint_util_push_tunnel_left(heightLower, TUNNEL_0); + break; + case 1: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_NW_NE | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 26, 26, 1, heightLower, 0, 0, heightLower, get_current_rotation()); + break; + case 2: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_NE_SE | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 24, 26, 1, heightLower, 2, 6, heightLower, get_current_rotation()); + paint_util_push_tunnel_right(heightLower, TUNNEL_0); + break; + case 3: + imageId = SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_SE_SW | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 24, 24, 1, heightLower, 6, 6, heightLower, get_current_rotation()); + paint_util_push_tunnel_right(heightLower, TUNNEL_0); + paint_util_push_tunnel_left(heightLower, TUNNEL_0); + break; + } + + paint_util_set_segment_support_height(segments_rotate(SEGMENT_B8 | SEGMENT_C8 | SEGMENT_C4 | SEGMENT_D0, direction), 0xFFFF, 0); + paint_util_set_support_height(height + 16, 0x20); +} + +static void submarine_ride_paint_track_right_quarter_turn_1_tile(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) +{ + submarine_ride_paint_track_left_quarter_turn_1_tile(rideIndex, trackSequence, (direction + 3) % 4, height, mapElement); +} + +/** + * rct2: 0x008995D4 + */ +TRACK_PAINT_FUNCTION get_track_paint_function_submarine_ride(int trackType, int direction) +{ + switch (trackType) { + case TRACK_ELEM_BEGIN_STATION: + case TRACK_ELEM_MIDDLE_STATION: + case TRACK_ELEM_END_STATION: + return submarine_ride_paint_track_station; + + case TRACK_ELEM_FLAT: + return submarine_ride_paint_track_flat; + + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES: + return submarine_ride_paint_track_left_quarter_turn_3_tiles; + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES: + return submarine_ride_paint_track_right_quarter_turn_3_tiles; + + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE: + return submarine_ride_paint_track_left_quarter_turn_1_tile; + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE: + return submarine_ride_paint_track_right_quarter_turn_1_tile; + } + + return NULL; +} From b07349eae35791a1761485ad5b75836f0405f268 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Mon, 9 May 2016 09:29:23 +0200 Subject: [PATCH 2/6] Draw ride pier --- src/ride/water/submarine_ride.c | 183 ++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/src/ride/water/submarine_ride.c b/src/ride/water/submarine_ride.c index 3bec769823..114c3669e4 100644 --- a/src/ride/water/submarine_ride.c +++ b/src/ride/water/submarine_ride.c @@ -20,6 +20,7 @@ #include "../../interface/viewport.h" #include "../../paint/paint.h" #include "../../paint/supports.h" +#include "../ride_data.h" enum { @@ -143,6 +144,125 @@ bool paint_util_should_paint_supports(rct_xy16 position) return false; } + +/* 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}, +}; + +typedef enum EDGE +{ + EDGE_NE, + EDGE_SE, + EDGE_SW, + EDGE_NW +} EDGE; + +static bool paint_util_has_fence(EDGE edge, rct_xy16 position, rct_map_element * mapElement, rct_ride * ride, uint8 rotation) +{ + rct_xy16 offset; + switch (edge) { + case EDGE_NE: + offset = loc_7667AC[rotation]; + break; + case EDGE_SE: + offset = loc_7667AE[(rotation + 2) & 3]; + break; + case EDGE_SW: + offset = loc_7667AC[(rotation + 2) & 3]; + break; + case EDGE_NW: + offset = loc_7667AE[rotation]; + break; + }; + + uint16 entranceLoc = + ((position.x / 32) + offset.x) | + (((position.y / 32) + offset.y) << 8); + + uint8 entranceId = (mapElement->properties.track.sequence & 0x70) >> 4; + + return (ride->entrances[entranceId] != entranceLoc && ride->exits[entranceId] != entranceLoc); +} + +enum +{ + SPR_STATION_COVER_OFFSET_NE_SW_BACK_0 = 0, + SPR_STATION_COVER_OFFSET_NE_SW_BACK_1, + SPR_STATION_COVER_OFFSET_NE_SW_FRONT, + SPR_STATION_COVER_OFFSET_SE_NW_BACK_0, + SPR_STATION_COVER_OFFSET_SE_NW_BACK_1, + SPR_STATION_COVER_OFFSET_SE_NW_FRONT, + SPR_STATION_COVER_OFFSET_HIGH +} SPR_STATION_COVER; + +static bool paint_util_draw_station_covers(EDGE edge, bool hasFence, const rct_ride_entrance_definition * entranceStyle, uint8 direction, uint16 height) +{ + uint32 imageId; + uint32 baseImageId = entranceStyle->flags; + int imageOffset; + rct_xyz16 offset, bounds, boundsOffset; + + offset = (rct_xyz16) {0, 0, height}; + switch (edge) { + case EDGE_NE: + bounds = (rct_xyz16) {1, 30, 0}; + boundsOffset = (rct_xyz16) {0, 1, height + 1}; + imageOffset = hasFence ? SPR_STATION_COVER_OFFSET_SE_NW_BACK_1 : SPR_STATION_COVER_OFFSET_SE_NW_BACK_0; + break; + case EDGE_SE: + bounds = (rct_xyz16) {32, 32, 0}; + boundsOffset = (rct_xyz16) {1, 0, height + 31}; + imageOffset = SPR_STATION_COVER_OFFSET_NE_SW_FRONT; + break; + case EDGE_SW: + bounds = (rct_xyz16) {32, 32, 0}; + boundsOffset = (rct_xyz16) {0, 0, height + 31}; + imageOffset = SPR_STATION_COVER_OFFSET_SE_NW_FRONT; + break; + case EDGE_NW: + bounds = (rct_xyz16) {30, 1, 30}; + boundsOffset = (rct_xyz16) {1, 0, height + 1}; + imageOffset = hasFence ? SPR_STATION_COVER_OFFSET_NE_SW_BACK_1 : SPR_STATION_COVER_OFFSET_NE_SW_BACK_0; + break; + } + + if (RCT2_GLOBAL(0x00F441A0, uint32) != 0x20000000) { + baseImageId &= 0x7FFFF; + } + + if (baseImageId <= 0x20) { + return false; + } + + if (baseImageId & 0x40000000) { + imageId = (baseImageId & 0xBFFFFFFF) + imageOffset; + sub_98197C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); + + uint32 edi = RCT2_GLOBAL(0x00F44198, uint32) & (0b11111 << 19); + + // weird jump + imageId = (baseImageId | edi) + 0x3800000 + imageOffset + 12; + sub_98199C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); + return true; + } + + imageId = (baseImageId + imageOffset) | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); + return true; +} + /** * * rct2: 0x006D44D5 @@ -226,11 +346,74 @@ enum SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_SE_SW = 16899, }; +enum +{ + SPR_STATION_PIER_EDGE_SE = 22404, + SPR_STATION_PIER_EDGE_SW = 22405, + SPR_STATION_PIER_EDGE_NW = 22406, + SPR_STATION_PIER_EDGE_NE = 22407, + SPR_STATION_PIER_EDGE_NW_FENCED = 22408, + SPR_STATION_PIER_EDGE_NE_FENCED = 22409, + SPR_STATION_PIER_FENCE_SE = 22410, + SPR_STATION_PIER_FENCE_SW = 22411, +}; + static void submarine_ride_paint_track_station(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) { rct_xy16 position = {RCT2_GLOBAL(0x009DE56A, sint16), RCT2_GLOBAL(0x009DE56E, sint16)}; + rct_ride * ride = get_ride(rideIndex); + const rct_ride_entrance_definition * entranceStyle = &RideEntranceDefinitions[ride->entrance_style]; int heightLower = height - 16; uint32 imageId; + bool hasFence; + + if (direction & 1) { + imageId = SPR_SUBMARINE_RIDE_FLAT_SE_NW | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 20, 32, 3, heightLower, 6, 0, heightLower, get_current_rotation()); + paint_util_push_tunnel_right(height, TUNNEL_FLAT); + + hasFence = paint_util_has_fence(EDGE_NE, position, mapElement, ride, get_current_rotation()); + imageId = (hasFence ? SPR_STATION_PIER_EDGE_NE_FENCED : SPR_STATION_PIER_EDGE_NE) | RCT2_GLOBAL(0x00F4419C, uint32); + sub_98197C(imageId, 0, 0, 6, 32, 1, height, 2, 0, height, get_current_rotation()); + paint_util_draw_station_covers(EDGE_NE, hasFence, entranceStyle, direction, height); + + imageId = SPR_STATION_PIER_EDGE_SW | RCT2_GLOBAL(0x00F4419C, uint32); + sub_98196C(imageId, 24, 0, 8, 32, 1, height, get_current_rotation()); + + if (RCT2_GLOBAL(0x0141E9DB, uint8) & 3) { + hasFence = paint_util_has_fence(EDGE_SW, position, mapElement, ride, get_current_rotation()); + if (hasFence) { + imageId = SPR_STATION_PIER_FENCE_SW | RCT2_GLOBAL(0x00F4419C, uint32); + sub_98196C(imageId, 31, 0, 1, 32, 7, height + 2, get_current_rotation()); + } + paint_util_draw_station_covers(EDGE_SW, hasFence, entranceStyle, direction, height); + } + + } else { + imageId = SPR_SUBMARINE_RIDE_FLAT_NE_SW | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, 0, 0, 32, 20, 3, heightLower, 0, 6, heightLower, get_current_rotation()); + paint_util_push_tunnel_left(height, TUNNEL_FLAT); + + hasFence = paint_util_has_fence(EDGE_NW, position, mapElement, ride, get_current_rotation()); + imageId = (hasFence ? SPR_STATION_PIER_EDGE_NW_FENCED : SPR_STATION_PIER_EDGE_NW) | RCT2_GLOBAL(0x00F4419C, uint32); + sub_98197C(imageId, 0, 0, 32, 6, 1, height, 0, 2, height, get_current_rotation()); + paint_util_draw_station_covers(EDGE_NW, hasFence, entranceStyle, direction, height); + + imageId = SPR_STATION_PIER_EDGE_SE | RCT2_GLOBAL(0x00F4419C, uint32); + sub_98196C(imageId, 0, 24, 32, 8, 1, height, get_current_rotation()); + + if (RCT2_GLOBAL(0x0141E9DB, uint8) & 3) { + hasFence = paint_util_has_fence(EDGE_SE, position, mapElement, ride, get_current_rotation()); + if (hasFence) { + imageId = SPR_STATION_PIER_FENCE_SE | RCT2_GLOBAL(0x00F4419C, uint32); + sub_98196C(imageId, 0, 31, 32, 1, 7, height + 2, get_current_rotation()); + } + paint_util_draw_station_covers(EDGE_SE, hasFence, entranceStyle, direction, height); + } + } + + paint_util_set_segment_support_height(SEGMENTS_ALL, 0xFFFF, 0); + paint_util_set_support_height(height + 32, 0x20); } static void submarine_ride_paint_track_flat(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) From c863174814ba48bda25acc7671ec3e5090054a29 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Mon, 9 May 2016 09:32:22 +0200 Subject: [PATCH 3/6] [fixup] remove monorail stuff --- src/ride/water/submarine_ride.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ride/water/submarine_ride.c b/src/ride/water/submarine_ride.c index 114c3669e4..1b502c077b 100644 --- a/src/ride/water/submarine_ride.c +++ b/src/ride/water/submarine_ride.c @@ -22,12 +22,6 @@ #include "../../paint/supports.h" #include "../ride_data.h" -enum -{ - SPR_MONORAIL_ELEM_FLAT_NE_SW = 23231, - SPR_MONORAIL_ELEM_FLAT_SE_NW = 23232, -} SPR_MONORAIL; - enum { SEGMENT_B4 = (1 << 0), From 9bcc0d05ed00fc6573a44c872b0696bf3e4db9df Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Wed, 18 May 2016 00:44:44 +0200 Subject: [PATCH 4/6] Rebase branch --- src/paint/map_element/map_element.c | 10 +- src/paint/map_element/map_element.h | 2 + src/ride/track_paint.c | 78 ++++++++ src/ride/track_paint.h | 12 ++ src/ride/water/submarine_ride.c | 287 ++-------------------------- 5 files changed, 121 insertions(+), 268 deletions(-) diff --git a/src/paint/map_element/map_element.c b/src/paint/map_element/map_element.c index deba3a7c1b..511ec4c36b 100644 --- a/src/paint/map_element/map_element.c +++ b/src/paint/map_element/map_element.c @@ -314,4 +314,12 @@ void paint_util_set_segment_support_height(int segments, uint16 height, uint8 sl } } } -} \ No newline at end of file +} + +uint16 paint_util_rotate_segments(uint16 segments, uint8 rotation) +{ + uint8 temp = segments & 0xFF; + temp = rol8(temp, rotation * 2); + + return (segments & 0xFF00) | temp; +} diff --git a/src/paint/map_element/map_element.h b/src/paint/map_element/map_element.h index f129a3ccdf..0e13cf8d72 100644 --- a/src/paint/map_element/map_element.h +++ b/src/paint/map_element/map_element.h @@ -49,6 +49,7 @@ extern const int SEGMENTS_ALL; enum { + TUNNEL_0 = 0, TUNNEL_6 = 6, }; @@ -58,6 +59,7 @@ void paint_util_push_tunnel_right(uint16 height, uint8 type); void paint_util_set_general_support_height(sint16 height, uint8 slope); void paint_util_force_set_general_support_height(sint16 height, uint8 slope); void paint_util_set_segment_support_height(int segments, uint16 height, uint8 slope); +uint16 paint_util_rotate_segments(uint16 segments, uint8 rotation); void map_element_paint_setup(int x, int y); diff --git a/src/ride/track_paint.c b/src/ride/track_paint.c index 09ef4ab715..c64e5494cf 100644 --- a/src/ride/track_paint.c +++ b/src/ride/track_paint.c @@ -119,6 +119,17 @@ const uint32 fenceSpritesRope[] = { SPR_FENCE_ROPE_NW }; +enum +{ + SPR_STATION_COVER_OFFSET_NE_SW_BACK_0 = 0, + SPR_STATION_COVER_OFFSET_NE_SW_BACK_1, + SPR_STATION_COVER_OFFSET_NE_SW_FRONT, + SPR_STATION_COVER_OFFSET_SE_NW_BACK_0, + SPR_STATION_COVER_OFFSET_SE_NW_BACK_1, + SPR_STATION_COVER_OFFSET_SE_NW_FRONT, + SPR_STATION_COVER_OFFSET_HIGH +}; + bool track_paint_util_has_fence(enum edge edge, rct_xy16 position, rct_map_element * mapElement, rct_ride * ride, uint8 rotation) { rct_xy16 offset; @@ -185,6 +196,73 @@ void track_paint_util_paint_fences(uint8 edges, rct_xy16 position, rct_map_eleme } } +/* Supports are only placed every 2 tiles for flat pieces*/ +bool track_paint_util_should_paint_supports(rct_xy16 position) +{ + if ((position.x & (1 << 5)) == (position.y & (1 << 5))) + return true; + + if ((!(position.x & (1 << 5))) && (!(position.y & (1 << 5)))) + return true; + + return false; +} + +bool track_paint_util_draw_station_covers(enum edge edge, bool hasFence, const rct_ride_entrance_definition * entranceStyle, uint8 direction, uint16 height) +{ + uint32 imageId; + uint32 baseImageId = entranceStyle->flags; + int imageOffset; + rct_xyz16 offset, bounds, boundsOffset; + + offset = (rct_xyz16) {0, 0, height}; + switch (edge) { + case EDGE_NE: + bounds = (rct_xyz16) {1, 30, 0}; + boundsOffset = (rct_xyz16) {0, 1, height + 1}; + imageOffset = hasFence ? SPR_STATION_COVER_OFFSET_SE_NW_BACK_1 : SPR_STATION_COVER_OFFSET_SE_NW_BACK_0; + break; + case EDGE_SE: + bounds = (rct_xyz16) {32, 32, 0}; + boundsOffset = (rct_xyz16) {1, 0, height + 31}; + imageOffset = SPR_STATION_COVER_OFFSET_NE_SW_FRONT; + break; + case EDGE_SW: + bounds = (rct_xyz16) {32, 32, 0}; + boundsOffset = (rct_xyz16) {0, 0, height + 31}; + imageOffset = SPR_STATION_COVER_OFFSET_SE_NW_FRONT; + break; + case EDGE_NW: + bounds = (rct_xyz16) {30, 1, 30}; + boundsOffset = (rct_xyz16) {1, 0, height + 1}; + imageOffset = hasFence ? SPR_STATION_COVER_OFFSET_NE_SW_BACK_1 : SPR_STATION_COVER_OFFSET_NE_SW_BACK_0; + break; + } + + if (RCT2_GLOBAL(0x00F441A0, uint32) != 0x20000000) { + baseImageId &= 0x7FFFF; + } + + if (baseImageId <= 0x20) { + return false; + } + + if (baseImageId & 0x40000000) { + imageId = (baseImageId & 0xBFFFFFFF) + imageOffset; + sub_98197C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); + + uint32 edi = RCT2_GLOBAL(0x00F44198, uint32) & (0b11111 << 19); + + // weird jump + imageId = (baseImageId | edi) + 0x3800000 + imageOffset + 12; + sub_98199C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); + return true; + } + + imageId = (baseImageId + imageOffset) | RCT2_GLOBAL(0x00F44198, uint32); + sub_98197C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); + return true; +} /** * diff --git a/src/ride/track_paint.h b/src/ride/track_paint.h index 3744260c13..3d37da77f9 100644 --- a/src/ride/track_paint.h +++ b/src/ride/track_paint.h @@ -17,6 +17,7 @@ #ifndef _TRACK_PAINT_H #define _TRACK_PAINT_H +#include "ride_data.h" #include "../common.h" #include "../world/map.h" #include "../paint/map_element/map_element.h" @@ -39,6 +40,15 @@ enum { SPR_FENCE_ROPE_SE = 22139, SPR_FENCE_ROPE_SW = 22140, SPR_FENCE_ROPE_NW = 22141, + + SPR_STATION_PIER_EDGE_SE = 22404, + SPR_STATION_PIER_EDGE_SW = 22405, + SPR_STATION_PIER_EDGE_NW = 22406, + SPR_STATION_PIER_EDGE_NE = 22407, + SPR_STATION_PIER_EDGE_NW_FENCED = 22408, + SPR_STATION_PIER_EDGE_NE_FENCED = 22409, + SPR_STATION_PIER_FENCE_SE = 22410, + SPR_STATION_PIER_FENCE_SW = 22411, }; extern const uint32 floorSpritesCork[]; @@ -48,6 +58,8 @@ extern const uint32 fenceSpritesRope[]; 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(uint8 edges, uint32 colourFlags, uint16 height, const uint32 floorSprites[4], uint8 rotation); void track_paint_util_paint_fences(uint8 edges, rct_xy16 position, rct_map_element * mapElement, rct_ride * ride, uint32 colourFlags, uint16 height, const uint32 fenceSprites[4], uint8 rotation); +bool track_paint_util_draw_station_covers(enum edge edge, bool hasFence, const rct_ride_entrance_definition * entranceStyle, uint8 direction, uint16 height); +bool track_paint_util_should_paint_supports(rct_xy16 position); 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); diff --git a/src/ride/water/submarine_ride.c b/src/ride/water/submarine_ride.c index 1b502c077b..eba9fc246f 100644 --- a/src/ride/water/submarine_ride.c +++ b/src/ride/water/submarine_ride.c @@ -22,241 +22,6 @@ #include "../../paint/supports.h" #include "../ride_data.h" -enum -{ - SEGMENT_B4 = (1 << 0), - SEGMENT_0 = SEGMENT_B4, - SEGMENT_B8 = (1 << 1), - SEGMENT_1 = SEGMENT_B8, - SEGMENT_BC = (1 << 2), - SEGMENT_2 = SEGMENT_BC, - SEGMENT_C0 = (1 << 3), - SEGMENT_3 = SEGMENT_C0, - SEGMENT_C4 = (1 << 4), - SEGMENT_4 = SEGMENT_C4, - SEGMENT_C8 = (1 << 5), - SEGMENT_5 = SEGMENT_C8, - SEGMENT_CC = (1 << 6), - SEGMENT_6 = SEGMENT_CC, - SEGMENT_D0 = (1 << 7), - SEGMENT_7 = SEGMENT_D0, - SEGMENT_D4 = (1 << 8), - SEGMENT_8 = SEGMENT_D4, -}; - -const int SEGMENTS_ALL = SEGMENT_B4 | SEGMENT_B8 | SEGMENT_BC | SEGMENT_C0 | SEGMENT_C4 | SEGMENT_C8 | SEGMENT_CC | SEGMENT_D0 | SEGMENT_D4; - -const int segmentOffsets[9] = { - 1 << 0, // 0 -> 0 - 1 << 6, // 1 -> 6 - 1 << 2, // 2 -> 2 - 1 << 4, // 3 -> 4 - 0, // center is skipped - 1 << 7, - 1 << 1, - 1 << 5, - 1 << 3 -}; - -static uint16 segments_rotate(uint16 segments, uint8 rotation) -{ - uint8 temp = 0; - - for (int s = 0; s < 9; s++) { - if (segments & (1 << s)) { - temp |= segmentOffsets[s]; - } - } - - temp = ror8(temp, rotation * 2); - - uint16 out = 0; - - for (int s = 0; s < 9; s++) { - if (temp & segmentOffsets[s]) { - out |= (1 << s); - } - } - - if (segments & SEGMENT_4) { - out |= SEGMENT_4; - } - - return out; -} - -static void paint_util_set_segment_support_height(int flags, uint16 height, uint8 segment_flags) -{ - for (int s = 0; s < 9; s++) { - if (flags & (1 << s)) { - RCT2_GLOBAL(0x0141E9B4 + s * 4, uint16) = height; - RCT2_GLOBAL(0x0141E9B6 + s * 4, uint8) = segment_flags; - } - } -} - -static void paint_util_set_support_height(uint16 height, uint8 flags) -{ - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PAINT_TILE_MAX_HEIGHT, sint16) < height) { - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PAINT_TILE_MAX_HEIGHT, sint16) = height; - RCT2_GLOBAL(0x141E9DA, uint8) = flags; - } -} - -enum -{ - TUNNEL_0, - TUNNEL_FLAT = 6, - TUNNEL_7 = 7, - TUNNEL_UP = 8, - TUNNEL_14 = 0x0E -}; - -static void paint_util_push_tunnel_left(uint16 height, uint8 type) -{ - uint32 eax = 0xFFFF0000 | ((height / 16) & 0xFF) | type << 8; - RCT2_ADDRESS(0x009E3138, uint32)[RCT2_GLOBAL(0x141F56A, uint8) / 2] = eax; - RCT2_GLOBAL(0x141F56A, uint8)++; -} - -static void paint_util_push_tunnel_right(uint16 height, uint8 type) -{ - uint32 eax = 0xFFFF0000 | ((height / 16) & 0xFF) | type << 8; - RCT2_ADDRESS(0x009E30B6, uint32)[RCT2_GLOBAL(0x141F56B, uint8) / 2] = eax; - RCT2_GLOBAL(0x141F56B, uint8)++; -} - -/* Supports are only placed every 2 tiles for flat pieces*/ -bool paint_util_should_paint_supports(rct_xy16 position) -{ - if ((position.x & (1 << 5)) == (position.y & (1 << 5))) - return true; - - if ((!(position.x & (1 << 5))) && (!(position.y & (1 << 5)))) - return true; - - return false; -} - - -/* 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}, -}; - -typedef enum EDGE -{ - EDGE_NE, - EDGE_SE, - EDGE_SW, - EDGE_NW -} EDGE; - -static bool paint_util_has_fence(EDGE edge, rct_xy16 position, rct_map_element * mapElement, rct_ride * ride, uint8 rotation) -{ - rct_xy16 offset; - switch (edge) { - case EDGE_NE: - offset = loc_7667AC[rotation]; - break; - case EDGE_SE: - offset = loc_7667AE[(rotation + 2) & 3]; - break; - case EDGE_SW: - offset = loc_7667AC[(rotation + 2) & 3]; - break; - case EDGE_NW: - offset = loc_7667AE[rotation]; - break; - }; - - uint16 entranceLoc = - ((position.x / 32) + offset.x) | - (((position.y / 32) + offset.y) << 8); - - uint8 entranceId = (mapElement->properties.track.sequence & 0x70) >> 4; - - return (ride->entrances[entranceId] != entranceLoc && ride->exits[entranceId] != entranceLoc); -} - -enum -{ - SPR_STATION_COVER_OFFSET_NE_SW_BACK_0 = 0, - SPR_STATION_COVER_OFFSET_NE_SW_BACK_1, - SPR_STATION_COVER_OFFSET_NE_SW_FRONT, - SPR_STATION_COVER_OFFSET_SE_NW_BACK_0, - SPR_STATION_COVER_OFFSET_SE_NW_BACK_1, - SPR_STATION_COVER_OFFSET_SE_NW_FRONT, - SPR_STATION_COVER_OFFSET_HIGH -} SPR_STATION_COVER; - -static bool paint_util_draw_station_covers(EDGE edge, bool hasFence, const rct_ride_entrance_definition * entranceStyle, uint8 direction, uint16 height) -{ - uint32 imageId; - uint32 baseImageId = entranceStyle->flags; - int imageOffset; - rct_xyz16 offset, bounds, boundsOffset; - - offset = (rct_xyz16) {0, 0, height}; - switch (edge) { - case EDGE_NE: - bounds = (rct_xyz16) {1, 30, 0}; - boundsOffset = (rct_xyz16) {0, 1, height + 1}; - imageOffset = hasFence ? SPR_STATION_COVER_OFFSET_SE_NW_BACK_1 : SPR_STATION_COVER_OFFSET_SE_NW_BACK_0; - break; - case EDGE_SE: - bounds = (rct_xyz16) {32, 32, 0}; - boundsOffset = (rct_xyz16) {1, 0, height + 31}; - imageOffset = SPR_STATION_COVER_OFFSET_NE_SW_FRONT; - break; - case EDGE_SW: - bounds = (rct_xyz16) {32, 32, 0}; - boundsOffset = (rct_xyz16) {0, 0, height + 31}; - imageOffset = SPR_STATION_COVER_OFFSET_SE_NW_FRONT; - break; - case EDGE_NW: - bounds = (rct_xyz16) {30, 1, 30}; - boundsOffset = (rct_xyz16) {1, 0, height + 1}; - imageOffset = hasFence ? SPR_STATION_COVER_OFFSET_NE_SW_BACK_1 : SPR_STATION_COVER_OFFSET_NE_SW_BACK_0; - break; - } - - if (RCT2_GLOBAL(0x00F441A0, uint32) != 0x20000000) { - baseImageId &= 0x7FFFF; - } - - if (baseImageId <= 0x20) { - return false; - } - - if (baseImageId & 0x40000000) { - imageId = (baseImageId & 0xBFFFFFFF) + imageOffset; - sub_98197C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); - - uint32 edi = RCT2_GLOBAL(0x00F44198, uint32) & (0b11111 << 19); - - // weird jump - imageId = (baseImageId | edi) + 0x3800000 + imageOffset + 12; - sub_98199C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); - return true; - } - - imageId = (baseImageId + imageOffset) | RCT2_GLOBAL(0x00F44198, uint32); - sub_98197C(imageId, offset.x, offset.y, bounds.x, bounds.y, bounds.z, offset.z, boundsOffset.x, boundsOffset.y, boundsOffset.z, get_current_rotation()); - return true; -} - /** * * rct2: 0x006D44D5 @@ -340,18 +105,6 @@ enum SPR_SUBMARINE_RIDE_FLAT_QUARTER_TURN_1_TILE_SE_SW = 16899, }; -enum -{ - SPR_STATION_PIER_EDGE_SE = 22404, - SPR_STATION_PIER_EDGE_SW = 22405, - SPR_STATION_PIER_EDGE_NW = 22406, - SPR_STATION_PIER_EDGE_NE = 22407, - SPR_STATION_PIER_EDGE_NW_FENCED = 22408, - SPR_STATION_PIER_EDGE_NE_FENCED = 22409, - SPR_STATION_PIER_FENCE_SE = 22410, - SPR_STATION_PIER_FENCE_SW = 22411, -}; - static void submarine_ride_paint_track_station(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) { rct_xy16 position = {RCT2_GLOBAL(0x009DE56A, sint16), RCT2_GLOBAL(0x009DE56E, sint16)}; @@ -364,50 +117,50 @@ static void submarine_ride_paint_track_station(uint8 rideIndex, uint8 trackSeque if (direction & 1) { imageId = SPR_SUBMARINE_RIDE_FLAT_SE_NW | RCT2_GLOBAL(0x00F44198, uint32); sub_98197C(imageId, 0, 0, 20, 32, 3, heightLower, 6, 0, heightLower, get_current_rotation()); - paint_util_push_tunnel_right(height, TUNNEL_FLAT); + paint_util_push_tunnel_right(height, TUNNEL_6); - hasFence = paint_util_has_fence(EDGE_NE, position, mapElement, ride, get_current_rotation()); + hasFence = track_paint_util_has_fence(EDGE_NE, position, mapElement, ride, get_current_rotation()); imageId = (hasFence ? SPR_STATION_PIER_EDGE_NE_FENCED : SPR_STATION_PIER_EDGE_NE) | RCT2_GLOBAL(0x00F4419C, uint32); sub_98197C(imageId, 0, 0, 6, 32, 1, height, 2, 0, height, get_current_rotation()); - paint_util_draw_station_covers(EDGE_NE, hasFence, entranceStyle, direction, height); + track_paint_util_draw_station_covers(EDGE_NE, hasFence, entranceStyle, direction, height); imageId = SPR_STATION_PIER_EDGE_SW | RCT2_GLOBAL(0x00F4419C, uint32); sub_98196C(imageId, 24, 0, 8, 32, 1, height, get_current_rotation()); if (RCT2_GLOBAL(0x0141E9DB, uint8) & 3) { - hasFence = paint_util_has_fence(EDGE_SW, position, mapElement, ride, get_current_rotation()); + hasFence = track_paint_util_has_fence(EDGE_SW, position, mapElement, ride, get_current_rotation()); if (hasFence) { imageId = SPR_STATION_PIER_FENCE_SW | RCT2_GLOBAL(0x00F4419C, uint32); sub_98196C(imageId, 31, 0, 1, 32, 7, height + 2, get_current_rotation()); } - paint_util_draw_station_covers(EDGE_SW, hasFence, entranceStyle, direction, height); + track_paint_util_draw_station_covers(EDGE_SW, hasFence, entranceStyle, direction, height); } } else { imageId = SPR_SUBMARINE_RIDE_FLAT_NE_SW | RCT2_GLOBAL(0x00F44198, uint32); sub_98197C(imageId, 0, 0, 32, 20, 3, heightLower, 0, 6, heightLower, get_current_rotation()); - paint_util_push_tunnel_left(height, TUNNEL_FLAT); + paint_util_push_tunnel_left(height, TUNNEL_6); - hasFence = paint_util_has_fence(EDGE_NW, position, mapElement, ride, get_current_rotation()); + hasFence = track_paint_util_has_fence(EDGE_NW, position, mapElement, ride, get_current_rotation()); imageId = (hasFence ? SPR_STATION_PIER_EDGE_NW_FENCED : SPR_STATION_PIER_EDGE_NW) | RCT2_GLOBAL(0x00F4419C, uint32); sub_98197C(imageId, 0, 0, 32, 6, 1, height, 0, 2, height, get_current_rotation()); - paint_util_draw_station_covers(EDGE_NW, hasFence, entranceStyle, direction, height); + track_paint_util_draw_station_covers(EDGE_NW, hasFence, entranceStyle, direction, height); imageId = SPR_STATION_PIER_EDGE_SE | RCT2_GLOBAL(0x00F4419C, uint32); sub_98196C(imageId, 0, 24, 32, 8, 1, height, get_current_rotation()); if (RCT2_GLOBAL(0x0141E9DB, uint8) & 3) { - hasFence = paint_util_has_fence(EDGE_SE, position, mapElement, ride, get_current_rotation()); + hasFence = track_paint_util_has_fence(EDGE_SE, position, mapElement, ride, get_current_rotation()); if (hasFence) { imageId = SPR_STATION_PIER_FENCE_SE | RCT2_GLOBAL(0x00F4419C, uint32); sub_98196C(imageId, 0, 31, 32, 1, 7, height + 2, get_current_rotation()); } - paint_util_draw_station_covers(EDGE_SE, hasFence, entranceStyle, direction, height); + track_paint_util_draw_station_covers(EDGE_SE, hasFence, entranceStyle, direction, height); } } paint_util_set_segment_support_height(SEGMENTS_ALL, 0xFFFF, 0); - paint_util_set_support_height(height + 32, 0x20); + paint_util_set_general_support_height(height + 32, 0x20); } static void submarine_ride_paint_track_flat(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) @@ -426,12 +179,12 @@ static void submarine_ride_paint_track_flat(uint8 rideIndex, uint8 trackSequence paint_util_push_tunnel_left(heightLower, TUNNEL_0); } - if (paint_util_should_paint_supports(position)) { + if (track_paint_util_should_paint_supports(position)) { metal_a_supports_paint_setup((direction & 1) ? 4 : 5, 4, -1, heightLower, RCT2_GLOBAL(0x00F4419C, uint32)); } - paint_util_set_segment_support_height(segments_rotate(SEGMENT_D0 | SEGMENT_C4 | SEGMENT_CC, direction), 0xFFFF, 0); - paint_util_set_support_height(height + 16, 0x20); + paint_util_set_segment_support_height(paint_util_rotate_segments(SEGMENT_D0 | SEGMENT_C4 | SEGMENT_CC, direction), 0xFFFF, 0); + paint_util_set_general_support_height(height + 16, 0x20); } static void submarine_ride_paint_track_quarter_turn_3_tiles_nw_sw(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) @@ -465,7 +218,7 @@ static void submarine_ride_paint_track_quarter_turn_3_tiles_nw_sw(uint8 rideInde break; } - paint_util_set_support_height(height + 16, 0x20); + paint_util_set_general_support_height(height + 16, 0x20); } static void submarine_ride_paint_track_quarter_turn_3_tiles_ne_nw(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) @@ -498,7 +251,7 @@ static void submarine_ride_paint_track_quarter_turn_3_tiles_ne_nw(uint8 rideInde break; } - paint_util_set_support_height(height + 16, 0x20); + paint_util_set_general_support_height(height + 16, 0x20); } static void submarine_ride_paint_track_quarter_turn_3_tiles_se_ne(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) @@ -532,7 +285,7 @@ static void submarine_ride_paint_track_quarter_turn_3_tiles_se_ne(uint8 rideInde break; } - paint_util_set_support_height(height + 16, 0x20); + paint_util_set_general_support_height(height + 16, 0x20); } static void submarine_ride_paint_track_quarter_turn_3_tiles_sw_se(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) @@ -566,7 +319,7 @@ static void submarine_ride_paint_track_quarter_turn_3_tiles_sw_se(uint8 rideInde break; } - paint_util_set_support_height(height + 16, 0x20); + paint_util_set_general_support_height(height + 16, 0x20); } static void submarine_ride_paint_track_left_quarter_turn_3_tiles(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) @@ -622,8 +375,8 @@ static void submarine_ride_paint_track_left_quarter_turn_1_tile(uint8 rideIndex, break; } - paint_util_set_segment_support_height(segments_rotate(SEGMENT_B8 | SEGMENT_C8 | SEGMENT_C4 | SEGMENT_D0, direction), 0xFFFF, 0); - paint_util_set_support_height(height + 16, 0x20); + paint_util_set_segment_support_height(paint_util_rotate_segments(SEGMENT_B8 | SEGMENT_C8 | SEGMENT_C4 | SEGMENT_D0, direction), 0xFFFF, 0); + paint_util_set_general_support_height(height + 16, 0x20); } static void submarine_ride_paint_track_right_quarter_turn_1_tile(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement) From 7c30f89a759bfac0830339a0c36de9086b0d9147 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Wed, 18 May 2016 22:57:43 +0200 Subject: [PATCH 5/6] Draw fences underground --- src/ride/track_paint.c | 4 ++++ src/ride/water/submarine_ride.c | 24 ++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ride/track_paint.c b/src/ride/track_paint.c index c64e5494cf..c636771e60 100644 --- a/src/ride/track_paint.c +++ b/src/ride/track_paint.c @@ -210,6 +210,10 @@ bool track_paint_util_should_paint_supports(rct_xy16 position) bool track_paint_util_draw_station_covers(enum edge edge, bool hasFence, const rct_ride_entrance_definition * entranceStyle, uint8 direction, uint16 height) { + if (RCT2_GLOBAL(0x0141E9DB, uint8) & 3) { + return false; + } + uint32 imageId; uint32 baseImageId = entranceStyle->flags; int imageOffset; diff --git a/src/ride/water/submarine_ride.c b/src/ride/water/submarine_ride.c index eba9fc246f..6f61c671a8 100644 --- a/src/ride/water/submarine_ride.c +++ b/src/ride/water/submarine_ride.c @@ -127,14 +127,12 @@ static void submarine_ride_paint_track_station(uint8 rideIndex, uint8 trackSeque imageId = SPR_STATION_PIER_EDGE_SW | RCT2_GLOBAL(0x00F4419C, uint32); sub_98196C(imageId, 24, 0, 8, 32, 1, height, get_current_rotation()); - if (RCT2_GLOBAL(0x0141E9DB, uint8) & 3) { - hasFence = track_paint_util_has_fence(EDGE_SW, position, mapElement, ride, get_current_rotation()); - if (hasFence) { - imageId = SPR_STATION_PIER_FENCE_SW | RCT2_GLOBAL(0x00F4419C, uint32); - sub_98196C(imageId, 31, 0, 1, 32, 7, height + 2, get_current_rotation()); - } - track_paint_util_draw_station_covers(EDGE_SW, hasFence, entranceStyle, direction, height); + hasFence = track_paint_util_has_fence(EDGE_SW, position, mapElement, ride, get_current_rotation()); + if (hasFence) { + imageId = SPR_STATION_PIER_FENCE_SW | RCT2_GLOBAL(0x00F4419C, uint32); + sub_98196C(imageId, 31, 0, 1, 32, 7, height + 2, get_current_rotation()); } + track_paint_util_draw_station_covers(EDGE_SW, hasFence, entranceStyle, direction, height); } else { imageId = SPR_SUBMARINE_RIDE_FLAT_NE_SW | RCT2_GLOBAL(0x00F44198, uint32); @@ -149,14 +147,12 @@ static void submarine_ride_paint_track_station(uint8 rideIndex, uint8 trackSeque imageId = SPR_STATION_PIER_EDGE_SE | RCT2_GLOBAL(0x00F4419C, uint32); sub_98196C(imageId, 0, 24, 32, 8, 1, height, get_current_rotation()); - if (RCT2_GLOBAL(0x0141E9DB, uint8) & 3) { - hasFence = track_paint_util_has_fence(EDGE_SE, position, mapElement, ride, get_current_rotation()); - if (hasFence) { - imageId = SPR_STATION_PIER_FENCE_SE | RCT2_GLOBAL(0x00F4419C, uint32); - sub_98196C(imageId, 0, 31, 32, 1, 7, height + 2, get_current_rotation()); - } - track_paint_util_draw_station_covers(EDGE_SE, hasFence, entranceStyle, direction, height); + hasFence = track_paint_util_has_fence(EDGE_SE, position, mapElement, ride, get_current_rotation()); + if (hasFence) { + imageId = SPR_STATION_PIER_FENCE_SE | RCT2_GLOBAL(0x00F4419C, uint32); + sub_98196C(imageId, 0, 31, 32, 1, 7, height + 2, get_current_rotation()); } + track_paint_util_draw_station_covers(EDGE_SE, hasFence, entranceStyle, direction, height); } paint_util_set_segment_support_height(SEGMENTS_ALL, 0xFFFF, 0); From 1bf9dc26f9a086c3b4c0a71600411304368eabcf Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Wed, 18 May 2016 23:00:26 +0200 Subject: [PATCH 6/6] Rename entrance flags to base_image_id --- src/paint/map_element/entrance.c | 2 +- src/ride/ride_data.h | 2 +- src/ride/track_paint.c | 2 +- src/windows/ride.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/paint/map_element/entrance.c b/src/paint/map_element/entrance.c index d3d39bc9c7..8ff9e79603 100644 --- a/src/paint/map_element/entrance.c +++ b/src/paint/map_element/entrance.c @@ -46,7 +46,7 @@ void ride_entrance_exit_paint(uint8 direction, int height, rct_map_element* map_ uint8 colour_1, colour_2; uint32 transparant_image_id = 0, image_id = 0; - if (style->flags & (1 << 30)) { + if (style->base_image_id & 0x40000000) { colour_1 = ride->track_colour_main[0] + 0x70; transparant_image_id = (colour_1 << 19) | 0x40000000; } diff --git a/src/ride/ride_data.h b/src/ride/ride_data.h index 0ab94c6fde..7ec189ee80 100644 --- a/src/ride/ride_data.h +++ b/src/ride/ride_data.h @@ -32,7 +32,7 @@ typedef struct rct_ride_entrance_definition { uint16 height; uint16 scrolling_mode; rct_string_id string_id; - uint32 flags; + uint32 base_image_id; uint16 colour_use_flags; } rct_ride_entrance_definition; diff --git a/src/ride/track_paint.c b/src/ride/track_paint.c index c636771e60..1c74bd660e 100644 --- a/src/ride/track_paint.c +++ b/src/ride/track_paint.c @@ -215,7 +215,7 @@ bool track_paint_util_draw_station_covers(enum edge edge, bool hasFence, const r } uint32 imageId; - uint32 baseImageId = entranceStyle->flags; + uint32 baseImageId = entranceStyle->base_image_id; int imageOffset; rct_xyz16 offset, bounds, boundsOffset; diff --git a/src/windows/ride.c b/src/windows/ride.c index 05d6704f6a..3e66f0642d 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -4316,7 +4316,7 @@ static void window_ride_colour_paint(rct_window *w, rct_drawpixelinfo *dpi) const rct_ride_entrance_definition *entranceStyle = &RideEntranceDefinitions[ride->entrance_style]; terniaryColour = 0; - if (entranceStyle->flags & 0x40000000) { + if (entranceStyle->base_image_id & 0x40000000) { terniaryColour = 0x40000000 | ((trackColour.main + 112) << 19); }