From 722306e606bb5eee0c0a4db17cfb387d6ed0c02d Mon Sep 17 00:00:00 2001 From: Eblo <7004497+Eblo@users.noreply.github.com> Date: Sun, 4 Jan 2026 08:52:18 -0500 Subject: Exclude Triforce from plentiful items, add error handling (#1433) * Exclude Triforce from plentiful, add error handling * Add max check because unsigned --- mm/2s2h/Rando/MiscBehavior/OnFileCreate.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mm/2s2h/Rando/MiscBehavior/OnFileCreate.cpp b/mm/2s2h/Rando/MiscBehavior/OnFileCreate.cpp index 6edec7fb1..3114798e9 100644 --- a/mm/2s2h/Rando/MiscBehavior/OnFileCreate.cpp +++ b/mm/2s2h/Rando/MiscBehavior/OnFileCreate.cpp @@ -280,6 +280,11 @@ void Rando::MiscBehavior::OnFileCreate(s16 fileNum) { std::vector plentifulItems; std::vector potentialPlentifulItems; for (size_t i = 0; i < itemPool.size(); i++) { + // The user can specify exactly how many pieces they want to shuffle, so skip those + if (Rando::StaticData::Items[itemPool[i]].randoItemId == RI_TRIFORCE_PIECE) { + continue; + } + switch (Rando::StaticData::Items[itemPool[i]].randoItemType) { case RITYPE_BOSS_KEY: case RITYPE_SMALL_KEY: @@ -409,6 +414,17 @@ void Rando::MiscBehavior::OnFileCreate(s16 fileNum) { RANDO_SAVE_OPTIONS[RO_TRIFORCE_PIECES_MAX] = piecesShuffled; RANDO_SAVE_OPTIONS[RO_TRIFORCE_PIECES_REQUIRED] = (piecesShuffled * currentRatio) + 1; } + + if (RANDO_SAVE_OPTIONS[RO_TRIFORCE_PIECES_MAX] < 1 || + RANDO_SAVE_OPTIONS[RO_TRIFORCE_PIECES_MAX] > 1000 || + RANDO_SAVE_OPTIONS[RO_TRIFORCE_PIECES_REQUIRED] < 1 || + RANDO_SAVE_OPTIONS[RO_TRIFORCE_PIECES_REQUIRED] > 1000) { + SPDLOG_ERROR("Error with adjusting Triforce Piece placement. Resulting shuffle requires {} " + "pieces and out of a total of {}", + RANDO_SAVE_OPTIONS[RO_TRIFORCE_PIECES_REQUIRED], + RANDO_SAVE_OPTIONS[RO_TRIFORCE_PIECES_MAX]); + throw std::runtime_error("Invalid Triforce Piece count"); + } } // Grant the starting items -- cgit v1.2.3