From 299e1873801c62b7cfc3a317f3f0c3fb15aa3fd1 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 28 Jul 2024 19:41:31 -0700 Subject: [PATCH] fix edge cases in drop table area computation --- src/ItemCreator.cc | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/ItemCreator.cc b/src/ItemCreator.cc index c42fc894..27e05d71 100644 --- a/src/ItemCreator.cc +++ b/src/ItemCreator.cc @@ -85,27 +85,33 @@ bool ItemCreator::are_rare_drops_allowed() const { } uint8_t ItemCreator::normalize_area_number(uint8_t area) const { - if (!this->restrictions || (this->restrictions->box_drop_area == 0) || (area < 0x10) || (area > 0x11)) { + if (this->restrictions && (this->restrictions->box_drop_area != 0)) { + return this->restrictions->box_drop_area - 1; + } else { switch (this->episode) { case Episode::EP1: - if (area >= 0x0F) { + if (area >= 0x11) { throw runtime_error("invalid Episode 1 area number"); } switch (area) { - case 11: - return 2; // Dragon -> Cave 1 - case 12: - return 5; // De Rol Le -> Mine 1 - case 13: - return 7; // Vol Opt -> Ruins 1 - case 14: - return 9; // Dark Falz -> Ruins 3 + case 0x0B: // Dragon -> Cave 1 + return 2; + case 0x0C: // De Rol Le -> Mine 1 + return 5; + case 0x0D: // Vol Opt -> Ruins 1 + return 7; + case 0x0E: // Dark Falz -> Ruins 3 + case 0x10: // Palace -> Ruins 3 + case 0x11: // Spaceship -> Ruins 3 + return 9; + case 0x0F: // Lobby + throw runtime_error("visual lobby does not have item drop tables"); default: return area - 1; } throw logic_error("this should be impossible"); case Episode::EP2: { - static const vector area_subs = { + static const array area_subs = { 0x00, // 13 (VR Temple Alpha) 0x01, // 14 (VR Temple Beta) 0x02, // 15 (VR Spaceship Alpha) @@ -127,7 +133,7 @@ uint8_t ItemCreator::normalize_area_number(uint8_t area) const { if ((area >= 0x13) && (area < 0x24)) { return area_subs.at(area - 0x13); } - return area - 1; + throw runtime_error("invalid Episode 2 area number"); } case Episode::EP4: if (area >= 0x24 && area < 0x2D) { @@ -137,9 +143,6 @@ uint8_t ItemCreator::normalize_area_number(uint8_t area) const { default: throw logic_error("invalid episode number"); } - - } else { - return this->restrictions->box_drop_area - 1; } }