[V3] Fishsanity Cleanup (#4380)

* Fix crash in fishsanity's flag set handler.
Code format cleanup.
Fix typedef warnings in fishsanity.h.

* Actually fix the crash now.

* Relocate RCTYPE check for broader application.
This commit is contained in:
Malkierian 2024-10-05 09:58:41 -07:00 committed by GitHub
parent 33c74a10b7
commit c4d211bc3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 27 deletions

View File

@ -75,19 +75,22 @@ namespace Rando {
FishsanityOptionsSource optionsSource) { FishsanityOptionsSource optionsSource) {
auto [mode, numFish, ageSplit] = GetOptions(optionsSource); auto [mode, numFish, ageSplit] = GetOptions(optionsSource);
if (loc->GetRCType() != RCTYPE_FISH || mode == RO_FISHSANITY_OFF) if (loc->GetRCType() != RCTYPE_FISH || mode == RO_FISHSANITY_OFF) {
return false; return false;
}
RandomizerCheck rc = loc->GetRandomizerCheck(); RandomizerCheck rc = loc->GetRandomizerCheck();
// Are pond fish enabled, and is this a pond fish location? // Are pond fish enabled, and is this a pond fish location?
if (mode != RO_FISHSANITY_OVERWORLD && numFish > 0 && loc->GetScene() == SCENE_FISHING_POND && if (mode != RO_FISHSANITY_OVERWORLD && numFish > 0 && loc->GetScene() == SCENE_FISHING_POND &&
loc->GetActorID() == ACTOR_FISHING) { loc->GetActorID() == ACTOR_FISHING) {
// Is this a child fish location? If so, is it within the defined number of pond fish checks? // Is this a child fish location? If so, is it within the defined number of pond fish checks?
if (rc >= RC_LH_CHILD_FISH_1 && rc <= RC_LH_CHILD_LOACH_2 && numFish > (loc->GetActorParams() - 100)) if (rc >= RC_LH_CHILD_FISH_1 && rc <= RC_LH_CHILD_LOACH_2 && numFish > (loc->GetActorParams() - 100)) {
return true; return true;
}
// Are adult fish available, and is this an adult fish location? If so, is it within the defined number of pond // Are adult fish available, and is this an adult fish location? If so, is it within the defined number of pond
// fish checks? // fish checks?
if (ageSplit && rc >= RC_LH_ADULT_FISH_1 && rc <= RC_LH_ADULT_LOACH && numFish > (loc->GetActorParams() - 100)) if (ageSplit && rc >= RC_LH_ADULT_FISH_1 && rc <= RC_LH_ADULT_LOACH && numFish > (loc->GetActorParams() - 100)) {
return true; return true;
}
} }
// Are overworld fish enabled, and is this an overworld fish location? // Are overworld fish enabled, and is this an overworld fish location?
if (mode != RO_FISHSANITY_POND && (loc->GetScene() == SCENE_GROTTOS || loc->GetScene() == SCENE_ZORAS_DOMAIN) if (mode != RO_FISHSANITY_POND && (loc->GetScene() == SCENE_GROTTOS || loc->GetScene() == SCENE_ZORAS_DOMAIN)
@ -238,7 +241,7 @@ namespace Rando {
bool Fishsanity::GetPondFishShuffled() { bool Fishsanity::GetPondFishShuffled() {
u8 fsMode = OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_FISHSANITY); u8 fsMode = OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_FISHSANITY);
return OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_FISHSANITY_POND_COUNT) > 0 && return OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_FISHSANITY_POND_COUNT) > 0 &&
(fsMode == RO_FISHSANITY_POND || fsMode == RO_FISHSANITY_BOTH); (fsMode == RO_FISHSANITY_POND || fsMode == RO_FISHSANITY_BOTH);
} }
bool Fishsanity::GetOverworldFishShuffled() { bool Fishsanity::GetOverworldFishShuffled() {
@ -253,8 +256,9 @@ namespace Rando {
bool Fishsanity::GetPondCleared() { bool Fishsanity::GetPondCleared() {
auto [mode, pondCount, ageSplit] = GetOptions(); auto [mode, pondCount, ageSplit] = GetOptions();
// no fish shuffled, so pond is always cleared :thumbsup: // no fish shuffled, so pond is always cleared :thumbsup:
if (pondCount == 0) if (pondCount == 0) {
return true; return true;
}
bool adultPond = LINK_IS_ADULT && ageSplit; bool adultPond = LINK_IS_ADULT && ageSplit;
// if we've collected the final shuffled fish, pond is complete // if we've collected the final shuffled fish, pond is complete
@ -268,23 +272,26 @@ namespace Rando {
for (auto tableEntry : Rando::StaticData::randomizerFishingPondFish) { for (auto tableEntry : Rando::StaticData::randomizerFishingPondFish) {
RandomizerCheck rc = adultPond ? tableEntry.second : tableEntry.first; RandomizerCheck rc = adultPond ? tableEntry.second : tableEntry.first;
// if we haven't collected this fish, then we're not done yet! get back in there, soldier // if we haven't collected this fish, then we're not done yet! get back in there, soldier
if (rc != RC_UNKNOWN_CHECK && !Flags_GetRandomizerInf(OTRGlobals::Instance->gRandomizer->GetRandomizerInfFromCheck(rc))) if (rc != RC_UNKNOWN_CHECK && !Flags_GetRandomizerInf(OTRGlobals::Instance->gRandomizer->GetRandomizerInfFromCheck(rc))) {
return false; return false;
}
} }
return true; return true;
} }
bool Fishsanity::GetDomainCleared() { bool Fishsanity::GetDomainCleared() {
for (RandomizerInf i = RAND_INF_ZD_FISH_1; i <= RAND_INF_ZD_FISH_5; i = (RandomizerInf)(i + 1)) { for (RandomizerInf i = RAND_INF_ZD_FISH_1; i <= RAND_INF_ZD_FISH_5; i = (RandomizerInf)(i + 1)) {
if (!Flags_GetRandomizerInf(i)) if (!Flags_GetRandomizerInf(i)) {
return false; return false;
}
} }
return true; return true;
} }
void Fishsanity::InitializeHelpers() { void Fishsanity::InitializeHelpers() {
if (fishsanityHelpersInit) if (fishsanityHelpersInit) {
return; return;
}
for (auto pair : Rando::StaticData::randomizerFishingPondFish) { for (auto pair : Rando::StaticData::randomizerFishingPondFish) {
pondFishAgeMap[pair.first] = LINK_AGE_CHILD; pondFishAgeMap[pair.first] = LINK_AGE_CHILD;
@ -314,25 +321,28 @@ namespace Rando {
} }
FishsanityCheckType Fishsanity::GetCheckType(RandomizerCheck rc) { FishsanityCheckType Fishsanity::GetCheckType(RandomizerCheck rc) {
// Is this a pond fish? // if it's not RCTYPE_FISH, obviously it's not a fish
if (std::binary_search(Rando::StaticData::GetPondFishLocations().begin(), Rando::StaticData::GetPondFishLocations().end(), rc)) if (Rando::StaticData::GetLocation(rc)->GetRCType() != RCTYPE_FISH) {
return FSC_POND; return FSC_NONE;
}
// Is this an overworld fish?
if (std::binary_search(Rando::StaticData::GetOverworldFishLocations().begin(), Rando::StaticData::GetOverworldFishLocations().end(), rc)) { auto loc = Rando::StaticData::GetLocation(rc);
if (rc < RC_ZD_FISH_1) switch (loc->GetScene()) {
return FSC_GROTTO; case SCENE_FISHING_POND:
else return FSC_POND;
return FSC_ZD; case SCENE_ZORAS_DOMAIN:
return FSC_ZD;
case SCENE_GROTTOS:
return FSC_GROTTO;
default:
return FSC_NONE;
} }
// Must not be a fishsanity check
return FSC_NONE;
} }
bool Fishsanity::IsFish(FishIdentity* fish) { bool Fishsanity::IsFish(FishIdentity* fish) {
if (fish->randomizerCheck == RC_UNKNOWN_CHECK || fish->randomizerInf == RAND_INF_MAX) if (fish->randomizerCheck == RC_UNKNOWN_CHECK || fish->randomizerInf == RAND_INF_MAX) {
return false; return false;
}
return GetCheckType(fish->randomizerCheck) != FSC_NONE; return GetCheckType(fish->randomizerCheck) != FSC_NONE;
} }

View File

@ -6,23 +6,23 @@
#include "randomizerTypes.h" #include "randomizerTypes.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" #include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
typedef struct FishsanityPondOptions { typedef struct {
u8 mode; u8 mode;
u8 numFish; u8 numFish;
bool ageSplit; bool ageSplit;
} FishsanityPondOptions; } FishsanityPondOptions;
typedef enum FishsanityOptionsSource { typedef enum {
FSO_SOURCE_RANDO, FSO_SOURCE_RANDO,
FSO_SOURCE_CVARS FSO_SOURCE_CVARS
}; } FishsanityOptionsSource;
typedef enum FishsanityCheckType { typedef enum {
FSC_NONE, FSC_NONE,
FSC_POND, FSC_POND,
FSC_GROTTO, FSC_GROTTO,
FSC_ZD, FSC_ZD,
}; } FishsanityCheckType;
#ifdef __cplusplus #ifdef __cplusplus
namespace Rando { namespace Rando {