From 00a862a252cb1c0e0cb3e37beec4f42010ff54a5 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Tue, 29 Nov 2022 22:43:05 -0500 Subject: [PATCH] use trial enum instead of magic numbers (#2039) * use trial enum instead of magic numbers * simplify trial count/random trial logic * set default to set number Co-authored-by: briaguya --- soh/soh/Enhancements/presets.h | 4 ++-- .../Enhancements/randomizer/3drando/settings.cpp | 4 ++-- soh/soh/Enhancements/randomizer/randomizer.cpp | 13 ++++--------- soh/soh/Enhancements/randomizer/randomizerTypes.h | 7 ++++++- soh/src/code/z_sram.c | 10 ++++------ 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/soh/soh/Enhancements/presets.h b/soh/soh/Enhancements/presets.h index 4c9897701..ba20cf5cd 100644 --- a/soh/soh/Enhancements/presets.h +++ b/soh/soh/Enhancements/presets.h @@ -555,7 +555,7 @@ const std::vector s6PresetEntries = { PRESET_ENTRY_S32("gRandomizeDoorOfTime", RO_DOOROFTIME_OPEN), PRESET_ENTRY_STRING("gRandomizeExcludedLocations", "48,"), PRESET_ENTRY_S32("gRandomizeForest", RO_FOREST_CLOSED_DEKU), - PRESET_ENTRY_S32("gRandomizeGanonTrial", 0), + PRESET_ENTRY_S32("gRandomizeGanonTrial", RO_GANONS_TRIALS_SKIP), PRESET_ENTRY_S32("gRandomizeGerudoFortress", RO_GF_FAST), PRESET_ENTRY_S32("gRandomizeIceTraps", RO_ICE_TRAPS_OFF), PRESET_ENTRY_S32("gRandomizeKakarikoGate", RO_KAK_GATE_OPEN), @@ -591,7 +591,7 @@ const std::vector hellModePresetEntries = { PRESET_ENTRY_S32("gRandomizeEnableBombchuDrops", 1), PRESET_ENTRY_S32("gRandomizeEnableGlitchCutscenes", 1), PRESET_ENTRY_S32("gRandomizeForest", RO_FOREST_OPEN), - PRESET_ENTRY_S32("gRandomizeGanonTrial", 2), + PRESET_ENTRY_S32("gRandomizeGanonTrial", RO_GANONS_TRIALS_SET_NUMBER), PRESET_ENTRY_S32("gRandomizeGanonTrialCount", 6), PRESET_ENTRY_S32("gRandomizeGerudoKeys", 3), PRESET_ENTRY_S32("gRandomizeGsExpectSunsSong", 1), diff --git a/soh/soh/Enhancements/randomizer/3drando/settings.cpp b/soh/soh/Enhancements/randomizer/3drando/settings.cpp index c4abd2266..e4bf7fa07 100644 --- a/soh/soh/Enhancements/randomizer/3drando/settings.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/settings.cpp @@ -2537,12 +2537,12 @@ namespace Settings { BridgeRewardCount.SetSelectedIndex(cvarSettings[RSK_RAINBOW_BRIDGE_REWARD_COUNT]); BridgeDungeonCount.SetSelectedIndex(cvarSettings[RSK_RAINBOW_BRIDGE_DUNGEON_COUNT]); BridgeTokenCount.SetSelectedIndex(cvarSettings[RSK_RAINBOW_BRIDGE_TOKEN_COUNT]); - if (cvarSettings[RSK_RANDOM_TRIALS] == 2) { + if (cvarSettings[RSK_GANONS_TRIALS] == RO_GANONS_TRIALS_RANDOM_NUMBER) { RandomGanonsTrials.SetSelectedIndex(1); } else { RandomGanonsTrials.SetSelectedIndex(0); } - if (cvarSettings[RSK_RANDOM_TRIALS] == 0) { + if (cvarSettings[RSK_GANONS_TRIALS] == RO_GANONS_TRIALS_SKIP) { GanonsTrialsCount.SetSelectedIndex(0); } else { GanonsTrialsCount.SetSelectedIndex(cvarSettings[RSK_TRIAL_COUNT]); diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 91ff2622a..0ef8bf345 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -194,8 +194,6 @@ std::unordered_map SpoilerfileSettingNameToEn { "Open Settings:Reward Count", RSK_RAINBOW_BRIDGE_REWARD_COUNT }, { "Open Settings:Dungeon Count", RSK_RAINBOW_BRIDGE_DUNGEON_COUNT }, { "Open Settings:Token Count", RSK_RAINBOW_BRIDGE_TOKEN_COUNT }, - { "Open Settings:Random Ganon's Trials", RSK_RANDOM_TRIALS }, - { "Open Settings:Trial Count", RSK_TRIAL_COUNT }, { "Shuffle Settings:Link's Pocket", RSK_LINKS_POCKET}, { "Shuffle Settings:Shuffle Gerudo Card", RSK_SHUFFLE_GERUDO_MEMBERSHIP_CARD }, { "Shuffle Settings:Shopsanity", RSK_SHOPSANITY }, @@ -669,7 +667,6 @@ void Randomizer::ParseRandomizerSettingsFile(const char* spoilerFileName) { case RSK_LACS_REWARD_COUNT: case RSK_LACS_DUNGEON_COUNT: case RSK_LACS_TOKEN_COUNT: - case RSK_TRIAL_COUNT: case RSK_BIG_POE_COUNT: case RSK_CUCCO_COUNT: case RSK_STARTING_SKULLTULA_TOKEN: @@ -708,7 +705,6 @@ void Randomizer::ParseRandomizerSettingsFile(const char* spoilerFileName) { case RSK_SHUFFLE_COWS: case RSK_SHUFFLE_ADULT_TRADE: case RSK_SHUFFLE_MAGIC_BEANS: - case RSK_RANDOM_TRIALS: case RSK_RANDOM_MQ_DUNGEONS: case RSK_STARTING_DEKU_SHIELD: case RSK_STARTING_KOKIRI_SWORD: @@ -2578,7 +2574,7 @@ void GenerateRandomizerImgui() { cvarSettings[RSK_RAINBOW_BRIDGE_REWARD_COUNT] = CVar_GetS32("gRandomizeRewardCount", 9); cvarSettings[RSK_RAINBOW_BRIDGE_DUNGEON_COUNT] = CVar_GetS32("gRandomizeDungeonCount", 8); cvarSettings[RSK_RAINBOW_BRIDGE_TOKEN_COUNT] = CVar_GetS32("gRandomizeTokenCount", 100); - cvarSettings[RSK_RANDOM_TRIALS] = CVar_GetS32("gRandomizeGanonTrial", 0); + cvarSettings[RSK_GANONS_TRIALS] = CVar_GetS32("gRandomizeGanonTrial", RO_GANONS_TRIALS_SET_NUMBER); cvarSettings[RSK_TRIAL_COUNT] = CVar_GetS32("gRandomizeGanonTrialCount", 6); cvarSettings[RSK_STARTING_OCARINA] = CVar_GetS32("gRandomizeStartingOcarina", 0); cvarSettings[RSK_SHUFFLE_OCARINA] = CVar_GetS32("gRandomizeShuffleOcarinas", 0) || @@ -3011,13 +3007,12 @@ void DrawRandoEditor(bool& open) { "\n" "Random Number - A Random number and set of trials will be required." ); - UIWidgets::EnhancementCombobox("gRandomizeGanonTrial", randoGanonsTrial, 3, CVar_GetS32("gRandomizeGanonTrial", 0)); + UIWidgets::EnhancementCombobox("gRandomizeGanonTrial", randoGanonsTrial, 3, RO_GANONS_TRIALS_SET_NUMBER); ImGui::PopItemWidth(); - if (CVar_GetS32("gRandomizeGanonTrial", 0) == 1) { + if (CVar_GetS32("gRandomizeGanonTrial", RO_GANONS_TRIALS_SET_NUMBER) == RO_GANONS_TRIALS_SET_NUMBER) { ImGui::Dummy(ImVec2(0.0f, 0.0f)); UIWidgets::EnhancementSliderInt("Ganon's Trial Count: %d", "##RandoTrialCount", - "gRandomizeGanonTrialCount", 1, 6, "", - CVar_GetS32("gRandomizeGanonTrialCount", 6), true); + "gRandomizeGanonTrialCount", 1, 6, "", 6, true); UIWidgets::InsertHelpHoverText("Set the number of trials required to enter Ganon's Tower."); } diff --git a/soh/soh/Enhancements/randomizer/randomizerTypes.h b/soh/soh/Enhancements/randomizer/randomizerTypes.h index f079a4f8c..35f4c89cb 100644 --- a/soh/soh/Enhancements/randomizer/randomizerTypes.h +++ b/soh/soh/Enhancements/randomizer/randomizerTypes.h @@ -987,7 +987,7 @@ typedef enum { RSK_RAINBOW_BRIDGE_REWARD_COUNT, RSK_RAINBOW_BRIDGE_DUNGEON_COUNT, RSK_RAINBOW_BRIDGE_TOKEN_COUNT, - RSK_RANDOM_TRIALS, + RSK_GANONS_TRIALS, RSK_TRIAL_COUNT, RSK_STARTING_OCARINA, RSK_SHUFFLE_OCARINA, @@ -1174,6 +1174,11 @@ typedef enum RandoOption { RO_GANON_BOSS_KEY_LACS_DUNGEONS, RO_GANON_BOSS_KEY_LACS_TOKENS, + //Ganon's Trials + RO_GANONS_TRIALS_SKIP = 0, + RO_GANONS_TRIALS_SET_NUMBER, + RO_GANONS_TRIALS_RANDOM_NUMBER, + //Shuffle Dungeon Entrance Settings (Off, on, plus ganon) RO_DUNGEON_ENTRANCE_SHUFFLE_OFF = 0, RO_DUNGEON_ENTRANCE_SHUFFLE_ON, diff --git a/soh/src/code/z_sram.c b/soh/src/code/z_sram.c index 5fb913083..7d9d85b68 100644 --- a/soh/src/code/z_sram.c +++ b/soh/src/code/z_sram.c @@ -324,12 +324,10 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx) { gSaveContext.randomizerInf[i] = 0; } - // Set all trials to cleared if trial count is random or anything other than 6 - if (Randomizer_GetSettingValue(RSK_RANDOM_TRIALS) || (Randomizer_GetSettingValue(RSK_TRIAL_COUNT) != 6)) { - for (u16 i = RAND_INF_TRIALS_DONE_LIGHT_TRIAL; i <= RAND_INF_TRIALS_DONE_SHADOW_TRIAL; i++) { - if (!Randomizer_IsTrialRequired(i)) { - Flags_SetRandomizerInf(i); - } + // If any trials aren't required, set them as completed + for (u16 i = RAND_INF_TRIALS_DONE_LIGHT_TRIAL; i <= RAND_INF_TRIALS_DONE_SHADOW_TRIAL; i++) { + if (!Randomizer_IsTrialRequired(i)) { + Flags_SetRandomizerInf(i); } }