diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 8d3cb3d111..37ee5ffd19 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -523,7 +523,7 @@ static void viewport_interaction_remove_footpath_item(rct_tile_element* tileElem void viewport_interaction_remove_park_entrance(rct_tile_element* tileElement, int32_t x, int32_t y) { int32_t rotation = tileElement->GetDirectionWithOffset(1); - switch (tileElement->properties.entrance.index & 0x0F) + switch (tileElement->AsEntrance()->GetSequenceIndex()) { case 1: x += CoordsDirectionDelta[rotation].x; diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index f49e976b01..32a2e49952 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1933,8 +1933,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) } else { - int16_t rideEntranceIndex = (tileElement->properties.entrance.index & 0x30) - >> 4; // TODO: use mask or function + int16_t rideEntranceIndex = tileElement->AsEntrance()->GetStationIndex(); if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { // Ride entrance ID @@ -1952,7 +1951,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE) { // Entrance part - rct_string_id entrancePart = ParkEntrancePartStringIds[tileElement->properties.entrance.index & 0x0F]; + rct_string_id entrancePart = ParkEntrancePartStringIds[tileElement->AsEntrance()->GetSequenceIndex()]; gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_ENTRANCE_PART, &entrancePart, COLOUR_DARK_GREEN, x, y + 22); } else diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index f35bfab3cb..41818e822b 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -151,7 +151,7 @@ void setup_in_use_selection_flags() if (iter.element->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) break; // Skip if not the middle part - if (iter.element->properties.entrance.index != 0) + if (iter.element->AsEntrance()->GetSequenceIndex() != 0) break; Editor::SetSelectedObject(OBJECT_TYPE_PARK_ENTRANCE, 0, OBJECT_SELECTION_FLAG_SELECTED); diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index bb92e4a021..45ed9d0a5a 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -192,7 +192,7 @@ public: newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); newElement->SetDirection(_direction); - newElement->properties.entrance.index = index; + newElement->AsEntrance()->SetSequenceIndex(index); newElement->AsEntrance()->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE); newElement->properties.entrance.path_type = gFootpathSelectedId; diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 9b80d604f1..078793ac0f 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -231,7 +231,7 @@ static void park_entrance_paint(paint_session* session, uint8_t direction, int32 // Index to which part of the entrance // Middle, left, right - uint8_t part_index = tile_element->properties.entrance.index & 0xF; + uint8_t part_index = tile_element->AsEntrance()->GetSequenceIndex(); rct_footpath_entry* path_entry = nullptr; // The left and right of the park entrance often have this set to 127. diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 9057bbedc4..345df07a81 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2486,7 +2486,7 @@ static void peep_interact_with_entrance( } peep->time_lost = 0; - uint8_t stationNum = (tile_element->properties.entrance.index >> 4) & 0x7; + uint8_t stationNum = tile_element->AsEntrance()->GetStationIndex(); // Guest walks up to the ride for the first time since entering // the path tile or since considering another ride attached to // the path tile. @@ -2538,7 +2538,7 @@ static void peep_interact_with_entrance( } // If not the centre of the entrance arch - if (tile_element->properties.entrance.index & 0xF) + if (tile_element->AsEntrance()->GetSequenceIndex() != 0) { peep_return_to_centre_of_tile(peep); return; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 5b9d1bc4a0..bcb08f6649 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1938,7 +1938,7 @@ void rct_peep::UpdateHeadingToInspect() if (current_ride != rideEntranceExitElement->AsEntrance()->GetRideIndex()) return; - uint8_t exit_index = ((rideEntranceExitElement->properties.entrance.index & 0x70) >> 4); + uint8_t exit_index = rideEntranceExitElement->AsEntrance()->GetStationIndex(); if (current_ride_station != exit_index) return; @@ -2056,7 +2056,7 @@ void rct_peep::UpdateAnswering() if (current_ride != rideEntranceExitElement->AsEntrance()->GetRideIndex()) return; - uint8_t exit_index = ((rideEntranceExitElement->properties.entrance.index & 0x70) >> 4); + uint8_t exit_index = rideEntranceExitElement->AsEntrance()->GetStationIndex(); if (current_ride_station != exit_index) return; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 9fc80041cb..17d490326e 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2710,7 +2710,7 @@ private: continue; if (element->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) continue; - if ((element->properties.entrance.index & 0x0F) != 0) + if ((element->AsEntrance()->GetSequenceIndex()) != 0) continue; gParkEntrances[entranceIndex].x = it.x * 32; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 91400d531a..9609231f77 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1880,7 +1880,7 @@ static int32_t ride_modify_entrance_or_exit(rct_tile_element* tileElement, int32 if (entranceType != ENTRANCE_TYPE_RIDE_ENTRANCE && entranceType != ENTRANCE_TYPE_RIDE_EXIT) return 0; - int32_t bl = (tileElement->properties.entrance.index & 0x70) >> 4; + int32_t stationIndex = tileElement->AsEntrance()->GetStationIndex(); // Get or create construction window for ride constructionWindow = window_find_by_class(WC_RIDE_CONSTRUCTION); @@ -1905,7 +1905,7 @@ static int32_t ride_modify_entrance_or_exit(rct_tile_element* tileElement, int32 TOOL_CROSSHAIR); gRideEntranceExitPlaceType = entranceType; gRideEntranceExitPlaceRideIndex = rideIndex; - gRideEntranceExitPlaceStationIndex = bl; + gRideEntranceExitPlaceStationIndex = stationIndex; input_set_flag(INPUT_FLAG_6, true); if (_rideConstructionState != RIDE_CONSTRUCTION_STATE_ENTRANCE_EXIT) { @@ -1921,7 +1921,7 @@ static int32_t ride_modify_entrance_or_exit(rct_tile_element* tileElement, int32 // Remove entrance / exit game_do_command( x, (GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_APPLY), y, rideIndex, - GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT, bl, 0); + GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT, stationIndex, 0); gCurrentToolWidget.widget_index = entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE ? WC_RIDE_CONSTRUCTION__WIDX_ENTRANCE : WC_RIDE_CONSTRUCTION__WIDX_EXIT; gRideEntranceExitPlaceType = entranceType; @@ -8205,8 +8205,7 @@ void sub_6CB945(int32_t rideIndex) ride_set_entrance_location(ride, stationId, entranceLocation); } - tileElement->properties.entrance.index &= 0x8F; - tileElement->properties.entrance.index |= stationId << 4; + tileElement->AsEntrance()->SetStationIndex(stationId); shouldRemove = false; } while (!(trackElement++)->IsLastForTile()); diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index df8e05b275..d7506fb478 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -268,7 +268,7 @@ static money32 RideEntranceExitPlace( tileElement->SetDirection(direction); tileElement->clearance_height = clear_z; tileElement->AsEntrance()->SetEntranceType(isExit ? ENTRANCE_TYPE_RIDE_EXIT : ENTRANCE_TYPE_RIDE_ENTRANCE); - tileElement->properties.entrance.index = stationNum << 4; + tileElement->AsEntrance()->SetStationIndex(stationNum); tileElement->AsEntrance()->SetRideIndex(rideIndex); if (flags & GAME_COMMAND_FLAG_GHOST) @@ -661,3 +661,14 @@ void EntranceElement::SetRideIndex(uint8_t newRideIndex) { rideIndex = newRideIndex; } + +uint8_t EntranceElement::GetSequenceIndex() const +{ + return index & 0xF; +} + +void EntranceElement::SetSequenceIndex(uint8_t newSequenceIndex) +{ + index &= ~0xF; + index |= (newSequenceIndex & 0xF); +} \ No newline at end of file diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index bc4f65b24f..85d5472f24 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -99,7 +99,7 @@ static constexpr const uint8_t connected_path_count[] = { int32_t entrance_get_directions(const rct_tile_element* tileElement) { uint8_t entranceType = tileElement->AsEntrance()->GetEntranceType(); - uint8_t sequence = tileElement->properties.entrance.index & 0x0F; + uint8_t sequence = tileElement->AsEntrance()->GetSequenceIndex(); return EntranceDirections[(entranceType * 8) + sequence]; } @@ -218,7 +218,7 @@ static money32 footpath_element_insert( entranceElement = map_get_park_entrance_element_at(x, y, z, false); // Make sure the entrance part is the middle - if (entranceElement != nullptr && (entranceElement->properties.entrance.index & 0x0F) == 0) + if (entranceElement != nullptr && (entranceElement->AsEntrance()->GetSequenceIndex()) == 0) { entrancePath = true; // Make the price the same as replacing a path @@ -589,7 +589,7 @@ static money32 footpath_place_from_track( entranceElement = map_get_park_entrance_element_at(x, y, z, false); // Make sure the entrance part is the middle - if (entranceElement != nullptr && (entranceElement->properties.entrance.index & 0x0F) == 0) + if (entranceElement != nullptr && (entranceElement->AsEntrance()->GetSequenceIndex()) == 0) { entrancePath = true; // Make the price the same as replacing a path @@ -1397,7 +1397,7 @@ static void loc_6A6D7E( { neighbour_list_push( neighbourList, 8, direction, tileElement->AsEntrance()->GetRideIndex(), - tileElement->properties.entrance.index); + tileElement->AsEntrance()->GetStationIndex()); } else { @@ -1427,7 +1427,7 @@ static void loc_6A6D7E( { neighbour_list_push( neighbourList, 4, direction, tileElement->properties.path.ride_index, - tileElement->properties.entrance.index); + tileElement->properties.path.additions); } else { @@ -1438,7 +1438,7 @@ static void loc_6A6D7E( { neighbour_list_push( neighbourList, 3, direction, tileElement->properties.path.ride_index, - tileElement->properties.entrance.index); + tileElement->properties.path.additions); } } } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 3ed1295dd4..b74fa8b9c8 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -3848,7 +3848,7 @@ static void clear_element_at(int32_t x, int32_t y, rct_tile_element** elementPtr case TILE_ELEMENT_TYPE_ENTRANCE: { int32_t rotation = element->GetDirectionWithOffset(1); - switch (element->properties.entrance.index & 0x0F) + switch (element->AsEntrance()->GetSequenceIndex()) { case 1: x += CoordsDirectionDelta[rotation].x; diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index e59c054a86..bac8289399 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -248,7 +248,7 @@ static bool map_animation_invalidate_park_entrance(int32_t x, int32_t y, int32_t continue; if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) continue; - if (tileElement->properties.entrance.index & 0x0F) + if (tileElement->AsEntrance()->GetSequenceIndex()) continue; baseZ = tileElement->base_height * 8; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index cf54f3bfe6..d7e1dd3380 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -389,6 +389,9 @@ public: uint8_t GetStationIndex() const; void SetStationIndex(uint8_t stationIndex); + + uint8_t GetSequenceIndex() const; + void SetSequenceIndex(uint8_t newSequenceIndex); }; assert_struct_size(EntranceElement, 8); diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 6f6ad0d949..af10f1d5a8 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -242,7 +242,7 @@ int32_t tile_inspector_rotate_element_at(int32_t x, int32_t y, int32_t elementIn // Update ride's known entrance/exit rotation Ride* ride = get_ride(tileElement->AsEntrance()->GetRideIndex()); - uint8_t stationIndex = tileElement->properties.entrance.index; + uint8_t stationIndex = tileElement->AsEntrance()->GetStationIndex(); auto entrance = ride_get_entrance_location(ride, stationIndex); auto exit = ride_get_exit_location(ride, stationIndex); uint8_t entranceType = tileElement->AsEntrance()->GetEntranceType(); @@ -442,7 +442,7 @@ int32_t tile_inspector_any_base_height_offset(int32_t x, int32_t y, int16_t elem { // Update the ride's known entrance or exit height Ride* ride = get_ride(tileElement->AsEntrance()->GetRideIndex()); - uint8_t entranceIndex = tileElement->properties.entrance.index; + uint8_t entranceIndex = tileElement->AsEntrance()->GetStationIndex(); auto entrance = ride_get_entrance_location(ride, entranceIndex); auto exit = ride_get_exit_location(ride, entranceIndex); uint8_t z = tileElement->base_height; @@ -671,7 +671,7 @@ int32_t tile_inspector_entrance_make_usable(int32_t x, int32_t y, int32_t elemen if (flags & GAME_COMMAND_FLAG_APPLY) { - uint8_t stationIndex = entranceElement->properties.entrance.index >> 6; + uint8_t stationIndex = entranceElement->AsEntrance()->GetStationIndex(); switch (entranceElement->AsEntrance()->GetEntranceType()) {