From b10c580d6f4518deebc1759e34e2e9b949bb5517 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sun, 14 Aug 2022 18:46:02 +0300 Subject: [PATCH] Fix displaying xp gained with Swift Learner bonus --- src/combat.cc | 6 ++++-- src/inventory.cc | 8 +++++--- src/stat.cc | 12 +++++++++--- src/stat.h | 4 ++-- src/world_map.cc | 14 +++++++------- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/combat.cc b/src/combat.cc index cc72f77..0f3599c 100644 --- a/src/combat.cc +++ b/src/combat.cc @@ -2822,7 +2822,9 @@ void _combat_give_exps(int exp_points) return; } - pcAddExperience(exp_points); + // SFALL: Display actual xp received. + int xpGained; + pcAddExperience(exp_points, &xpGained); v7.num = 621; // %s you earn %d exp. points. if (!messageListGetItem(&gProtoMessageList, &v7)) { @@ -2841,7 +2843,7 @@ void _combat_give_exps(int exp_points) return; } - sprintf(text, v7.text, v9.text, exp_points); + sprintf(text, v7.text, v9.text, xpGained); displayMonitorAddMessage(text); } diff --git a/src/inventory.cc b/src/inventory.cc index b9ffe05..bd1891d 100644 --- a/src/inventory.cc +++ b/src/inventory.cc @@ -3901,15 +3901,17 @@ int inventoryOpenLooting(Object* a1, Object* a2) stealingXp = std::min(300 - skillGetValue(a1, SKILL_STEAL), stealingXp); debugPrint("\n[[[%d]]]", 300 - skillGetValue(a1, SKILL_STEAL)); + // SFALL: Display actual xp received. + int xpGained; + pcAddExperience(stealingXp, &xpGained); + // You gain %d experience points for successfully using your Steal skill. messageListItem.num = 29; if (messageListGetItem(&gInventoryMessageList, &messageListItem)) { char formattedText[200]; - sprintf(formattedText, messageListItem.text, stealingXp); + sprintf(formattedText, messageListItem.text, xpGained); displayMonitorAddMessage(formattedText); } - - pcAddExperience(stealingXp); } } } diff --git a/src/stat.cc b/src/stat.cc index 2be253a..9f33b44 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -717,14 +717,16 @@ int statRoll(Object* critter, int stat, int modifier, int* howMuch) } // 0x4AFAA8 -int pcAddExperience(int xp) +int pcAddExperience(int xp, int* xpGained) { - return pcAddExperienceWithOptions(xp, true); + return pcAddExperienceWithOptions(xp, true, xpGained); } // 0x4AFAB8 -int pcAddExperienceWithOptions(int xp, bool a2) +int pcAddExperienceWithOptions(int xp, bool a2, int* xpGained) { + int oldXp = gPcStatValues[PC_STAT_EXPERIENCE]; + int newXp = gPcStatValues[PC_STAT_EXPERIENCE]; newXp += xp; newXp += perkGetRank(gDude, PERK_SWIFT_LEARNER) * 5 * xp / 100; @@ -784,6 +786,10 @@ int pcAddExperienceWithOptions(int xp, bool a2) } } + if (xpGained != NULL) { + *xpGained = newXp - oldXp; + } + return 0; } diff --git a/src/stat.h b/src/stat.h index d5132b9..afe5444 100644 --- a/src/stat.h +++ b/src/stat.h @@ -35,8 +35,8 @@ char* pcStatGetName(int pcStat); char* pcStatGetDescription(int pcStat); int statGetFrmId(int stat); int statRoll(Object* critter, int stat, int modifier, int* howMuch); -int pcAddExperience(int xp); -int pcAddExperienceWithOptions(int xp, bool a2); +int pcAddExperience(int xp, int* xpGained = NULL); +int pcAddExperienceWithOptions(int xp, bool a2, int* xpGained = NULL); int pcSetExperience(int a1); static inline bool statIsValid(int stat) diff --git a/src/world_map.cc b/src/world_map.cc index 21e1d3a..e33bbe8 100644 --- a/src/world_map.cc +++ b/src/world_map.cc @@ -3678,21 +3678,21 @@ int _wmRndEncounterOccurred() int xp = 100 - outdoorsman; if (xp > 0) { + // SFALL: Display actual xp received. + debugPrint("WorldMap: Giving Player [%d] Experience For Catching Rnd Encounter!", xp); + + int xpGained; + pcAddExperience(xp, &xpGained); + MessageListItem messageListItem; char* text = getmsg(&gMiscMessageList, &messageListItem, 8500); if (strlen(text) < 110) { char formattedText[120]; - sprintf(formattedText, text, xp); + sprintf(formattedText, text, xpGained); displayMonitorAddMessage(formattedText); } else { debugPrint("WorldMap: Error: Rnd Encounter string too long!"); } - - debugPrint("WorldMap: Giving Player [%d] Experience For Catching Rnd Encounter!", xp); - - if (xp < 100) { - pcAddExperience(xp); - } } } } else {