Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Burn damage calculation not fixed? #2045

Closed
wzdev-ci opened this issue Aug 2, 2010 · 15 comments
Closed

Burn damage calculation not fixed? #2045

wzdev-ci opened this issue Aug 2, 2010 · 15 comments

Comments

@wzdev-ci
Copy link
Contributor

wzdev-ci commented Aug 2, 2010

keyword_Burn_damage resolution_fixed type_bug | by fjodorvanveen@...


The very same problem as last time. I was using cheats in an 8 player map, I played against 7 hard enemies all in team G. Screenshot seems irrelevant, just like last time. The enemies incendiary mortar kills all units in one shot, as well as it's fire.


Issue migrated from trac:2045 at 2022-04-15 22:11:16 -0700

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 2, 2010

anonymous uploaded file InBug.7z (75.0 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 2, 2010

Daltx commented


Added a savegame. (forgot to to change my name)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 2, 2010

cybersphinx uploaded file burnfix.patch (1.3 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 2, 2010

cybersphinx commented


That patch makes the code a. work and b. readable. The "if (damageToDo > 20)" block after that still looks strange, not sure if that works right, but at least we don't get "(uint)(- a bit) / 1000" damage anymore.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 2, 2010

Zarel commented


Why'd you take out the cast to (SDWORD)? You can tell that it's Pumpkin code and not my code by the fact that it says SDWORD and not int32_t - they may have had good reason to cast to signed.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 2, 2010

Zarel uploaded file burnfix-2.patch (2.2 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 2, 2010

Zarel commented


This patch is cybersphinx's patch, plus a bit of cleanup, plus adding the cast to signed back, plus duplicating the code to the other place where burn damage is calculated. It is now ready for commit.

The if (damageToDo > 20) block is to limit rounding errors to +/- 5%, since damage is only done in lumps of 20. Back when damage was done in lumps of 1, rounding error was +/- 100% (since 1 damage, plus a 1.25x damage modifier, plus a 1.5x upgrade modifier, was still 1 damage after rounding down).

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 2, 2010

Zarel commented


(No, I will not be committing this fix personally; someone else should commit it, since I am on commit-sabbatical.)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 3, 2010

cybersphinx commented


Replying to Warzone2100/old-trac-import#2045 (comment:3):

Why'd you take out the cast to (SDWORD)? You can tell that it's Pumpkin code and not my code by the fact that it says SDWORD and not int32_t - they may have had good reason to cast to signed.

Because casts are ugly, and it didn't seem to be needed. Is there a reason for burnDamage to be over ~2.000.000.000, which should be interpreted as negative in this case? Maybe there is a reason for it to be negative (do some units heal themselves when they burn?), but then the variable itself should be signed, and not casted.

Replying to Warzone2100/old-trac-import#2045 (comment:4):

This patch is cybersphinx's patch, plus a bit of cleanup, plus adding the cast to signed back, plus duplicating the code to the other place where burn damage is calculated.

Minus the testing it seems, since it doesn't compile.

It is now ready for commit.

...

The if (damageToDo > 20) block is to limit rounding errors to +/- 5%, since damage is only done in lumps of 20. Back when damage was done in lumps of 1, rounding error was +/- 100% (since 1 damage, plus a 1.25x damage modifier, plus a 1.5x upgrade modifier, was still 1 damage after rounding down).

But where is the 20 damage done? It looks like it reduces damageToDo by its %20, and then does damageToDo damage. But maybe I just don't understand it, I haven't looked that much at it.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 3, 2010

Zarel uploaded file burnfix-3.patch (2.2 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 3, 2010

Zarel commented


Replying to Warzone2100/old-trac-import#2045 (comment:6):

Because casts are ugly, and it didn't seem to be needed. Is there a reason for burnDamage to be over ~2.000.000.000, which should be interpreted as negative in this case? Maybe there is a reason for it to be negative (do some units heal themselves when they burn?), but then the variable itself should be signed, and not casted.

You don't use signed integers to prevent overflow, you use them to prevent underflow. It's unlikely that burnDamage would be over 2 billion. It's certainly possible that burnDamage could go negative. The fact that Pumpkin casted to signed suggests that there may have been at least one such underflow bug, and even if it were fixed, a future commit could reintroduce such a problem. Remove it if you want.

Minus the testing it seems, since it doesn't compile.

Gah, uploaded the wrong patch.

But where is the 20 damage done? It looks like it reduces damageToDo by its %20, and then does damageToDo damage. But maybe I just don't understand it, I haven't looked that much at it.

Reducing damageToDo by its %20 means that afterwards, damageToDo will be either 0 or 20. In other words, we accumulate until we have more than 20 damage, then we deal it in lumps of 20.

So (for some theoretical extremely high damage burn) damageToDo will look something like:

  • 3
  • 7
  • 10
  • 14
  • 17
  • 22 [deal 20 damage] 2
  • 5
  • 8

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 8, 2010

cybersphinx commented


Replying to Warzone2100/old-trac-import#2045 (comment:7):

It's certainly possible that burnDamage could go negative.

I don't see how, it's either set to zero or increased by damageToDo when that is positive.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 8, 2010

the_cybersphinx changed status from new to closed

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 8, 2010

the_cybersphinx changed resolution from `` to fixed

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Aug 8, 2010

the_cybersphinx commented


(In [11393]) Really fix burn damage calculations.

Closes #2045.

@wzdev-ci wzdev-ci closed this as completed Aug 8, 2010
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant