diff --git a/soh/soh/Enhancements/randomizer/3drando/fill.cpp b/soh/soh/Enhancements/randomizer/3drando/fill.cpp index 8885117c3..94b495639 100644 --- a/soh/soh/Enhancements/randomizer/3drando/fill.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/fill.cpp @@ -421,7 +421,7 @@ bool AddCheckToLogic(LocationAccess& locPair, GetAccessibleLocationsStruct& gals Rando::ItemLocation* location = ctx->GetItemLocation(loc); RandomizerGet locItem = location->GetPlacedRandomizerGet(); - if (!location->IsAddedToPool() && locPair.ConditionsMet(parentRegion, gals.calculatingAvailableChecks)) { + if (!location->IsAddedToPool() && locPair.ConditionsMet(parentRegion)) { if (gals.calculatingAvailableChecks) { gals.accessibleLocations.push_back(loc); StopPerformanceTimer(PT_LOCATION_LOGIC); diff --git a/soh/soh/Enhancements/randomizer/3drando/fill.hpp b/soh/soh/Enhancements/randomizer/3drando/fill.hpp index 1da8cb0c1..a9b864ce2 100644 --- a/soh/soh/Enhancements/randomizer/3drando/fill.hpp +++ b/soh/soh/Enhancements/randomizer/3drando/fill.hpp @@ -71,8 +71,3 @@ void GeneratePlaythrough(); bool CheckBeatable(RandomizerGet ignore=RG_NONE); void ValidateEntrances(bool checkPoeCollectorAccess, bool checkOtherEntranceAccess); - -struct PriceSettingsStruct; -extern PriceSettingsStruct shopsanityPrices; -extern PriceSettingsStruct scrubPrices; -extern PriceSettingsStruct merchantPrices; diff --git a/soh/soh/Enhancements/randomizer/location_access.cpp b/soh/soh/Enhancements/randomizer/location_access.cpp index 6cf2aa2ab..0be683b9b 100644 --- a/soh/soh/Enhancements/randomizer/location_access.cpp +++ b/soh/soh/Enhancements/randomizer/location_access.cpp @@ -10,7 +10,9 @@ #include "soh/Enhancements/debugger/performanceTimer.h" #include +#include +#include "3drando/shops.hpp" extern "C" { extern SaveContext gSaveContext; extern PlayState* gPlayState; @@ -32,7 +34,7 @@ bool LocationAccess::CheckConditionAtAgeTime(bool& age, bool& time) const { return GetConditionsMet(); } -bool LocationAccess::ConditionsMet(Region* parentRegion, bool calculatingAvailableChecks) const { +bool LocationAccess::ConditionsMet(Region* parentRegion) const { // WARNING enterance validation can run this after resetting the access for sphere 0 validation // When refactoring ToD access, either fix the above or do not assume that we // have any access at all just because this is being run @@ -45,17 +47,70 @@ bool LocationAccess::ConditionsMet(Region* parentRegion, bool calculatingAvailab conditionsMet = true; } - return conditionsMet && - (calculatingAvailableChecks || CanBuy()); // TODO: run CanBuy when price is known due to settings + return conditionsMet && CanBuy(); +} + +static uint16_t GetMiniumPrice(const Rando::Location* loc) { + extern PriceSettingsStruct shopsanityPrices; + extern PriceSettingsStruct scrubPrices; + extern PriceSettingsStruct merchantPrices; + PriceSettingsStruct priceSettings = loc->GetRCType() == RCTYPE_SHOP ? shopsanityPrices + : loc->GetRCType() == RCTYPE_SCRUB ? scrubPrices + : merchantPrices; + + auto ctx = Rando::Context::GetInstance(); + switch (ctx->GetOption(priceSettings.main).Get()) { + case RO_PRICE_VANILLA: + return loc->GetVanillaPrice(); + case RO_PRICE_CHEAP_BALANCED: + return 0; + case RO_PRICE_BALANCED: + return 0; + case RO_PRICE_FIXED: + return ctx->GetOption(priceSettings.fixedPrice).Get() * 5; + case RO_PRICE_RANGE: { + uint16_t range1 = ctx->GetOption(priceSettings.range1).Get() * 5; + uint16_t range2 = ctx->GetOption(priceSettings.range1).Get() * 5; + return range1 < range2 ? range1 : range2; + } + case RO_PRICE_SET_BY_WALLET: { + if (ctx->GetOption(priceSettings.noWallet).Get()) { + return 0; + } else if (ctx->GetOption(priceSettings.childWallet).Get()) { + return 1; + } else if (ctx->GetOption(priceSettings.adultWallet).Get()) { + return 100; + } else if (ctx->GetOption(priceSettings.giantWallet).Get()) { + return 201; + } else { + return 501; + } + } + default: + return 0; + } } bool LocationAccess::CanBuy() const { - return CanBuyAnother(location); + const auto& loc = Rando::StaticData::GetLocation(location); + const auto& itemLoc = OTRGlobals::Instance->gRandoContext->GetItemLocation(location); + + if (loc->GetRCType() == RCTYPE_SHOP || loc->GetRCType() == RCTYPE_SCRUB || loc->GetRCType() == RCTYPE_MERCHANT) { + if (itemLoc->GetCheckStatus() != RCSHOW_IDENTIFIED) { + return CanBuyAnother(GetMiniumPrice(loc)); + } else { + return CanBuyAnother(itemLoc->GetPrice()); + } + } + + return true; } bool CanBuyAnother(RandomizerCheck rc) { - uint16_t price = ctx->GetItemLocation(rc)->GetPrice(); + return CanBuyAnother(ctx->GetItemLocation(rc)->GetPrice()); +} +bool CanBuyAnother(uint16_t price) { if (price > 500) { return logic->HasItem(RG_TYCOON_WALLET); } else if (price > 200) { diff --git a/soh/soh/Enhancements/randomizer/location_access.h b/soh/soh/Enhancements/randomizer/location_access.h index 828c31a08..8d6815089 100644 --- a/soh/soh/Enhancements/randomizer/location_access.h +++ b/soh/soh/Enhancements/randomizer/location_access.h @@ -84,7 +84,7 @@ class LocationAccess { bool CheckConditionAtAgeTime(bool& age, bool& time) const; - bool ConditionsMet(Region* parentRegion, bool calculatingAvailableChecks) const; + bool ConditionsMet(Region* parentRegion) const; RandomizerCheck GetLocation() const { return location; @@ -103,6 +103,7 @@ class LocationAccess { bool CanBuy() const; }; +bool CanBuyAnother(uint16_t price); bool CanBuyAnother(RandomizerCheck rc); namespace Rando { diff --git a/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp index 600f76cbb..dda6c2e5c 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp @@ -12,7 +12,6 @@ #include "entrance.h" #include "location_access.h" #include "3drando/fill.hpp" -#include "3drando/shops.hpp" #include "soh/Enhancements/debugger/performanceTimer.h" #include @@ -1959,68 +1958,6 @@ void ImGuiDrawTwoColorPickerSection(const char* text, const char* cvarMainName, UIWidgets::PopStyleCombobox(); } -static RandomizerGet PriceToWallet(uint16_t price) { - if (price <= 0) { - return RG_NONE; - } else if (price <= 99) { - return RG_CHILD_WALLET; - } else if (price <= 200) { - return RG_ADULT_WALLET; - } else if (price <= 500) { - return RG_GIANT_WALLET; - } else if (price <= 999) { - return RG_TYCOON_WALLET; - } else { - return RG_WALLET_INF; - } -} - -// Location RCType should be RCTYPE_SHOP, RCTYPE_SCRUB, or RCTYPE_MERCHANT -static RandomizerGet GetMiniumWalletRequirement(const Rando::Location* loc) { - PriceSettingsStruct priceSettings = loc->GetRCType() == RCTYPE_SHOP ? shopsanityPrices - : loc->GetRCType() == RCTYPE_SCRUB ? scrubPrices - : merchantPrices; - - auto ctx = Rando::Context::GetInstance(); - switch (ctx->GetOption(priceSettings.main).Get()) { - case RO_PRICE_VANILLA: { - uint16_t vanillaPrice = loc->GetVanillaPrice(); - return PriceToWallet(vanillaPrice); - } - case RO_PRICE_CHEAP_BALANCED: - return RG_NONE; - case RO_PRICE_BALANCED: - return RG_NONE; - case RO_PRICE_FIXED: { - uint16_t fixedPrice = ctx->GetOption(priceSettings.fixedPrice).Get() * 5; - return PriceToWallet(fixedPrice); - } - case RO_PRICE_RANGE: { - uint16_t range1 = ctx->GetOption(priceSettings.range1).Get() * 5; - uint16_t range2 = ctx->GetOption(priceSettings.range1).Get() * 5; - return PriceToWallet(range1 < range2 ? range1 : range2); - } - case RO_PRICE_SET_BY_WALLET: { - bool includeTycoon = ctx->GetOption(RSK_INCLUDE_TYCOON_WALLET).Get(); - if (ctx->GetOption(priceSettings.noWallet).Get()) { - return RG_NONE; - } else if (ctx->GetOption(priceSettings.childWallet).Get()) { - return RG_CHILD_WALLET; - } else if (ctx->GetOption(priceSettings.adultWallet).Get()) { - return RG_ADULT_WALLET; - } else if (ctx->GetOption(priceSettings.giantWallet).Get()) { - return RG_GIANT_WALLET; - } else if (includeTycoon && ctx->GetOption(priceSettings.tycoonWallet).Get()) { - return RG_TYCOON_WALLET; - } else { - return RG_WALLET_INF; - } - } - default: - return RG_NONE; - } -} - void RecalculateAvailableChecks() { if (!enableAvailableChecks) { return; @@ -2042,21 +1979,8 @@ void RecalculateAvailableChecks() { std::vector availableChecks = ReachabilitySearch(targetLocations, RG_NONE, true); for (auto& rc : availableChecks) { - const auto& location = Rando::StaticData::GetLocation(rc); const auto& itemLocation = OTRGlobals::Instance->gRandoContext->GetItemLocation(rc); - - if (location->GetRCType() == RCTYPE_SHOP || location->GetRCType() == RCTYPE_SCRUB || - location->GetRCType() == RCTYPE_MERCHANT) { - if (itemLocation->GetCheckStatus() != RCSHOW_IDENTIFIED) { - auto minimumWallet = GetMiniumWalletRequirement(location); - itemLocation->SetAvailable(minimumWallet == RG_NONE || logic->HasItem(minimumWallet)); - } else { - auto requiredWallet = PriceToWallet(itemLocation->GetPrice()); - itemLocation->SetAvailable(requiredWallet == RG_NONE || logic->HasItem(requiredWallet)); - } - } else { - itemLocation->SetAvailable(true); - } + itemLocation->SetAvailable(true); } totalChecksAvailable = 0;