From c24112ffad5a35c2353d687e0329dc53c01bd26d Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 22 Dec 2019 07:36:20 +0100 Subject: [PATCH] Refactor out gCommandExpenditureType --- src/openrct2/GameState.cpp | 1 + src/openrct2/actions/GameAction.h | 2 +- src/openrct2/actions/StaffHireNewAction.hpp | 1 + src/openrct2/management/Finance.cpp | 18 ++-------------- src/openrct2/management/Finance.h | 10 ++------- src/openrct2/peep/Guest.cpp | 24 ++++++++++----------- src/openrct2/peep/GuestPathfinding.cpp | 1 + src/openrct2/peep/Peep.cpp | 6 ++---- src/openrct2/peep/Peep.h | 5 +++-- 9 files changed, 25 insertions(+), 43 deletions(-) diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index b3ea1fafc4..4a195010b6 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -23,6 +23,7 @@ #include "localisation/Localisation.h" #include "management/NewsItem.h" #include "network/network.h" +#include "peep/Staff.h" #include "platform/Platform2.h" #include "scenario/Scenario.h" #include "title/TitleScreen.h" diff --git a/src/openrct2/actions/GameAction.h b/src/openrct2/actions/GameAction.h index c5f24d2534..22cb897406 100644 --- a/src/openrct2/actions/GameAction.h +++ b/src/openrct2/actions/GameAction.h @@ -74,7 +74,7 @@ public: std::array ErrorMessageArgs; CoordsXYZ Position = { LOCATION_NULL, LOCATION_NULL, LOCATION_NULL }; money32 Cost = 0; - uint16_t ExpenditureType = 0; + rct_expenditure_type ExpenditureType = RCT_EXPENDITURE_TYPE_COUNT; GameActionResult() = default; GameActionResult(GA_ERROR error, rct_string_id message); diff --git a/src/openrct2/actions/StaffHireNewAction.hpp b/src/openrct2/actions/StaffHireNewAction.hpp index c1c290be35..f765a4eeab 100644 --- a/src/openrct2/actions/StaffHireNewAction.hpp +++ b/src/openrct2/actions/StaffHireNewAction.hpp @@ -17,6 +17,7 @@ #include "../localisation/Localisation.h" #include "../localisation/StringIds.h" #include "../management/Finance.h" +#include "../peep/Staff.h" #include "../ride/Ride.h" #include "../scenario/Scenario.h" #include "../ui/UiContext.h" diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index 80b0e46934..b9a137cb83 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -24,18 +24,6 @@ #include "../world/Park.h" #include "../world/Sprite.h" -/** - * Monthly staff wages - * - * rct2: 0x00992A00 - */ -const money32 wage_table[STAFF_TYPE_COUNT] = { - MONEY(50, 00), // Handyman - MONEY(80, 00), // Mechanic - MONEY(60, 00), // Security guard - MONEY(55, 00), // Entertainer -}; - // Monthly research funding costs const money32 research_cost_table[RESEARCH_FUNDING_COUNT] = { MONEY(0, 00), // No funding @@ -63,8 +51,6 @@ money32 gWeeklyProfitHistory[FINANCE_GRAPH_SIZE]; money32 gParkValueHistory[FINANCE_GRAPH_SIZE]; money32 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][RCT_EXPENDITURE_TYPE_COUNT]; -uint8_t gCommandExpenditureType; - /** * Checks the condition if the game is required to use money. * @param flags game command flags. @@ -130,7 +116,7 @@ void finance_pay_wages() FOR_ALL_STAFF (spriteIndex, peep) { - finance_payment(wage_table[peep->staff_type] / 4, RCT_EXPENDITURE_TYPE_WAGES); + finance_payment(gStaffWageTable[peep->staff_type] / 4, RCT_EXPENDITURE_TYPE_WAGES); } } @@ -268,7 +254,7 @@ void finance_update_daily_profit() FOR_ALL_STAFF (sprite_index, peep) { - current_profit -= wage_table[peep->staff_type]; + current_profit -= gStaffWageTable[peep->staff_type]; } // Research costs diff --git a/src/openrct2/management/Finance.h b/src/openrct2/management/Finance.h index 7277a591e3..40aa41b53f 100644 --- a/src/openrct2/management/Finance.h +++ b/src/openrct2/management/Finance.h @@ -10,14 +10,11 @@ #pragma once #include "../common.h" -#include "../peep/Staff.h" #include "Research.h" -using rct_expenditure_type = int32_t; - -enum +enum rct_expenditure_type : int32_t { - RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION, + RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION = 0, RCT_EXPENDITURE_TYPE_RIDE_RUNNING_COSTS, RCT_EXPENDITURE_TYPE_LAND_PURCHASE, RCT_EXPENDITURE_TYPE_LANDSCAPING, @@ -37,7 +34,6 @@ enum #define EXPENDITURE_TABLE_MONTH_COUNT 16 #define FINANCE_GRAPH_SIZE 128 -extern const money32 wage_table[STAFF_TYPE_COUNT]; extern const money32 research_cost_table[RESEARCH_FUNDING_COUNT]; extern money32 gInitialCash; @@ -61,8 +57,6 @@ extern money32 gWeeklyProfitHistory[FINANCE_GRAPH_SIZE]; extern money32 gParkValueHistory[FINANCE_GRAPH_SIZE]; extern money32 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][RCT_EXPENDITURE_TYPE_COUNT]; -extern uint8_t gCommandExpenditureType; - bool finance_check_money_required(uint32_t flags); bool finance_check_affordability(money32 cost, uint32_t flags); void finance_payment(money32 amount, rct_expenditure_type type); diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 168cd8c3a6..cfb63a405a 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -36,6 +36,7 @@ #include "../world/Sprite.h" #include "../world/Surface.h" #include "Peep.h" +#include "Staff.h" #include #include @@ -1707,25 +1708,25 @@ loc_69B221: no_of_souvenirs++; money16* expend_type = &paid_on_souvenirs; - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_SHOP_STOCK; + rct_expenditure_type expenditure = RCT_EXPENDITURE_TYPE_SHOP_STOCK; if (shop_item_is_food(shopItem)) { expend_type = &paid_on_food; - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_FOODDRINK_STOCK; + expenditure = RCT_EXPENDITURE_TYPE_FOODDRINK_STOCK; } if (shop_item_is_drink(shopItem)) { expend_type = &paid_on_drink; - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_FOODDRINK_STOCK; + expenditure = RCT_EXPENDITURE_TYPE_FOODDRINK_STOCK; } if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) - finance_payment(ShopItems[shopItem].Cost, gCommandExpenditureType); + finance_payment(ShopItems[shopItem].Cost, expenditure); // Sets the expenditure type to *_FOODDRINK_SALES or *_SHOP_SALES appropriately. - gCommandExpenditureType--; + expenditure = static_cast(static_cast(expenditure) - 1); if (hasVoucher) { item_standard_flags &= ~PEEP_ITEM_VOUCHER; @@ -1733,7 +1734,7 @@ loc_69B221: } else if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) { - SpendMoney(*expend_type, price); + SpendMoney(*expend_type, price, expenditure); } ride->total_profit += (price - ShopItems[shopItem].Cost); ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; @@ -2329,10 +2330,10 @@ bool Guest::ShouldGoToShop(Ride* ride, bool peepAtShop) } // Used when no logging to an expend type required -void Guest::SpendMoney(money32 amount) +void Guest::SpendMoney(money32 amount, rct_expenditure_type expenditure) { money16 unused; - SpendMoney(unused, amount); + SpendMoney(unused, amount, expenditure); } /** @@ -2340,7 +2341,7 @@ void Guest::SpendMoney(money32 amount) * rct2: 0x0069926C * Expend type was previously an offset saved in 0x00F1AEC0 */ -void Guest::SpendMoney(money16& peep_expend_type, money32 amount) +void Guest::SpendMoney(money16& peep_expend_type, money32 amount, rct_expenditure_type expenditure) { assert(!(gParkFlags & PARK_FLAGS_NO_MONEY)); @@ -2351,7 +2352,7 @@ void Guest::SpendMoney(money16& peep_expend_type, money32 amount) window_invalidate_by_number(WC_PEEP, sprite_index); - finance_payment(-amount, gCommandExpenditureType); + finance_payment(-amount, expenditure); if (gConfigGeneral.show_guest_purchases && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) { @@ -3872,8 +3873,7 @@ void Guest::UpdateRideFreeVehicleEnterRide(Ride* ride) { ride->total_profit += ridePrice; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS; - SpendMoney(paid_on_rides, ridePrice); + SpendMoney(paid_on_rides, ridePrice, RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS); } } diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 312f70769e..c1f1c09f52 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -15,6 +15,7 @@ #include "../world/Entrance.h" #include "../world/Footpath.h" #include "Peep.h" +#include "Staff.h" #include diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 8c5cc1044a..e826b1f414 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2623,8 +2623,7 @@ static void peep_interact_with_entrance(Peep* peep, int16_t x, int16_t y, TileEl } gTotalIncomeFromAdmissions += entranceFee; - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_PARK_ENTRANCE_TICKETS; - guest->SpendMoney(peep->paid_to_enter, entranceFee); + guest->SpendMoney(peep->paid_to_enter, entranceFee, RCT_EXPENDITURE_TYPE_PARK_ENTRANCE_TICKETS); peep->peep_flags |= PEEP_FLAGS_HAS_PAID_FOR_PARK_ENTRY; } @@ -2961,11 +2960,10 @@ static bool peep_interact_with_shop(Peep* peep, int16_t x, int16_t y, TileElemen { ride->total_profit += cost; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS; // TODO: Refactor? SpendMoney previously accepted nullptr to not track money, passing a temporary variable as a // workaround money16 money = 0; - guest->SpendMoney(money, cost); + guest->SpendMoney(money, cost, RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS); } peep->destination_x = (x & 0xFFE0) + 16; peep->destination_y = (y & 0xFFE0) + 16; diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 4474244de6..049f56a17e 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -12,6 +12,7 @@ #include "../common.h" #include "../core/Optional.hpp" +#include "../management/Finance.h" #include "../rct12/RCT12.h" #include "../ride/Ride.h" #include "../ride/RideTypes.h" @@ -762,8 +763,8 @@ public: bool ShouldFindBench(); bool UpdateWalkingFindBench(); bool UpdateWalkingFindBin(); - void SpendMoney(money16& peep_expend_type, money32 amount); - void SpendMoney(money32 amount); + void SpendMoney(money16& peep_expend_type, money32 amount, rct_expenditure_type type); + void SpendMoney(money32 amount, rct_expenditure_type type); void SetHasRidden(const Ride* ride); bool HasRidden(const Ride* ride) const; void SetHasRiddenRideType(int32_t rideType);