home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / d-linux.zip / dm-dist / utils.h < prev    next >
Text File  |  1991-03-01  |  7KB  |  204 lines

  1. /* ************************************************************************
  2. *  file: utils.h, Utility module.                         Part of DIKUMUD *
  3. *  Usage: Utility macros                                                  *
  4. ************************************************************************* */
  5.  
  6. #define TRUE  1
  7.  
  8. #define FALSE 0
  9.  
  10. #define LOWER(c) (((c)>='A'  && (c) <= 'Z') ? ((c)+('a'-'A')) : (c))
  11.  
  12. #define UPPER(c) (((c)>='a'  && (c) <= 'z') ? ((c)+('A'-'a')) : (c) )
  13.  
  14. /* Functions in utility.c                     */
  15. /* #define MAX(a,b) (((a) > (b)) ? (a) : (b)) */
  16. /* #define MIN(a,b) (((a) < (b)) ? (a) : (b)) */
  17.  
  18. #define ISNEWL(ch) ((ch) == '\n' || (ch) == '\r') 
  19.  
  20. #define IF_STR(st) ((st) ? (st) : "\0")
  21.  
  22. #define CAP(st)  (*(st) = UPPER(*(st)), st)
  23.  
  24. #define CREATE(result, type, number)  do {\
  25.     if (!((result) = (type *) calloc ((number), sizeof(type))))\
  26.         { perror("malloc failure"); abort(); } } while(0)
  27.  
  28. #define RECREATE(result,type,number) do {\
  29.   if (!((result) = (type *) realloc ((result), sizeof(type) * (number))))\
  30.         { perror("realloc failure"); abort(); } } while(0)
  31.  
  32. #define IS_SET(flag,bit)  ((flag) & (bit))
  33.  
  34. #define SWITCH(a,b) { (a) ^= (b); \
  35.                       (b) ^= (a); \
  36.                       (a) ^= (b); }
  37.  
  38. #define IS_AFFECTED(ch,skill) ( IS_SET((ch)->specials.affected_by, (skill)) )
  39.  
  40. #define IS_DARK(room)  (!world[room].light && IS_SET(world[room].room_flags, DARK))
  41.  
  42. #define IS_LIGHT(room)  (world[room].light || !IS_SET(world[room].room_flags, DARK))
  43.  
  44. #define SET_BIT(var,bit)  ((var) = (var) | (bit))
  45.  
  46. #define REMOVE_BIT(var,bit)  ((var) = (var) & ~(bit) )
  47.  
  48. /* Can subject see character "obj"? */
  49. #define CAN_SEE(sub, obj)   ( ((!IS_AFFECTED((obj),AFF_INVISIBLE) ||        \
  50.                                  IS_AFFECTED((sub),AFF_DETECT_INVISIBLE)) &&\
  51.                                 !IS_AFFECTED((sub),AFF_BLIND) ) &&            \
  52.                                  IS_LIGHT(sub->in_room) )
  53.  
  54. #define GET_REQ(i) (i<2  ? "Awful" :(i<4  ? "Bad"     :(i<7  ? "Poor"      :\
  55. (i<10 ? "Average" :(i<14 ? "Fair"    :(i<20 ? "Good"    :(i<24 ? "Very good" :\
  56.         "Superb" )))))))
  57.  
  58. #define HSHR(ch) ((ch)->player.sex ?                    \
  59.     (((ch)->player.sex == 1) ? "his" : "her") : "its")
  60.  
  61. #define HSSH(ch) ((ch)->player.sex ?                    \
  62.     (((ch)->player.sex == 1) ? "he" : "she") : "it")
  63.  
  64. #define HMHR(ch) ((ch)->player.sex ?                     \
  65.     (((ch)->player.sex == 1) ? "him" : "her") : "it")    
  66.  
  67. #define ANA(obj) (index("aeiouyAEIOUY", *(obj)->name) ? "An" : "A")
  68.  
  69. #define SANA(obj) (index("aeiouyAEIOUY", *(obj)->name) ? "an" : "a")
  70.  
  71. #define IS_NPC(ch)  (IS_SET((ch)->specials.act, ACT_ISNPC))
  72.  
  73. #define IS_MOB(ch)  (IS_SET((ch)->specials.act, ACT_ISNPC) && ((ch)->nr >-1))
  74.  
  75. #define GET_POS(ch)     ((ch)->specials.position)
  76.  
  77. #define GET_COND(ch, i) ((ch)->specials.conditions[(i)])
  78.  
  79. #define GET_NAME(ch)    ((ch)->player.name)
  80.  
  81. #define GET_TITLE(ch)   ((ch)->player.title)
  82.  
  83. #define GET_LEVEL(ch)   ((ch)->player.level)
  84.  
  85. #define GET_CLASS(ch)   ((ch)->player.class)
  86.  
  87. #define GET_HOME(ch)        ((ch)->player.hometown)
  88.  
  89. #define GET_AGE(ch)     (age(ch).year)
  90.  
  91. #define GET_STR(ch)     ((ch)->tmpabilities.str)
  92.  
  93. #define GET_ADD(ch)     ((ch)->tmpabilities.str_add)
  94.  
  95. #define GET_DEX(ch)     ((ch)->tmpabilities.dex)
  96.  
  97. #define GET_INT(ch)     ((ch)->tmpabilities.intel)
  98.  
  99. #define GET_WIS(ch)     ((ch)->tmpabilities.wis)
  100.  
  101. #define GET_CON(ch)     ((ch)->tmpabilities.con)
  102.  
  103. #define STRENGTH_APPLY_INDEX(ch) \
  104.         ( ((GET_ADD(ch)==0) || (GET_STR(ch) != 18)) ? GET_STR(ch) :\
  105.           (GET_ADD(ch) <= 50) ? 26 :( \
  106.           (GET_ADD(ch) <= 75) ? 27 :( \
  107.           (GET_ADD(ch) <= 90) ? 28 :( \
  108.           (GET_ADD(ch) <= 99) ? 29 :  30 ) ) )                   \
  109.         )
  110.  
  111. #define GET_AC(ch)      ((ch)->points.armor)
  112.  
  113. #define GET_HIT(ch)     ((ch)->points.hit)
  114.  
  115. #define GET_MAX_HIT(ch) (hit_limit(ch))
  116.  
  117. #define GET_MOVE(ch)    ((ch)->points.move)
  118.  
  119. #define GET_MAX_MOVE(ch) (move_limit(ch))
  120.  
  121. #define GET_MANA(ch)    ((ch)->points.mana)
  122.  
  123. #define GET_MAX_MANA(ch) (mana_limit(ch))
  124.  
  125. #define GET_GOLD(ch)    ((ch)->points.gold)
  126.  
  127. #define GET_EXP(ch)     ((ch)->points.exp)
  128.  
  129. #define GET_HEIGHT(ch)  ((ch)->player.height)
  130.  
  131. #define GET_WEIGHT(ch)  ((ch)->player.weight)
  132.  
  133. #define GET_SEX(ch)     ((ch)->player.sex)
  134.  
  135. #define GET_HITROLL(ch) ((ch)->points.hitroll)
  136.  
  137. #define GET_DAMROLL(ch) ((ch)->points.damroll)
  138.  
  139. #define AWAKE(ch) (GET_POS(ch) > POSITION_SLEEPING)
  140.  
  141. #define WAIT_STATE(ch, cycle)  (((ch)->desc) ? (ch)->desc->wait = (cycle) : 0)
  142.  
  143.  
  144.  
  145.  
  146. /* Object And Carry related macros */
  147.  
  148. #define CAN_SEE_OBJ(sub, obj)                                    \
  149.     ( (( !IS_SET((obj)->obj_flags.extra_flags, ITEM_INVISIBLE) ||   \
  150.          IS_AFFECTED((sub),AFF_DETECT_INVISIBLE) ) &&               \
  151.          !IS_AFFECTED((sub),AFF_BLIND)) && IS_LIGHT(sub->in_room) )
  152.  
  153. #define GET_ITEM_TYPE(obj) ((obj)->obj_flags.type_flag)
  154.  
  155. #define CAN_WEAR(obj, part) (IS_SET((obj)->obj_flags.wear_flags,part))
  156.  
  157. #define GET_OBJ_WEIGHT(obj) ((obj)->obj_flags.weight)
  158.  
  159. #define CAN_CARRY_W(ch) (str_app[STRENGTH_APPLY_INDEX(ch)].carry_w)
  160.  
  161. #define CAN_CARRY_N(ch) (5+GET_DEX(ch)/2+GET_LEVEL(ch)/2)
  162.  
  163. #define IS_CARRYING_W(ch) ((ch)->specials.carry_weight)
  164.  
  165. #define IS_CARRYING_N(ch) ((ch)->specials.carry_items)
  166.  
  167. #define CAN_CARRY_OBJ(ch,obj)  \
  168.    (((IS_CARRYING_W(ch) + GET_OBJ_WEIGHT(obj)) <= CAN_CARRY_W(ch)) &&   \
  169.     ((IS_CARRYING_N(ch) + 1) <= CAN_CARRY_N(ch)))
  170.  
  171. #define CAN_GET_OBJ(ch, obj)   \
  172.    (CAN_WEAR((obj), ITEM_TAKE) && CAN_CARRY_OBJ((ch),(obj)) &&          \
  173.     CAN_SEE_OBJ((ch),(obj)))
  174.  
  175. #define IS_OBJ_STAT(obj,stat) (IS_SET((obj)->obj_flags.extra_flags,stat))
  176.  
  177.  
  178.  
  179. /* char name/short_desc(for mobs) or someone?  */
  180.  
  181. #define PERS(ch, vict)   (                                          \
  182.     CAN_SEE(vict, ch) ?                                                            \
  183.       (!IS_NPC(ch) ? (ch)->player.name : (ch)->player.short_descr) :    \
  184.       "someone")
  185.  
  186. #define OBJS(obj, vict) (CAN_SEE_OBJ((vict), (obj)) ? \
  187.     (obj)->short_description  : "something")
  188.  
  189. #define OBJN(obj, vict) (CAN_SEE_OBJ((vict), (obj)) ? \
  190.     fname((obj)->name) : "something")
  191.  
  192. #define OUTSIDE(ch) (!IS_SET(world[(ch)->in_room].room_flags,INDOORS))
  193.  
  194. #define EXIT(ch, door)  (world[(ch)->in_room].dir_option[door])
  195.  
  196. #define CAN_GO(ch, door) (EXIT(ch,door)  &&  (EXIT(ch,door)->to_room != NOWHERE) \
  197.                           && !IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED))
  198.  
  199. #define GET_ALIGNMENT(ch) ((ch)->specials.alignment)
  200.  
  201. #define IS_GOOD(ch)    (GET_ALIGNMENT(ch) >= 350)
  202. #define IS_EVIL(ch)    (GET_ALIGNMENT(ch) <= -350)
  203. #define IS_NEUTRAL(ch) (!IS_GOOD(ch) && !IS_EVIL(ch))
  204.