From 462ab00c7e9856c3a8a7da0d808ca5654af3320a Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Tue, 14 Feb 2023 19:50:59 -0600 Subject: [PATCH] Save skipped checks (#2476) --- soh/include/z64save.h | 1 + .../randomizer/randomizer_check_tracker.cpp | 14 ++++++++++---- soh/soh/SaveManager.cpp | 9 +++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/soh/include/z64save.h b/soh/include/z64save.h index 7d409485c..5e78c332a 100644 --- a/soh/include/z64save.h +++ b/soh/include/z64save.h @@ -64,6 +64,7 @@ typedef struct { /* */ u32 count[COUNT_MAX]; /* */ u32 entrancesDiscovered[SAVEFILE_ENTRANCES_DISCOVERED_IDX_COUNT]; /* */ u32 scenesDiscovered[SAVEFILE_SCENES_DISCOVERED_IDX_COUNT]; + /* */ u8 locationsSkipped[RC_MAX]; } SohStats; typedef struct { diff --git a/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp index 7cd74c4d1..9788b3446 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_check_tracker.cpp @@ -31,6 +31,7 @@ void UpdateOrdering(bool init = false); bool ShouldUpdateChecks(); bool CompareCheckObject(RandomizerCheckObject i, RandomizerCheckObject j); bool HasItemBeenCollected(RandomizerCheckObject obj); +bool HasItemBeenSkipped(RandomizerCheckObject obj); void RainbowTick(); RandomizerCheckShow GetCheckStatus(RandomizerCheckObject rcObj, int idx); @@ -700,8 +701,7 @@ RandomizerCheckShow GetCheckStatus(RandomizerCheckObject rcObj, int idx) { if (HasItemBeenCollected(rcObj)) return RCSHOW_SAVED; // TODO: use SAVED until we hook into game elements without requiring a save. Then we'll use CHECKED - //If the status hasn't updated, keep showing as skipped - if (checkStatusMap.find(rcObj.rc)->second == RCSHOW_SKIPPED) + if (HasItemBeenSkipped(rcObj)) return RCSHOW_SKIPPED; return RCSHOW_UNCHECKED; @@ -709,6 +709,9 @@ RandomizerCheckShow GetCheckStatus(RandomizerCheckObject rcObj, int idx) { // TODO Seen, Hinted, Scummed, saved/checked } +bool HasItemBeenSkipped(RandomizerCheckObject obj) { + return gSaveContext.sohStats.locationsSkipped[obj.rc] == 1; +} bool HasItemBeenCollected(RandomizerCheckObject obj) { ItemLocation* x = Location(obj.rc); @@ -816,10 +819,13 @@ void DrawLocation(RandomizerCheckObject rcObj, RandomizerCheckShow* thisCheckSta if (*thisCheckStatus == RCSHOW_UNCHECKED || *thisCheckStatus == RCSHOW_SKIPPED) { bool skipped = (*thisCheckStatus == RCSHOW_SKIPPED); if (ImGui::ArrowButton(std::to_string(rcObj.rc).c_str(), skipped ? ImGuiDir_Left : ImGuiDir_Right)) { - if (skipped) + if (skipped) { + gSaveContext.sohStats.locationsSkipped[rcObj.rc] = 0; *thisCheckStatus = RCSHOW_UNCHECKED; - else + } else { + gSaveContext.sohStats.locationsSkipped[rcObj.rc] = 1; *thisCheckStatus = RCSHOW_SKIPPED; + } } } else { ImGui::InvisibleButton("", ImVec2(20.0f, 10.0f)); diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index b2e2905ed..611abb667 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -483,6 +483,9 @@ void SaveManager::InitFileNormal() { for (int entrancesIdx = 0; entrancesIdx < ARRAY_COUNT(gSaveContext.sohStats.entrancesDiscovered); entrancesIdx++) { gSaveContext.sohStats.entrancesDiscovered[entrancesIdx] = 0; } + for (int rc = 0; rc < ARRAY_COUNT(gSaveContext.sohStats.locationsSkipped); rc++) { + gSaveContext.sohStats.locationsSkipped[rc] = 0; + } for (int scene = 0; scene < ARRAY_COUNT(gSaveContext.sceneFlags); scene++) { gSaveContext.sceneFlags[scene].chest = 0; gSaveContext.sceneFlags[scene].swch = 0; @@ -1255,6 +1258,9 @@ void SaveManager::LoadBaseVersion3() { SaveManager::Instance->LoadArray("entrancesDiscovered", ARRAY_COUNT(gSaveContext.sohStats.entrancesDiscovered), [](size_t i) { SaveManager::Instance->LoadData("", gSaveContext.sohStats.entrancesDiscovered[i]); }); + SaveManager::Instance->LoadArray("locationsSkipped", ARRAY_COUNT(gSaveContext.sohStats.locationsSkipped), [](size_t i) { + SaveManager::Instance->LoadData("", gSaveContext.sohStats.locationsSkipped[i]); + }); }); SaveManager::Instance->LoadArray("sceneFlags", ARRAY_COUNT(gSaveContext.sceneFlags), [](size_t i) { SaveManager::Instance->LoadStruct("", [&i]() { @@ -1445,6 +1451,9 @@ void SaveManager::SaveBase() { SaveManager::Instance->SaveArray("entrancesDiscovered", ARRAY_COUNT(gSaveContext.sohStats.entrancesDiscovered), [](size_t i) { SaveManager::Instance->SaveData("", gSaveContext.sohStats.entrancesDiscovered[i]); }); + SaveManager::Instance->SaveArray("locationsSkipped", ARRAY_COUNT(gSaveContext.sohStats.locationsSkipped), [](size_t i) { + SaveManager::Instance->SaveData("", gSaveContext.sohStats.locationsSkipped[i]); + }); }); SaveManager::Instance->SaveArray("sceneFlags", ARRAY_COUNT(gSaveContext.sceneFlags), [](size_t i) { SaveManager::Instance->SaveStruct("", [&i]() {