5 ms·
>That is, suppose a unit is sitting there at full health, and you research a tech that increases that unit’s max hp? Should the unit now be at less than full he
by ilyt 4y ago
>That is, suppose a unit is sitting there at full health, and you research a tech that increases that unit’s max hp? Should the unit now be at less than full health, as if it had been in combat? Users probably don’t like that.
>Suppose it is at full health, and then it gets downgraded to a type with less maximum health. Does it stay at it’s current HP? Users probably won’t like being attacked with supercharged units that have extra HP; they’ll think that the other player was cheating somehow.
>What if it is damaged and at half health, then gets upgraded. Should it be fully healed? Gain HP equal to the difference between the new and old maximum HP? Or should it gain half of that, so that it stays at half health?
if (oldHP == maxOldHP) { newHP = newMaxHP }
else { newHP = max(1,scale(oldHP,oldMaxHP,newMaxHP))
not exactly complex
- ghusbands 4y agoSure, if you fully predict all bugs in advance and compensate for them, nothing is complex, but that's not really feasible.
- mrguyorama 4y ago>Sure, if you fully predict all bugs in advance and compensate for them, nothing is complex, but that's not really feasible. Uhh, last time I checked, that was literally my job, and specifically what I went to school for!
- db48x 4y agoNot exactly complex, but you posted too quickly to have found the best solution. A better solution is to kill the unit when it drops below zero HP, not when it drops below 1.0; scaling will never move the current HP past zero in either direction. Having 0.9999994 HP instead of 1.0 HP would not cause any problems then; the unit is still one hit away from death in either case. The best solution is probably to store the current HP as a percentage of the max, because then you never have to rescale it in the first place.
- InitialLastName 4y ago> The best solution is probably to store the current HP as a percentage of the max, because then you never have to rescale it in the first place. Doesn't this solution make the more common calculations more expensive, complicated, and error-prone to make one rare calculation easier? It seems like far more of the operations on the unit's current HP will be "gets damaged by X hp" or "gets healed by X hp", both of which would require the equivalent of the above conversion to establish a result.
- db48x 4y agoIf you’ve changed HP to a percentage, why wouldn’t you also change the damage and other related numbers (such as damage reduction and so on) to percentages as well? Nobody would be dumb enough to store them in different units and then convert every time they manipulate them.
- mlyle 4y ago> why wouldn’t you also change the damage and other related numbers (such as damage reduction and so on) to percentages as well? Because a sword might do 5HP of damage, not 10% of anyone's damage (whether they've got 50 or 5000HP). Otherwise, hit points are meaningless: 10 attacks with a 10%-damage weapon kills a lowly serf or a mighty dragon. And because damage reduction might reduce a fixed amount of damage from an attack. Etc.
- db48x 4y agoObviously a dragon doesn’t get damaged at all by a puny little sword. You can’t just say that hitting a dragon with a sword a thousand times would kill it, when none of the attacks can get through the dragon’s armored hide. On the other hand, it will die immediately if pierced by an arrow provided that arrow hits the one spot where the hide is missing a scale. The dragon has 100% DR, except in that one spot.
- account42 4y ago