diff options
| author | Philip Dubé <159546+serprex@users.noreply.github.com> | 2026-08-30 01:32:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-30 01:32:33 +0000 |
| commit | a5a18261850afe1a8a3fdb94f71be46bcc546bba (patch) | |
| tree | 15f6fe27c69684ba6f90d3ca2113cf539c023f41 | |
| parent | bb6d1d3b4bef74a94248f7364b6d3fa25287d454 (diff) | |
Fix check tracker chest game key logic (#7133)
| -rw-r--r-- | soh/soh/Enhancements/randomizer/dungeon.cpp | 41 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/dungeon.h | 7 |
2 files changed, 25 insertions, 23 deletions
diff --git a/soh/soh/Enhancements/randomizer/dungeon.cpp b/soh/soh/Enhancements/randomizer/dungeon.cpp index 49ca37ce7..e0fb53132 100644 --- a/soh/soh/Enhancements/randomizer/dungeon.cpp +++ b/soh/soh/Enhancements/randomizer/dungeon.cpp @@ -107,11 +107,7 @@ RandomizerSettingKey DungeonInfo::GetMQSetting() const { return mqSetting; } -int8_t FindUsedSmallKeys(const SaveContext* saveContext, const SceneID scene, const std::vector<uint8_t>* DoorFlags) { - if (DoorFlags == nullptr) { - return 0; - } - +int8_t FindUsedSmallKeys(const SaveContext* saveContext, const SceneID scene, std::span<const uint8_t> doorFlags) { // Get the swch value for the scene uint32_t swch; if (gPlayState != nullptr && gPlayState->sceneNum == scene) { @@ -122,7 +118,7 @@ int8_t FindUsedSmallKeys(const SaveContext* saveContext, const SceneID scene, co // Count the number of small keys doors unlocked int8_t unlockedSmallKeyDoors = 0; - for (auto& smallKeyDoor : *DoorFlags) { + for (const uint8_t smallKeyDoor : doorFlags) { unlockedSmallKeyDoors += swch >> smallKeyDoor & 1; } return unlockedSmallKeyDoors; @@ -137,27 +133,31 @@ int8_t FindCurrentSmallKeys(const SaveContext* saveContext, const SceneID scene) return dungeonKeys; } -int8_t FindTotalSmallKeys(const SaveContext* saveContext, const SceneID scene, const std::vector<uint8_t>* DoorFlags) { - return FindCurrentSmallKeys(saveContext, scene) + FindUsedSmallKeys(saveContext, scene, DoorFlags); +int8_t FindTotalSmallKeys(const SaveContext* saveContext, const SceneID scene, std::span<const uint8_t> doorFlags) { + return FindCurrentSmallKeys(saveContext, scene) + FindUsedSmallKeys(saveContext, scene, doorFlags); } -// Thieves' Hideout isn't a dungeon, and how many of its doors are locked depends on the carpenter setting. -static std::vector<uint8_t> ThievesHideoutDoorFlags() { +// Thieves' Hideout isn't a dungeon, and how many of its doors are locked depends on the carpenter setting +static std::span<const uint8_t> ThievesHideoutDoorFlags() { + static constexpr std::array<uint8_t, 4> doorFlags = { 1, 2, 3, 4 }; if (RAND_GET_OPTION(RSK_GERUDO_FORTRESS).Is(RO_GF_CARPENTERS_FAST)) { - return { 1 }; + return std::span(doorFlags).first(1); } if (RAND_GET_OPTION(RSK_GERUDO_FORTRESS).Is(RO_GF_CARPENTERS_FREE)) { return {}; } - return { 1, 2, 3, 4 }; + return doorFlags; } +// Chest game's locked doors without 0x20 after rando converts to perm flags +static constexpr std::array<uint8_t, 6> chestGameDoorFlags = { 0, 1, 2, 3, 4, 5 }; + uint8_t GetSceneSmallKeyMax(const SceneID scene) { if (scene == SCENE_THIEVES_HIDEOUT) { return static_cast<uint8_t>(ThievesHideoutDoorFlags().size()); } if (scene == SCENE_TREASURE_BOX_SHOP) { - return 6; + return static_cast<uint8_t>(chestGameDoorFlags.size()); } // ask which layout actually loads rather than what the seed asked for, so an MQ-only rom still lines up const DungeonInfo* dungeon = Context::GetInstance()->GetDungeons()->GetDungeonFromScene(scene); @@ -166,13 +166,14 @@ uint8_t GetSceneSmallKeyMax(const SceneID scene) { int8_t GetSceneTotalSmallKeys(const SaveContext* saveContext, const SceneID scene) { if (scene == SCENE_THIEVES_HIDEOUT) { - const std::vector<uint8_t> doorFlags = ThievesHideoutDoorFlags(); - return FindTotalSmallKeys(saveContext, scene, &doorFlags); + return FindTotalSmallKeys(saveContext, scene, ThievesHideoutDoorFlags()); + } + if (scene == SCENE_TREASURE_BOX_SHOP) { + return FindTotalSmallKeys(saveContext, scene, chestGameDoorFlags); } if (const DungeonInfo* dungeon = Context::GetInstance()->GetDungeons()->GetDungeonFromScene(scene)) { return FindTotalSmallKeys(saveContext, scene, dungeon->GetDoorFlags()); } - // the chest game keeps no door flags, so what you hold is all you ever got return FindCurrentSmallKeys(saveContext, scene); } @@ -188,15 +189,15 @@ int8_t DungeonInfo::GetTotalSmallKeys(SaveContext* saveContext) const { return FindTotalSmallKeys(saveContext, scene, GetDoorFlags()); } -const std::vector<uint8_t>* DungeonInfo::GetDoorFlags() const { +std::span<const uint8_t> DungeonInfo::GetDoorFlags() const { if (IsMQ()) { - return &MQDoorFlags; + return MQDoorFlags; } if (IS_RANDO) { // Specifically non-MQ Rando, to handle an edge case in water temple - return &randoDoorFlags; + return randoDoorFlags; } - return &vanillaDoorFlags; + return vanillaDoorFlags; } void DungeonInfo::SetDungeonKnown(bool known) { diff --git a/soh/soh/Enhancements/randomizer/dungeon.h b/soh/soh/Enhancements/randomizer/dungeon.h index 192b725b9..f956b7bfe 100644 --- a/soh/soh/Enhancements/randomizer/dungeon.h +++ b/soh/soh/Enhancements/randomizer/dungeon.h @@ -1,6 +1,7 @@ #pragma once #include <array> +#include <span> #include <vector> #include <string> #include "nlohmann/json.hpp" @@ -42,7 +43,7 @@ class DungeonInfo { int8_t GetCurrentSmallKeys(SaveContext* saveContext) const; int8_t GetTotalSmallKeys(SaveContext* saveContext) const; RandomizerSettingKey GetMQSetting() const; - const std::vector<uint8_t>* GetDoorFlags() const; + std::span<const uint8_t> GetDoorFlags() const; void SetDungeonKnown(bool known); void PlaceVanillaMap() const; void PlaceVanillaCompass() const; @@ -74,9 +75,9 @@ class DungeonInfo { std::vector<uint8_t> MQDoorFlags; }; -int8_t FindUsedSmallKeys(const SaveContext* saveContext, const SceneID scene, const std::vector<uint8_t>* DoorFlags); +int8_t FindUsedSmallKeys(const SaveContext* saveContext, const SceneID scene, std::span<const uint8_t> doorFlags); int8_t FindCurrentSmallKeys(const SaveContext* saveContext, const SceneID scene); -int8_t FindTotalSmallKeys(const SaveContext* saveContext, const SceneID scene, const std::vector<uint8_t>* DoorFlags); +int8_t FindTotalSmallKeys(const SaveContext* saveContext, const SceneID scene, std::span<const uint8_t> doorFlags); /// How many small keys the scene takes in total. Covers dungeons, Thieves' Hideout and the chest game. uint8_t GetSceneSmallKeyMax(SceneID scene); |
