From 2050173666cd2935899d964b17edbb3c9d6c9db8 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 3 Jan 2024 00:29:35 -0800 Subject: [PATCH] fix incorrect ItemPT meseta ranges giving 65535 meseta --- src/ItemCreator.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ItemCreator.cc b/src/ItemCreator.cc index e6f3374b..cb4ca576 100644 --- a/src/ItemCreator.cc +++ b/src/ItemCreator.cc @@ -285,16 +285,17 @@ uint32_t ItemCreator::choose_meseta_amount( uint16_t min = ranges[table_index].min; uint16_t max = ranges[table_index].max; - // Note: The original code seems like it has a bug here: it compares to 0xFF - // instead of 0xFFFF (and returns 0xFF if either limit matches 0xFF). - uint32_t ret = 0; - if (((min == 0xFFFF) || (max == 0xFFFF)) || (max < min)) { - ret = 0xFFFF; - } else if (min != max) { - ret = this->rand_int((max - min) + 1) + min; - } else { + // Note: The original code returns 0xFF here if either limit is equal to 0xFF + // (despite them being 16-bit integers!) + uint16_t ret; + if (min == max) { ret = min; + } else if (max < min) { + ret = this->rand_int((min - max) + 1) + max; + } else { + ret = this->rand_int((max - min) + 1) + min; } + this->log.info("Chose %" PRIu32 " Meseta from range [%hu, %hu]", ret, min, max); return ret; }