From 757d705e1326d7e3ce75c529b24060df0736a0b7 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 12:02:41 +0200 Subject: [PATCH 01/12] Add private fields --- src/openrct2/world/Entrance.cpp | 6 +++--- src/openrct2/world/TileElement.h | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index e5b207d65b..a7f655c7d7 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -633,11 +633,11 @@ void fix_park_entrance_locations(void) uint8_t EntranceElement::GetStationIndex() const { - return (temp.index & MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK) >> 4; + return (index & MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK) >> 4; } void EntranceElement::SetStationIndex(uint8_t stationIndex) { - temp.index &= ~MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK; - temp.index |= (stationIndex << 4); + index &= ~MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK; + index |= (stationIndex << 4); } diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index bb8aa6a378..a02462b8ff 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -374,7 +374,11 @@ assert_struct_size(WallElement, 8); struct EntranceElement : TileElementBase { - rct_tile_element_entrance_properties temp; +private: + uint8_t entranceType; // 4 + uint8_t index; // 5 + uint8_t pathType; // 6 + uint8_t rideIndex; // 7 public: uint8_t GetStationIndex() const; From cc7f8e612d70e6dd6c6a064cebecd2a3deb7e733 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 12:13:44 +0200 Subject: [PATCH 02/12] Port entrance type lookup --- .../interface/ViewportInteraction.cpp | 2 +- src/openrct2-ui/windows/Map.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 10 +++++----- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- .../actions/PlaceParkEntranceAction.hpp | 2 +- src/openrct2/actions/RideDemolishAction.hpp | 2 +- .../paint/tile_element/Paint.Entrance.cpp | 4 ++-- src/openrct2/peep/Guest.cpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 4 ++-- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 4 ++-- src/openrct2/ride/Ride.cpp | 16 ++++++++-------- src/openrct2/ride/TrackDesignSave.cpp | 9 +++++---- src/openrct2/world/Entrance.cpp | 14 ++++++++++++-- src/openrct2/world/Footpath.cpp | 8 ++++---- src/openrct2/world/Map.cpp | 17 ++++++----------- src/openrct2/world/Map.h | 2 -- src/openrct2/world/MapAnimation.cpp | 4 ++-- src/openrct2/world/Park.cpp | 2 +- src/openrct2/world/TileElement.h | 3 +++ src/openrct2/world/TileInspector.cpp | 6 +++--- 21 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 8d4c587354..8d3cb3d111 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -243,7 +243,7 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) { rct_string_id stringId; - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { if (ride->num_stations > 1) { diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index d0fd9d16e6..2c4551bdc4 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -1587,7 +1587,7 @@ static uint16_t map_window_get_pixel_colour_ride(CoordsXY c) colourA = MAP_COLOUR(PALETTE_INDEX_14); // lighter grey break; case TILE_ELEMENT_TYPE_ENTRANCE: - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_PARK_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE) break; // fall-through case TILE_ELEMENT_TYPE_TRACK: diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 0b4ef97058..2fd4e082a9 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1608,7 +1608,7 @@ static void window_tile_inspector_invalidate(rct_window* w) w->widgets[WIDX_ENTRANCE_BUTTON_MAKE_USABLE].top = GBBT(propertiesAnchor, 1); w->widgets[WIDX_ENTRANCE_BUTTON_MAKE_USABLE].bottom = GBBB(propertiesAnchor, 1); widget_set_enabled( - w, WIDX_ENTRANCE_BUTTON_MAKE_USABLE, tileElement->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE); + w, WIDX_ENTRANCE_BUTTON_MAKE_USABLE, tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE); break; case TILE_INSPECTOR_PAGE_WALL: { @@ -1918,10 +1918,10 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // Details // Entrance type - rct_string_id entranceType = EntranceTypeStringIds[tileElement->properties.entrance.type]; + rct_string_id entranceType = EntranceTypeStringIds[tileElement->AsEntrance()->GetEntranceType()]; gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_ENTRANCE_TYPE, &entranceType, COLOUR_DARK_GREEN, x, y); - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_PARK_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE) { // Park entrance ID int32_t middleX = windowTileInspectorTileX << 5; @@ -1935,7 +1935,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { int16_t rideEntranceIndex = (tileElement->properties.entrance.index & 0x30) >> 4; // TODO: use mask or function - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { // Ride entrance ID gfx_draw_string_left( @@ -1949,7 +1949,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) } } - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_PARK_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE) { // Entrance part rct_string_id entrancePart = ParkEntrancePartStringIds[tileElement->properties.entrance.index & 0x0F]; diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index fd0ec9c1c0..f35bfab3cb 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -148,7 +148,7 @@ void setup_in_use_selection_flags() Editor::SetSelectedObject(OBJECT_TYPE_SMALL_SCENERY, type, OBJECT_SELECTION_FLAG_SELECTED); break; case TILE_ELEMENT_TYPE_ENTRANCE: - if (iter.element->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE) + if (iter.element->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) break; // Skip if not the middle part if (iter.element->properties.entrance.index != 0) diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index c6654fdbb6..9e90f12c12 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -193,7 +193,7 @@ public: newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); newElement->SetDirection(_direction); newElement->properties.entrance.index = index; - newElement->properties.entrance.type = ENTRANCE_TYPE_PARK_ENTRANCE; + newElement->AsEntrance()->GetEntranceType() = ENTRANCE_TYPE_PARK_ENTRANCE; newElement->properties.entrance.path_type = gFootpathSelectedId; if (!(flags & GAME_COMMAND_FLAG_GHOST)) diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index 4aba6b8e1a..a6bbf9756a 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -288,7 +288,7 @@ private: if (tile_type == TILE_ELEMENT_TYPE_ENTRANCE) { - uint8_t type = entrance_element_get_type(it.element); + uint8_t type = it.element->AsEntrance()->GetEntranceType(); if (type == ENTRANCE_TYPE_PARK_ENTRANCE) continue; diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index c9d1194245..5a58b409fa 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -30,7 +30,7 @@ static uint32_t _unk9E32BC; static void ride_entrance_exit_paint( paint_session* session, uint8_t direction, int32_t height, const rct_tile_element* tile_element) { - uint8_t is_exit = tile_element->properties.entrance.type == ENTRANCE_TYPE_RIDE_EXIT; + uint8_t is_exit = tile_element->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT; if (gTrackDesignSaveMode || (gCurrentViewportFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) { @@ -345,7 +345,7 @@ void entrance_paint(paint_session* session, uint8_t direction, int32_t height, c } } - switch (tile_element->properties.entrance.type) + switch (tile_element->AsEntrance()->GetEntranceType()) { case ENTRANCE_TYPE_RIDE_ENTRANCE: case ENTRANCE_TYPE_RIDE_EXIT: diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index fd397c9aaa..45cd9f2249 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -4820,7 +4820,7 @@ void rct_peep::UpdateRideMazePathfinding() } if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE - && tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_EXIT) + && tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT) { mazeType = maze_type::entrance_or_exit; break; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index c2ffd16716..49418f0458 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -313,7 +313,7 @@ static uint8_t footpath_element_dest_in_dir( case TILE_ELEMENT_TYPE_ENTRANCE: if (loc.z != tileElement->base_height) continue; - switch (tileElement->properties.entrance.type) + switch (tileElement->AsEntrance()->GetEntranceType()) { case ENTRANCE_TYPE_RIDE_ENTRANCE: direction = tileElement->GetDirection(); @@ -673,7 +673,7 @@ static void peep_pathfind_heuristic_search( continue; int32_t direction; searchResult = PATH_SEARCH_OTHER; - switch (tileElement->properties.entrance.type) + switch (tileElement->AsEntrance()->GetEntranceType()) { case ENTRANCE_TYPE_RIDE_ENTRANCE: /* For peeps heading for a ride without a queue, the diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 5687634de6..f8a0c69f8b 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2429,7 +2429,7 @@ static void peep_return_to_centre_of_tile(rct_peep* peep) static void peep_interact_with_entrance( rct_peep* peep, int16_t x, int16_t y, rct_tile_element* tile_element, uint8_t& pathing_result) { - uint8_t entranceType = tile_element->properties.entrance.type; + uint8_t entranceType = tile_element->AsEntrance()->GetEntranceType(); uint8_t rideIndex = tile_element->properties.entrance.ride_index; // Store some details to determine when to override the default diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 814ae42079..9fc80041cb 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2536,7 +2536,7 @@ private: break; } case TILE_ELEMENT_TYPE_ENTRANCE: - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_PARK_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE) { uint8_t pathType = tileElement->properties.entrance.path_type; if (pathType == 0) @@ -2708,7 +2708,7 @@ private: if (element->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (element->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE) + if (element->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) continue; if ((element->properties.entrance.index & 0x0F) != 0) continue; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index d999c6e09e..1617747773 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1876,7 +1876,7 @@ static int32_t ride_modify_entrance_or_exit(rct_tile_element* tileElement, int32 rideIndex = tileElement->properties.entrance.ride_index; - entranceType = tileElement->properties.entrance.type; + entranceType = tileElement->AsEntrance()->GetEntranceType(); if (entranceType != ENTRANCE_TYPE_RIDE_ENTRANCE && entranceType != ENTRANCE_TYPE_RIDE_EXIT) return 0; @@ -3612,7 +3612,7 @@ static void ride_entrance_set_map_tooltip(rct_tile_element* tileElement) if (ride->station_starts[i].xy == RCT_XY8_UNDEFINED) stationIndex--; - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { // Get the queue length int32_t queueLength = 0; @@ -4731,8 +4731,8 @@ static void ride_set_maze_entrance_exit_points(Ride* ride) { if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_ENTRANCE - && tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_EXIT) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE + && tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT) { continue; } @@ -8147,7 +8147,7 @@ void sub_6CB945(int32_t rideIndex) continue; if (tileElement->properties.entrance.ride_index != rideIndex) continue; - if (tileElement->properties.entrance.type > ENTRANCE_TYPE_RIDE_EXIT) + if (tileElement->AsEntrance()->GetEntranceType() > ENTRANCE_TYPE_RIDE_EXIT) continue; CoordsXY nextLocation = location; @@ -8181,7 +8181,7 @@ void sub_6CB945(int32_t rideIndex) stationId = trackElement->AsTrack()->GetStationIndex(); } - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_EXIT) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT) { if (!ride_get_exit_location(ride, stationId).isNull()) break; @@ -8863,7 +8863,7 @@ void determine_ride_entrance_and_exit_locations() // The expected height is where entrances and exit reside in non-hacked parks. const uint8_t expectedHeight = ride->station_heights[stationIndex]; - if (fixEntrance && tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_ENTRANCE) + if (fixEntrance && tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { if (alreadyFoundEntrance) { @@ -8887,7 +8887,7 @@ void determine_ride_entrance_and_exit_locations() "Fixed disconnected entrance of ride %d, station %d to x = %d, y = %d and z = %d.", rideIndex, stationIndex, x, y, tileElement->base_height); } - else if (fixExit && tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_EXIT) + else if (fixExit && tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT) { if (alreadyFoundExit) { diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 07b51b8669..11f7350204 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -605,9 +605,10 @@ static bool track_design_save_should_select_scenery_around(int32_t rideIndex, rc return true; break; case TILE_ELEMENT_TYPE_ENTRANCE: - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_ENTRANCE) + // FIXME: This will always break and return false! + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) break; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_EXIT) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT) break; if (tileElement->properties.entrance.ride_index == rideIndex) return true; @@ -926,7 +927,7 @@ static bool track_design_save_to_td6_for_maze(uint8_t rideIndex, rct_track_td6* { if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) continue; if (tileElement->properties.entrance.ride_index == rideIndex) break; @@ -956,7 +957,7 @@ static bool track_design_save_to_td6_for_maze(uint8_t rideIndex, rct_track_td6* { if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_EXIT) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT) continue; if (tileElement->properties.entrance.ride_index == rideIndex) break; diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index a7f655c7d7..02b2efa7db 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -267,7 +267,7 @@ static money32 RideEntranceExitPlace( tileElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); tileElement->SetDirection(direction); tileElement->clearance_height = clear_z; - tileElement->properties.entrance.type = isExit; + tileElement->AsEntrance()->SetEntranceType(isExit ? ENTRANCE_TYPE_RIDE_EXIT : ENTRANCE_TYPE_RIDE_ENTRANCE); tileElement->properties.entrance.index = stationNum << 4; tileElement->properties.entrance.ride_index = rideIndex; @@ -390,7 +390,7 @@ static money32 RideEntranceExitRemove(int16_t x, int16_t y, uint8_t rideIndex, u maze_entrance_hedge_replacement(x, y, tileElement); footpath_remove_edges_at(x, y, tileElement); - bool isExit = tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_EXIT; + bool isExit = tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT; tile_element_remove(tileElement); @@ -641,3 +641,13 @@ void EntranceElement::SetStationIndex(uint8_t stationIndex) index &= ~MAP_ELEM_TRACK_SEQUENCE_STATION_INDEX_MASK; index |= (stationIndex << 4); } + +uint8_t EntranceElement::GetEntranceType() const +{ + return entranceType; +} + +void EntranceElement::SetEntranceType(uint8_t newType) +{ + entranceType = newType; +} diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 613a9a940d..6f37ae0402 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -98,7 +98,7 @@ static constexpr const uint8_t connected_path_count[] = { int32_t entrance_get_directions(const rct_tile_element* tileElement) { - uint8_t entranceType = tileElement->properties.entrance.type; + uint8_t entranceType = tileElement->AsEntrance()->GetEntranceType(); uint8_t sequence = tileElement->properties.entrance.index & 0x0F; return EntranceDirections[(entranceType * 8) + sequence]; } @@ -1401,7 +1401,7 @@ static void loc_6A6D7E( } else { - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) { footpath_queue_chain_push(tileElement->properties.entrance.ride_index); } @@ -1753,7 +1753,7 @@ void footpath_update_queue_chains() { if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) continue; if (tileElement->properties.entrance.ride_index != rideIndex) continue; @@ -2336,7 +2336,7 @@ void footpath_update_queue_entrance_banner(int32_t x, int32_t y, rct_tile_elemen } break; case TILE_ELEMENT_TYPE_ENTRANCE: - if (tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { footpath_queue_chain_push(tileElement->properties.entrance.ride_index); footpath_chain_ride_queue(255, 0, x, y, tileElement, tileElement->GetDirectionWithOffset(2)); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index daf9f1033f..3ed1295dd4 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -3144,7 +3144,7 @@ void map_remove_all_rides() } break; case TILE_ELEMENT_TYPE_ENTRANCE: - if (it.element->properties.entrance.type == ENTRANCE_TYPE_PARK_ENTRANCE) + if (it.element->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE) break; // fall-through @@ -3424,7 +3424,7 @@ void map_obstruction_set_error_text(rct_tile_element* tileElement) set_format_arg(0, rct_string_id, sceneryEntry->name); break; case TILE_ELEMENT_TYPE_ENTRANCE: - switch (tileElement->properties.entrance.type) + switch (tileElement->AsEntrance()->GetEntranceType()) { case ENTRANCE_TYPE_RIDE_ENTRANCE: errorStringId = STR_RIDE_ENTRANCE_IN_THE_WAY; @@ -3972,7 +3972,7 @@ rct_tile_element* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t if (tileElement->base_height != z) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) continue; if ((ghost == false) && (tileElement->flags & TILE_ELEMENT_FLAG_GHOST)) @@ -3997,7 +3997,7 @@ rct_tile_element* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t if (tileElement->base_height != z) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) continue; if ((ghost == false) && (tileElement->flags & TILE_ELEMENT_FLAG_GHOST)) @@ -4022,7 +4022,7 @@ rct_tile_element* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, if (tileElement->base_height != z) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_EXIT) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT) continue; if ((ghost == false) && (tileElement->flags & TILE_ELEMENT_FLAG_GHOST)) @@ -4821,7 +4821,7 @@ uint16_t check_max_allowable_land_rights_for_tile(uint8_t x, uint8_t y, uint8_t { int32_t type = tileElement->GetType(); if (type == TILE_ELEMENT_TYPE_PATH - || (type == TILE_ELEMENT_TYPE_ENTRANCE && tileElement->properties.entrance.type == ENTRANCE_TYPE_PARK_ENTRANCE)) + || (type == TILE_ELEMENT_TYPE_ENTRANCE && tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE)) { destOwnership = OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED; // Do not own construction rights if too high/below surface @@ -4851,8 +4851,3 @@ void FixLandOwnershipTilesWithOwnership(std::initializer_list tile update_park_fences_around_tile({ (*tile).x * 32, (*tile).y * 32 }); } } - -uint8_t entrance_element_get_type(const rct_tile_element* tileElement) -{ - return (tileElement->properties.entrance.type); -} diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 15d80f0cda..0f01733bd3 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -297,6 +297,4 @@ void FixLandOwnershipTilesWithOwnership(std::initializer_list tile bool place_peep_spawn(CoordsXYZD location); -uint8_t entrance_element_get_type(const rct_tile_element* tileElement); - #endif diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index 9a447ae583..ac751b6724 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -114,7 +114,7 @@ static bool map_animation_invalidate_ride_entrance(int32_t x, int32_t y, int32_t continue; if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_RIDE_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) continue; ride = get_ride(tileElement->properties.entrance.ride_index); @@ -246,7 +246,7 @@ static bool map_animation_invalidate_park_entrance(int32_t x, int32_t y, int32_t continue; if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) continue; if (tileElement->properties.entrance.index & 0x0F) continue; diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 531b1f15dc..ef6b54603f 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -185,7 +185,7 @@ void update_park_fences(const CoordsXY coords) if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE) + if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) continue; if (!(tileElement->flags & TILE_ELEMENT_FLAG_GHOST)) diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index a02462b8ff..08dbaa8b8e 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -381,6 +381,9 @@ private: uint8_t rideIndex; // 7 public: + uint8_t GetEntranceType() const; + void SetEntranceType(uint8_t newType); + uint8_t GetStationIndex() const; void SetStationIndex(uint8_t stationIndex); }; diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 1b1a18cac3..580ca589d4 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -245,7 +245,7 @@ int32_t tile_inspector_rotate_element_at(int32_t x, int32_t y, int32_t elementIn uint8_t stationIndex = tileElement->properties.entrance.index; auto entrance = ride_get_entrance_location(ride, stationIndex); auto exit = ride_get_exit_location(ride, stationIndex); - uint8_t entranceType = entrance_element_get_type(tileElement); + uint8_t entranceType = tileElement->AsEntrance()->GetEntranceType(); uint8_t z = tileElement->base_height; // Make sure this is the correct entrance or exit @@ -437,7 +437,7 @@ int32_t tile_inspector_any_base_height_offset(int32_t x, int32_t y, int16_t elem { if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) { - uint8_t entranceType = tileElement->properties.entrance.type; + uint8_t entranceType = tileElement->AsEntrance()->GetEntranceType(); if (entranceType != ENTRANCE_TYPE_PARK_ENTRANCE) { // Update the ride's known entrance or exit height @@ -673,7 +673,7 @@ int32_t tile_inspector_entrance_make_usable(int32_t x, int32_t y, int32_t elemen { uint8_t stationIndex = entranceElement->properties.entrance.index >> 6; - switch (entranceElement->properties.entrance.type) + switch (entranceElement->AsEntrance()->GetEntranceType()) { case ENTRANCE_TYPE_RIDE_ENTRANCE: ride_set_entrance_location( From c7eaa1ba8069e7b8824052eb130770ea6c21a037 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 12:30:27 +0200 Subject: [PATCH 03/12] Port entrance ride index lookup --- src/openrct2-ui/windows/Ride.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2/actions/PlaceParkEntranceAction.hpp | 2 +- src/openrct2/actions/RideDemolishAction.hpp | 2 +- .../paint/tile_element/Paint.Entrance.cpp | 6 +++--- src/openrct2/peep/GuestPathfinding.cpp | 6 +++--- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/peep/Staff.cpp | 4 ++-- src/openrct2/ride/Ride.cpp | 12 ++++++------ src/openrct2/ride/TrackDesignSave.cpp | 6 +++--- src/openrct2/world/Entrance.cpp | 16 +++++++++++++--- src/openrct2/world/Footpath.cpp | 8 ++++---- src/openrct2/world/MapAnimation.cpp | 2 +- src/openrct2/world/TileElement.cpp | 2 +- src/openrct2/world/TileElement.h | 5 ++++- src/openrct2/world/TileInspector.cpp | 6 +++--- 16 files changed, 48 insertions(+), 35 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 7ebdf4bfab..fddef51490 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1640,7 +1640,7 @@ rct_window* window_ride_open_track(rct_tile_element* tileElement) if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) { - int32_t rideIndex = tileElement->properties.entrance.ride_index; + int32_t rideIndex = tileElement->AsEntrance()->GetRideIndex(); // Open ride window in station view return window_ride_open_station(rideIndex, tileElement->AsEntrance()->GetStationIndex()); } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 2fd4e082a9..f49e976b01 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1958,7 +1958,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) else { // Ride ID - int16_t rideId = tileElement->properties.entrance.ride_index; + int16_t rideId = tileElement->AsEntrance()->GetRideIndex(); gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_ENTRANCE_RIDE_ID, &rideId, COLOUR_DARK_GREEN, x, y + 22); } diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index 9e90f12c12..bb92e4a021 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -193,7 +193,7 @@ public: newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); newElement->SetDirection(_direction); newElement->properties.entrance.index = index; - newElement->AsEntrance()->GetEntranceType() = ENTRANCE_TYPE_PARK_ENTRANCE; + newElement->AsEntrance()->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE); newElement->properties.entrance.path_type = gFootpathSelectedId; if (!(flags & GAME_COMMAND_FLAG_GHOST)) diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index a6bbf9756a..5182f24362 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -292,7 +292,7 @@ private: if (type == ENTRANCE_TYPE_PARK_ENTRANCE) continue; - if (it.element->properties.entrance.ride_index == _rideIndex) + if (it.element->AsEntrance()->GetRideIndex() == _rideIndex) { tile_element_remove(it.element); tile_element_iterator_restart_for_tile(&it); diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 5a58b409fa..9b80d604f1 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -34,7 +34,7 @@ static void ride_entrance_exit_paint( if (gTrackDesignSaveMode || (gCurrentViewportFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) { - if (tile_element->properties.entrance.ride_index != gTrackDesignSaveRideIndex) + if (tile_element->AsEntrance()->GetRideIndex() != gTrackDesignSaveRideIndex) return; } @@ -68,7 +68,7 @@ static void ride_entrance_exit_paint( } #endif - Ride* ride = get_ride(tile_element->properties.entrance.ride_index); + Ride* ride = get_ride(tile_element->AsEntrance()->GetRideIndex()); if (ride->entrance_style == RIDE_ENTRANCE_STYLE_NONE) return; @@ -155,7 +155,7 @@ static void ride_entrance_exit_paint( paint_util_push_tunnel_left(session, height, TUNNEL_6); } - if (!is_exit && !(tile_element->flags & TILE_ELEMENT_FLAG_GHOST) && tile_element->properties.entrance.ride_index != 0xFF) + if (!is_exit && !(tile_element->flags & TILE_ELEMENT_FLAG_GHOST) && tile_element->AsEntrance()->GetRideIndex() != 0xFF) { set_format_arg(0, uint32_t, 0); set_format_arg(4, uint32_t, 0); diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 49418f0458..f2bd51ac5a 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -319,7 +319,7 @@ static uint8_t footpath_element_dest_in_dir( direction = tileElement->GetDirection(); if (direction == chosenDirection) { - *outRideIndex = tileElement->properties.entrance.ride_index; + *outRideIndex = tileElement->AsEntrance()->GetRideIndex(); return PATH_SEARCH_RIDE_ENTRANCE; } break; @@ -327,7 +327,7 @@ static uint8_t footpath_element_dest_in_dir( direction = tileElement->GetDirection(); if (direction == chosenDirection) { - *outRideIndex = tileElement->properties.entrance.ride_index; + *outRideIndex = tileElement->AsEntrance()->GetRideIndex(); return PATH_SEARCH_RIDE_EXIT; } break; @@ -686,7 +686,7 @@ static void peep_pathfind_heuristic_search( { /* The rideIndex will be useful for * adding transport rides later. */ - rideIndex = tileElement->properties.entrance.ride_index; + rideIndex = tileElement->AsEntrance()->GetRideIndex(); searchResult = PATH_SEARCH_RIDE_ENTRANCE; found = true; break; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index f8a0c69f8b..9057bbedc4 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2430,7 +2430,7 @@ static void peep_interact_with_entrance( rct_peep* peep, int16_t x, int16_t y, rct_tile_element* tile_element, uint8_t& pathing_result) { uint8_t entranceType = tile_element->AsEntrance()->GetEntranceType(); - uint8_t rideIndex = tile_element->properties.entrance.ride_index; + uint8_t rideIndex = tile_element->AsEntrance()->GetRideIndex(); // Store some details to determine when to override the default // behaviour (defined below) for when staff attempt to enter a ride diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 971f541798..5b9d1bc4a0 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1935,7 +1935,7 @@ void rct_peep::UpdateHeadingToInspect() return; } - if (current_ride != rideEntranceExitElement->properties.entrance.ride_index) + if (current_ride != rideEntranceExitElement->AsEntrance()->GetRideIndex()) return; uint8_t exit_index = ((rideEntranceExitElement->properties.entrance.index & 0x70) >> 4); @@ -2053,7 +2053,7 @@ void rct_peep::UpdateAnswering() return; } - if (current_ride != rideEntranceExitElement->properties.entrance.ride_index) + if (current_ride != rideEntranceExitElement->AsEntrance()->GetRideIndex()) return; uint8_t exit_index = ((rideEntranceExitElement->properties.entrance.index & 0x70) >> 4); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 1617747773..91400d531a 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1874,7 +1874,7 @@ static int32_t ride_modify_entrance_or_exit(rct_tile_element* tileElement, int32 int32_t rideIndex, entranceType; rct_window* constructionWindow; - rideIndex = tileElement->properties.entrance.ride_index; + rideIndex = tileElement->AsEntrance()->GetRideIndex(); entranceType = tileElement->AsEntrance()->GetEntranceType(); if (entranceType != ENTRANCE_TYPE_RIDE_ENTRANCE && entranceType != ENTRANCE_TYPE_RIDE_EXIT) @@ -3603,7 +3603,7 @@ static void ride_entrance_set_map_tooltip(rct_tile_element* tileElement) int32_t i, rideIndex, stationIndex; Ride* ride; - rideIndex = tileElement->properties.entrance.ride_index; + rideIndex = tileElement->AsEntrance()->GetRideIndex(); ride = get_ride(rideIndex); // Get the station @@ -8145,7 +8145,7 @@ void sub_6CB945(int32_t rideIndex) { if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) continue; - if (tileElement->properties.entrance.ride_index != rideIndex) + if (tileElement->AsEntrance()->GetRideIndex() != rideIndex) continue; if (tileElement->AsEntrance()->GetEntranceType() > ENTRANCE_TYPE_RIDE_EXIT) continue; @@ -8802,7 +8802,7 @@ void determine_ride_entrance_and_exit_locations() { tileElement = map_get_ride_entrance_element_at(entranceLoc.x * 32, entranceLoc.y * 32, entranceLoc.z, false); - if (tileElement == nullptr || tileElement->properties.entrance.ride_index != rideIndex + if (tileElement == nullptr || tileElement->AsEntrance()->GetRideIndex() != rideIndex || tileElement->AsEntrance()->GetStationIndex() != stationIndex) { fixEntrance = true; @@ -8817,7 +8817,7 @@ void determine_ride_entrance_and_exit_locations() { tileElement = map_get_ride_exit_element_at(exitLoc.x * 32, exitLoc.y * 32, entranceLoc.z, false); - if (tileElement == nullptr || tileElement->properties.entrance.ride_index != rideIndex + if (tileElement == nullptr || tileElement->AsEntrance()->GetRideIndex() != rideIndex || tileElement->AsEntrance()->GetStationIndex() != stationIndex) { fixExit = true; @@ -8851,7 +8851,7 @@ void determine_ride_entrance_and_exit_locations() { continue; } - if (tileElement->properties.entrance.ride_index != rideIndex) + if (tileElement->AsEntrance()->GetRideIndex() != rideIndex) { continue; } diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 11f7350204..62f23245fa 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -610,7 +610,7 @@ static bool track_design_save_should_select_scenery_around(int32_t rideIndex, rc break; if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT) break; - if (tileElement->properties.entrance.ride_index == rideIndex) + if (tileElement->AsEntrance()->GetRideIndex() == rideIndex) return true; break; } @@ -929,7 +929,7 @@ static bool track_design_save_to_td6_for_maze(uint8_t rideIndex, rct_track_td6* continue; if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) continue; - if (tileElement->properties.entrance.ride_index == rideIndex) + if (tileElement->AsEntrance()->GetRideIndex() == rideIndex) break; } while (!(tileElement++)->IsLastForTile()); // Add something that stops this from walking off the end @@ -959,7 +959,7 @@ static bool track_design_save_to_td6_for_maze(uint8_t rideIndex, rct_track_td6* continue; if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_EXIT) continue; - if (tileElement->properties.entrance.ride_index == rideIndex) + if (tileElement->AsEntrance()->GetRideIndex() == rideIndex) break; } while (!(tileElement++)->IsLastForTile()); // Add something that stops this from walking off the end diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index 02b2efa7db..df8e05b275 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -269,7 +269,7 @@ static money32 RideEntranceExitPlace( tileElement->clearance_height = clear_z; tileElement->AsEntrance()->SetEntranceType(isExit ? ENTRANCE_TYPE_RIDE_EXIT : ENTRANCE_TYPE_RIDE_ENTRANCE); tileElement->properties.entrance.index = stationNum << 4; - tileElement->properties.entrance.ride_index = rideIndex; + tileElement->AsEntrance()->SetRideIndex(rideIndex); if (flags & GAME_COMMAND_FLAG_GHOST) { @@ -548,7 +548,7 @@ void maze_entrance_hedge_replacement(int32_t x, int32_t y, rct_tile_element* til x += CoordsDirectionDelta[direction].x; y += CoordsDirectionDelta[direction].y; int32_t z = tileElement->base_height; - int32_t rideIndex = tileElement->properties.entrance.ride_index; + int32_t rideIndex = tileElement->AsEntrance()->GetRideIndex(); tileElement = map_get_first_element_at(x >> 5, y >> 5); do @@ -584,7 +584,7 @@ void maze_entrance_hedge_removal(int32_t x, int32_t y, rct_tile_element* tileEle x += CoordsDirectionDelta[direction].x; y += CoordsDirectionDelta[direction].y; int32_t z = tileElement->base_height; - int32_t rideIndex = tileElement->properties.entrance.ride_index; + int32_t rideIndex = tileElement->AsEntrance()->GetRideIndex(); tileElement = map_get_first_element_at(x >> 5, y >> 5); do @@ -651,3 +651,13 @@ void EntranceElement::SetEntranceType(uint8_t newType) { entranceType = newType; } + +uint8_t EntranceElement::GetRideIndex() const +{ + return rideIndex; +} + +void EntranceElement::SetRideIndex(uint8_t newRideIndex) +{ + rideIndex = newRideIndex; +} diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 6f37ae0402..bc4f65b24f 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1396,14 +1396,14 @@ static void loc_6A6D7E( if (query) { neighbour_list_push( - neighbourList, 8, direction, tileElement->properties.entrance.ride_index, + neighbourList, 8, direction, tileElement->AsEntrance()->GetRideIndex(), tileElement->properties.entrance.index); } else { if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE) { - footpath_queue_chain_push(tileElement->properties.entrance.ride_index); + footpath_queue_chain_push(tileElement->AsEntrance()->GetRideIndex()); } } goto loc_6A6FD2; @@ -1755,7 +1755,7 @@ void footpath_update_queue_chains() continue; if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) continue; - if (tileElement->properties.entrance.ride_index != rideIndex) + if (tileElement->AsEntrance()->GetRideIndex() != rideIndex) continue; uint8_t direction = tileElement->GetDirectionWithOffset(2); @@ -2338,7 +2338,7 @@ void footpath_update_queue_entrance_banner(int32_t x, int32_t y, rct_tile_elemen case TILE_ELEMENT_TYPE_ENTRANCE: if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { - footpath_queue_chain_push(tileElement->properties.entrance.ride_index); + footpath_queue_chain_push(tileElement->AsEntrance()->GetRideIndex()); footpath_chain_ride_queue(255, 0, x, y, tileElement, tileElement->GetDirectionWithOffset(2)); } break; diff --git a/src/openrct2/world/MapAnimation.cpp b/src/openrct2/world/MapAnimation.cpp index ac751b6724..e59c054a86 100644 --- a/src/openrct2/world/MapAnimation.cpp +++ b/src/openrct2/world/MapAnimation.cpp @@ -117,7 +117,7 @@ static bool map_animation_invalidate_ride_entrance(int32_t x, int32_t y, int32_t if (tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_RIDE_ENTRANCE) continue; - ride = get_ride(tileElement->properties.entrance.ride_index); + ride = get_ride(tileElement->AsEntrance()->GetRideIndex()); entranceDefinition = &RideEntranceDefinitions[ride->entrance_style]; int32_t height = (tileElement->base_height * 8) + entranceDefinition->height + 8; diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index 31b1baa9b0..8da29d02d4 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -132,7 +132,7 @@ uint8_t tile_element_get_ride_index(const rct_tile_element* tileElement) case TILE_ELEMENT_TYPE_TRACK: return tileElement->AsTrack()->GetRideIndex(); case TILE_ELEMENT_TYPE_ENTRANCE: - return tileElement->properties.entrance.ride_index; + return tileElement->AsEntrance()->GetRideIndex(); case TILE_ELEMENT_TYPE_PATH: return tileElement->properties.path.ride_index; default: diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 08dbaa8b8e..cf54f3bfe6 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -376,7 +376,7 @@ struct EntranceElement : TileElementBase { private: uint8_t entranceType; // 4 - uint8_t index; // 5 + uint8_t index; // 5. 0bUSSS????, S = station index. uint8_t pathType; // 6 uint8_t rideIndex; // 7 @@ -384,6 +384,9 @@ public: uint8_t GetEntranceType() const; void SetEntranceType(uint8_t newType); + uint8_t GetRideIndex() const; + void SetRideIndex(uint8_t newRideIndex); + uint8_t GetStationIndex() const; void SetStationIndex(uint8_t stationIndex); }; diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 580ca589d4..6f6ad0d949 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -241,7 +241,7 @@ int32_t tile_inspector_rotate_element_at(int32_t x, int32_t y, int32_t elementIn tileElement->SetDirection(newRotation); // Update ride's known entrance/exit rotation - Ride* ride = get_ride(tileElement->properties.entrance.ride_index); + Ride* ride = get_ride(tileElement->AsEntrance()->GetRideIndex()); uint8_t stationIndex = tileElement->properties.entrance.index; auto entrance = ride_get_entrance_location(ride, stationIndex); auto exit = ride_get_exit_location(ride, stationIndex); @@ -441,7 +441,7 @@ int32_t tile_inspector_any_base_height_offset(int32_t x, int32_t y, int16_t elem if (entranceType != ENTRANCE_TYPE_PARK_ENTRANCE) { // Update the ride's known entrance or exit height - Ride* ride = get_ride(tileElement->properties.entrance.ride_index); + Ride* ride = get_ride(tileElement->AsEntrance()->GetRideIndex()); uint8_t entranceIndex = tileElement->properties.entrance.index; auto entrance = ride_get_entrance_location(ride, entranceIndex); auto exit = ride_get_exit_location(ride, entranceIndex); @@ -664,7 +664,7 @@ int32_t tile_inspector_entrance_make_usable(int32_t x, int32_t y, int32_t elemen if (entranceElement == nullptr || entranceElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) return MONEY32_UNDEFINED; - Ride* ride = get_ride(entranceElement->properties.entrance.ride_index); + Ride* ride = get_ride(entranceElement->AsEntrance()->GetRideIndex()); if (ride == nullptr) return MONEY32_UNDEFINED; From 3c93aca72799cf299832f43d14d6433379ce65db Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 12:54:44 +0200 Subject: [PATCH 04/12] Port entrance station index and sequence lookup --- src/openrct2-ui/interface/ViewportInteraction.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 5 ++--- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- src/openrct2/actions/PlaceParkEntranceAction.hpp | 2 +- src/openrct2/paint/tile_element/Paint.Entrance.cpp | 2 +- src/openrct2/peep/Peep.cpp | 4 ++-- src/openrct2/peep/Staff.cpp | 4 ++-- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/ride/Ride.cpp | 9 ++++----- src/openrct2/world/Entrance.cpp | 13 ++++++++++++- src/openrct2/world/Footpath.cpp | 12 ++++++------ src/openrct2/world/Map.cpp | 2 +- src/openrct2/world/MapAnimation.cpp | 2 +- src/openrct2/world/TileElement.h | 3 +++ src/openrct2/world/TileInspector.cpp | 6 +++--- 15 files changed, 41 insertions(+), 29 deletions(-) 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()) { From 995c6debf14b4160ae82d42e474094ab2f8fb882 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 13:02:51 +0200 Subject: [PATCH 05/12] Port entrance path type lookup --- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- src/openrct2/actions/PlaceParkEntranceAction.hpp | 2 +- src/openrct2/paint/tile_element/Paint.Entrance.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 4 ++-- src/openrct2/world/Entrance.cpp | 10 ++++++++++ src/openrct2/world/Footpath.cpp | 8 ++++---- src/openrct2/world/TileElement.h | 13 +++---------- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 41818e822b..e70c572a46 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -156,7 +156,7 @@ void setup_in_use_selection_flags() Editor::SetSelectedObject(OBJECT_TYPE_PARK_ENTRANCE, 0, OBJECT_SELECTION_FLAG_SELECTED); - type = iter.element->properties.entrance.path_type; + type = iter.element->AsEntrance()->GetPathType(); assert(type < object_entry_group_counts[OBJECT_TYPE_PATHS]); Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED); break; diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index 45ed9d0a5a..d6dad9a262 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -194,7 +194,7 @@ public: newElement->SetDirection(_direction); newElement->AsEntrance()->SetSequenceIndex(index); newElement->AsEntrance()->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE); - newElement->properties.entrance.path_type = gFootpathSelectedId; + newElement->AsEntrance()->SetPathType(gFootpathSelectedId); if (!(flags & GAME_COMMAND_FLAG_GHOST)) { diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 078793ac0f..87733df724 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -237,7 +237,7 @@ static void park_entrance_paint(paint_session* session, uint8_t direction, int32 // The left and right of the park entrance often have this set to 127. // So only attempt to get the footpath type if we're dealing with the middle bit of the entrance. if (part_index == 0) - path_entry = get_footpath_entry(tile_element->properties.entrance.path_type); + path_entry = get_footpath_entry(tile_element->AsEntrance()->GetPathType()); rct_entrance_type* entrance; uint8_t di = ((direction / 2 + part_index / 2) & 1) ? 0x1A : 0x20; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 17d490326e..1d3f6c688b 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2538,13 +2538,13 @@ private: case TILE_ELEMENT_TYPE_ENTRANCE: if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE) { - uint8_t pathType = tileElement->properties.entrance.path_type; + uint8_t pathType = tileElement->AsEntrance()->GetPathType(); if (pathType == 0) { pathType = RCT1_FOOTPATH_TYPE_TARMAC_GRAY; } uint8_t entryIndex = _pathTypeToEntryMap[pathType]; - tileElement->properties.entrance.path_type = entryIndex & 0x7F; + tileElement->AsEntrance()->SetPathType(entryIndex & 0x7F); } break; } diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index d7506fb478..90501dfffe 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -671,4 +671,14 @@ void EntranceElement::SetSequenceIndex(uint8_t newSequenceIndex) { index &= ~0xF; index |= (newSequenceIndex & 0xF); +} + +uint8_t EntranceElement::GetPathType() const +{ + return pathType; +} + +void EntranceElement::SetPathType(uint8_t newPathType) +{ + pathType = newPathType; } \ No newline at end of file diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 85d5472f24..0859a6c290 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -222,7 +222,7 @@ static money32 footpath_element_insert( { entrancePath = true; // Make the price the same as replacing a path - if (entranceElement->properties.entrance.path_type == (type & 0xF)) + if (entranceElement->AsEntrance()->GetPathType() == (type & 0xF)) entranceIsSamePath = true; else gFootpathPrice -= MONEY(6, 00); @@ -256,7 +256,7 @@ static money32 footpath_element_insert( if (!(flags & GAME_COMMAND_FLAG_GHOST) && !entranceIsSamePath) { // Set the path type but make sure it's not a queue as that will not show up - entranceElement->properties.entrance.path_type = type & 0x7F; + entranceElement->AsEntrance()->SetPathType(type & 0x7F); map_invalidate_tile_full(x, y); } } @@ -593,7 +593,7 @@ static money32 footpath_place_from_track( { entrancePath = true; // Make the price the same as replacing a path - if (entranceElement->properties.entrance.path_type == (type & 0xF)) + if (entranceElement->AsEntrance()->GetPathType() == (type & 0xF)) entranceIsSamePath = true; else gFootpathPrice -= MONEY(6, 00); @@ -636,7 +636,7 @@ static money32 footpath_place_from_track( if (!(flags & GAME_COMMAND_FLAG_GHOST) && !entranceIsSamePath) { // Set the path type but make sure it's not a queue as that will not show up - entranceElement->properties.entrance.path_type = type & 0x7F; + entranceElement->AsEntrance()->SetPathType(type & 0x7F); map_invalidate_tile_full(x, y); } } diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index d7e1dd3380..fb7986eb9d 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -28,15 +28,6 @@ struct rct_tile_element_path_properties }; assert_struct_size(rct_tile_element_path_properties, 4); -struct rct_tile_element_entrance_properties -{ - uint8_t type; // 4 - uint8_t index; // 5 - uint8_t path_type; // 6 - uint8_t ride_index; // 7 -}; -assert_struct_size(rct_tile_element_entrance_properties, 4); - struct rct_tile_element_banner_properties { BannerIndex index; // 4 @@ -49,7 +40,6 @@ assert_struct_size(rct_tile_element_banner_properties, 4); union rct_tile_element_properties { rct_tile_element_path_properties path; - rct_tile_element_entrance_properties entrance; rct_tile_element_banner_properties banner; }; assert_struct_size(rct_tile_element_properties, 4); @@ -392,6 +382,9 @@ public: uint8_t GetSequenceIndex() const; void SetSequenceIndex(uint8_t newSequenceIndex); + + uint8_t GetPathType() const; + void SetPathType(uint8_t newPathType); }; assert_struct_size(EntranceElement, 8); From a8e087b5607fd100f595bb40d31feba258491fb5 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 13:20:47 +0200 Subject: [PATCH 06/12] Return actual entrance elements from map functions --- .../actions/PlaceParkEntranceAction.hpp | 2 +- src/openrct2/ride/Ride.cpp | 42 +++++++++---------- src/openrct2/world/Entrance.cpp | 4 +- src/openrct2/world/Footpath.cpp | 18 ++++---- src/openrct2/world/Map.cpp | 12 +++--- src/openrct2/world/Map.h | 6 +-- src/openrct2/world/TileElement.cpp | 5 +++ src/openrct2/world/TileElement.h | 1 + 8 files changed, 49 insertions(+), 41 deletions(-) diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index d6dad9a262..7b1cfb10f3 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -121,7 +121,7 @@ public: } // Check that entrance element does not already exist at this location - rct_tile_element* entranceElement = map_get_park_entrance_element_at(entranceLoc.x, entranceLoc.y, zLow, false); + EntranceElement* entranceElement = map_get_park_entrance_element_at(entranceLoc.x, entranceLoc.y, zLow, false); if (entranceElement != nullptr) { return std::make_unique( diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 9609231f77..681b4ae8d4 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -8794,36 +8794,35 @@ void determine_ride_entrance_and_exit_locations() TileCoordsXYZD exitLoc = ride->exits[stationIndex]; bool fixEntrance = false; bool fixExit = false; - const rct_tile_element* tileElement; // Skip if the station has no entrance if (!entranceLoc.isNull()) { - tileElement = map_get_ride_entrance_element_at(entranceLoc.x * 32, entranceLoc.y * 32, entranceLoc.z, false); + const EntranceElement* entranceElement = map_get_ride_entrance_element_at(entranceLoc.x * 32, entranceLoc.y * 32, entranceLoc.z, false); - if (tileElement == nullptr || tileElement->AsEntrance()->GetRideIndex() != rideIndex - || tileElement->AsEntrance()->GetStationIndex() != stationIndex) + if (entranceElement == nullptr || entranceElement->GetRideIndex() != rideIndex + || entranceElement->GetStationIndex() != stationIndex) { fixEntrance = true; } else { - ride->entrances[stationIndex].direction = (uint8_t)tileElement->GetDirection(); + ride->entrances[stationIndex].direction = (uint8_t)entranceElement->GetDirection(); } } if (!exitLoc.isNull()) { - tileElement = map_get_ride_exit_element_at(exitLoc.x * 32, exitLoc.y * 32, entranceLoc.z, false); + const EntranceElement* entranceElement = map_get_ride_exit_element_at(exitLoc.x * 32, exitLoc.y * 32, entranceLoc.z, false); - if (tileElement == nullptr || tileElement->AsEntrance()->GetRideIndex() != rideIndex - || tileElement->AsEntrance()->GetStationIndex() != stationIndex) + if (entranceElement == nullptr || entranceElement->GetRideIndex() != rideIndex + || entranceElement->GetStationIndex() != stationIndex) { fixExit = true; } else { - ride->exits[stationIndex].direction = (uint8_t)tileElement->GetDirection(); + ride->exits[stationIndex].direction = (uint8_t)entranceElement->GetDirection(); } } @@ -8840,7 +8839,7 @@ void determine_ride_entrance_and_exit_locations() { for (uint8_t y = 1; y < MAXIMUM_MAP_SIZE_TECHNICAL - 1; y++) { - tileElement = map_get_first_element_at(x, y); + rct_tile_element* tileElement = map_get_first_element_at(x, y); if (tileElement != nullptr) { @@ -8850,11 +8849,12 @@ void determine_ride_entrance_and_exit_locations() { continue; } - if (tileElement->AsEntrance()->GetRideIndex() != rideIndex) + const EntranceElement* entranceElement = tileElement->AsEntrance(); + if (entranceElement->GetRideIndex() != rideIndex) { continue; } - if (tileElement->AsEntrance()->GetStationIndex() != stationIndex) + if (entranceElement->GetStationIndex() != stationIndex) { continue; } @@ -8862,13 +8862,13 @@ void determine_ride_entrance_and_exit_locations() // The expected height is where entrances and exit reside in non-hacked parks. const uint8_t expectedHeight = ride->station_heights[stationIndex]; - if (fixEntrance && tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) + if (fixEntrance && entranceElement->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { if (alreadyFoundEntrance) { if (ride->entrances[stationIndex].z == expectedHeight) continue; - if (ride->entrances[stationIndex].z > tileElement->base_height) + if (ride->entrances[stationIndex].z > entranceElement->base_height) continue; } @@ -8876,35 +8876,35 @@ void determine_ride_entrance_and_exit_locations() TileCoordsXYZD newEntranceLoc = { x, y, - tileElement->base_height, - (uint8_t)tileElement->GetDirection(), + entranceElement->base_height, + (uint8_t)entranceElement->GetDirection(), }; ride_set_entrance_location(ride, stationIndex, newEntranceLoc); alreadyFoundEntrance = true; log_verbose( "Fixed disconnected entrance of ride %d, station %d to x = %d, y = %d and z = %d.", - rideIndex, stationIndex, x, y, tileElement->base_height); + rideIndex, stationIndex, x, y, entranceElement->base_height); } - else if (fixExit && tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT) + else if (fixExit && entranceElement->GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT) { if (alreadyFoundExit) { if (ride->exits[stationIndex].z == expectedHeight) continue; - if (ride->exits[stationIndex].z > tileElement->base_height) + if (ride->exits[stationIndex].z > entranceElement->base_height) continue; } // Found our exit ride_set_exit_location( ride, stationIndex, - { x, y, tileElement->base_height, (uint8_t)tileElement->GetDirection() }); + { x, y, entranceElement->base_height, (uint8_t)entranceElement->GetDirection() }); alreadyFoundExit = true; log_verbose( "Fixed disconnected exit of ride %d, station %d to x = %d, y = %d and z = %d.", rideIndex, - stationIndex, x, y, tileElement->base_height); + stationIndex, x, y, entranceElement->base_height); } } while (!(tileElement++)->IsLastForTile()); } diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index 90501dfffe..6ea2e71e99 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -33,7 +33,7 @@ uint8_t gRideEntranceExitGhostStationIndex; static void ParkEntranceRemoveSegment(int32_t x, int32_t y, int32_t z) { - rct_tile_element* tileElement; + EntranceElement* tileElement; tileElement = map_get_park_entrance_element_at(x, y, z, true); if (tileElement == nullptr) @@ -42,7 +42,7 @@ static void ParkEntranceRemoveSegment(int32_t x, int32_t y, int32_t z) } map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); - tile_element_remove(tileElement); + tileElement->Remove(); update_park_fences({ x, y }); } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 0859a6c290..edb9183d48 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -195,7 +195,8 @@ static constexpr const uint8_t byte_98D7EC[] = { 207, 159, 63, 111 }; static money32 footpath_element_insert( int32_t type, int32_t x, int32_t y, int32_t z, int32_t slope, int32_t flags, uint8_t pathItemType) { - rct_tile_element *tileElement, *entranceElement; + rct_tile_element* tileElement; + EntranceElement* entranceElement; int32_t bl, zHigh; bool entrancePath = false, entranceIsSamePath = false; @@ -218,11 +219,11 @@ 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->AsEntrance()->GetSequenceIndex()) == 0) + if (entranceElement != nullptr && (entranceElement->GetSequenceIndex()) == 0) { entrancePath = true; // Make the price the same as replacing a path - if (entranceElement->AsEntrance()->GetPathType() == (type & 0xF)) + if (entranceElement->GetPathType() == (type & 0xF)) entranceIsSamePath = true; else gFootpathPrice -= MONEY(6, 00); @@ -256,7 +257,7 @@ static money32 footpath_element_insert( if (!(flags & GAME_COMMAND_FLAG_GHOST) && !entranceIsSamePath) { // Set the path type but make sure it's not a queue as that will not show up - entranceElement->AsEntrance()->SetPathType(type & 0x7F); + entranceElement->SetPathType(type & 0x7F); map_invalidate_tile_full(x, y); } } @@ -530,7 +531,8 @@ void game_command_place_footpath( static money32 footpath_place_from_track( int32_t type, int32_t x, int32_t y, int32_t z, int32_t slope, int32_t edges, int32_t flags) { - rct_tile_element *tileElement, *entranceElement; + rct_tile_element* tileElement; + EntranceElement* entranceElement; bool entrancePath = false, entranceIsSamePath = false; gCommandExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; @@ -589,11 +591,11 @@ 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->AsEntrance()->GetSequenceIndex()) == 0) + if (entranceElement != nullptr && (entranceElement->GetSequenceIndex()) == 0) { entrancePath = true; // Make the price the same as replacing a path - if (entranceElement->AsEntrance()->GetPathType() == (type & 0xF)) + if (entranceElement->GetPathType() == (type & 0xF)) entranceIsSamePath = true; else gFootpathPrice -= MONEY(6, 00); @@ -636,7 +638,7 @@ static money32 footpath_place_from_track( if (!(flags & GAME_COMMAND_FLAG_GHOST) && !entranceIsSamePath) { // Set the path type but make sure it's not a queue as that will not show up - entranceElement->AsEntrance()->SetPathType(type & 0x7F); + entranceElement->SetPathType(type & 0x7F); map_invalidate_tile_full(x, y); } } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index b74fa8b9c8..51448120f8 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -3959,7 +3959,7 @@ rct_tile_element* map_get_large_scenery_segment(int32_t x, int32_t y, int32_t z, return nullptr; } -rct_tile_element* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost) +EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost) { rct_tile_element* tileElement = map_get_first_element_at(x >> 5, y >> 5); if (tileElement != nullptr) @@ -3978,13 +3978,13 @@ rct_tile_element* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t if ((ghost == false) && (tileElement->flags & TILE_ELEMENT_FLAG_GHOST)) continue; - return tileElement; + return tileElement->AsEntrance(); } while (!(tileElement++)->IsLastForTile()); } return nullptr; } -rct_tile_element* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost) +EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost) { rct_tile_element* tileElement = map_get_first_element_at(x >> 5, y >> 5); if (tileElement != nullptr) @@ -4003,13 +4003,13 @@ rct_tile_element* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t if ((ghost == false) && (tileElement->flags & TILE_ELEMENT_FLAG_GHOST)) continue; - return tileElement; + return tileElement->AsEntrance(); } while (!(tileElement++)->IsLastForTile()); } return nullptr; } -rct_tile_element* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost) +EntranceElement* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost) { rct_tile_element* tileElement = map_get_first_element_at(x >> 5, y >> 5); if (tileElement != nullptr) @@ -4028,7 +4028,7 @@ rct_tile_element* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, if ((ghost == false) && (tileElement->flags & TILE_ELEMENT_FLAG_GHOST)) continue; - return tileElement; + return tileElement->AsEntrance(); } while (!(tileElement++)->IsLastForTile()); } return nullptr; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 0f01733bd3..d882cdca26 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -141,9 +141,9 @@ rct_tile_element* map_get_surface_element_at(CoordsXY coords); rct_tile_element* map_get_path_element_at(int32_t x, int32_t y, int32_t z); rct_tile_element* map_get_wall_element_at(int32_t x, int32_t y, int32_t z, int32_t direction); rct_tile_element* map_get_small_scenery_element_at(int32_t x, int32_t y, int32_t z, int32_t type, uint8_t quadrant); -rct_tile_element* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost); -rct_tile_element* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost); -rct_tile_element* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost); +EntranceElement* map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost); +EntranceElement* map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost); +EntranceElement* map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost); int32_t tile_element_height(int32_t x, int32_t y); bool map_coord_is_connected(int32_t x, int32_t y, int32_t z, uint8_t faceDirection); void map_remove_provisional_elements(); diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index 8da29d02d4..36a1920260 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -148,3 +148,8 @@ void rct_tile_element::ClearAs(uint8_t newType) clearance_height = 2; memset(pad_04, 0, sizeof(pad_04)); } + +void TileElementBase::Remove() +{ + tile_element_remove((rct_tile_element*)this); +} diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index fb7986eb9d..aae072b587 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -96,6 +96,7 @@ struct TileElementBase uint8_t GetDirectionWithOffset(uint8_t offset) const; bool IsLastForTile() const; bool IsGhost() const; + void Remove(); }; /** From d01b21a1ac727efb33cc1b48295c495d6b176509 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 14:07:04 +0200 Subject: [PATCH 07/12] Port banner index --- .../interface/ViewportInteraction.cpp | 4 ++-- src/openrct2-ui/windows/Banner.cpp | 4 ++-- src/openrct2-ui/windows/TileInspector.cpp | 4 ++-- src/openrct2-ui/windows/TopToolbar.cpp | 4 ++-- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- .../paint/tile_element/Paint.Banner.cpp | 8 +++---- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/world/Banner.cpp | 22 ++++++++++++++----- src/openrct2/world/TileElement.cpp | 4 ++-- src/openrct2/world/TileElement.h | 12 +++++++++- 10 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 37ee5ffd19..f652f1854f 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -330,7 +330,7 @@ int32_t viewport_interaction_get_item_right(int32_t x, int32_t y, viewport_inter break; case VIEWPORT_INTERACTION_ITEM_BANNER: - banner = &gBanners[tileElement->properties.banner.index]; + banner = &gBanners[tileElement->AsBanner()->GetIndex()]; sceneryEntry = get_banner_entry(banner->type); set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY); @@ -452,7 +452,7 @@ int32_t viewport_interaction_right_click(int32_t x, int32_t y) viewport_interaction_remove_large_scenery(info.tileElement, info.x, info.y); break; case VIEWPORT_INTERACTION_ITEM_BANNER: - context_open_detail_window(WD_BANNER, info.tileElement->properties.banner.index); + context_open_detail_window(WD_BANNER, info.tileElement->AsBanner()->GetIndex()); break; } diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index a42f252960..d204380bab 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -135,7 +135,7 @@ rct_window* window_banner_open(rct_windownumber number) rct_tile_element* tile_element = map_get_first_element_at(view_x / 32, view_y / 32); while (1) { - if ((tile_element->GetType() == TILE_ELEMENT_TYPE_BANNER) && (tile_element->properties.banner.index == w->number)) + if ((tile_element->GetType() == TILE_ELEMENT_TYPE_BANNER) && (tile_element->AsBanner()->GetIndex() == w->number)) { break; } @@ -175,7 +175,7 @@ static void window_banner_mouseup(rct_window* w, rct_widgetindex widgetIndex) while (1) { - if ((tile_element->GetType() == TILE_ELEMENT_TYPE_BANNER) && (tile_element->properties.banner.index == w->number)) + if ((tile_element->GetType() == TILE_ELEMENT_TYPE_BANNER) && (tile_element->AsBanner()->GetIndex() == w->number)) break; tile_element++; } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 32a2e49952..c6394db628 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -2051,7 +2051,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // Details // Banner info - const uint8_t bannerIndex = tileElement->properties.banner.index; + const uint8_t bannerIndex = tileElement->AsBanner()->GetIndex(); if (gBanners[bannerIndex].flags & BANNER_FLAG_NO_ENTRY) { rct_string_id noEntryStringIdx = STR_NO_ENTRY; @@ -2166,7 +2166,7 @@ static void window_tile_inspector_scrollpaint(rct_window* w, rct_drawpixelinfo* case TILE_ELEMENT_TYPE_BANNER: snprintf( buffer, sizeof(buffer), "%s (%d)", language_get_string(STR_BANNER_WINDOW_TITLE), - tileElement->properties.banner.index); + tileElement->AsBanner()->GetIndex()); typeName = buffer; break; case TILE_ELEMENT_TYPE_CORRUPT: diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index eb4bdf6b9c..c267d92042 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1031,7 +1031,7 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg } case VIEWPORT_INTERACTION_ITEM_BANNER: { - rct_banner* banner = &gBanners[tile_element->properties.banner.index]; + rct_banner* banner = &gBanners[tile_element->AsBanner()->GetIndex()]; rct_scenery_entry* scenery_entry = get_banner_entry(banner->type); if (scenery_entry->banner.flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR) { @@ -1114,7 +1114,7 @@ static void scenery_eyedropper_tool_down(int16_t x, int16_t y, rct_widgetindex w } case VIEWPORT_INTERACTION_ITEM_BANNER: { - int32_t bannerIndex = tileElement->properties.banner.index; + int32_t bannerIndex = tileElement->AsBanner()->GetIndex(); rct_banner* banner = &gBanners[bannerIndex]; rct_scenery_entry* sceneryEntry = get_banner_entry(banner->type); if (sceneryEntry != nullptr) diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index e70c572a46..dbeff817b8 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -171,7 +171,7 @@ void setup_in_use_selection_flags() Editor::SetSelectedObject(OBJECT_TYPE_LARGE_SCENERY, type, OBJECT_SELECTION_FLAG_SELECTED); break; case TILE_ELEMENT_TYPE_BANNER: - banner = &gBanners[iter.element->properties.banner.index]; + banner = &gBanners[iter.element->AsBanner()->GetIndex()]; type = banner->type; assert(type < object_entry_group_counts[OBJECT_TYPE_BANNERS]); Editor::SetSelectedObject(OBJECT_TYPE_BANNERS, type, OBJECT_SELECTION_FLAG_SELECTED); diff --git a/src/openrct2/paint/tile_element/Paint.Banner.cpp b/src/openrct2/paint/tile_element/Paint.Banner.cpp index 48f5700dd6..f6e08eae59 100644 --- a/src/openrct2/paint/tile_element/Paint.Banner.cpp +++ b/src/openrct2/paint/tile_element/Paint.Banner.cpp @@ -43,7 +43,7 @@ void banner_paint(paint_session* session, uint8_t direction, int32_t height, con height -= 16; - rct_scenery_entry* banner_scenery = get_banner_entry(gBanners[tile_element->properties.banner.index].type); + rct_scenery_entry* banner_scenery = get_banner_entry(gBanners[tile_element->AsBanner()->GetIndex()].type); if (banner_scenery == nullptr) { @@ -67,7 +67,7 @@ void banner_paint(paint_session* session, uint8_t direction, int32_t height, con } else { - image_id |= (gBanners[tile_element->properties.banner.index].colour << 19) | IMAGE_TYPE_REMAP; + image_id |= (gBanners[tile_element->AsBanner()->GetIndex()].colour << 19) | IMAGE_TYPE_REMAP; } sub_98197C(session, image_id, 0, 0, 1, 1, 0x15, height, boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ); @@ -96,9 +96,9 @@ void banner_paint(paint_session* session, uint8_t direction, int32_t height, con set_format_arg(4, uint32_t, 0); rct_string_id string_id = STR_NO_ENTRY; - if (!(gBanners[tile_element->properties.banner.index].flags & BANNER_FLAG_NO_ENTRY)) + if (!(gBanners[tile_element->AsBanner()->GetIndex()].flags & BANNER_FLAG_NO_ENTRY)) { - set_format_arg(0, rct_string_id, gBanners[tile_element->properties.banner.index].string_idx); + set_format_arg(0, rct_string_id, gBanners[tile_element->AsBanner()->GetIndex()].string_idx); string_id = STR_BANNER_TEXT_FORMAT; } if (gConfigGeneral.upper_case_banners) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 1d3f6c688b..4d02b92907 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2646,7 +2646,7 @@ private: { if (tileElement->GetType() == TILE_ELEMENT_TYPE_BANNER) { - uint8_t index = tileElement->properties.banner.index; + uint8_t index = tileElement->AsBanner()->GetIndex(); rct_banner* src = &_s4.banners[index]; rct_banner* dst = &gBanners[index]; ImportBanner(dst, src); diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index 7f182492d3..e30153ea90 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -86,7 +86,7 @@ static money32 BannerRemove(int16_t x, int16_t y, uint8_t baseHeight, uint8_t di return MONEY32_UNDEFINED; } - rct_banner* banner = &gBanners[tileElement->properties.banner.index]; + rct_banner* banner = &gBanners[tileElement->AsBanner()->GetIndex()]; rct_scenery_entry* bannerEntry = get_banner_entry(banner->type); money32 refund = 0; if (bannerEntry != nullptr) @@ -153,10 +153,10 @@ static money32 BannerSetColour(int16_t x, int16_t y, uint8_t baseHeight, uint8_t } auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); - intent.putExtra(INTENT_EXTRA_BANNER_INDEX, tileElement->properties.banner.index); + intent.putExtra(INTENT_EXTRA_BANNER_INDEX, tileElement->AsBanner()->GetIndex()); context_broadcast_intent(&intent); - gBanners[tileElement->properties.banner.index].colour = colour; + gBanners[tileElement->AsBanner()->GetIndex()].colour = colour; map_invalidate_tile_zoom1(x, y, z, z + 32); } @@ -252,7 +252,7 @@ static money32 BannerPlace( newTileElement->properties.banner.position = direction; newTileElement->properties.banner.flags = 0xFF; newTileElement->properties.banner.unused = 0; - newTileElement->properties.banner.index = *bannerIndex; + newTileElement->AsBanner()->SetIndex(*bannerIndex); if (flags & GAME_COMMAND_FLAG_GHOST) { newTileElement->flags |= TILE_ELEMENT_FLAG_GHOST; @@ -481,7 +481,7 @@ void fix_duplicated_banners() // multiple tiles that should both refer to the same banner index. if (tileElement->GetType() == TILE_ELEMENT_TYPE_BANNER) { - uint8_t bannerIndex = tileElement->properties.banner.index; + uint8_t bannerIndex = tileElement->AsBanner()->GetIndex(); if (activeBanners[bannerIndex]) { log_info( @@ -518,7 +518,7 @@ void fix_duplicated_banners() newBanner.string_idx = newStringIdx; } - tileElement->properties.banner.index = newBannerIndex; + tileElement->AsBanner()->SetIndex(newBannerIndex); } // Mark banner index as in-use @@ -569,3 +569,13 @@ void game_command_set_banner_style( { *ebx = BannerSetStyle(*ecx & 0xFF, *edx & 0xFF, *edi & 0xFF, *ebp & 0xFF, *ebx & 0xFF); } + +BannerIndex BannerElement::GetIndex() const +{ + return index; +} + +void BannerElement::SetIndex(BannerIndex newIndex) +{ + index = newIndex; +} diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index 36a1920260..b9b4c01440 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -84,7 +84,7 @@ BannerIndex tile_element_get_banner_index(rct_tile_element* tileElement) return tileElement->AsWall()->GetBannerIndex(); case TILE_ELEMENT_TYPE_BANNER: - return tileElement->properties.banner.index; + return tileElement->AsBanner()->GetIndex(); default: return BANNER_INDEX_NULL; } @@ -101,7 +101,7 @@ void tile_element_set_banner_index(rct_tile_element* tileElement, BannerIndex ba tileElement->AsLargeScenery()->SetBannerIndex(bannerIndex); break; case TILE_ELEMENT_TYPE_BANNER: - tileElement->properties.banner.index = bannerIndex; + tileElement->AsBanner()->SetIndex(bannerIndex); break; default: log_error("Tried to set banner index on unsuitable tile element!"); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index aae072b587..92841ead40 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -391,7 +391,17 @@ assert_struct_size(EntranceElement, 8); struct BannerElement : TileElementBase { - rct_tile_element_banner_properties temp; +private: + BannerIndex index; // 4 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-private-field" + uint8_t position; // 5 + uint8_t flags; // 6 + uint8_t unused; // 7 +#pragma clang diagnostic pop +public: + BannerIndex GetIndex() const; + void SetIndex(BannerIndex newIndex); }; assert_struct_size(BannerElement, 8); From 3b7fc4cf8c542c501486f958e865a13ac209809e Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 14:52:16 +0200 Subject: [PATCH 08/12] Port rest of banner functions --- src/openrct2-ui/windows/Banner.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 8 ++-- src/openrct2-ui/windows/TopToolbar.cpp | 2 +- .../paint/tile_element/Paint.Banner.cpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 2 +- src/openrct2/world/Banner.cpp | 40 +++++++++++++++---- src/openrct2/world/Entrance.cpp | 2 +- src/openrct2/world/Footpath.cpp | 6 +-- src/openrct2/world/Map.cpp | 4 +- src/openrct2/world/TileElement.h | 19 ++++----- src/openrct2/world/TileInspector.cpp | 16 ++++---- 11 files changed, 63 insertions(+), 40 deletions(-) diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index d204380bab..bc25d5835f 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -187,7 +187,7 @@ static void window_banner_mouseup(rct_window* w, rct_widgetindex widgetIndex) break; case WIDX_BANNER_DEMOLISH: game_do_command( - x, 1, y, tile_element->base_height | (tile_element->properties.banner.position << 8), + x, 1, y, tile_element->base_height | (tile_element->AsBanner()->GetPosition() << 8), GAME_COMMAND_REMOVE_BANNER, 0, 0); break; case WIDX_BANNER_TEXT: diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index c6394db628..3f38f6efa0 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1658,16 +1658,16 @@ static void window_tile_inspector_invalidate(rct_window* w) w->widgets[WIDX_BANNER_CHECK_BLOCK_NW].bottom = GBBB(propertiesAnchor, 1); widget_set_checkbox_value( w, WIDX_BANNER_CHECK_BLOCK_NE, - !(tileElement->properties.banner.flags & (1 << ((0 - get_current_rotation()) & 3)))); + !(tileElement->AsBanner()->GetAllowedEdges() & (1 << ((0 - get_current_rotation()) & 3)))); widget_set_checkbox_value( w, WIDX_BANNER_CHECK_BLOCK_SE, - !(tileElement->properties.banner.flags & (1 << ((1 - get_current_rotation()) & 3)))); + !(tileElement->AsBanner()->GetAllowedEdges() & (1 << ((1 - get_current_rotation()) & 3)))); widget_set_checkbox_value( w, WIDX_BANNER_CHECK_BLOCK_SW, - !(tileElement->properties.banner.flags & (1 << ((2 - get_current_rotation()) & 3)))); + !(tileElement->AsBanner()->GetAllowedEdges() & (1 << ((2 - get_current_rotation()) & 3)))); widget_set_checkbox_value( w, WIDX_BANNER_CHECK_BLOCK_NW, - !(tileElement->properties.banner.flags & (1 << ((3 - get_current_rotation()) & 3)))); + !(tileElement->AsBanner()->GetAllowedEdges() & (1 << ((3 - get_current_rotation()) & 3)))); break; case TILE_INSPECTOR_PAGE_CORRUPT: w->widgets[WIDX_CORRUPT_SPINNER_HEIGHT].top = GBBT(propertiesAnchor, 0) + 3; diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index c267d92042..c309f52361 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1037,7 +1037,7 @@ static void repaint_scenery_tool_down(int16_t x, int16_t y, rct_widgetindex widg { gGameCommandErrorTitle = STR_CANT_REPAINT_THIS; game_do_command( - grid_x, 1, grid_y, tile_element->base_height | ((tile_element->properties.banner.position & 0x3) << 8), + grid_x, 1, grid_y, tile_element->base_height | ((tile_element->AsBanner()->GetPosition() & 0x3) << 8), GAME_COMMAND_SET_BANNER_COLOUR, 0, gWindowSceneryPrimaryColour | (gWindowScenerySecondaryColour << 8)); } break; diff --git a/src/openrct2/paint/tile_element/Paint.Banner.cpp b/src/openrct2/paint/tile_element/Paint.Banner.cpp index f6e08eae59..df16842555 100644 --- a/src/openrct2/paint/tile_element/Paint.Banner.cpp +++ b/src/openrct2/paint/tile_element/Paint.Banner.cpp @@ -50,7 +50,7 @@ void banner_paint(paint_session* session, uint8_t direction, int32_t height, con return; } - direction += tile_element->properties.banner.position; + direction += tile_element->AsBanner()->GetPosition(); direction &= 3; boundBoxOffsetX = BannerBoundBoxes[direction][0].x; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index f2bd51ac5a..bac872c6be 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -86,7 +86,7 @@ static int32_t banner_clear_path_edges(rct_tile_element* tileElement, int32_t ed { do { - edges &= bannerElement->properties.banner.flags; + edges &= bannerElement->AsBanner()->GetAllowedEdges(); } while ((bannerElement = get_banner_on_path(bannerElement)) != nullptr); } return edges; diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index e30153ea90..aa3841701a 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -140,7 +140,7 @@ static money32 BannerSetColour(int16_t x, int16_t y, uint8_t baseHeight, uint8_t if (tileElement->GetType() != TILE_ELEMENT_TYPE_BANNER) continue; - if (tileElement->properties.banner.position != direction) + if (tileElement->AsBanner()->GetPosition() != direction) continue; found = true; @@ -247,11 +247,10 @@ static money32 BannerPlace( gBanners[*bannerIndex].colour = colour; gBanners[*bannerIndex].x = x / 32; gBanners[*bannerIndex].y = y / 32; - newTileElement->SetType(TILE_ELEMENT_TYPE_BANNER); + newTileElement->ClearAs(TILE_ELEMENT_TYPE_BANNER); newTileElement->clearance_height = newTileElement->base_height + 2; - newTileElement->properties.banner.position = direction; - newTileElement->properties.banner.flags = 0xFF; - newTileElement->properties.banner.unused = 0; + newTileElement->AsBanner()->SetPosition(direction); + newTileElement->AsBanner()->ResetAllowedEdges(); newTileElement->AsBanner()->SetIndex(*bannerIndex); if (flags & GAME_COMMAND_FLAG_GHOST) { @@ -300,11 +299,12 @@ static money32 BannerSetStyle(BannerIndex bannerIndex, uint8_t colour, uint8_t t banner->text_colour = textColour; banner->flags = bannerFlags; - tileElement->properties.banner.flags = 0xFF; + uint8_t allowedEdges = 0xF; if (banner->flags & BANNER_FLAG_NO_ENTRY) { - tileElement->properties.banner.flags &= ~(1 << tileElement->properties.banner.position); + allowedEdges &= ~(1 << tileElement->AsBanner()->GetPosition()); } + tileElement->AsBanner()->SetAllowedEdges(allowedEdges); int32_t colourCodepoint = FORMAT_COLOUR_CODE_START + banner->text_colour; @@ -579,3 +579,29 @@ void BannerElement::SetIndex(BannerIndex newIndex) { index = newIndex; } + +uint8_t BannerElement::GetPosition() const +{ + return position; +} + +void BannerElement::SetPosition(uint8_t newPosition) +{ + position = newPosition; +} + +uint8_t BannerElement::GetAllowedEdges() const +{ + return flags & 0b00001111; +} + +void BannerElement::SetAllowedEdges(uint8_t newEdges) +{ + flags &= ~ 0b00001111; + flags |= (newEdges & 0b00001111); +} + +void BannerElement::ResetAllowedEdges() +{ + flags |= 0b00001111; +} diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index 6ea2e71e99..5fbd2f5495 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -681,4 +681,4 @@ uint8_t EntranceElement::GetPathType() const void EntranceElement::SetPathType(uint8_t newPathType) { pathType = newPathType; -} \ No newline at end of file +} diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index edb9183d48..b666d7b24b 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -511,7 +511,7 @@ void remove_banners_at_element(int32_t x, int32_t y, rct_tile_element* tileEleme continue; game_do_command( - x, 1, y, tileElement->base_height | tileElement->properties.banner.position << 8, GAME_COMMAND_REMOVE_BANNER, 0, 0); + x, 1, y, tileElement->base_height | tileElement->AsBanner()->GetPosition() << 8, GAME_COMMAND_REMOVE_BANNER, 0, 0); tileElement--; } } @@ -1881,7 +1881,7 @@ static int32_t footpath_is_connected_to_map_edge_recurse( break; if (tileElement[i].type != TILE_ELEMENT_TYPE_BANNER) break; - edges &= tileElement[i].properties.banner.flags; + edges &= tileElement[i].AsBanner()->GetAllowedEdges(); } } if (tileElement[2].type == TILE_ELEMENT_TYPE_BANNER && tileElement[1].type != TILE_ELEMENT_TYPE_PATH) @@ -1892,7 +1892,7 @@ static int32_t footpath_is_connected_to_map_edge_recurse( break; if (tileElement[i].type != TILE_ELEMENT_TYPE_BANNER) break; - edges &= tileElement[i].properties.banner.flags; + edges &= tileElement[i].AsBanner()->GetAllowedEdges(); } } } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 51448120f8..f1d98093c9 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -321,7 +321,7 @@ rct_tile_element* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uin continue; if (tileElement->base_height != z) continue; - if (tileElement->properties.banner.position != position) + if (tileElement->AsBanner()->GetPosition() != position) continue; return tileElement; @@ -3880,7 +3880,7 @@ static void clear_element_at(int32_t x, int32_t y, rct_tile_element** elementPtr case TILE_ELEMENT_TYPE_BANNER: gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; game_do_command( - x, GAME_COMMAND_FLAG_APPLY, y, (element->base_height) | ((element->properties.banner.position & 3) << 8), + x, GAME_COMMAND_FLAG_APPLY, y, (element->base_height) | ((element->AsBanner()->GetPosition() & 3) << 8), GAME_COMMAND_REMOVE_BANNER, 0, 0); break; default: diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 92841ead40..0033932249 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -28,19 +28,9 @@ struct rct_tile_element_path_properties }; assert_struct_size(rct_tile_element_path_properties, 4); -struct rct_tile_element_banner_properties -{ - BannerIndex index; // 4 - uint8_t position; // 5 - uint8_t flags; // 6 - uint8_t unused; // 7 -}; -assert_struct_size(rct_tile_element_banner_properties, 4); - union rct_tile_element_properties { rct_tile_element_path_properties path; - rct_tile_element_banner_properties banner; }; assert_struct_size(rct_tile_element_properties, 4); @@ -393,15 +383,22 @@ struct BannerElement : TileElementBase { private: BannerIndex index; // 4 + uint8_t position; // 5 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t position; // 5 uint8_t flags; // 6 uint8_t unused; // 7 #pragma clang diagnostic pop public: BannerIndex GetIndex() const; void SetIndex(BannerIndex newIndex); + + uint8_t GetPosition() const; + void SetPosition(uint8_t newPosition); + + uint8_t GetAllowedEdges() const; + void SetAllowedEdges(uint8_t newEdges); + void ResetAllowedEdges(); }; assert_struct_size(BannerElement, 8); diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index af10f1d5a8..099d59efee 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -267,12 +267,10 @@ int32_t tile_inspector_rotate_element_at(int32_t x, int32_t y, int32_t elementIn break; case TILE_ELEMENT_TYPE_BANNER: { - uint8_t unblockedEdges = tileElement->properties.banner.flags & 0xF; + uint8_t unblockedEdges = tileElement->AsBanner()->GetAllowedEdges(); unblockedEdges = (unblockedEdges << 1 | unblockedEdges >> 3) & 0xF; - tileElement->properties.banner.flags &= ~0xF; - tileElement->properties.banner.flags |= unblockedEdges; - tileElement->properties.banner.position++; - tileElement->properties.banner.position &= 3; + tileElement->AsBanner()->SetAllowedEdges(unblockedEdges); + tileElement->AsBanner()->SetPosition((tileElement->AsBanner()->GetPosition() + 1) & 3); break; } } @@ -1031,14 +1029,16 @@ int32_t tile_inspector_scenery_set_quarter_collision( int32_t tile_inspector_banner_toggle_blocking_edge(int32_t x, int32_t y, int32_t elementIndex, int32_t edgeIndex, int32_t flags) { - rct_tile_element* const bannerElement = map_get_nth_element_at(x, y, elementIndex); + BannerElement* const bannerElement = map_get_nth_element_at(x, y, elementIndex)->AsBanner(); - if (bannerElement == nullptr || bannerElement->GetType() != TILE_ELEMENT_TYPE_BANNER) + if (bannerElement == nullptr) return MONEY32_UNDEFINED; if (flags & GAME_COMMAND_FLAG_APPLY) { - bannerElement->properties.banner.flags ^= 1 << edgeIndex; + uint8_t edges = bannerElement->GetAllowedEdges(); + edges ^= (1 << edgeIndex); + bannerElement->SetAllowedEdges(edges); if ((uint32_t)x == windowTileInspectorTileX && (uint32_t)y == windowTileInspectorTileY) { From ce13d1b9616c1f53dac0fde9c3465020049bd416 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 15:44:03 +0200 Subject: [PATCH 09/12] Fix tests --- test/tests/TileElements.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests/TileElements.cpp b/test/tests/TileElements.cpp index 72be0a4e2e..a0e0e7a655 100644 --- a/test/tests/TileElements.cpp +++ b/test/tests/TileElements.cpp @@ -88,7 +88,7 @@ TEST_F(TileElementWantsFootpathConnection, Stall) TEST_F(TileElementWantsFootpathConnection, RideEntrance) { // Ride entrances and exits want a connection in one direction - const rct_tile_element* const entranceElement = map_get_ride_entrance_element_at(18 << 5, 8 << 5, 14, false); + const EntranceElement* const entranceElement = map_get_ride_entrance_element_at(18 << 5, 8 << 5, 14, false); ASSERT_NE(entranceElement, nullptr); EXPECT_TRUE(tile_element_wants_path_connection_towards({ 18, 8, 14, 0 }, nullptr)); EXPECT_FALSE(tile_element_wants_path_connection_towards({ 18, 8, 14, 1 }, nullptr)); @@ -100,7 +100,7 @@ TEST_F(TileElementWantsFootpathConnection, RideEntrance) TEST_F(TileElementWantsFootpathConnection, RideExit) { // The exit has been rotated; it wants a path connection in direction 1, but not 0 like the entrance - const rct_tile_element* const exitElement = map_get_ride_exit_element_at(18 << 5, 10 << 5, 14, false); + const EntranceElement* const exitElement = map_get_ride_exit_element_at(18 << 5, 10 << 5, 14, false); ASSERT_NE(exitElement, nullptr); EXPECT_FALSE(tile_element_wants_path_connection_towards({ 18, 10, 14, 0 }, nullptr)); EXPECT_TRUE(tile_element_wants_path_connection_towards({ 18, 10, 14, 1 }, nullptr)); From f8483b4726b324d81148118bde5e1719d9d394bc Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 26 Sep 2018 15:44:09 +0200 Subject: [PATCH 10/12] Fix formatting --- src/openrct2-ui/windows/Banner.cpp | 4 ++-- src/openrct2-ui/windows/TileInspector.cpp | 3 ++- src/openrct2/ride/Ride.cpp | 6 ++++-- src/openrct2/world/Banner.cpp | 2 +- src/openrct2/world/Map.cpp | 3 ++- src/openrct2/world/TileElement.h | 4 ++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index bc25d5835f..519bafaf68 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -187,8 +187,8 @@ static void window_banner_mouseup(rct_window* w, rct_widgetindex widgetIndex) break; case WIDX_BANNER_DEMOLISH: game_do_command( - x, 1, y, tile_element->base_height | (tile_element->AsBanner()->GetPosition() << 8), - GAME_COMMAND_REMOVE_BANNER, 0, 0); + x, 1, y, tile_element->base_height | (tile_element->AsBanner()->GetPosition() << 8), GAME_COMMAND_REMOVE_BANNER, + 0, 0); break; case WIDX_BANNER_TEXT: window_text_input_open( diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 3f38f6efa0..29d4c36cf3 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1608,7 +1608,8 @@ static void window_tile_inspector_invalidate(rct_window* w) w->widgets[WIDX_ENTRANCE_BUTTON_MAKE_USABLE].top = GBBT(propertiesAnchor, 1); w->widgets[WIDX_ENTRANCE_BUTTON_MAKE_USABLE].bottom = GBBB(propertiesAnchor, 1); widget_set_enabled( - w, WIDX_ENTRANCE_BUTTON_MAKE_USABLE, tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE); + w, WIDX_ENTRANCE_BUTTON_MAKE_USABLE, + tileElement->AsEntrance()->GetEntranceType() != ENTRANCE_TYPE_PARK_ENTRANCE); break; case TILE_INSPECTOR_PAGE_WALL: { diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 681b4ae8d4..3ec1404e5b 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -8798,7 +8798,8 @@ void determine_ride_entrance_and_exit_locations() // Skip if the station has no entrance if (!entranceLoc.isNull()) { - const EntranceElement* entranceElement = map_get_ride_entrance_element_at(entranceLoc.x * 32, entranceLoc.y * 32, entranceLoc.z, false); + const EntranceElement* entranceElement = map_get_ride_entrance_element_at( + entranceLoc.x * 32, entranceLoc.y * 32, entranceLoc.z, false); if (entranceElement == nullptr || entranceElement->GetRideIndex() != rideIndex || entranceElement->GetStationIndex() != stationIndex) @@ -8813,7 +8814,8 @@ void determine_ride_entrance_and_exit_locations() if (!exitLoc.isNull()) { - const EntranceElement* entranceElement = map_get_ride_exit_element_at(exitLoc.x * 32, exitLoc.y * 32, entranceLoc.z, false); + const EntranceElement* entranceElement = map_get_ride_exit_element_at( + exitLoc.x * 32, exitLoc.y * 32, entranceLoc.z, false); if (entranceElement == nullptr || entranceElement->GetRideIndex() != rideIndex || entranceElement->GetStationIndex() != stationIndex) diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index aa3841701a..c088cd647e 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -597,7 +597,7 @@ uint8_t BannerElement::GetAllowedEdges() const void BannerElement::SetAllowedEdges(uint8_t newEdges) { - flags &= ~ 0b00001111; + flags &= ~0b00001111; flags |= (newEdges & 0b00001111); } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index f1d98093c9..bb8ac2797c 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -4821,7 +4821,8 @@ uint16_t check_max_allowable_land_rights_for_tile(uint8_t x, uint8_t y, uint8_t { int32_t type = tileElement->GetType(); if (type == TILE_ELEMENT_TYPE_PATH - || (type == TILE_ELEMENT_TYPE_ENTRANCE && tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE)) + || (type == TILE_ELEMENT_TYPE_ENTRANCE + && tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_PARK_ENTRANCE)) { destOwnership = OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED; // Do not own construction rights if too high/below surface diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 0033932249..d9dd7196bf 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -386,8 +386,8 @@ private: uint8_t position; // 5 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t flags; // 6 - uint8_t unused; // 7 + uint8_t flags; // 6 + uint8_t unused; // 7 #pragma clang diagnostic pop public: BannerIndex GetIndex() const; From fa67883cafb7d2dda98fafaa19d57d1b0957a268 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Thu, 27 Sep 2018 22:51:56 +0200 Subject: [PATCH 11/12] Fix crash and address most line notes --- src/openrct2/actions/PlaceParkEntranceAction.hpp | 13 +++++++------ src/openrct2/world/Banner.cpp | 14 +++++++------- src/openrct2/world/Map.cpp | 4 ++-- src/openrct2/world/Map.h | 2 +- src/openrct2/world/TileInspector.cpp | 8 ++++---- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index 7b1cfb10f3..b1bb6351d2 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -183,18 +183,19 @@ public: rct_tile_element* newElement = tile_element_insert(entranceLoc.x / 32, entranceLoc.y / 32, zLow, 0xF); Guard::Assert(newElement != nullptr); - newElement->clearance_height = zHigh; + newElement->ClearAs(TILE_ELEMENT_TYPE_ENTRANCE); + auto entranceElement = newElement->AsEntrance(); + entranceElement->clearance_height = zHigh; if (flags & GAME_COMMAND_FLAG_GHOST) { newElement->flags |= TILE_ELEMENT_FLAG_GHOST; } - newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); - newElement->SetDirection(_direction); - newElement->AsEntrance()->SetSequenceIndex(index); - newElement->AsEntrance()->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE); - newElement->AsEntrance()->SetPathType(gFootpathSelectedId); + entranceElement->SetDirection(_direction); + entranceElement->SetSequenceIndex(index); + entranceElement->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE); + entranceElement->SetPathType(gFootpathSelectedId); if (!(flags & GAME_COMMAND_FLAG_GHOST)) { diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index c088cd647e..71d88e49c8 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -80,13 +80,13 @@ static money32 BannerRemove(int16_t x, int16_t y, uint8_t baseHeight, uint8_t di // Slight modification to the code so that it now checks height as well // This was causing a bug with banners on two paths stacked. - rct_tile_element* tileElement = map_get_banner_element_at(x / 32, y / 32, baseHeight, direction); + BannerElement* tileElement = map_get_banner_element_at(x / 32, y / 32, baseHeight, direction); if (tileElement == nullptr) { return MONEY32_UNDEFINED; } - rct_banner* banner = &gBanners[tileElement->AsBanner()->GetIndex()]; + rct_banner* banner = &gBanners[tileElement->GetIndex()]; rct_scenery_entry* bannerEntry = get_banner_entry(banner->type); money32 refund = 0; if (bannerEntry != nullptr) @@ -105,9 +105,9 @@ static money32 BannerRemove(int16_t x, int16_t y, uint8_t baseHeight, uint8_t di network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord); } - tile_element_remove_banner_entry(tileElement); + tile_element_remove_banner_entry((rct_tile_element*)tileElement); map_invalidate_tile_zoom1(x, y, z, z + 32); - tile_element_remove(tileElement); + tileElement->Remove(); } if (gParkFlags & PARK_FLAGS_NO_MONEY) @@ -217,8 +217,8 @@ static money32 BannerPlace( } uint8_t baseHeight = (pathBaseHeight + 1) * 2; - tileElement = map_get_banner_element_at(x / 32, y / 32, baseHeight, direction); - if (tileElement != nullptr) + BannerElement* bannerElement = map_get_banner_element_at(x / 32, y / 32, baseHeight, direction); + if (bannerElement != nullptr) { gGameCommandErrorText = STR_BANNER_SIGN_IN_THE_WAY; return MONEY32_UNDEFINED; @@ -247,7 +247,7 @@ static money32 BannerPlace( gBanners[*bannerIndex].colour = colour; gBanners[*bannerIndex].x = x / 32; gBanners[*bannerIndex].y = y / 32; - newTileElement->ClearAs(TILE_ELEMENT_TYPE_BANNER); + newTileElement->SetType(TILE_ELEMENT_TYPE_BANNER); newTileElement->clearance_height = newTileElement->base_height + 2; newTileElement->AsBanner()->SetPosition(direction); newTileElement->AsBanner()->ResetAllowedEdges(); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index bb8ac2797c..68d2e564ce 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -307,7 +307,7 @@ rct_tile_element* map_get_path_element_at(int32_t x, int32_t y, int32_t z) return nullptr; } -rct_tile_element* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t position) +BannerElement* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t position) { rct_tile_element* tileElement = map_get_first_element_at(x, y); @@ -324,7 +324,7 @@ rct_tile_element* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uin if (tileElement->AsBanner()->GetPosition() != position) continue; - return tileElement; + return tileElement->AsBanner(); } while (!(tileElement++)->IsLastForTile()); return nullptr; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index d882cdca26..cb55ae47e8 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -135,7 +135,7 @@ rct_tile_element* map_get_first_element_at(int32_t x, int32_t y); rct_tile_element* map_get_nth_element_at(int32_t x, int32_t y, int32_t n); void map_set_tile_elements(int32_t x, int32_t y, rct_tile_element* elements); int32_t map_height_from_slope(int32_t x, int32_t y, int32_t slope); -rct_tile_element* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t direction); +BannerElement* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t direction); rct_tile_element* map_get_surface_element_at(int32_t x, int32_t y); rct_tile_element* map_get_surface_element_at(CoordsXY coords); rct_tile_element* map_get_path_element_at(int32_t x, int32_t y, int32_t z); diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 099d59efee..891d3c2142 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -1029,16 +1029,16 @@ int32_t tile_inspector_scenery_set_quarter_collision( int32_t tile_inspector_banner_toggle_blocking_edge(int32_t x, int32_t y, int32_t elementIndex, int32_t edgeIndex, int32_t flags) { - BannerElement* const bannerElement = map_get_nth_element_at(x, y, elementIndex)->AsBanner(); + rct_tile_element* const bannerElement = map_get_nth_element_at(x, y, elementIndex); - if (bannerElement == nullptr) + if (bannerElement == nullptr || bannerElement->GetType() != TILE_ELEMENT_TYPE_BANNER) return MONEY32_UNDEFINED; if (flags & GAME_COMMAND_FLAG_APPLY) { - uint8_t edges = bannerElement->GetAllowedEdges(); + uint8_t edges = bannerElement->AsBanner()->GetAllowedEdges(); edges ^= (1 << edgeIndex); - bannerElement->SetAllowedEdges(edges); + bannerElement->AsBanner()->SetAllowedEdges(edges); if ((uint32_t)x == windowTileInspectorTileX && (uint32_t)y == windowTileInspectorTileY) { From 3738cdaf5eb1cf1c10433664dcb404423d875f92 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 29 Sep 2018 10:24:11 +0200 Subject: [PATCH 12/12] Make CIs happy --- src/openrct2/actions/PlaceParkEntranceAction.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index b1bb6351d2..9eb6a33a2e 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -183,8 +183,13 @@ public: rct_tile_element* newElement = tile_element_insert(entranceLoc.x / 32, entranceLoc.y / 32, zLow, 0xF); Guard::Assert(newElement != nullptr); - newElement->ClearAs(TILE_ELEMENT_TYPE_ENTRANCE); + newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); auto entranceElement = newElement->AsEntrance(); + if (entranceElement == nullptr) + { + Guard::Assert(false); + return nullptr; + } entranceElement->clearance_height = zHigh; if (flags & GAME_COMMAND_FLAG_GHOST)