From c2d9d727d9278f8f5d21982bbf72edd6c3246420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 12 Oct 2021 20:50:17 +0300 Subject: [PATCH 1/6] Fix #15566: Litter age underflow --- src/openrct2/world/Litter.cpp | 5 +++++ src/openrct2/world/Litter.h | 1 + src/openrct2/world/Park.cpp | 10 ++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/openrct2/world/Litter.cpp b/src/openrct2/world/Litter.cpp index c3348056a0..a5310d9f42 100644 --- a/src/openrct2/world/Litter.cpp +++ b/src/openrct2/world/Litter.cpp @@ -126,3 +126,8 @@ rct_string_id Litter::GetName() const return STR_NONE; return litterNames[EnumValue(SubType)]; } + +uint32_t Litter::GetAge() const +{ + return gCurrentTicks - creationTick; +} diff --git a/src/openrct2/world/Litter.h b/src/openrct2/world/Litter.h index 2aafcfeecf..52c8381f60 100644 --- a/src/openrct2/world/Litter.h +++ b/src/openrct2/world/Litter.h @@ -40,4 +40,5 @@ struct Litter : EntityBase static void RemoveAt(const CoordsXYZ& litterPos); void Serialise(DataSerialiser& stream); rct_string_id GetName() const; + uint32_t GetAge() const; }; diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index c8ff39b4bd..709269153c 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -464,13 +464,15 @@ int32_t Park::CalculateParkRating() const // Litter { int32_t litterCount = 0; - for (auto litter : EntityList()) + for (auto* litter : EntityList()) { - // Ignore recently dropped litter - if (litter->creationTick - gCurrentTicks >= 7680) + if (litter->GetAge() < 7680) { - litterCount++; + // Ignore recently dropped litter. + continue; } + + litterCount++; } result -= 600 - (4 * (150 - std::min(150, litterCount))); } From f2372337bfb2946f9da2d862443b182f9e86f370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 12 Oct 2021 21:36:13 +0300 Subject: [PATCH 2/6] Bump up network version --- src/openrct2/network/NetworkBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 6e7564d2a1..4022d40a3c 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -38,7 +38,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "13" +#define NETWORK_STREAM_VERSION "14" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; From ba96d6a7fd4d1c8f71c55017ea10e21f1c17dac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 12 Oct 2021 21:44:30 +0300 Subject: [PATCH 3/6] Update replays --- CMakeLists.txt | 4 ++-- openrct2.proj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b422d41619..dd15138ef2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,9 +65,9 @@ set(OBJECTS_VERSION "1.0.21") set(OBJECTS_URL "https://github.com/OpenRCT2/objects/releases/download/v${OBJECTS_VERSION}/objects.zip") set(OBJECTS_SHA1 "c38af45d51a6e440386180feacf76c64720b6ac5") -set(REPLAYS_VERSION "0.0.55") +set(REPLAYS_VERSION "0.0.56") set(REPLAYS_URL "https://github.com/OpenRCT2/replays/releases/download/v${REPLAYS_VERSION}/replays.zip") -set(REPLAYS_SHA1 "70B4B7CB26A428801676BCC615F3881E72A45406") +set(REPLAYS_SHA1 "C47048B71A95A95428A08035C94AD10E7A020D4D") option(FORCE32 "Force 32-bit build. It will add `-m32` to compiler flags.") option(WITH_TESTS "Build tests") diff --git a/openrct2.proj b/openrct2.proj index d8fcfb7bc1..a895838c42 100644 --- a/openrct2.proj +++ b/openrct2.proj @@ -48,8 +48,8 @@ 304d13a126c15bf2c86ff13b81a2f2cc1856ac8d https://github.com/OpenRCT2/objects/releases/download/v1.0.21/objects.zip c38af45d51a6e440386180feacf76c64720b6ac5 - https://github.com/OpenRCT2/replays/releases/download/v0.0.55/replays.zip - 70B4B7CB26A428801676BCC615F3881E72A45406 + https://github.com/OpenRCT2/replays/releases/download/v0.0.56/replays.zip + C47048B71A95A95428A08035C94AD10E7A020D4D From f2bfec977f2569a79e44b4056d7c5b49e306bf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 13 Oct 2021 21:35:21 +0300 Subject: [PATCH 4/6] Update changelog.txt --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 9d9fde6605..f7855cd3e8 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -37,6 +37,7 @@ - Fix: [#15503] Freeze when doing specific coaster merges with block brakes. - Fix: [#15514] Two different “quit to menu” menu items are available in track designer and track design manager. - Fix: [#15560] Memory leak due to OpenGL Renderer not releasing a texture. +- Fix: [#15567] Litter not being counted correctly during Park rating calculation (original bug). - Improved: [#3417] Crash dumps are now placed in their own folder. - Improved: [#13524] macOS arm64 native (universal) app - Improved: [#15538] Software rendering can now draw in parallel when Multithreading is enabled. From f701d2ceb5c9cc0c7f296c9415e932a33acfe692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 14 Oct 2021 16:31:37 +0300 Subject: [PATCH 5/6] Make EntityList const correct --- src/openrct2/world/EntityList.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2/world/EntityList.h b/src/openrct2/world/EntityList.h index 19489ae49b..60d967aac5 100644 --- a/src/openrct2/world/EntityList.h +++ b/src/openrct2/world/EntityList.h @@ -165,11 +165,11 @@ public: { } - EntityListIterator_t begin() + EntityListIterator_t begin() const { return EntityListIterator_t(std::cbegin(vec), std::cend(vec)); } - EntityListIterator_t end() + EntityListIterator_t end() const { return EntityListIterator_t(std::cend(vec), std::cend(vec)); } From e1fb987c12e62c1bd94824046d2af2bbd252e9ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 14 Oct 2021 16:32:05 +0300 Subject: [PATCH 6/6] Replace loop with count_if --- src/openrct2/world/Park.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 709269153c..ddcec0d235 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -463,17 +463,11 @@ int32_t Park::CalculateParkRating() const // Litter { - int32_t litterCount = 0; - for (auto* litter : EntityList()) - { - if (litter->GetAge() < 7680) - { - // Ignore recently dropped litter. - continue; - } + // Counts the amount of litter whose age is min. 7680 ticks (5~ min) old. + const auto litterList = EntityList(); + const auto litterCount = std::count_if( + litterList.begin(), litterList.end(), [](auto* litter) { return litter->GetAge() >= 7680; }); - litterCount++; - } result -= 600 - (4 * (150 - std::min(150, litterCount))); }