Bug in calculating total hitpoints from CON bonus for critters...

Discussion in 'General Modification' started by Drifter, Jun 13, 2005.

Remove all ads!
  1. Drifter

    Drifter Established Member

    Joined:
    Dec 24, 2004
    Messages:
    118
    Likes Received:
    1
    Bugfix: calculation of total hitpoints from CON bonus for critters...

    ... and a bunch of observations on the whole HPs matter (nothing earthshaking, everything was already told before on various occasions, but as such info isn't collected into one help thread, and not everyone knows these things still, no harm in repeating some).


    For those who can't be bothered to read whole post, lets go straight to the point -

    the HP bonus from CON calculation is buggy - it reads incorrect value of HD. Wrong addressing in memory or whatever the reason, but instead of taking the monster HD value (as in Column 162 of protos.tab) it takes some nearby value, which happens to be 3 everytime. So doesn't matter if the critter has 7d or 1d or whatever, that function reads 3 and calculates CON bonus accordingly - as if it was 3d.
    The bug doesn't affect PCs (object type 0x0D), because the game doesn't read the HD value for them.

    Big thanks to Orion79 who was persistent giving me a prod to investigate this, and did some great testing.

    http://files.co8.org/patch/fix_con_bonus_hp.zip


    Of course, this issue is not a showstopper, but it has caused some "CON doesn't work as supposed to" shouts from perfectionists and some haziness when modding critters, for example in this thread.
    Another unclear (at least to some people) question was, whether the HP bonuses are applied automatically or not.

    To answer that, you have to understand how it works in this game: Total stats are re-calculated "live" each friggin second (so to speak), from [Base stat] + [various bonuses or penalties in effect], and generally cannot be set otherwise. Btw, racial stat modifiers (such as -2 CON, +2 DEX for elf) belong to the bonuses, and are not added to base stat upon creation.
    Hitpoints is no exception, Total HPs are calculated from base_hp + bonuses, and this is done not when creating critter, but when the game thinks it is necessary (which is all the time). For all the critters on the map, yay.

    Now about base_hp
    (and protos.tab. I'll mostly refer to things as they are seen in Phalzyr's editor).

    For PCs it's simple - it is hitpoints from their Class Levels rolls. Max roll granted for 1st level.
    For everyone else it is sum of hps gotten from Class Levels (if any) rolls and HP Dice (if any) rolls. However these can be overriden by value from Column 25 (if not empty) - in such case Class Levels and HP Dice values are ignored. This also means that some NPCs are nerfed with Column 25 (in original protos.tab from patch2). Max roll for 1st class level is not given, which nerfs NPCs some more (btw I fixed this while I was at it, as it was a simple 1 byte change).
    When you recruit NPC, he starts adding class level rolls to his base_hp on each levelup just like PC.
    Btw, stats for creatures outside your party are not saved into savegame.

    One of possible bonuses is CON bonus, and it is calculated from: Clvl * Con_modifier + HD * Con_modifier. (And this is where the bug described in the beginning of the post happens).

    On a general note, protos.tab stats for a particular creature on the map might be overriden by stats in .mob file. But for spawned prototypes everything is as set in protos.tab.



    Commands and temple.dll cracks (not the actual bugfix, just some usefull things) that I used:

    Code:
    ;display exact total Hitpoints for non-PCs (just like for PCs)
    ;instead of rough description of their condition ("Unscathed", "Hurt", etc.)
    ;
    ;(offset: old new)
    0012441D: A9 00
    
    Code:
    ;Max HPs for NPCs from Class Levels (no random roll)
    ;
    0007F7BB: E8 8B
    0007F7BC: A0 C5
    0007F7BD: 93 90
    0007F7BE: FB 90
    0007F7BF: FF 90
    
    Code:
    ;Max HPs for NPCs from HD (no random roll)
    ;
    0007F828: E8 0F
    0007F829: 33 AF
    0007F82A: 93 DD
    0007F82B: FB 03
    0007F82C: FF C3
    
    Code:
    ;Max HPs on levelup (same as in my standalone MaxHP crack)
    ;
    000733AC: E8 90
    000733AD: AF 90
    000733AE: 57 90
    000733AF: FC 90
    000733B0: FF 90
    

    Two console commands to spawn objects (including critters):
    game.obj_create(#,loc)
    create #
    The difference, concerning our topic, between those two commands is that the latter (one of short "cheat" commands) ignores "Col 25" when setting base_hp for the critter, and spawns critter on top of the active party member. And the first command is "the real way" to spaw any object, I suppose.

    So for example,

    spawn some critter near active pc:
    dude1=game.obj_create(#,game.leader.location)

    after he is spawned:
    to check his Total CON:
    dude1.stat_level_get(stat_constitution)
    to check his Base CON:
    dude1.stat_base_get(stat_constitution)
    to set his Base CON to X:
    dude1.stat_base_set(stat_constitution,X)
    to check his base hp:
    dude1.stat_base_get(stat_hp_max)
    to set his base hp to X:
    dude1.stat_base_set(stat_hp_max,X)
    to check his Total HPs:
    dude1.stat_level_get(stat_hp_current)


    I guess that's it folks.
     
    Last edited: Jun 16, 2005
  2. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,654
    Likes Received:
    352
    Oooooooooooo I remember the wars over this... so it was bugged all along? Good work Drifter!!!
     
  3. Morpheus

    Morpheus Mindflayer Veteran

    Joined:
    Nov 11, 2003
    Messages:
    539
    Likes Received:
    1
    As Shiningted said, good work! Maybe we can finally put this contentious issue to rest now. ;)

    Thanks to Drifter for fixing this, and thanks to 0rion79 for his persistence in investigating it!
     
  4. 0rion79

    0rion79 Established Member

    Joined:
    Apr 9, 2005
    Messages:
    573
    Likes Received:
    0
    ^_^
    Glad that I could help.
     
  5. RobertB

    RobertB Member

    Joined:
    May 1, 2005
    Messages:
    2
    Likes Received:
    0
    Umm, when I apply this patch to an existing game, it repopulates areas that I've already cleared (for example, the ogre caves or Imiryd's (sp) Run).

    Also, it seems to bug combat by freezing the game on an enemy's turn. (I can still hit "Escape" and quit the game.)

    Any thoughts?

    Robert
     
  6. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,654
    Likes Received:
    352
    You need a matching protos.tab: this patch lets the game calculate HP correctly, the protos.tab gives the correct HD to be calculated. There is one in my mod (if you don't mind a big download and a bunch of new stuff) or else there is a thread around here by Allyx where you can get the protos.tab by itself (he did the corrections).

    And while you are looking around, Drifter has 4 other bug-fix patches for the .dll, look for a 'downloads' thread, there is probably one on the front page.

    These patches are also already in my mod <spruik spruik> :gotmyatte

    Hope that helps, too sleepy to be more useful.
     
  7. RobertB

    RobertB Member

    Joined:
    May 1, 2005
    Messages:
    2
    Likes Received:
    0
    I downloaded and installed the protos.tab files that go along with the con bonus fix when I first tried them. That's not my problem.

    Here's the scenario. I've been running through the adventure using just the CO8 and Livonya mods. I found the other fixes in the handy post by Morpheus and loaded those also. When I loaded an existing save game, some of the areas that I had cleared before were now populated again. I was able to track this problem to the con fix by reinstalling the game from scratch, loading each mod individually, and then loading the save to see if the ogre cave was populated. Sure enough, when I loaded the con fix, the ogres were back. When I unloaded the fix using the patcher file, the ogres went away.

    This issue does not occur within the different levels of the temple (that is, the entire temple doesn't repopulate with all the monsters I've killed already) just those small areas with specific encounters. Could the issue have something to do with the quest log? My thinking is that the ogre caves and Imeryd's Run are both quest locations. Just a thought.

    On a related note, I tried fighting the ogres. Combat is fine until it comes to the second ogre's turn. Then the game stops. It's not a freeze because I can still hit the escape key and load a different save game, or quit the game altogether. It's almost like the game is thinking real hard about the ogre's action (or it's caught in some kind of loop).

    I'd like to load the con fix since I am a purist, but I'm not going to start the game from the beginning (I'm exploring the elemental nodes now).

    Thanks,
    Robert
     
  8. Allyx

    Allyx Master Crafter Global Moderator Supporter

    Joined:
    Dec 2, 2004
    Messages:
    5,001
    Likes Received:
    250
    I can only suggest, play without it for now. When you've finished your current game, add the fix before you start a new game.
     
    Last edited: Aug 13, 2005
  9. Drifter

    Drifter Established Member

    Joined:
    Dec 24, 2004
    Messages:
    118
    Likes Received:
    1
    Could you zip that savegame and upload it somewhere so I can take a look?
    I don't have the game installed atm and so on, so it might take awhile, but I'd like to check it.
     
Our Host!