diff --git a/distribution/changelog.txt b/distribution/changelog.txt index bff1a228b4..302ed18c90 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -36,6 +36,7 @@ - Fix: [#20642] Track list is sometimes empty due to uninitialized data for the filter string. - Fix: [#20659] Phantom rides remain when closing construction window while paused. - Fix: [#20684] Footpath additions getting removed by Miniature railway ghost elements. +- Fix: [#20693] Incorrect information shown when hovering over station when another station before it was removed. 0.4.5 (2023-05-08) ------------------------------------------------------------------------ diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 470222a2ee..03d2e600e1 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1038,6 +1038,20 @@ RideStation& Ride::GetStation(StationIndex stationIndex) return stations[stationIndex.ToUnderlying()]; } +StationIndex::UnderlyingType Ride::GetStationNumber(StationIndex in) const +{ + StationIndex::UnderlyingType nullStationsSeen{ 0 }; + for (size_t i = 0; i < in.ToUnderlying(); i++) + { + if (stations[i].Start.IsNull()) + { + nullStationsSeen++; + } + } + + return in.ToUnderlying() - nullStationsSeen + 1; +} + const RideStation& Ride::GetStation(StationIndex stationIndex) const { return stations[stationIndex.ToUnderlying()]; @@ -2430,21 +2444,15 @@ static void RideStationSetMapTooltip(const TrackElement& trackElement) if (ride == nullptr) return; - auto stationIndex = trackElement.GetStationIndex(); - for (int32_t i = stationIndex.ToUnderlying(); i >= 0; i--) - { - if (ride->GetStations()[i].Start.IsNull()) - { - stationIndex = StationIndex::FromUnderlying(stationIndex.ToUnderlying() - 1); - } - } + const auto stationIndex = trackElement.GetStationIndex(); + const auto stationNumber = ride->GetStationNumber(stationIndex); auto ft = Formatter(); ft.Add(STR_RIDE_MAP_TIP); ft.Add(ride->num_stations <= 1 ? STR_RIDE_STATION : STR_RIDE_STATION_X); ride->FormatNameTo(ft); ft.Add(GetRideComponentName(ride->GetRideTypeDescriptor().NameConvention.station).capitalised); - ft.Add(stationIndex.ToUnderlying() + 1); + ft.Add(stationNumber); ride->FormatStatusTo(ft); auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); intent.PutExtra(INTENT_EXTRA_FORMATTER, &ft); @@ -2458,20 +2466,11 @@ static void RideEntranceSetMapTooltip(const EntranceElement& entranceElement) if (ride == nullptr) return; - // Get the station - auto stationIndex = entranceElement.GetStationIndex(); - for (int32_t i = stationIndex.ToUnderlying(); i >= 0; i--) - { - if (ride->GetStations()[i].Start.IsNull()) - { - stationIndex = StationIndex::FromUnderlying(stationIndex.ToUnderlying() - 1); - } - } - if (entranceElement.GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { // Get the queue length int32_t queueLength = 0; + const auto stationIndex = entranceElement.GetStationIndex(); if (!ride->GetStation(stationIndex).Entrance.IsNull()) { queueLength = ride->GetStation(stationIndex).QueueLength; @@ -2485,36 +2484,29 @@ static void RideEntranceSetMapTooltip(const EntranceElement& entranceElement) // String IDs have an extra pop16 for some reason ft.Increment(sizeof(uint16_t)); - ft.Add(stationIndex.ToUnderlying() + 1); - if (queueLength == 0) + const auto stationNumber = ride->GetStationNumber(stationIndex); + ft.Add(stationNumber); + + switch (queueLength) { - ft.Add(STR_QUEUE_EMPTY); - } - else if (queueLength == 1) - { - ft.Add(STR_QUEUE_ONE_PERSON); - } - else - { - ft.Add(STR_QUEUE_PEOPLE); + case 0: + ft.Add(STR_QUEUE_EMPTY); + break; + case 1: + ft.Add(STR_QUEUE_ONE_PERSON); + break; + default: + ft.Add(STR_QUEUE_PEOPLE); + break; } ft.Add(queueLength); + auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); intent.PutExtra(INTENT_EXTRA_FORMATTER, &ft); ContextBroadcastIntent(&intent); } else { - // Get the station - stationIndex = entranceElement.GetStationIndex(); - for (int32_t i = stationIndex.ToUnderlying(); i >= 0; i--) - { - if (ride->GetStations()[i].Start.IsNull()) - { - stationIndex = StationIndex::FromUnderlying(stationIndex.ToUnderlying() - 1); - } - } - auto ft = Formatter(); ft.Add(ride->num_stations <= 1 ? STR_RIDE_EXIT : STR_RIDE_STATION_X_EXIT); ride->FormatNameTo(ft); @@ -2522,7 +2514,9 @@ static void RideEntranceSetMapTooltip(const EntranceElement& entranceElement) // String IDs have an extra pop16 for some reason ft.Increment(sizeof(uint16_t)); - ft.Add(stationIndex.ToUnderlying() + 1); + const auto stationIndex = entranceElement.GetStationIndex(); + const auto stationNumber = ride->GetStationNumber(stationIndex); + ft.Add(stationNumber); auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); intent.PutExtra(INTENT_EXTRA_FORMATTER, &ft); ContextBroadcastIntent(&intent); diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index bb58915f47..63d673fe1b 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -293,6 +293,10 @@ public: const std::array& GetStations() const; StationIndex GetStationIndex(const RideStation* station) const; + // Returns the logical station number from the given station. Index 0 = station 1, index 1 = station 2. It accounts for gaps + // in the station array. e.g. if only slot 0 and 2 are in use, index 2 returns 2 instead of 3. + StationIndex::UnderlyingType GetStationNumber(StationIndex in) const; + public: uint16_t inversions; uint16_t holes;