From 93a145608e174e2b4c0dcba3c506cd3e7333e709 Mon Sep 17 00:00:00 2001 From: Eric Robinson <68359262+kphoenix137@users.noreply.github.com> Date: Mon, 30 Jan 2023 13:14:37 -0500 Subject: [PATCH] Optimize AddPlrExperience() (#5737) --- Source/player.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/player.cpp b/Source/player.cpp index 2f4eb301a..598364961 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -2686,6 +2686,12 @@ void AddPlrExperience(Player &player, int lvl, int exp) return; } + // exit function early if player is unable to gain more experience by checking final index of ExpLvlsTbl + int expLvlsTblSize = sizeof(ExpLvlsTbl) / sizeof(ExpLvlsTbl[0]); + if (player._pExperience >= ExpLvlsTbl[expLvlsTblSize - 1]) { + return; + } + if (player._pHitPoints <= 0) { return; } @@ -2711,8 +2717,10 @@ void AddPlrExperience(Player &player, int lvl, int exp) RedrawEverything(); } - if (player._pExperience >= ExpLvlsTbl[49]) { - player._pLevel = 50; + /* set player level to MaxCharacterLevel if the experience value for MaxCharacterLevel is reached, which exits the function early + and does not call NextPlrLevel(), which is responsible for giving Attribute points and Life/Mana on level up */ + if (player._pExperience >= ExpLvlsTbl[MaxCharacterLevel - 1]) { + player._pLevel = MaxCharacterLevel; return; }