Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Exp, Hp, and Mana all going into the negative...
Exp, Hp, and Mana all going into the negative...
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
3
Posted by
| Toy
(206 posts) Bio
|
Date
| Mon 24 May 2004 08:07 AM (UTC) |
Message
| Ran into a problem which is sorta well known, but searching through the forum, I couldn't find exactly how to fix it.
I raised the top level of my mud from 60 to 210, and the integers went into the negatives. Something i expected, but not sure how to fix. Can someone gimme some advice?
-Toy |
It's always good to know how far you are willing to go to be the best...
Karl Mancine
aka
Toy the Dark Puppet | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Mon 24 May 2004 08:16 AM (UTC) |
Message
| How far up do the numbers go before they go negative?
I can't remember if the numbers are ints or shorts... but if they're shorts, changing them to int should be enough. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Toy
(206 posts) Bio
|
Date
| Reply #2 on Mon 24 May 2004 09:11 AM (UTC) |
Message
| Ok, I went into mud.h and changed each of these from sh_int to int
hit
max_hit
mana
max_mana
move
max_move
practices
exp
everything is ok except for exp, which reaches a negative number at lvl 120 going from 2,022,190,800 to any number over 2,100,000.
-Toy |
It's always good to know how far you are willing to go to be the best...
Karl Mancine
aka
Toy the Dark Puppet | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Mon 24 May 2004 09:45 AM (UTC) |
Message
| You could make exp a long, or even a long long (__int64 on Windows).
Although, perhaps you should use sub-levels instead. It will be harder to program, but you won't have all these number problems. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Meerclar
USA (733 posts) Bio
|
Date
| Reply #4 on Mon 24 May 2004 10:16 AM (UTC) |
Message
| Or make it an unsigned int which will take you to 4.2 million. If you need more than 4.2mil, go to unsigned long long and youll have more range than you should ever need. |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | Top |
|
Posted by
| Toy
(206 posts) Bio
|
Date
| Reply #5 on Mon 24 May 2004 12:26 PM (UTC) |
Message
| How do I make it an unsigned integer?
-Toy |
It's always good to know how far you are willing to go to be the best...
Karl Mancine
aka
Toy the Dark Puppet | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #6 on Mon 24 May 2004 07:11 PM (UTC) |
Message
| Instead of 'int' use 'unsigned int'. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Reply #7 on Mon 24 May 2004 08:00 PM (UTC) |
Message
| I'm not sure, but you may have to use another var name or something. Like I had to use %llu for long long unsigned. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
Posted by
| Toy
(206 posts) Bio
|
Date
| Reply #8 on Mon 24 May 2004 10:05 PM (UTC) |
Message
| Ok, I changed it in mud.h to look like this:
unsigned int exp
recompiled and ran the mud, and exp still goes into the negative after reaching 2,100,000.
Test - level 122 - exp: 2,125,873,200
Test - level 123 - exp: -2,115,949,696
and for some reason, once your exp goes negative, your mental state takes a shot of around -90 points. Get this message, which is wierd, because the Test character is a mage:
Damn you heathen! Go forth and do evil or suffer the consequences!
You feel very unmotivated.
-Toy |
It's always good to know how far you are willing to go to be the best...
Karl Mancine
aka
Toy the Dark Puppet | Top |
|
Posted by
| Meerclar
USA (733 posts) Bio
|
Date
| Reply #9 on Mon 24 May 2004 10:08 PM (UTC) |
Message
| Somethin somewhere didnt get recast to unsigned. Youll need to be sure EVERY reference to that pointer gets recast to display and reference as unsigned int. |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | Top |
|
Posted by
| Toy
(206 posts) Bio
|
Date
| Reply #10 on Mon 24 May 2004 10:27 PM (UTC) |
Message
| I've looked throughout handler.c and mud.h. Did a grep from all calls for exp, and I either can't find it or have overlooked it. Any ideas of what I'm overlooking?
-Toy |
It's always good to know how far you are willing to go to be the best...
Karl Mancine
aka
Toy the Dark Puppet | Top |
|
Posted by
| Greven
Canada (835 posts) Bio
|
Date
| Reply #11 on Mon 24 May 2004 10:36 PM (UTC) |
Message
| It may even be in the function that calculates the xp. If you have one variable that is used, but is not of the same type, it will assign a negatinve number into the long int, which is still valid, and from there keep getting used. |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #12 on Tue 25 May 2004 12:31 AM (UTC) |
Message
| For one, you need to get the right numbers :)
Quote: 2,100,000.
Test - level 122 - exp: 2,125,873,200
Your first number is 2 million, the second number is 2 billion.
And lo and behold:
2^32 = 4,294,967,296 (max+1 of unsigned int)
4294967296 / 2 = 2,147,483,648 (max+1 of signed int)
So, somewhere you still have a signed integer instead of an unsigned integer.
However there is no short lying around, because that is:
2^16 = 65536
Clearly the experience was already an integer; you just have to make sure that *every* experience calculation uses unsigned ints and not ints. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Toy
(206 posts) Bio
|
Date
| Reply #13 on Tue 25 May 2004 11:33 AM (UTC) |
Message
| Ok, I've tried to find all the exp calculations, this is what I've found so far:
in handler.c:
get_exp( CHAR_DATA *ch )
get_exp_worth( CHAR_DATA *ch ) and it's call to int exp
get_exp_base( CHAR_DATA *ch )
exp_level( CHAR_DATA *ch, sh_int level )
level_exp( CHAR_DATA *ch, unsigned int exp )
in magic.c:
rd_parse(CHAR_DATA *ch, int level, char *exp)
dice_parse(CHAR_DATA *ch, int level, char *exp)
in update.c:
void gain_exp( CHAR_DATA *ch, unsigned int gain ) and it's call to int modgain
in mud.h:
(under class_type) int exp_base
(under race_type) int exp_multiplier
(under mob_index_data) int exp
(under char_data) int exp
(under handler.c call) get_exp args( ( CHAR_DATA *ch ) );
get_exp_worth args( ( CHAR_DATA *ch ) );
exp_level args( ( CHAR_DATA *ch, sh_int level ) );
(under magic.c call)
dice_parse args( (CHAR_DATA *ch, int level, char *exp) );
(under update.c call)
gain_exp args( ( CHAR_DATA *ch, unsigned int gain ) );
Have spent awhile working on this, and still looking. If anyone knows any I've missed, lemme know so I can finish this up. :)
-Toy |
It's always good to know how far you are willing to go to be the best...
Karl Mancine
aka
Toy the Dark Puppet | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #14 on Tue 25 May 2004 12:18 PM (UTC) Amended on Tue 25 May 2004 12:19 PM (UTC) by David Haley
|
Message
|
Quote: (under class_type) int exp_base
(under race_type) int exp_multiplier
(under mob_index_data) int exp
(under char_data) int exp
For one, those want to be unsigned ints...
Basically, every time you see an integer in an exp calculation, make it an unsigned integer.
[addendum]If you can, compile with g++, even if you're coding in C. It'll give you a lot of freaky (to the coder not aware of the intricacies of C/C++) warnings and even errors, but it's much stricter and will help you find places where you mixed int and unsigned int. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
90,002 views.
This is page 1, subject is 3 pages long: 1 2
3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top