Ah, sorry Maximus, it seems like I've gotten sidetracked to the point of your original question. Which was why Max HP seems to overflow before the 16bit upper limit. First thing to look at is if HP is actually used as a
signed integer. I would've thought that the game logic would just check for underflow (HP after damage greater than initial HP), and set to zero, but it's also possible that they would use a signed data type and just check for a less than zero value, since there are cases where damage actually does heal (plate armor stolen from dragons).
WARNING: Wall of text incomingExperiment:
- Set an enemy HP right at the 32,767 max
- Modify an attack element to make enemy HP visible
- Heal enemy and check HP
(I'll list my disc modifications based on a 2352 sector size, and using disc 1 only)
So I set the Beach Bum HP to 32,767. since these are always male, the value is actually 31,207 * 1.05. The disc address and values used:
- 0x13B8EDEE: 0xE7
- 0x13B8EDEF: 0x79
Next I modified Aquabeam so that it does zero damage but shows enemy HP:
- 0x13BA00FC: 0x00 (zero damage)
- 0x13BA00FE: 0x64 (stat effect 100% chance of hitting)
- 0x13BA010E: 0x40 (HP vis stat)
And last, I changed Tablet, so that it targets enemies:
Then I started a battle, and cast Aquabeam on a full HP Beach Bum. When I targeted him next, he had 32,767/32,767 HP. So far so good.
Next I used a Tablet on him, which did... something odd. He sagged like he was close to death. And when I checked his HP it was far outside the 16bit boundary: 934,557/32,767 (and colored red like low HP). A single 1 stamina attack then killed it
So it seems like the game doesn't display negative HP values properly, but it sure acted like one. This makes me think that HP, while not explicitly signed, is contingent on some game logic that treats it as such, but isn't well enforced.
I also double checked that an enemy with a reasonable HP value, when healed, doesn't go above it's max HP. It seems like this overflow is only possible during the heal calculation if the result is lower than the max HP because of the sign change.
The last thing to note, giving an enemy a default HP value of 32768, made it's max HP overflow too, which creates some odd interactions. This seems like a bug in the game logic. It might be possible to fix the damage formula to allow for full 16bit values, but that'll take someone with more experience than me. In the meantime, probably best to only use HP values under 32,767. Or, if you are planning on having a mod that can be played in NG+, 16,383.