diff --git a/src/openrct2/ride/thrill/SwingingShip.cpp b/src/openrct2/ride/thrill/SwingingShip.cpp index 5b11e2e3ae..68ea9662c5 100644 --- a/src/openrct2/ride/thrill/SwingingShip.cpp +++ b/src/openrct2/ride/thrill/SwingingShip.cpp @@ -35,7 +35,7 @@ struct swinging_ship_bound_box }; /** rct2: 0x008A83B0 */ -static constexpr const uint32_t swinging_ship_base_sprite_offset[] = { +static constexpr const uint32_t SwingingShipBaseSpriteOffset[] = { 0, 9, 0, @@ -43,7 +43,7 @@ static constexpr const uint32_t swinging_ship_base_sprite_offset[] = { }; /** rct2: 0x008A83C0 */ -static constexpr const swinging_ship_bound_box swinging_ship_data[] = { +static constexpr const swinging_ship_bound_box SwingingShipData[] = { { 31, 16, 1, 8 }, { 16, 31, 8, 1 }, { 31, 16, 1, 8 }, @@ -58,41 +58,57 @@ enum SPR_SWINGING_SHIP_FRAME_FRONT_NW_SE = 21997, }; -static constexpr const uint32_t swinging_ship_frame_sprites[][2] = { +static constexpr const uint32_t SwingingShipFrameSprites[][2] = { { SPR_SWINGING_SHIP_FRAME_SW_NE, SPR_SWINGING_SHIP_FRAME_FRONT_SW_NE }, { SPR_SWINGING_SHIP_FRAME_NW_SE, SPR_SWINGING_SHIP_FRAME_FRONT_NW_SE }, }; -/** rct2: 0x4AF254 */ -static void paint_swinging_ship_structure( - paint_session* session, const Ride* ride, uint8_t direction, int8_t axisOffset, uint16_t height) +static void PaintSwingingShipRiders( + paint_session* session, const Ride& ride, const Vehicle& vehicle, ImageIndex baseImageIndex, Direction direction, + const CoordsXYZ& offset, const CoordsXYZ& bbLength, const CoordsXYZ& bbOffset) { - uint32_t imageId, baseImageId; + if (session->DPI.zoom_level > ZoomLevel{ 1 }) + return; + if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) + return; + + int32_t peep = 0; + for (int32_t row = 0; row < 4; row++) + { + for (int32_t col = 0; col < 2; col++) + { + if (vehicle.num_peeps <= peep) + break; + + auto frameNum = 1 + (row * 2) + (direction >> 1); + auto imageIndex = baseImageIndex + frameNum; + auto imageId = ImageId(imageIndex, vehicle.peep_tshirt_colours[row], vehicle.peep_tshirt_colours[row + 1]); + PaintAddImageAsChild(session, imageId, offset, bbLength, bbOffset); + + peep += 2; + } + } +} + +static void PaintSwingingShipStructure( + paint_session* session, const Ride& ride, uint8_t direction, int8_t axisOffset, uint16_t height) +{ const TileElement* savedTileElement = static_cast(session->CurrentlyDrawnItem); - rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); + rct_ride_entry* rideEntry = get_ride_entry(ride.subtype); if (rideEntry == nullptr) - { return; - } Vehicle* vehicle = nullptr; - - int8_t xOffset = !(direction & 1) ? axisOffset : 0; - int8_t yOffset = (direction & 1) ? axisOffset : 0; - - height += 7; - - if (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && ride->vehicles[0] != SPRITE_INDEX_NULL) + if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && ride.vehicles[0] != SPRITE_INDEX_NULL) { - vehicle = GetEntity(ride->vehicles[0]); - + vehicle = GetEntity(ride.vehicles[0]); session->InteractionType = ViewportInteractionItem::Entity; session->CurrentlyDrawnItem = vehicle; } - baseImageId = rideEntry->vehicles[0].base_image_id + swinging_ship_base_sprite_offset[direction]; + auto baseImageId = rideEntry->vehicles[0].base_image_id + SwingingShipBaseSpriteOffset[direction]; if (vehicle != nullptr) { int32_t rotation = static_cast(vehicle->Pitch); @@ -111,76 +127,37 @@ static void paint_swinging_ship_structure( } } - uint32_t imageColourFlags = session->TrackColours[SCHEME_MISC]; - if (imageColourFlags == IMAGE_TYPE_REMAP) + auto imageTemplate = ImageId(0, ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim); + auto imageFlags = session->TrackColours[SCHEME_MISC]; + if (imageFlags != IMAGE_TYPE_REMAP) { - imageColourFlags = SPRITE_ID_PALETTE_COLOUR_2(ride->vehicle_colours[0].Body, ride->vehicle_colours[0].Trim); + imageTemplate = ImageId::FromUInt32(imageFlags); } - swinging_ship_bound_box bounds = swinging_ship_data[direction]; + const auto& bounds = SwingingShipData[direction]; + CoordsXYZ offset((direction & 1) ? 0 : axisOffset, (direction & 1) ? axisOffset : 0, height + 7); + CoordsXYZ bbLength(bounds.length_x, bounds.length_y, 80); + CoordsXYZ bbOffset(bounds.offset_x, bounds.offset_y, height + 7); - imageId = swinging_ship_frame_sprites[(direction & 1)][0] | session->TrackColours[SCHEME_TRACK]; - PaintAddImageAsParent( - session, imageId, { xOffset, yOffset, height }, { bounds.length_x, bounds.length_y, 80 }, - { bounds.offset_x, bounds.offset_y, height }); + auto imageId = imageTemplate.WithIndex(SwingingShipFrameSprites[(direction & 1)][0]); + PaintAddImageAsParent(session, imageId, offset, bbLength, bbOffset); - imageId = baseImageId | imageColourFlags; - PaintAddImageAsChild( - session, imageId, xOffset, yOffset, bounds.length_x, bounds.length_y, 80, height, bounds.offset_x, bounds.offset_y, - height); + imageId = imageTemplate.WithIndex(baseImageId); + PaintAddImageAsChild(session, imageId, offset, bbLength, bbOffset); - rct_drawpixelinfo* dpi = &session->DPI; - - if (dpi->zoom_level <= ZoomLevel{ 1 } && ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr) + if (vehicle != nullptr) { - int32_t peep = 0; - int32_t offset = 1; - while (peep < 16) - { - if (vehicle->num_peeps <= peep) - { - break; - } - - int32_t frameNum = offset + (direction >> 1); - imageColourFlags = SPRITE_ID_PALETTE_COLOUR_2( - vehicle->peep_tshirt_colours[peep], vehicle->peep_tshirt_colours[peep + 1]); - imageId = (baseImageId + frameNum) | imageColourFlags; - PaintAddImageAsChild( - session, imageId, xOffset, yOffset, bounds.length_x, bounds.length_y, 80, height, bounds.offset_x, - bounds.offset_y, height); - - peep += 2; - - if (vehicle->num_peeps <= peep) - { - break; - } - - frameNum = offset + ((direction >> 1) ^ 1); - imageColourFlags = SPRITE_ID_PALETTE_COLOUR_2( - vehicle->peep_tshirt_colours[peep], vehicle->peep_tshirt_colours[peep + 1]); - imageId = (baseImageId + frameNum) | imageColourFlags; - PaintAddImageAsChild( - session, imageId, xOffset, yOffset, bounds.length_x, bounds.length_y, 80, height, bounds.offset_x, - bounds.offset_y, height); - - peep += 2; - offset += 2; - } + PaintSwingingShipRiders(session, ride, *vehicle, baseImageId, direction, offset, bbLength, bbOffset); } - imageId = swinging_ship_frame_sprites[(direction & 1)][1] | session->TrackColours[SCHEME_TRACK]; - PaintAddImageAsChild( - session, imageId, xOffset, yOffset, bounds.length_x, bounds.length_y, 80, height, bounds.offset_x, bounds.offset_y, - height); + imageId = imageTemplate.WithIndex(SwingingShipFrameSprites[(direction & 1)][1]); + PaintAddImageAsChild(session, imageId, offset, bbLength, bbOffset); session->CurrentlyDrawnItem = savedTileElement; session->InteractionType = ViewportInteractionItem::Ride; } -/** rct2: 0x008A85C4 */ -static void paint_swinging_ship( +static void PaintSwingingShip( paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height, const TrackElement& trackElement) { @@ -325,28 +302,25 @@ static void paint_swinging_ship( switch (relativeTrackSequence) { case 1: - paint_swinging_ship_structure(session, ride, direction, 64, height); + PaintSwingingShipStructure(session, *ride, direction, 64, height); break; case 2: - paint_swinging_ship_structure(session, ride, direction, 32, height); + PaintSwingingShipStructure(session, *ride, direction, 32, height); break; case 0: - paint_swinging_ship_structure(session, ride, direction, 0, height); + PaintSwingingShipStructure(session, *ride, direction, 0, height); break; case 3: - paint_swinging_ship_structure(session, ride, direction, -32, height); + PaintSwingingShipStructure(session, *ride, direction, -32, height); break; case 4: - paint_swinging_ship_structure(session, ride, direction, -64, height); + PaintSwingingShipStructure(session, *ride, direction, -64, height); break; } paint_util_set_general_support_height(session, height + 112, 0x20); } -/** - * rct2: 0x008A83E0 - */ TRACK_PAINT_FUNCTION get_track_paint_function_swinging_ship(int32_t trackType) { if (trackType != TrackElemType::FlatTrack1x5) @@ -354,5 +328,5 @@ TRACK_PAINT_FUNCTION get_track_paint_function_swinging_ship(int32_t trackType) return nullptr; } - return paint_swinging_ship; + return PaintSwingingShip; }