As a French person I feel like it's my duty to explain strikes to you. - AdrienIer

Create an account  

 
"Ghost units" bug

We have this bug where if units lose maximum health somehow overland, they keep the same amount of damage, but the number of figures get recalculated and as damage>total health, it'll end up with zero (or negative) figures.

One of the causes of this is the Lion Heart item power. It's buggy and only grants the health bonus in combat.
I've looked into it but it cannot be fixed in a reasonably easy way, at least I can't do it.
The problem is caused by the procedure applying health only having access to the overland unit data, which is bad because items abilities are only in the "battle" unit data. Overland data only contains the ID of the hero, and the hero data contains the items, and the item data contains the enchantment.
There are two possible ways of solution I can think of.
-If enough space can be freed up in code in the same code segment anywhere (probably around 50+ bytes which are a LOT), it's possible to check for the item through the above mentioned data and apply the effect. This would most likely be a huge amount of work, and I actually don't know where the equipment of heroes are stored so I can't do it at the moment even if I do manage to make this much room.
-The other, the procedure that applies the item effects into the battle data is actually at near range and can be called...but I don't understand the required parameters well enough to even try that. We would also need to create a blank "dummy" battle data of a unit for this.

Either way, the "ghost unit" bug can be caused by other reasons, especially units losing the enchantment that grants the buff. As this cannot be avoided (and isn't even a bug), whether someone manages to fix Lionheart or not, the ghost bug needs to be fixed separately.

Which is where I'd like to ask if anyone has any idea how to handle this?
I think we would need to inject code somewhere that checks if the unit has more damage than health, and reduce the damage to the effective health minus one. Problem is..where. I know close to nothing about how the game handles overland damage and adding it to the wrong place would either not guarantee that the unit gets fixed before it is used or targeted by something, or it might even make it invincible to death through damage (if we put it before the game checks for leathal damage to delete dead units).

I definitely do not want my heroes or other units to enter battle with negative health...or to even exist like that considering in might have unexpected consequences that destabilize the game from division by zero to doing negative damage and whatnot.

...now that I think about it, we cannot even do "damage=max health-1"...as we don't know the max health, it isn't stored on the unit frown
Which pretty much leaves the unit's natural healing process, which needs to know the maximum health, the only place where this can be done...but that won't help units that get into combat between the disenchant and the end of that turn.
..or not...ghost units don't naturally heal as far as I know.
I'm out of ideas.
Reply

In my mod i choose the simply solution: I mark zero health unit as "absent" (3), at the start of the battle.
if this is a death unit then mark it as "dead" after battle.

The problem is wider. It need other question to be solved first, for example "its hard to keep wrath at full health". or what will we do with damaged units if "charm of life" is disenchanted. do you want redesign the way damage stored for the entire game?
Reply

(October 11th, 2015, 00:12)Asfex Wrote: do you want redesign the way damage stored for the entire game?

No, that would be too hard. Ghost units not entering battle is a good idea. Or, maybe...ghost units automatically heal to 1 remaining health at the start of battle? Battle data does have the maximum health stored.

Thanks for the great idea!

I did this.
I changed the "CreateBattleUnitFromOverland" at 8EAB9 to include this after making room

Code:
8ECD4:
mov     es:[bx+0Dh], dl
cmp     dl, 0
jg      short loc_9859B
mov     es:[bx+0Dh], 1
mov     dl, es:[bx+10h]
dec     dl
mov     es:[bx+39h], dl
loc_9859B:
...original code

This converts any overland unit with 0 or fewer figures into 1 figure with 1 remaining health.

As a side effect, this also fixes the Lionheart bug. Even if the overland unit has negative health, it enters battle with 1 health and isn't buggy. On top, it gains the extra health from Lionheart, so it actually is even better than it should, the unit will always get healed to 4 health automatically. The only drawback is the unit will instantly die if targeted by something like Fire Storm as it does not actually have the +3 health, although at that low remaining health it might happen anyway.
It also makes the unit appear with 1 health when right clicking on it, as displaying the unit does convert it to battle stats first.

Now, if I only could do something about these units not getting healed at end of turn, it would be perfect. I wonder why they don't, as far as I can see it only skips death units and units that already healed that turn.
..hmm healer works. Oh, the normal healing has a check "if unit damage > maximum health, skip healing"..easy to remove, yay!
Reply



Forum Jump: