src/hcode/include/macros.h

Go to the documentation of this file.
00001 
00002 /*
00003  * $Id: macros.h,v 1.1 2005/06/13 20:50:52 murrayma Exp $
00004  *
00005  * Author: Markus Stenberg <fingon@iki.fi>
00006  *
00007  *  Copyright (c) 1996 Markus Stenberg
00008  *       All rights reserved
00009  *
00010  * Created: Wed Oct  9 10:49:55 1996 fingon
00011  * Last modified: Wed Aug 12 14:36:33 1998 fingon
00012  *
00013  */
00014 
00015 #ifndef MACROS_H
00016 #define MACROS_H
00017 
00018 #ifdef notify
00019 #undef notify
00020 #endif
00021 #ifdef notify_except
00022 #undef notify_except
00023 #endif
00024 #define notify(a,b) mecha_notify(a,b)
00025 #define notify_except(a,b,c,d) mecha_notify_except(a,b,c,d)
00026 
00027 /* DOCHECK: Macros for the lazy
00028    DOCHEK(a,b) basically replaces if (a) { <somewaytopassmessage b>, return }
00029 
00030    Macros ending with 0 return 0, and N NULL. Default behaviour is to
00031    return nothing.
00032 
00033    Default behavior to pass message is to use notify to notify the
00034    player who's executing the function. MA = MECHALL, sends to
00035    everyone within the mech executing the command, MP = MECHPILOT,
00036    sends to pilot of the mech
00037    */
00038 #ifndef DOCHECK
00039 #define DOCHECK(a,b) if (a) { notify(player, b); return; }
00040 #define DOCHECKMA(a,b) if (a) { mech_notify(mech, MECHALL, b); return; }
00041 #define DOCHECKMA0(a,b) if (a) { mech_notify(mech, MECHALL, b); return 0; }
00042 #define DOCHECKMP(a,b) if (a) { mech_notify(mech, MECHPILOT, b); return; }
00043 #define DOCHECKMP0(a,b) if (a) { mech_notify(mech, MECHPILOT, b); return 0; }
00044 #define DOCHECKMP1(a,b) if (a) { mech_notify(mech, MECHPILOT, b); return 1; }
00045 #define DOCHECK0(a,b) if (a) { notify(player, b); return 0; }
00046 #define DOCHECK1(a,b) if (a) { notify(player, b); return -1; }
00047 #define DOCHECKN(a,b) if (a) { notify(player, b); return NULL; }
00048 #define FUNCHECK(a,b) \
00049 if (a) { safe_tprintf_str(buff, bufc, b); return; }
00050 #endif
00051 
00052 /* Dice-rolling function used everywhere converted to a macro */
00053 /* Shift the random number to get rid of the usually not-very-random
00054    lower order bits. Because Number() is used with a wide range of numbers,
00055    as high as 5000 at least, we do a little dance to determine the amount
00056    to shift */
00057 #define Number(a,b) ((a) + (random() >> ( \
00058     ((b) - (a)) > 16777216 ? 0 : \
00059     ((b) - (a)) > 65536 ? 8 : \
00060     ((b) - (a)) > 4096 ? 16 : 20 \
00061   )) % ((b)-(a)+1))
00062 
00063 #define skipws(name)     while (name && *name && isspace(*name)) name++
00064 #define readint(to,from) \
00065 (!from || !*from || (!(to = atoi(from)) && strcmp(from, "0")))
00066 
00067 #define Readnum(tovar,fromvar) \
00068         (!(tovar = atoi(fromvar)) && strcmp(fromvar, "0"))
00069 
00070 #define SetBit(val,bit)   (val |= bit)
00071 #define UnSetBit(val,bit) (val &= ~(bit))
00072 #define EvalBit(val,bit,state) \
00073         do {if (state) SetBit(val,bit); else UnSetBit(val,bit);} while (0)
00074 #define ToggleBit(val,bit) \
00075 do { if (!(val & bit)) SetBit(val,bit);else UnSetBit(val,bit); } while (0)
00076 
00077 #define WizPo(p,fun) (fun(Owner(p)) && Inherits(p))
00078 
00079 #define Wiz(p)  WizPo(p,Wizard)
00080 #define WizR(p) WizPo(p,WizRoy)
00081 #define WizP(p) WizPo(p,Security)
00082 
00083 #define hush_teleport(p,t) move_via_teleport(p,t,1,7)
00084 #define loud_teleport(p,t) move_via_teleport(p,t,1,0)
00085 
00086 #if 0
00087 /* Old cheater @luck code. Removed. If you got an issue with it's removal, you prolly had an issue to start with. */
00088 #define ValidLuckPlayer(mech) ((In_Character(mech->mynum) && In_Character(Location(mech->mynum))) ? MechPilot(mech) : -1)
00089 #define NRoll(mech) luck_die_mod(ValidLuckPlayer(mech), -1)
00090 #define PRoll(mech) luck_die_mod(ValidLuckPlayer(mech), 1)
00091 
00092 #define NRoll2(mech,mech2) \
00093   ((!mech2 || mech == mech2) ? NRoll(mech) : luck_die_mod_base(-1, player_luck(ValidLuckPlayer(mech)) - player_luck(ValidLuckPlayer(mech2))))
00094 
00095 #define PRoll2(mech,mech2) \
00096   ((!mech2 || mech == mech2) ? PRoll(mech) : luck_die_mod_base(1, player_luck(ValidLuckPlayer(mech)) - player_luck(ValidLuckPlayer(mech2))))
00097 
00098 /* Negative, player-spesific */
00099 #define NPRoll(player) \
00100   luck_die_mod_base(-1, player_luck(player))
00101 #endif
00102 
00103 #define can_pass_lock(guy,lockobj,lockname) could_doit(guy,lockobj,lockname)
00104 
00105 
00106 #endif                          /* MACROS_H */

Generated on Mon May 28 04:25:24 2007 for BattletechMUX by  doxygen 1.4.7