Author Topic: Parsing soldier stats from .sav  (Read 244 times)

Offline rkagerer

  • Sergeant
  • **
  • Posts: 11
    • View Profile
Parsing soldier stats from .sav
« on: April 12, 2024, 12:30:42 am »
Hi there,

I'm making a spreadsheet that uses VBA scripting to locate my latest X-Com Files savegame, and pull in solider names and stats.  I've got it parsing out soliders from various bases, mostly fed from the soldierStats sections of the yaml file.

Unfortunately I just realized what's listed in the .sav doesn't match what's shown in-game on the agent info screen.  I'm guessing there are some bonuses or something that apply on top, possibly from the commendations history or elsewhere in the savegame's records for a particular solder.

Could you help point me to the correct way to calculate the stats, so that my import algorithm will match what's displayed in-game?

Thanks!

Offline psavola

  • Commander
  • *****
  • Posts: 640
    • View Profile
Re: Parsing soldier stats from .sav
« Reply #1 on: April 12, 2024, 07:34:32 am »
The function prepareStatsWithBonuses() with all the things it calls might be want you essentially are looking to duplicate. Not sure if you really want it all.

https://github.com/MeridianOXC/OpenXcom/blob/oxce-plus/src/Savegame/Soldier.cpp#L2045

Offline rkagerer

  • Sergeant
  • **
  • Posts: 11
    • View Profile
Re: Parsing soldier stats from .sav
« Reply #2 on: April 12, 2024, 07:48:53 am »
Thanks for that link, it's very helpful!

Looks like I'll have to parse through mod rules and each soldier's diary of commendations - youch.
Any further hints on where the relevant data is stored (in the filesystem) which ties each commendation to it's quantitative stat?  (Trying to glean it out of the code but tough to fill in all the blanks without the convenience breakpoints / inspection).

Offline rkagerer

  • Sergeant
  • **
  • Posts: 11
    • View Profile
Re: Parsing soldier stats from .sav
« Reply #3 on: April 14, 2024, 11:36:44 pm »
I think I've mostly figured it out.  One that's still causing me a minor headache is the Weapon Master bonus aka STR_MEDAL_WEAPON_PROFICIENCY_NAME.

In the commendations diary of my save file it appears twice, once for each gun:

Code: [Select]
            - {commendationName: STR_MEDAL_WEAPON_PROFICIENCY_NAME, noun: STR_BLACKOPS_MAGNUM, decorationLevel: 0}
            ...
            - {commendationName: STR_MEDAL_WEAPON_PROFICIENCY_NAME, noun: STR_NITRO_EXPRESS, decorationLevel: 0}

But I gather the bonus (+1 throwing) is not in fact added twice.  How does the game compute the bonus to apply?  Does it pick the entry with the highest decorationLevel and ignore the others?

Would the same logic apply to STR_MEDAL_RACE_KILLS_NAME and any other case where there are multiple entries with the same commendationName but differing nouns?

In case it helps, the relevant section in commendations_XCOMFILES.rul is:

Code: [Select]
  - type: STR_MEDAL_WEAPON_PROFICIENCY_NAME #KOs by weapon
    description: STR_MEDAL_WEAPON_PROFICIENCY_UFOPEDIA
    soldierBonusTypes: [STR_MEDAL_WEAPON_PROFICIENCY_1, STR_MEDAL_WEAPON_PROFICIENCY_2, STR_MEDAL_WEAPON_PROFICIENCY_3, STR_MEDAL_WEAPON_PROFICIENCY_4, STR_MEDAL_WEAPON_PROFICIENCY_5, STR_MEDAL_WEAPON_PROFICIENCY_6, STR_MEDAL_WEAPON_PROFICIENCY_7, STR_MEDAL_WEAPON_PROFICIENCY_8, STR_MEDAL_WEAPON_PROFICIENCY_9, STR_MEDAL_WEAPON_PROFICIENCY_10]
    sprite: 2
    criteria:
      totalKillsWithAWeapon: [15, 25, 40, 60, 80, 100, 150, 200, 350, 500]

and in soldierBonuses_XCOMFILES.rul:

Code: [Select]
  - name: STR_MEDAL_WEAPON_PROFICIENCY_1
    stats:
      throwing: 1
  - name: STR_MEDAL_WEAPON_PROFICIENCY_2
    stats:
      throwing: 1
      melee: 1
    ...

Offline Juku121

  • Commander
  • *****
  • Posts: 1650
  • We're all mad here.
    • View Profile
Re: Parsing soldier stats from .sav
« Reply #4 on: April 14, 2024, 11:47:51 pm »
But I gather the bonus (+1 throwing) is not in fact added twice.  How does the game compute the bonus to apply?  Does it pick the entry with the highest decorationLevel and ignore the others?
What it does is it gives the bonus associated with the commendation and level. And bonuses do not stack and are shared between all 'Master of' commendations.

Would the same logic apply to STR_MEDAL_RACE_KILLS_NAME and any other case where there are multiple entries with the same commendationName but differing nouns?
'Bane of' is the same, yes. I don't think there's any other commendation that automagically multiplies itself across some parameter (weapon/enemy).

Offline rkagerer

  • Sergeant
  • **
  • Posts: 11
    • View Profile
Re: Parsing soldier stats from .sav
« Reply #5 on: April 15, 2024, 02:08:09 am »
Thanks for responding so quickly.

I've investigated some more and can say with confidence the behavior I'm seeing is:
  • Commendations with the same name and decoration level do not stack.
  • Commendations with the same name but different decoration levels do stack.
Or put another way, you can gain some extra bonus stats by purposely mastering different weapons to different thresholds.  This seems a bit odd / unintuitive and I'm not sure it's by design.

Once I accounted for this I got perfect results out of my SAV-to-Excel soldier stat extraction script.  Across all 47 of my soldiers of varying length of service and experience.  Tested on OpenXcom Extended 7.11 with the X-Com Files mod.  I'll throw some screenshots in the next comment.

After the fact I found some more information here which might shed some light if anyone stumbles across this thread in the future:
https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)
https://openxcom.org/forum/index.php?topic=7405.0

EDIT: I believe this is because the X-Come Files rules file maps different decoration levels for commendations to distinct soldierBonuses entries in soldierBonuses_XCOMFILES.rul.
« Last Edit: April 15, 2024, 03:52:38 am by rkagerer »

Offline rkagerer

  • Sergeant
  • **
  • Posts: 11
    • View Profile
Re: Parsing soldier stats from .sav
« Reply #6 on: April 15, 2024, 02:12:46 am »
Screenshots as promised.






Offline Juku121

  • Commander
  • *****
  • Posts: 1650
  • We're all mad here.
    • View Profile
Re: Parsing soldier stats from .sav
« Reply #7 on: April 15, 2024, 09:23:45 am »
I've investigated some more and can say with confidence the behavior I'm seeing is:
  • Commendations with the same name and decoration level do not stack.
  • Commendations with the same name but different decoration levels do stack.
That's exactly because of what I said: it's not the commendations that matter, it's the associated bonuses. Identical bonuses do not stack, and bonuses are shared between all 'Master of' and 'Bane of' type commendations.

This seems a bit odd / unintuitive and I'm not sure it's by design.
It's odd, but by design, since all possible alternatives were deemed worse.

I believe this is because the X-Come Files rules file maps different decoration levels for commendations to distinct soldierBonuses entries in soldierBonuses_XCOMFILES.rul.
That's not unique to these commendations, that's how pretty much every commendation with a stat boost I've seen works. What's unique in this case is the existence of multiple commendations mapping to the same set of bonuses.