Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
Bug in do_drag( )
Oct 8, 2017, 12:40 am
By GatewaySysop
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Beastmaster 6D sound files
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Google, Yandex, DotBot

Members: 0
Guests: 11
Stats
Files
Topics
Posts
Members
Newest Member
476
3,704
19,231
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Bugfix Lists » AFKMud Bugfix List » [Bug] Utility Macros sometime...
Forum Rules | Mark all | Recent Posts

[Bug] Utility Macros sometimes give bad results
< Newer Topic :: Older Topic > AFKMud 2.02

Pages:<< prev 1 next >>
Post is unread #1 Jan 6, 2008, 11:04 am   Last edited Jan 6, 2008, 11:29 am by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
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:
/*
 * 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://www.smaugmuds.org/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 >>