From e8d6383f5774ba7e80da79983d3ff44818285f8c Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 8 Jun 2020 14:23:33 +0200 Subject: [PATCH] Clean up voucher arguments --- src/openrct2-ui/windows/Guest.cpp | 4 ++-- src/openrct2/GameStateSnapshots.cpp | 2 +- src/openrct2/actions/RideDemolishAction.hpp | 2 +- src/openrct2/management/Marketing.cpp | 4 ++-- src/openrct2/management/Marketing.h | 3 ++- src/openrct2/peep/Guest.cpp | 8 ++++---- src/openrct2/peep/Peep.h | 7 ++++++- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Exporter.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/RideData.h | 2 +- src/openrct2/ride/ShopItem.h | 2 ++ test/tests/S6ImportExportTests.cpp | 2 +- 13 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 1a10488506..bc1583fd37 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1988,7 +1988,7 @@ static rct_string_id window_guest_inventory_format_item(Peep* peep, int32_t item ft.Add(parkName); break; case VOUCHER_TYPE_RIDE_FREE: - ride = get_ride(peep->VoucherArguments); + ride = get_ride(peep->VoucherRideId); if (ride != nullptr) { ft.Rewind(); @@ -2008,7 +2008,7 @@ static rct_string_id window_guest_inventory_format_item(Peep* peep, int32_t item ft.Rewind(); ft.Increment(6); ft.Add(STR_PEEP_INVENTORY_VOUCHER_FOOD_OR_DRINK_FREE); - ft.Add(ShopItems[peep->VoucherArguments].Naming.Singular); + ft.Add(ShopItems[peep->VoucherShopItem].Naming.Singular); break; } break; diff --git a/src/openrct2/GameStateSnapshots.cpp b/src/openrct2/GameStateSnapshots.cpp index a46b0a48a8..17e713271f 100644 --- a/src/openrct2/GameStateSnapshots.cpp +++ b/src/openrct2/GameStateSnapshots.cpp @@ -304,7 +304,7 @@ struct GameStateSnapshots final : public IGameStateSnapshots COMPARE_FIELD(Peep, AmountOfSouvenirs); COMPARE_FIELD(Peep, VandalismSeen); COMPARE_FIELD(Peep, VoucherType); - COMPARE_FIELD(Peep, VoucherArguments); + COMPARE_FIELD(Peep, VoucherRideId); COMPARE_FIELD(Peep, SurroundingsThoughtTimeout); COMPARE_FIELD(Peep, Angriness); COMPARE_FIELD(Peep, TimeLost); diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index 87506d6b1b..97ee2f4430 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -176,7 +176,7 @@ private: // remove any free voucher for this ride from peep if (peep->ItemStandardFlags & PEEP_ITEM_VOUCHER) { - if (peep->VoucherType == VOUCHER_TYPE_RIDE_FREE && peep->VoucherArguments == _rideIndex) + if (peep->VoucherType == VOUCHER_TYPE_RIDE_FREE && peep->VoucherRideId == _rideIndex) { peep->ItemStandardFlags &= ~(PEEP_ITEM_VOUCHER); } diff --git a/src/openrct2/management/Marketing.cpp b/src/openrct2/management/Marketing.cpp index 9ad7e31e63..610e4c7a4c 100644 --- a/src/openrct2/management/Marketing.cpp +++ b/src/openrct2/management/Marketing.cpp @@ -141,7 +141,7 @@ void marketing_set_guest_campaign(Peep* peep, int32_t campaignType) case ADVERTISING_CAMPAIGN_RIDE_FREE: peep->ItemStandardFlags |= PEEP_ITEM_VOUCHER; peep->VoucherType = VOUCHER_TYPE_RIDE_FREE; - peep->VoucherArguments = campaign->RideId; + peep->VoucherRideId = campaign->RideId; peep->GuestHeadingToRideId = campaign->RideId; peep->GuestIsLostCountdown = 240; break; @@ -152,7 +152,7 @@ void marketing_set_guest_campaign(Peep* peep, int32_t campaignType) case ADVERTISING_CAMPAIGN_FOOD_OR_DRINK_FREE: peep->ItemStandardFlags |= PEEP_ITEM_VOUCHER; peep->VoucherType = VOUCHER_TYPE_FOOD_OR_DRINK_FREE; - peep->VoucherArguments = campaign->ShopItemType; + peep->VoucherShopItem = campaign->ShopItemType; break; case ADVERTISING_CAMPAIGN_PARK: break; diff --git a/src/openrct2/management/Marketing.h b/src/openrct2/management/Marketing.h index 36c931754b..21892ed472 100644 --- a/src/openrct2/management/Marketing.h +++ b/src/openrct2/management/Marketing.h @@ -12,6 +12,7 @@ #include "../Cheats.h" #include "../common.h" #include "../peep/Peep.h" +#include "../ride/ShopItem.h" #include @@ -48,7 +49,7 @@ struct MarketingCampaign union { ride_id_t RideId{}; - uint8_t ShopItemType; + ShopItemIndex ShopItemType; }; }; diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index c080c8fcad..1e275451f4 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -1483,7 +1483,7 @@ bool Guest::DecideAndBuyItem(Ride* ride, int32_t shopItem, money32 price) bool hasVoucher = false; if ((ItemStandardFlags & PEEP_ITEM_VOUCHER) && (VoucherType == VOUCHER_TYPE_FOOD_OR_DRINK_FREE) - && (VoucherArguments == shopItem)) + && (VoucherShopItem == shopItem)) { hasVoucher = true; } @@ -2415,7 +2415,7 @@ void Guest::ReadMap() static bool peep_has_voucher_for_free_ride(Peep* peep, Ride* ride) { return peep->ItemStandardFlags & PEEP_ITEM_VOUCHER && peep->VoucherType == VOUCHER_TYPE_RIDE_FREE - && peep->VoucherArguments == ride->id; + && peep->VoucherRideId == ride->id; } /** @@ -2636,7 +2636,7 @@ static void peep_update_ride_at_entrance_try_leave(Guest* peep) static bool peep_check_ride_price_at_entrance(Guest* peep, Ride* ride, money32 ridePrice) { if ((peep->ItemStandardFlags & PEEP_ITEM_VOUCHER) && peep->VoucherType == VOUCHER_TYPE_RIDE_FREE - && peep->VoucherArguments == peep->CurrentRide) + && peep->VoucherRideId == peep->CurrentRide) return true; if (peep->CashInPocket <= 0 && !(gParkFlags & PARK_FLAGS_NO_MONEY)) @@ -3856,7 +3856,7 @@ void Guest::UpdateRideFreeVehicleEnterRide(Ride* ride) if (ridePrice != 0) { if ((ItemStandardFlags & PEEP_ITEM_VOUCHER) && (VoucherType == VOUCHER_TYPE_RIDE_FREE) - && (VoucherArguments == CurrentRide)) + && (VoucherRideId == CurrentRide)) { ItemStandardFlags &= ~PEEP_ITEM_VOUCHER; WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY; diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index abb874455e..fbc3717e48 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -15,6 +15,7 @@ #include "../rct12/RCT12.h" #include "../ride/Ride.h" #include "../ride/RideTypes.h" +#include "../ride/ShopItem.h" #include "../world/Location.hpp" #include "../world/SpriteBase.h" @@ -743,7 +744,11 @@ struct Peep : SpriteBase uint8_t AmountOfSouvenirs; uint8_t VandalismSeen; // 0xC0 vandalism thought timeout, 0x3F vandalism tiles seen uint8_t VoucherType; - uint8_t VoucherArguments; // ride_id or string_offset_id + union + { + ride_id_t VoucherRideId; + ShopItemIndex VoucherShopItem; + }; uint8_t SurroundingsThoughtTimeout; uint8_t Angriness; uint8_t TimeLost; // the time the peep has been lost when it reaches 254 generates the lost thought diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index f2ac683685..b1d1ff7a20 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1493,7 +1493,7 @@ private: dst->PaidOnFood = src->paid_on_food; dst->PaidOnSouvenirs = src->paid_on_souvenirs; - dst->VoucherArguments = src->voucher_arguments; + dst->VoucherRideId = src->voucher_arguments; dst->VoucherType = src->voucher_type; dst->SurroundingsThoughtTimeout = src->surroundings_thought_timeout; diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index a561e2f591..4d2b2bdd69 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -1228,7 +1228,7 @@ void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src) dst->no_of_souvenirs = src->AmountOfSouvenirs; dst->vandalism_seen = src->VandalismSeen; dst->voucher_type = src->VoucherType; - dst->voucher_arguments = src->VoucherArguments; + dst->voucher_arguments = src->VoucherRideId; dst->surroundings_thought_timeout = src->SurroundingsThoughtTimeout; dst->angriness = src->Angriness; dst->time_lost = src->TimeLost; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 8581e99f44..0431b41d51 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1510,7 +1510,7 @@ public: dst->AmountOfSouvenirs = src->no_of_souvenirs; dst->VandalismSeen = src->vandalism_seen; dst->VoucherType = src->voucher_type; - dst->VoucherArguments = src->voucher_arguments; + dst->VoucherRideId = src->voucher_arguments; dst->SurroundingsThoughtTimeout = src->surroundings_thought_timeout; dst->Angriness = src->angriness; dst->TimeLost = src->time_lost; diff --git a/src/openrct2/ride/RideData.h b/src/openrct2/ride/RideData.h index 5ea9f64b59..f8049e9ffa 100644 --- a/src/openrct2/ride/RideData.h +++ b/src/openrct2/ride/RideData.h @@ -165,7 +165,7 @@ struct RideTypeDescriptor money16 DefaultPrices[NUM_SHOP_ITEMS_PER_RIDE]; uint8_t DefaultMusic; /** rct2: 0x0097D7CB */ - uint8_t PhotoItem; + ShopItemIndex PhotoItem; /** rct2: 0x0097D21E */ uint8_t BonusValue; track_colour_preset_list ColourPresets; diff --git a/src/openrct2/ride/ShopItem.h b/src/openrct2/ride/ShopItem.h index c7efe57992..c2d58e4759 100644 --- a/src/openrct2/ride/ShopItem.h +++ b/src/openrct2/ride/ShopItem.h @@ -11,6 +11,8 @@ #include "../common.h" +using ShopItemIndex = uint8_t; + struct Ride; enum diff --git a/test/tests/S6ImportExportTests.cpp b/test/tests/S6ImportExportTests.cpp index 05a3adc737..536272f734 100644 --- a/test/tests/S6ImportExportTests.cpp +++ b/test/tests/S6ImportExportTests.cpp @@ -256,7 +256,7 @@ static void CompareSpriteDataPeep(const Peep& left, const Peep& right) COMPARE_FIELD(AmountOfSouvenirs); COMPARE_FIELD(VandalismSeen); COMPARE_FIELD(VoucherType); - COMPARE_FIELD(VoucherArguments); + COMPARE_FIELD(VoucherRideId); COMPARE_FIELD(SurroundingsThoughtTimeout); COMPARE_FIELD(Angriness); COMPARE_FIELD(TimeLost);