Date sent: Wed, 16 Jul 1997 18:43:40 -0200 To: "Liner/Nosferatu" From: Rick Rogers (by way of Rick Rogers ) Subject: RCL: utils.h Here is a list of some of the utility functions we use in specs. You'll recognise some of them. Rick ---------- /* ************************************************************************ * file: utils.h, Utility module. Part of DIKUMUD * * Usage: Utility macros * ************************************************************************* */ #include "utility.h" #define CHAR_REAL_ROOM(char_s) (char_s ? (char_s)->in_room_r : -1) #define CHAR_VIRTUAL_ROOM(char_s) (char_s ? (char_s)->in_room_v : 0) #define MOB_NAME(o) (o->player.name ? o->player.name : mob_proto_table[o->nr].name) #define MOB_DESCRIPTION(o) (o->player.description ? o->player.description : mob_proto_table[o->nr].description) #define MOB_SHORT(o) (o->player.short_descr ? o->player.short_descr : mob_proto_table[o->nr].short_descr) #define MOB_LONG(o) (o->player.long_descr ? o->player.long_descr : mob_proto_table[o->nr].long_descr) #define OBJ_NAME(o) (o->name ? o->name : obj_proto_table[o->item_number].name) #define OBJ_DESCRIPTION(o) (o->description ? o->description : obj_proto_table[o->item_number].description) #define OBJ_SHORT(o) (o->short_description ? o->short_description : obj_proto_table[o->item_number].short_description) #define OBJ_ACTION(o) (o->action_description ? o->action_description : obj_proto_table[o->item_number].action_description) #define GET_OPPONENT(ch) ((ch) ? (ch)->specials.fighting : NULL) #define GET_ZONE(ch) (world[CHAR_REAL_ROOM(ch)].zone) #define IS_MORTAL(ch) ((ch) ? !IS_NPC(ch) && GET_LEVEL(ch) < LEVEL_IMM : FALSE) #define ROOM_SPEC(rm) (world[(rm)].spec_tmp) #define OBJ_SPEC(o) ((o)->spec_tmp) #define ITEM(zone,x) ((zone)+(x)) /*#define MOB_FUNCT(mob) mob_proto_table[real_mobile(mob)].func #define OBJ_FUNCT(obj) obj_proto_table[real_object(obj)].func #define ROOM_FUNCT(room) world[real_room(room)].funct*/ #define IS_NIGHT (time_info.hours>18||time_info.hours<6) #define IS_DAY !IS_NIGHT #define ROOM 1 #define ZONE 2 #define WORLD 3 #define TRUE 1 #define FALSE 0 #define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c)) #define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c) ) #define ISNEWL(ch) ((ch) == '\n' || (ch) == '\r') #define IF_STR(st) ((st) ? (st) : "\0") #define CAP(st) (*(st) = UPPER(*(st)), st) #define CREATE(result, type, number) do {\ if (!((result) = (type *) calloc ((number), sizeof(type))))\ { perror("malloc failure"); abort(); } else \ {memset(result,0,number*sizeof(type));} } while(0) #define RECREATE(result,type,number) do {\ if (!((result) = (type *) realloc ((result), sizeof(type) * (number))))\ { perror("realloc failure"); abort(); } } while(0) #define IS_SET(flag,bit) ((flag) & (bit)) #define SWITCH(a,b) { (a) ^= (b); \ (b) ^= (a); \ (a) ^= (b); } #define IS_AFFECTED(ch,skill) (ch ? IS_SET((ch)->specials.affected_by, (skill) ): FALSE ) #define IS_DARK(room) (!world[room].light && IS_SET(world[room].room_flags, DARK)) #define IS_LIGHT(room) (world[room].light || !IS_SET(world[room].room_flags, DARK)) #define SET_BIT(var,bit) ((var) = (var) | (bit)) #define REMOVE_BIT(var,bit) ((var) = (var) & ~(bit) ) #define WIZ_INV(ch, vict) \ ( (((vict)->new.wizinv > GET_LEVEL(ch)) && !IS_NPC(vict)) || \ (((vict)->new.wizinv > LEVEL_IMM) && IS_NPC(ch)) ) #define IMP_INV(ch, vict) (IS_AFFECTED(vict, AFF_IMINV) && GET_LEVEL(ch) < 31) /* Can subject see character "obj"? */ #define CAN_SEE(sub, obj) \ (!WIZ_INV(sub,obj) && !IMP_INV(sub,obj) && !IS_AFFECTED(sub,AFF_BLIND) && \ (!IS_AFFECTED(obj,AFF_INVISIBLE) || IS_AFFECTED(sub, AFF_DETECT_INVISIBLE) || (GET_LEVEL(sub) > 30)) && \ (IS_LIGHT(CHAR_REAL_ROOM(sub)) || ((GET_LEVEL(sub) > 30) || IS_AFFECTED(sub,AFF_INFRAVISION)))) #define GET_REQ(i) (i<2 ? "Awful" :(i<4 ? "Bad" :(i<7 ? "Poor" :\ (i<10 ? "Average" :(i<14 ? "Fair" :(i<20 ? "Good" :(i<24 ? "Very good" :\ "Superb" ))))))) #define HSHR(ch) ((ch)->player.sex ? \ (((ch)->player.sex == 1) ? "his" : "her") : "its") #define HSSH(ch) ((ch)->player.sex ? \ (((ch)->player.sex == 1) ? "he" : "she") : "it") #define HMHR(ch) ((ch)->player.sex ? \ (((ch)->player.sex == 1) ? "him" : "her") : "it") #define ANA(obj) (index("aeiouyAEIOUY", *(obj)->name) ? "An" : "A") #define SANA(obj) (index("aeiouyAEIOUY", *(obj)->name) ? "an" : "a") #define IS_NPC(ch) (ch ? IS_SET((ch)->specials.act, ACT_ISNPC) : FALSE ) #define IS_MOB(ch) (IS_SET((ch)->specials.act, ACT_ISNPC) && ((ch)->nr >-1)) #define GET_POS(ch) ((ch)->specials.position) #define GET_COND(ch, i) ((ch)->specials.conditions[(i)]) #define GET_NAME(ch) (!IS_MOB(ch) ? (ch)->player.name : MOB_NAME(ch)) #define GET_LONG(ch) (!IS_MOB(ch) ? "none" : MOB_LONG(ch)) #define GET_SHORT(ch) (!IS_MOB(ch) ? "none" : MOB_SHORT(ch)) #define GET_TITLE(ch) ((ch)->player.title) #define GET_LEVEL(ch) ((ch)->player.level) #define GET_CLASS(ch) ((ch)->player.class) #define GET_HOME(ch) ((ch)->player.hometown) #define GET_AGE(ch) (age(ch).year) #define GET_STR(ch) ((ch)->tmpabilities.str) #define GET_ADD(ch) ((ch)->tmpabilities.str_add) #define GET_DEX(ch) ((ch)->tmpabilities.dex) #define GET_INT(ch) ((ch)->tmpabilities.intel) #define GET_WIS(ch) ((ch)->tmpabilities.wis) #define GET_CON(ch) ((ch)->tmpabilities.con) #define GET_WIMPY(ch) ((CH)->specials.wimpy) #define STRENGTH_APPLY_INDEX(ch) \ ( ((GET_ADD(ch)==0) || (GET_STR(ch) != 18)) ? GET_STR(ch) :\ (GET_ADD(ch) <= 50) ? 26 :( \ (GET_ADD(ch) <= 75) ? 27 :( \ (GET_ADD(ch) <= 90) ? 28 :( \ (GET_ADD(ch) <= 99) ? 29 : 30 ) ) ) \ ) #define GET_AC(ch) ((ch)->points.armor) #define GET_HIT(ch) ((ch)->points.hit) #define GET_MAX_HIT(ch) (hit_limit(ch)) #define GET_MOVE(ch) ((ch)->points.move) #define GET_MAX_MOVE(ch) (move_limit(ch)) #define GET_MANA(ch) ((ch)->points.mana) #define GET_MAX_MANA(ch) (mana_limit(ch)) #define GET_GOLD(ch) ((ch)->points.gold) #define GET_BANK(ch) ((ch)->points.bank) #define GET_EXP(ch) ((ch)->points.exp) #define GET_HEIGHT(ch) ((ch)->player.height) #define GET_WEIGHT(ch) ((ch)->player.weight) #define GET_SEX(ch) ((ch)->player.sex) #define GET_HITROLL(ch) ((ch)->points.hitroll) #define GET_DAMROLL(ch) ((ch)->points.damroll) #define AWAKE(ch) (GET_POS(ch) > POSITION_SLEEPING) #define WAIT_STATE(ch, cycle) (((ch)->desc) ? (ch)->desc->wait = (cycle) : 0) /* Object And Carry related macros */ #define CAN_SEE_OBJ(sub, obj) \ ( (( !IS_SET((obj)->obj_flags.extra_flags, ITEM_INVISIBLE) || \ IS_AFFECTED((sub),AFF_DETECT_INVISIBLE) || (GET_LEVEL(sub) > 30)) && \ (!IS_AFFECTED((sub),AFF_BLIND)) && IS_LIGHT(CHAR_REAL_ROOM(sub)))|| \ IS_AFFECTED((sub),AFF_INFRAVISION) || (GET_LEVEL(sub) > 30)) #define GET_ITEM_TYPE(obj) ((obj)->obj_flags.type_flag) #define GET_SPEC_TMP(obj) ((obj)->spec_tmp) #define CAN_WEAR(obj, part) (IS_SET((obj)->obj_flags.wear_flags,part)) #define CAN_CARRY_W(ch) (str_app[STRENGTH_APPLY_INDEX(ch)].carry_w) #define CAN_CARRY_N(ch) (5+GET_DEX(ch)/2+GET_LEVEL(ch)/2) #define CAN_CARRY_OBJ(ch,obj) \ (((IS_CARRYING_W(ch) + GETOBJ_WEIGHT(obj)) <= 3*CAN_CARRY_W(ch)) && \ ((IS_CARRYING_N(ch) + 1) <= CAN_CARRY_N(ch)) || (!IS_NPC(ch) && GET_LEVEL(ch)>=LEVEL_IMM)) #define CAN_GET_OBJ(ch, obj) \ (CAN_WEAR((obj), ITEM_TAKE) && CAN_CARRY_OBJ((ch),(obj)) && \ CAN_SEE_OBJ((ch),(obj))) #define IS_OBJ_STAT(obj,stat) (IS_SET((obj)->obj_flags.extra_flags,stat)) /* char name/short_desc(for mobs) or someone? */ /* #define PERS(ch, vict) (CAN_SEE(vict, ch) ? \ (!IS_NPC(ch) ? MOB_NAME(ch) : MOB_SHORT(ch)) :\ "someone") */ #define OBJS(obj, vict) (CAN_SEE_OBJ((vict), (obj)) ? \ OBJ_SHORT((obj)) : "something") #define OBJN(obj, vict) (CAN_SEE_OBJ((vict), (obj)) ? \ fname(OBJ_NAME((obj))) : "something") #define OUTSIDE(ch) (!IS_SET(world[CHAR_REAL_ROOM(ch)].room_flags,INDOORS)) #define EXIT(ch, door) (world[CHAR_REAL_ROOM(ch)].dir_option[door]) #define CAN_GO(ch, door) (EXIT(ch,door) && (EXIT(ch,door)->to_room_r != NOWHERE) \ && !IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED) \ && !IS_SET(EXIT(ch, door)->exit_info,EX_CRAWL) \ && !IS_SET(EXIT(ch, door)->exit_info,EX_JUMP) \ && !IS_SET(EXIT(ch, door)->exit_info,EX_CLIMB)) #define GET_ALIGNMENT(ch) ((ch)->specials.alignment) #define IS_GOOD(ch) (GET_ALIGNMENT(ch) >= 350) #define IS_EVIL(ch) (GET_ALIGNMENT(ch) <= -350) #define IS_NEUTRAL(ch) (!IS_GOOD(ch) && !IS_EVIL(ch)) #define COLORNAME(ch,i) (Color[(ch->colors[i]+1)]) #define COLOR(ch,i) if(ch->colors[0]&&ch->colors[i]) {send_to_char(Color[(((ch->colors[i])*2)-2)],ch);send_to_char(BKColor[ch->co lors[13]],ch);} #define ENDCOLOR(ch) if(ch->colors[0]&&ch->colors[1]) {COLOR(ch,1);send_to_char(BKColor[ch->colors[13]],ch);} #define IS_RENTABLE(obj) ( (obj) ? (((obj)->item_number > -1) &&\ (!IS_OBJ_STAT((obj), ITEM_ANTI_RENT) ) &&\ ((obj)->obj_flags.type_flag != ITEM_FOOD ) &&\ ((obj)->obj_flags.type_flag != ITEM_TRASH) &&\ ((obj)->obj_flags.type_flag != ITEM_KEY ) ) : 0 ) #define GET_OBJ_WEIGHT(obj) ((obj)->obj_flags.weight)