Skip to content

Commit

Permalink
EngineSettings: Add validation to XP table thresholds
Browse files Browse the repository at this point in the history
This checks to see if a given XP threshold is less than any previous
levels. If it is, the threshold is set to the highest value plus one.
  • Loading branch information
dorkster committed Jan 12, 2025
1 parent d1a3739 commit 448cc01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Engine fixes:
* The text for dialog options now respects the 'font_dialog' property in menus/talker.txt.
* Fixed books not closing properly when trying to load another book with an invalid filename.
* Fixed combat text being shown for zero damage reflect.
* Added validation to player XP table parsing to ensure that XP thresholds are not less than those for previous levels.
* Android: Fix 'Flare' directory not being automatically created.
* Android: Added a dialog to direct the player to the wiki page for installing if no game data is found.

Expand Down
17 changes: 17 additions & 0 deletions src/EngineSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,11 +1081,28 @@ void EngineSettings::XPTable::load() {
xp_table.resize(lvl_id);

xp_table[lvl_id - 1] = lvl_xp;

// validate that XP is greater than previous levels
// corrections are done after then entire table is loaded
for (size_t i = 0; i < lvl_id - 1; ++i) {
if (xp_table[lvl_id - 1] <= xp_table[i]) {
infile.error("EngineSettings: XP for level %u is less than previous levels.", lvl_id);
break;
}
}
}
}
infile.close();
}

// set invalid XP thresolds to valid values
for (size_t i = 1; i < xp_table.size(); ++i) {
if (xp_table[i] <= xp_table[i-1]) {
xp_table[i] = xp_table[i-1] + 1;
Utils::logInfo("EngineSettings: Setting XP for level %u to %lu.", i+1, xp_table[i]);
}
}

if (xp_table.empty()) {
Utils::logError("EngineSettings: No XP table defined.");
xp_table.push_back(0);
Expand Down
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/

#include <SDL.h>

Version VersionInfo::ENGINE(1, 14, 90);
Version VersionInfo::ENGINE(1, 14, 91);
Version VersionInfo::MIN(0, 0, 0);
Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);

Expand Down

0 comments on commit 448cc01

Please sign in to comment.