diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index f02864eeba..9ab427b5b8 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -773,6 +773,11 @@ declare global { * The total number of customers the ride has served since it was built. */ totalCustomers: number; + + /** + * The date in months when the ride was built. + */ + buildDate: number; } type RideClassification = "ride" | "stall" | "facility"; diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 168fb93d37..93b348094d 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2019 OpenRCT2 developers + * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -6980,7 +6980,7 @@ static void window_ride_customer_paint(rct_window* w, rct_drawpixelinfo* dpi) { int32_t x, y; uint8_t shopItem; - int16_t popularity, satisfaction, queueTime, age; + int16_t popularity, satisfaction, queueTime; int32_t customersPerHour; rct_string_id stringId; @@ -7080,7 +7080,7 @@ static void window_ride_customer_paint(rct_window* w, rct_drawpixelinfo* dpi) // Age // If the ride has a build date that is in the future, show it as built this year. - age = std::max((gDateMonthsElapsed - ride->build_date) / 8, 0); + int16_t age = std::max(date_get_year(ride->GetAge()), 0); stringId = age == 0 ? STR_BUILT_THIS_YEAR : age == 1 ? STR_BUILT_LAST_YEAR : STR_BUILT_YEARS_AGO; gfx_draw_string_left(dpi, stringId, &age, COLOUR_BLACK, x, y); } diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index d9ee1e3921..9230132738 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2019 OpenRCT2 developers + * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -665,7 +665,7 @@ static void window_ride_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, break; case INFORMATION_TYPE_AGE: { - int16_t age = date_get_year(gDateMonthsElapsed - ride->build_date); + int16_t age = date_get_year(ride->GetAge()); switch (age) { case 0: diff --git a/src/openrct2/rct1/RCT1.h b/src/openrct2/rct1/RCT1.h index 1be1252336..0fa870505d 100644 --- a/src/openrct2/rct1/RCT1.h +++ b/src/openrct2/rct1/RCT1.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2019 OpenRCT2 developers + * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -176,7 +176,7 @@ struct rct1_ride uint8_t pad_11F[0x7]; // 0x11F uint8_t spiral_slide_progress; // 0x126 uint8_t pad_127[0x9]; // 0x127 - int16_t build_date; // 0x130 + uint16_t build_date; // 0x130 money16 upkeep_cost; // 0x131 uint16_t race_winner; // 0x132 uint8_t unk_134[2]; // 0x134 diff --git a/src/openrct2/rct2/RCT2.h b/src/openrct2/rct2/RCT2.h index 7e764acfc0..7fd20e0787 100644 --- a/src/openrct2/rct2/RCT2.h +++ b/src/openrct2/rct2/RCT2.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2019 OpenRCT2 developers + * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -251,7 +251,7 @@ struct rct2_ride uint8_t pad_16F[0x7]; // 0x16F uint8_t spiral_slide_progress; // 0x176 uint8_t pad_177[0x9]; // 0x177 - int16_t build_date; // 0x180 + uint16_t build_date; // 0x180 money16 upkeep_cost; // 0x182 uint16_t race_winner; // 0x184 uint8_t pad_186[0x02]; // 0x186 diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 03a2b48536..4947e80d25 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -248,6 +248,11 @@ int32_t ride_get_count() return static_cast(GetRideManager().size()); } +int32_t Ride::GetAge() const +{ + return static_cast(gDateMonthsElapsed) - build_date; +} + int32_t Ride::GetTotalQueueLength() const { int32_t i, queueLength = 0; @@ -891,7 +896,9 @@ void ride_init_all() void reset_all_ride_build_dates() { for (auto& ride : GetRideManager()) - ride.build_date -= gDateMonthsElapsed; + { + ride.build_date = gDateMonthsElapsed; + } } #pragma endregion @@ -2214,8 +2221,7 @@ static void ride_inspection_update(Ride* ride) static int32_t get_age_penalty(Ride* ride) { - int32_t years; - years = date_get_year(gDateMonthsElapsed - ride->build_date); + auto years = date_get_year(ride->GetAge()); switch (years) { case 0: @@ -2308,7 +2314,7 @@ static void ride_breakdown_update(Ride* ride) */ static int32_t ride_get_new_breakdown_problem(Ride* ride) { - int32_t availableBreakdownProblems, monthsOld, totalProbability, randomProbability, problemBits, breakdownProblem; + int32_t availableBreakdownProblems, totalProbability, randomProbability, problemBits, breakdownProblem; // Brake failure is more likely when it's raining _breakdownProblemProbabilities[BREAKDOWN_BRAKES_FAILURE] = climate_is_raining() ? 20 : 3; @@ -2356,7 +2362,7 @@ static int32_t ride_get_new_breakdown_problem(Ride* ride) if (gCheatsDisableBrakesFailure) return -1; - monthsOld = gDateMonthsElapsed - ride->build_date; + auto monthsOld = ride->GetAge(); if (monthsOld < 16 || ride->reliability_percentage > 50) return -1; diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 4ea175f957..6f06d17494 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2019 OpenRCT2 developers + * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -306,7 +306,7 @@ struct Ride }; uint8_t slide_peep_t_shirt_colour; uint8_t spiral_slide_progress; - int16_t build_date; + uint16_t build_date; money16 upkeep_cost; uint16_t race_winner; uint32_t music_position; @@ -411,6 +411,7 @@ public: rct_ride_entry* GetRideEntry() const; + int32_t GetAge() const; int32_t GetTotalQueueLength() const; int32_t GetMaxQueueTime() const; diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index d12ec006b8..27c093ebcc 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-2019 OpenRCT2 developers + * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 @@ -846,7 +846,7 @@ static void ride_ratings_calculate_value(Ride* ride) int32_t monthsOld = 0; if (!gCheatsDisableRideValueAging) { - monthsOld = gDateMonthsElapsed - ride->build_date; + monthsOld = ride->GetAge(); } const row* ageTable = ageTableNew; diff --git a/src/openrct2/scripting/ScRide.hpp b/src/openrct2/scripting/ScRide.hpp index dde56e0a1c..e8d7470716 100644 --- a/src/openrct2/scripting/ScRide.hpp +++ b/src/openrct2/scripting/ScRide.hpp @@ -549,6 +549,21 @@ namespace OpenRCT2::Scripting } } + int16_t buildDate_get() const + { + auto ride = GetRide(); + return ride != nullptr ? ride->build_date : 0; + } + void buildDate_set(int16_t value) + { + ThrowIfGameStateNotMutable(); + auto ride = GetRide(); + if (ride != nullptr) + { + ride->build_date = value; + } + } + Ride* GetRide() const { return get_ride(_rideId); @@ -581,6 +596,7 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScRide::intensity_get, &ScRide::intensity_set, "intensity"); dukglue_register_property(ctx, &ScRide::nausea_get, &ScRide::nausea_set, "nausea"); dukglue_register_property(ctx, &ScRide::totalCustomers_get, &ScRide::totalCustomers_set, "totalCustomers"); + dukglue_register_property(ctx, &ScRide::buildDate_get, &ScRide::buildDate_set, "buildDate"); } }; } // namespace OpenRCT2::Scripting