Pages:<< prev 1 next >>
#1 Jan 6, 2008 1:04 pm
Last edited Jan 6, 2008 1:29 pm by Samson
Black Hand
GroupAdministrators
Posts3,697
JoinedJan 1, 2002
Bug: Utility Macros sometimes give bad results
Danger: Medium - When they work, they're good. When they don't, you get unexpected and hard to trace errors.
Discovered in: AFKMud 2.02
Found by: Remcon
Fixed by: Remcon
---
mud.h
Locate:
Change to:
handler.cpp
Locate:
Below that, add these new functions:
character.cpp, char_data::gain_exp
Locate:
Change to:
fight.cpp, one_hit
Locate:
Change to:
This problem is best explained through this post: http://smaugmuds.afkmods.com/index.php?a=topic&t=808
The fix here is part of the same fix Remcon applied to his LoP codebase.
Danger: Medium - When they work, they're good. When they don't, you get unexpected and hard to trace errors.
Discovered in: AFKMud 2.02
Found by: Remcon
Fixed by: Remcon
---
mud.h
Locate:
/* * Utility macros. */ #define UMIN(a, b) ((a) < (b) ? (a) : (b)) #define UMAX(a, b) ((a) > (b) ? (a) : (b)) #define URANGE(a, b, c) ((b) < (a) ? (a) : ((b) > (c) ? (c) : (b))) #define LOWER(c) ((c) >= 'A' && (c) <= 'Z' ? (c)+'a'-'A' : (c)) #define UPPER(c) ((c) >= 'a' && (c) <= 'z' ? (c)+'A'-'a' : (c))
Change to:
// Utility macros. int umin( int check, int ncheck ); int umax( int check, int ncheck ); int urange( int mincheck, int check, int maxcheck ); #define UMIN( a, b ) ( umin( (a), (b) ) ) #define UMAX( a, b ) ( umax( (a), (b) ) ) #define URANGE(a, b, c ) ( urange( (a), (b), (c) ) ) #define LOWER( c ) ( (c) >= 'A' && (c) <= 'Z' ? (c) + 'a' - 'A' : (c) ) #define UPPER( c ) ( (c) >= 'a' && (c) <= 'z' ? (c) + 'A' - 'a' : (c) )
handler.cpp
Locate:
void init_memory( void *start, void *end, unsigned int size ) { memset( start, 0, ( int )( ( char * )end + size - ( char * )start ) ); }
Below that, add these new functions:
int umin( int check, int ncheck ) { if( check < ncheck ) return check; return ncheck; } int umax( int check, int ncheck ) { if( check > ncheck ) return check; return ncheck; } int urange( int mincheck, int check, int maxcheck ) { if( check < mincheck ) return mincheck; if( check > maxcheck ) return maxcheck; return check; }
character.cpp, char_data::gain_exp
Locate:
/* * xp cap to prevent any one event from giving enuf xp to * gain more than one level - FB */ modgain = UMIN( modgain, exp_level( this->level + 2 ) - exp_level( this->level + 1 ) ); this->exp = ( int )( UMAX( 0, this->exp + modgain ) );
Change to:
/* * xp cap to prevent any one event from giving enuf xp to * gain more than one level - FB */ modgain = UMIN( (int)modgain, exp_level( this->level + 2 ) - exp_level( this->level + 1 ) ); this->exp = ( int )( UMAX( 0, this->exp + (int)modgain ) );
fight.cpp, one_hit
Locate:
dam = UMAX( dam, 1 ); plusris = 0;
Change to:
dam = UMAX( (int)dam, 1 ); plusris = 0;
This problem is best explained through this post: http://smaugmuds.afkmods.com/index.php?a=topic&t=808
The fix here is part of the same fix Remcon applied to his LoP codebase.
Pages:<< prev 1 next >>