From 12bc9777d3ddb9bbf14d4b11ce1aa527c8eb88fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 25 May 2023 17:50:09 +0300 Subject: [PATCH] Cleanup calls to GetShopItemDescriptor in Guest::DecideAndBuyItem --- src/openrct2/entity/Guest.cpp | 45 ++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index b0f1b893b5..30e29baef4 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -1466,7 +1466,7 @@ void Guest::CheckCantFindExit() * * rct2: 0x0069AF1E */ -bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) +bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price) { money64 itemValue; @@ -1485,7 +1485,8 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) return false; } - if (GetShopItemDescriptor(shopItem).IsFoodOrDrink()) + const auto& shopItemDescriptor = GetShopItemDescriptor(shopItem); + if (shopItemDescriptor.IsFoodOrDrink()) { int32_t food = UtilBitScanForward(GetFoodOrDrinkFlags()); if (food != -1) @@ -1510,19 +1511,19 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) return false; } - if (GetShopItemDescriptor(shopItem).IsFood() && (Hunger > 75)) + if (shopItemDescriptor.IsFood() && (Hunger > 75)) { InsertNewThought(PeepThoughtType::NotHungry); return false; } - if (GetShopItemDescriptor(shopItem).IsDrink() && (Thirst > 75)) + if (shopItemDescriptor.IsDrink() && (Thirst > 75)) { InsertNewThought(PeepThoughtType::NotThirsty); return false; } - if (!isRainingAndUmbrella && (shopItem != ShopItem::Map) && GetShopItemDescriptor(shopItem).IsSouvenir() && !hasVoucher) + if (!isRainingAndUmbrella && (shopItem != ShopItem::Map) && shopItemDescriptor.IsSouvenir() && !hasVoucher) { if (((ScenarioRand() & 0x7F) + 0x73) > Happiness || GuestNumRides < 3) return false; @@ -1545,11 +1546,11 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) } if (gClimateCurrent.Temperature >= 21) - itemValue = GetShopItemDescriptor(shopItem).HotValue; + itemValue = shopItemDescriptor.HotValue; else if (gClimateCurrent.Temperature <= 11) - itemValue = GetShopItemDescriptor(shopItem).ColdValue; + itemValue = shopItemDescriptor.ColdValue; else - itemValue = GetShopItemDescriptor(shopItem).BaseValue; + itemValue = shopItemDescriptor.BaseValue; if (itemValue < price) { @@ -1567,7 +1568,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) if (itemValue > (static_cast(ScenarioRand() & 0x07))) { // "I'm not paying that much for x" - InsertNewThought(GetShopItemDescriptor(shopItem).TooMuchThought, ride.id); + InsertNewThought(shopItemDescriptor.TooMuchThought, ride.id); return false; } } @@ -1582,7 +1583,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) if (itemValue >= static_cast(ScenarioRand() & 0x07)) { // "This x is a really good value" - InsertNewThought(GetShopItemDescriptor(shopItem).GoodValueThought, ride.id); + InsertNewThought(shopItemDescriptor.GoodValueThought, ride.id); } } @@ -1593,11 +1594,11 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) // reset itemValue for satisfaction calculation if (gClimateCurrent.Temperature >= 21) - itemValue = GetShopItemDescriptor(shopItem).HotValue; + itemValue = shopItemDescriptor.HotValue; else if (gClimateCurrent.Temperature <= 11) - itemValue = GetShopItemDescriptor(shopItem).ColdValue; + itemValue = shopItemDescriptor.ColdValue; else - itemValue = GetShopItemDescriptor(shopItem).BaseValue; + itemValue = shopItemDescriptor.BaseValue; itemValue -= price; uint8_t satisfaction = 0; if (itemValue > -8) @@ -1633,7 +1634,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) if (shopItem == ShopItem::Map) ResetPathfindGoal(); - uint16_t consumptionTime = GetShopItemDescriptor(shopItem).ConsumptionTime; + uint16_t consumptionTime = shopItemDescriptor.ConsumptionTime; TimeToConsume = std::min((TimeToConsume + consumptionTime), 255); if (shopItem == ShopItem::Photo) @@ -1654,39 +1655,39 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) { auto ft = Formatter(); FormatNameTo(ft); - ft.Add(GetShopItemDescriptor(shopItem).Naming.Indefinite); + ft.Add(shopItemDescriptor.Naming.Indefinite); if (gConfigNotifications.GuestBoughtItem) { News::AddItemToQueue(News::ItemType::PeepOnRide, STR_PEEP_TRACKING_NOTIFICATION_BOUGHT_X, Id, ft); } } - if (GetShopItemDescriptor(shopItem).IsFood()) + if (shopItemDescriptor.IsFood()) AmountOfFood++; - if (GetShopItemDescriptor(shopItem).IsDrink()) + if (shopItemDescriptor.IsDrink()) AmountOfDrinks++; - if (GetShopItemDescriptor(shopItem).IsSouvenir()) + if (shopItemDescriptor.IsSouvenir()) AmountOfSouvenirs++; money64* expend_type = &PaidOnSouvenirs; ExpenditureType expenditure = ExpenditureType::ShopStock; - if (GetShopItemDescriptor(shopItem).IsFood()) + if (shopItemDescriptor.IsFood()) { expend_type = &PaidOnFood; expenditure = ExpenditureType::FoodDrinkStock; } - if (GetShopItemDescriptor(shopItem).IsDrink()) + if (shopItemDescriptor.IsDrink()) { expend_type = &PaidOnDrink; expenditure = ExpenditureType::FoodDrinkStock; } if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) - FinancePayment(GetShopItemDescriptor(shopItem).Cost, expenditure); + FinancePayment(shopItemDescriptor.Cost, expenditure); // Sets the expenditure type to *_FOODDRINK_SALES or *_SHOP_SALES appropriately. expenditure = static_cast(static_cast(expenditure) - 1); @@ -1699,7 +1700,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, ShopItem shopItem, money64 price) { SpendMoney(*expend_type, price, expenditure); } - ride.total_profit += (price - GetShopItemDescriptor(shopItem).Cost); + ride.total_profit += (price - shopItemDescriptor.Cost); ride.window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; ride.cur_num_customers++; ride.total_customers++;