Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current HP is improperly calculated on CON change #41

Open
GoogleCodeExporter opened this issue Mar 19, 2015 · 2 comments
Open

Current HP is improperly calculated on CON change #41

GoogleCodeExporter opened this issue Mar 19, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Heal character to max 
2. Equip Girdle of the Dwarves so that CON bonus changes (i.e. from 14-18
to 15-19)

What is the expected output? What do you see instead?
HP current remains equal to max, with the increased value.
Instead, HP becomes the difference between old and new max.

What version of the product are you using? On what operating system?
1.0.20 on Win XP

Please provide any additional information below.
References are from SVN dated 11 Sep 2009.
Notes marked with //S:

ovr024.cs, line 1087:
                if (player.hit_point_max > map_hp)
                {
                    player.hit_point_current = (byte)(player.hit_point_max
- map_hp);
                }

                if (player.hit_point_max < map_hp)
                {
                    if (player.hit_point_current > map_hp -
player.hit_point_max)
                    {
                        player.hit_point_current = (byte)(map_hp -
player.hit_point_max);
                    }
                    else
                    {
                        player.hit_point_current = 0;
                    }
                }

//S: the minimum fix would be using "+=" and "-=" instead of "=":
                    player.hit_point_current += (byte)(player.hit_point_max
- map_hp);
                    //...
                        player.hit_point_current -= (byte)(map_hp -
player.hit_point_max);

//S: however, the whole story is much simpler than this and can be cleaned
up as:
                //S: some caution is needed here... this must be a 
                //S: signed comparison!
                if (player.hit_point_current > 
                    map_hp – player.hit_point_max)
                {
                    player.hit_point_current += 
                        (byte)(player.hit_point_max – map_hp);
                }
                else
                {
                    player.hit_point_current = 0;
                }

Original issue reported on code.google.com by surrano on 16 Sep 2009 at 6:54

@GoogleCodeExporter
Copy link
Author

Ended up with the following solution because of the signs... maybe the original 
looks
better, having fewer type casts :)

                int maxdelta = (int) map_hp - player.hit_point_max;
                System.Console.WriteLine("HPChange: " + map_hp + "-" +
player.hit_point_max + "=" + maxdelta + 
                    " current=" + player.hit_point_current);
                if ((int)player.hit_point_current > maxdelta)
                {
                    player.hit_point_current = (byte)((int)player.hit_point_current -
maxdelta);
                }
                else
                {
                    player.hit_point_current = 0;
                }


Original comment by surrano on 18 Sep 2009 at 7:40

@GoogleCodeExporter
Copy link
Author

Original comment by simeon.pilgrim on 28 Jul 2010 at 10:32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant