diff --git a/src/openrct2/ride/thrill/SwingingInverterShip.cpp b/src/openrct2/ride/thrill/SwingingInverterShip.cpp index 8a51899e46..e535affd08 100644 --- a/src/openrct2/ride/thrill/SwingingInverterShip.cpp +++ b/src/openrct2/ride/thrill/SwingingInverterShip.cpp @@ -19,7 +19,7 @@ #include "../Vehicle.h" /** rct2: 0x01428010 */ -static constexpr const uint32_t swinging_inverter_ship_base_sprite_offset[] = { +static constexpr const uint32_t SwingingInverterShipBaseSpriteOffset[] = { 0, 16, 0, @@ -27,7 +27,7 @@ static constexpr const uint32_t swinging_inverter_ship_base_sprite_offset[] = { }; /** rct2: 0x01428020 */ -static constexpr const uint32_t swinging_inverter_ship_animating_base_sprite_offset[] = { +static constexpr const uint32_t SwingingInverterShipAnimatingBaseSpriteOffset[] = { 32, 33, 32, @@ -58,14 +58,14 @@ enum SPR_SWINGING_INVERTER_SHIP_FRAME_3 = 22001, }; -static constexpr const uint32_t swinging_inverter_ship_frame_sprites[] = { +static constexpr const uint32_t SwingingInverterShipFrameSprites[] = { SPR_SWINGING_INVERTER_SHIP_FRAME_0, SPR_SWINGING_INVERTER_SHIP_FRAME_1, SPR_SWINGING_INVERTER_SHIP_FRAME_2, SPR_SWINGING_INVERTER_SHIP_FRAME_3, }; -static void paint_swinging_inverter_ship_structure( +static void PaintSwingingInverterShipStructure( paint_session* session, const Ride& ride, uint8_t direction, int8_t axisOffset, uint16_t height) { const TileElement* savedTileElement = static_cast(session->CurrentlyDrawnItem); @@ -74,28 +74,29 @@ static void paint_swinging_inverter_ship_structure( if (rideEntry == nullptr) return; + const auto& boundBox = swinging_inverter_ship_bounds[direction]; + CoordsXYZ offset((direction & 1) ? 0 : axisOffset, (direction & 1) ? axisOffset : 0, height); + CoordsXYZ bbLength(boundBox.length_x, boundBox.length_y, 127); + CoordsXYZ bbOffset(boundBox.offset_x, boundBox.offset_y, height); + Vehicle* vehicle = nullptr; - - int8_t xOffset = !(direction & 1) ? axisOffset : 0; - int8_t yOffset = (direction & 1) ? axisOffset : 0; - - if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && ride.vehicles[0] != SPRITE_INDEX_NULL) + if (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK) { vehicle = GetEntity(ride.vehicles[0]); - - session->InteractionType = ViewportInteractionItem::Entity; - session->CurrentlyDrawnItem = vehicle; + if (vehicle != nullptr) + { + session->InteractionType = ViewportInteractionItem::Entity; + session->CurrentlyDrawnItem = vehicle; + } } - uint32_t vehicleImageId = rideEntry->vehicles[0].base_image_id + swinging_inverter_ship_base_sprite_offset[direction]; + ImageIndex vehicleImageIndex = rideEntry->vehicles[0].base_image_id + SwingingInverterShipBaseSpriteOffset[direction]; if (vehicle != nullptr) { int32_t rotation = static_cast(vehicle->Pitch); if (rotation != 0) { - vehicleImageId = rideEntry->vehicles[0].base_image_id - + swinging_inverter_ship_animating_base_sprite_offset[direction]; - + vehicleImageIndex = rideEntry->vehicles[0].base_image_id + SwingingInverterShipAnimatingBaseSpriteOffset[direction]; if (direction & 2) { rotation = -rotation; @@ -104,46 +105,36 @@ static void paint_swinging_inverter_ship_structure( { rotation += 72; } - - vehicleImageId += (rotation - 1) << 1; + vehicleImageIndex += (rotation - 1) << 1; } } - uint32_t colourFlags = session->TrackColours[SCHEME_MISC]; - if (colourFlags == IMAGE_TYPE_REMAP) + auto vehicleImageTemplate = ImageId(0, ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim); + auto imageFlags = session->TrackColours[SCHEME_MISC]; + if (imageFlags != IMAGE_TYPE_REMAP) { - colourFlags = SPRITE_ID_PALETTE_COLOUR_2(ride.vehicle_colours[0].Body, ride.vehicle_colours[0].Trim); + vehicleImageTemplate = ImageId::FromUInt32(imageFlags); } - - swinging_inverter_ship_bound_box boundBox = swinging_inverter_ship_bounds[direction]; - vehicleImageId = vehicleImageId | colourFlags; - uint32_t frameImageId = swinging_inverter_ship_frame_sprites[direction] | session->TrackColours[SCHEME_TRACK]; + auto frameImageTemplate = ImageId::FromUInt32(session->TrackColours[SCHEME_TRACK]); + auto vehicleImageId = vehicleImageTemplate.WithIndex(vehicleImageIndex); + auto frameImageId = frameImageTemplate.WithIndex(SwingingInverterShipFrameSprites[direction]); if (direction & 2) { - PaintAddImageAsParent( - session, vehicleImageId, { xOffset, yOffset, height }, { boundBox.length_x, boundBox.length_y, 127 }, - { boundBox.offset_x, boundBox.offset_y, height }); - PaintAddImageAsChild( - session, frameImageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x, - boundBox.offset_y, height); + PaintAddImageAsParent(session, vehicleImageId, offset, bbLength, bbOffset); + PaintAddImageAsChild(session, frameImageId, offset, bbLength, bbOffset); } else { - PaintAddImageAsParent( - session, frameImageId, { xOffset, yOffset, height }, { boundBox.length_x, boundBox.length_y, 127 }, - { boundBox.offset_x, boundBox.offset_y, height }); - PaintAddImageAsChild( - session, vehicleImageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x, - boundBox.offset_y, height); + PaintAddImageAsParent(session, frameImageId, offset, bbLength, bbOffset); + PaintAddImageAsChild(session, vehicleImageId, offset, bbLength, bbOffset); } session->CurrentlyDrawnItem = savedTileElement; session->InteractionType = ViewportInteractionItem::Ride; } -/** rct2: 0x00760260 */ -static void paint_swinging_inverter_ship( +static void PaintSwingingInverterShip( paint_session* session, const Ride* ride, uint8_t trackSequence, uint8_t direction, int32_t height, const TrackElement& trackElement) { @@ -199,16 +190,16 @@ static void paint_swinging_inverter_ship( switch (relativeTrackSequence) { case 1: - paint_swinging_inverter_ship_structure(session, *ride, direction, 48, height + 7); + PaintSwingingInverterShipStructure(session, *ride, direction, 48, height + 7); break; case 2: - paint_swinging_inverter_ship_structure(session, *ride, direction, 16, height + 7); + PaintSwingingInverterShipStructure(session, *ride, direction, 16, height + 7); break; case 0: - paint_swinging_inverter_ship_structure(session, *ride, direction, -16, height + 7); + PaintSwingingInverterShipStructure(session, *ride, direction, -16, height + 7); break; case 3: - paint_swinging_inverter_ship_structure(session, *ride, direction, -48, height + 7); + PaintSwingingInverterShipStructure(session, *ride, direction, -48, height + 7); break; } } @@ -217,9 +208,6 @@ static void paint_swinging_inverter_ship( paint_util_set_general_support_height(session, height + 176, 0x20); } -/** - * rct2: 0x00760070 - */ TRACK_PAINT_FUNCTION get_track_paint_function_swinging_inverter_ship(int32_t trackType) { if (trackType != TrackElemType::FlatTrack1x4B) @@ -227,5 +215,5 @@ TRACK_PAINT_FUNCTION get_track_paint_function_swinging_inverter_ship(int32_t tra return nullptr; } - return paint_swinging_inverter_ship; + return PaintSwingingInverterShip; }