| 1 | /** |
| 2 | * @file |
| 3 | * Core defines: object types, flags, etc. |
| 4 | * |
| 5 | * This file is really too large. With all the .h files |
| 6 | * around, this file should be better split between them - things |
| 7 | * that deal with objects should be in objects.h, things dealing |
| 8 | * with players in player.h, etc. As it is, everything just seems |
| 9 | * to be dumped in here. |
| 10 | * |
| 11 | * This file is best viewed with a window width of about 100 character. |
| 12 | */ |
| 13 | |
| 14 | #ifndef DEFINE_H |
| 15 | #define DEFINE_H |
| 16 | |
| 17 | #ifndef WIN32 /* ---win32 exclude unix configuration part */ |
| 18 | #include <autoconf.h> |
| 19 | #endif |
| 20 | |
| 21 | /** Decstations have trouble with fabs()... */ |
| 22 | #define FABS(x) ((x) < 0 ? -(x) : (x)) |
| 23 | |
| 24 | #ifdef __NetBSD__ |
| 25 | #include <sys/param.h> |
| 26 | #endif |
| 27 | |
| 28 | /** NAME_MAX used by random maps may not be defined on pure ansi systems */ |
| 29 | #ifndef NAME_MAX |
| 30 | #define NAME_MAX 255 |
| 31 | #endif |
| 32 | |
| 33 | #define MIN_STAT 1 /**< The minimum legal value of any stat */ |
| 34 | |
| 35 | #define MAX_BUF 256 /**< Used for all kinds of things */ |
| 36 | #define VERY_BIG_BUF 1024 |
| 37 | #define HUGE_BUF 4096 /**< Used for messages - some can be quite long */ |
| 38 | |
| 39 | #define MAX_ANIMATIONS 256 |
| 40 | |
| 41 | #define MAX_NAME 48 |
| 42 | #define BIG_NAME 32 |
| 43 | |
| 44 | /** |
| 45 | * Fatal variables; used as arguments to fatal(). |
| 46 | */ |
| 47 | enum fatal_error { |
| 48 | OUT_OF_MEMORY = 0, |
| 49 | MAP_ERROR = 1, |
| 50 | ARCHTABLE_TOO_SMALL = 2, |
| 51 | ARCHETYPE_ISSUE = 3, |
| 52 | SEE_LAST_ERROR = 4, |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * @defgroup TYPE_BUILDER Subtypes for ::BUILDER objects. |
| 57 | */ |
| 58 | /*@{*/ |
| 59 | #define ST_BD_BUILD 1 /**< Builds an item */ |
| 60 | #define ST_BD_REMOVE 2 /**< Removes an item */ |
| 61 | /*@}*/ |
| 62 | |
| 63 | /** |
| 64 | * @defgroup TYPE_MATERIAL Subtypes for ::MATERIAL objects. |
| 65 | */ |
| 66 | /*@{*/ |
| 67 | #define ST_MAT_FLOOR 1 /**< Floor. */ |
| 68 | #define ST_MAT_WALL 2 /**< Wall. */ |
| 69 | #define ST_MAT_ITEM 3 /**< Most other items, including doors & such. */ |
| 70 | #define ST_MAT_WINDOW 4 /**< Window. */ |
| 71 | /*@}*/ |
| 72 | |
| 73 | /** |
| 74 | * @defgroup TYPE_WEAPON Weapon types |
| 75 | */ |
| 76 | /*@{*/ |
| 77 | #define WEAP_HIT 0 /**< the basic */ |
| 78 | #define WEAP_SLASH 1 /**< slash */ |
| 79 | #define WEAP_PIERCE 2 /**< arrows, stiletto */ |
| 80 | #define WEAP_CLEAVE 3 /**< axe */ |
| 81 | #define WEAP_SLICE 4 /**< katana */ |
| 82 | #define WEAP_STAB 5 /**< knife, dagger */ |
| 83 | #define WEAP_WHIP 6 /**< whips n chains */ |
| 84 | #define WEAP_CRUSH 7 /**< big hammers, flails */ |
| 85 | #define WEAP_BLUD 8 /**< bludgeoning, club, stick */ |
| 86 | /*@}*/ |
| 87 | |
| 88 | /** Link an object type with skill needed to identify, and general name. */ |
| 89 | typedef struct typedata { |
| 90 | int number; /**< Type. */ |
| 91 | const char *name; /**< Object name. */ |
| 92 | const char *name_pl;/**< Plural name. */ |
| 93 | int identifyskill; /**< Skill used to identify this object class. */ |
| 94 | int identifyskill2; /**< Second skill used to identify this object class. */ |
| 95 | } typedata; |
| 96 | |
| 97 | |
| 98 | /** |
| 99 | * @defgroup PU_xxx Pickup modes |
| 100 | * Definitions for detailed pickup descriptions. |
| 101 | * The objective is to define intelligent groups of items that the |
| 102 | * user can pick up or leave as he likes. |
| 103 | */ |
| 104 | /*@{*/ |
| 105 | /* high bit as flag for new pickup options */ |
| 106 | #define PU_NOTHING 0x00000000 |
| 107 | |
| 108 | #define PU_DEBUG 0x10000000 |
| 109 | #define PU_INHIBIT 0x20000000 |
| 110 | #define PU_STOP 0x40000000 |
| 111 | #define PU_NEWMODE 0x80000000 |
| 112 | |
| 113 | #define PU_RATIO 0x0000000F |
| 114 | |
| 115 | #define PU_FOOD 0x00000010 |
| 116 | #define PU_DRINK 0x00000020 |
| 117 | #define PU_VALUABLES 0x00000040 |
| 118 | #define PU_BOW 0x00000080 |
| 119 | |
| 120 | #define PU_ARROW 0x00000100 |
| 121 | #define PU_HELMET 0x00000200 |
| 122 | #define PU_SHIELD 0x00000400 |
| 123 | #define PU_ARMOUR 0x00000800 |
| 124 | |
| 125 | #define PU_BOOTS 0x00001000 |
| 126 | #define PU_GLOVES 0x00002000 |
| 127 | #define PU_CLOAK 0x00004000 |
| 128 | #define PU_KEY 0x00008000 |
| 129 | |
| 130 | #define PU_MISSILEWEAPON 0x00010000 |
| 131 | #define PU_MELEEWEAPON 0x00020000 |
| 132 | #define PU_MAGICAL 0x00040000 |
| 133 | #define PU_POTION 0x00080000 |
| 134 | |
| 135 | #define PU_SPELLBOOK 0x00100000 |
| 136 | #define PU_SKILLSCROLL 0x00200000 |
| 137 | #define PU_READABLES 0x00400000 |
| 138 | #define PU_MAGIC_DEVICE 0x00800000 |
| 139 | |
| 140 | #define PU_NOT_CURSED 0x01000000 |
| 141 | #define PU_JEWELS 0x02000000 |
| 142 | #define PU_FLESH 0x04000000 |
| 143 | #define PU_CONTAINER 0x08000000 |
| 144 | /*@}*/ |
| 145 | |
| 146 | /* Instead of using arbitrary constants for indexing the |
| 147 | * freearr, add these values. <= SIZEOFFREE1 will get you |
| 148 | * within 1 space. <= SIZEOFFREE2 wll get you withing |
| 149 | * 2 spaces, and the entire array (< SIZEOFFREE) is |
| 150 | * three spaces |
| 151 | */ |
| 152 | #define SIZEOFFREE1 8 |
| 153 | #define SIZEOFFREE2 24 |
| 154 | #define SIZEOFFREE 49 |
| 155 | |
| 156 | #define NROF_SOUNDS (23+NROFREALSPELLS) /* Number of sounds */ |
| 157 | |
| 158 | /** |
| 159 | * @defgroup IS_xxx Convenience macros to determine what kind of things we are dealing with. |
| 160 | */ |
| 161 | /*@{*/ |
| 162 | #define IS_WEAPON(op) \ |
| 163 | (op->type == ARROW || op->type == BOW || op->type == WEAPON) |
| 164 | |
| 165 | #define IS_ARMOR(op) \ |
| 166 | (op->type == ARMOUR || op->type == HELMET || \ |
| 167 | op->type == BOOTS || op->type == GLOVES) |
| 168 | |
| 169 | #define IS_SHIELD(op) \ |
| 170 | (op->type == SHIELD) |
| 171 | |
| 172 | #define IS_LIVE(op) \ |
| 173 | ((op->type == PLAYER || QUERY_FLAG(op, FLAG_MONSTER) || \ |
| 174 | (QUERY_FLAG(op, FLAG_ALIVE) && !QUERY_FLAG(op, FLAG_GENERATOR) && \ |
| 175 | !(op->type == DOOR))) && (!QUERY_FLAG(op, FLAG_IS_A_TEMPLATE))) |
| 176 | |
| 177 | #define IS_ARROW(op) \ |
| 178 | (op->type == ARROW || \ |
| 179 | (op->type == SPELL_EFFECT && (op->subtype == SP_BULLET || op->subtype == SP_MAGIC_MISSILE))) |
| 180 | /*@}*/ |
| 181 | |
| 182 | /** This return TRUE if object has still randomitems which could be expanded. */ |
| 183 | #define HAS_RANDOM_ITEMS(op) (op->randomitems && (!QUERY_FLAG(op, FLAG_IS_A_TEMPLATE))) |
| 184 | |
| 185 | /** |
| 186 | * @defgroup FLAG_xxx Object flags |
| 187 | * |
| 188 | * Those flags are object-related flags, stored in the obj::flags fields. |
| 189 | * |
| 190 | * Flag structure now changed. |
| 191 | * Each flag is now a bit offset, starting at zero. The macros |
| 192 | * will update/read the appropriate flag element in the object |
| 193 | * structure. |
| 194 | * |
| 195 | * Hopefully, since these offsets are integer constants set at run time, |
| 196 | * the compiler will reduce the macros something as simple as the |
| 197 | * old system was. |
| 198 | * |
| 199 | * Flags now have FLAG as the prefix. This to be clearer, and also |
| 200 | * to make sure F_ names are not still being used anyplace. |
| 201 | * |
| 202 | * The macros below assume that the flag size for each element is 32 |
| 203 | * bits. IF it is smaller, bad things will happen. See structs.h |
| 204 | * for more info. |
| 205 | * |
| 206 | * All functions should use the macros below. In process of converting |
| 207 | * to the new system, I find several files that did not use the previous |
| 208 | * macros. |
| 209 | * |
| 210 | * If any FLAG's are or changed, make sure the flag_names structure in |
| 211 | * common/loader.l is updated. |
| 212 | * |
| 213 | * - flags[0] is 0 to 31 |
| 214 | * - flags[1] is 32 to 63 |
| 215 | * - flags[2] is 64 to 95 |
| 216 | * - flags[3] is 96 to 127 |
| 217 | * |
| 218 | * Values can go up to 127 before the size of the flags array in the |
| 219 | * object structure needs to be enlarged. |
| 220 | * So there are 18 available flags slots |
| 221 | */ |
| 222 | /*@{*/ |
| 223 | #define SET_FLAG(xyz, p) set_flag(xyz, p) |
| 224 | #define CLEAR_FLAG(xyz, p) clear_flag(xyz, p) |
| 225 | #define QUERY_FLAG(xyz, p) query_flag(xyz, p) |
| 226 | #define COMPARE_FLAGS(p, q) compare_flags(p, q) |
| 227 | |
| 228 | /* the flags themselves. */ |
| 229 | |
| 230 | #define FLAG_ALIVE 0 /**< Object can fight (or be fought) */ |
| 231 | #define FLAG_WIZ 1 /**< Object has special privilegies */ |
| 232 | #define FLAG_REMOVED 2 /**< Object is not in any map or invenory */ |
| 233 | #define FLAG_FREED 3 /**< Object is in the list of free objects */ |
| 234 | #define FLAG_WAS_WIZ 4 /**< Player was once a wiz */ |
| 235 | #define FLAG_APPLIED 5 /**< Object is ready for use by living */ |
| 236 | #define FLAG_UNPAID 6 /**< Object hasn't been paid for yet */ |
| 237 | #define FLAG_USE_SHIELD 7 /**< Can this creature use a shield? */ |
| 238 | |
| 239 | #define FLAG_NO_PICK 8 /**< Object can't be picked up */ |
| 240 | #define FLAG_CLIENT_ANIM_SYNC 9 /**< Let client animate this, synchronized */ |
| 241 | #define FLAG_CLIENT_ANIM_RANDOM 10 /**< Client animate this, randomized */ |
| 242 | #define FLAG_ANIMATE 11 /**< The object looks at archetype for faces */ |
| 243 | #define FLAG_DIALOG_PARSED 12 /**< Was the object::msg field parsed? Temporary flag not saved */ |
| 244 | #define FLAG_NO_SAVE 13 /**< If set (through plugins), the object is not saved on maps. */ |
| 245 | #define FLAG_MONSTER 14 /**< Will attack players */ |
| 246 | #define FLAG_FRIENDLY 15 /**< Will help players */ |
| 247 | |
| 248 | #define FLAG_GENERATOR 16 /**< Will generate type ob->stats.food */ |
| 249 | #define FLAG_IS_THROWN 17 /**< Object is designed to be thrown. */ |
| 250 | #define FLAG_AUTO_APPLY 18 /**< Will be applied when created */ |
| 251 | #define FLAG_TREASURE 19 /**< Will generate treasure when applied */ |
| 252 | #define FLAG_PLAYER_SOLD 20 /**< Object was sold to a shop by a player. */ |
| 253 | #define FLAG_SEE_INVISIBLE 21 /**< Will see invisible player */ |
| 254 | #define FLAG_CAN_ROLL 22 /**< Object can be rolled */ |
| 255 | #define FLAG_OVERLAY_FLOOR 23 /**< Object is an overlay floor */ |
| 256 | #define FLAG_IS_TURNABLE 24 /**< Object can change face with direction */ |
| 257 | #define FLAG_PROBE 25 /**< Object displays HP information to player. */ |
| 258 | /*#define FLAG_FLY_ON 26*//* As WALK_ON, but only with FLAG_FLYING */ |
| 259 | /*#define FLAG_FLY_OFF 27*//* As WALK_OFF, but only with FLAG_FLYING */ |
| 260 | #define FLAG_IS_USED_UP 28 /**< When (--food<0) the object will exit */ |
| 261 | #define FLAG_IDENTIFIED 29 /**< Player knows full info about item */ |
| 262 | #define FLAG_REFLECTING 30 /**< Object reflects from walls (lightning) */ |
| 263 | #define FLAG_CHANGING 31 /**< Changes to other_arch when anim is done*/ |
| 264 | |
| 265 | /* Start of values in flags[1] */ |
| 266 | #define FLAG_SPLITTING 32 /**< Object splits into stats.food other objs */ |
| 267 | #define FLAG_HITBACK 33 /**< Object will hit back when hit */ |
| 268 | #define FLAG_STARTEQUIP 34 /**< Object was given to player at start */ |
| 269 | #define FLAG_BLOCKSVIEW 35 /**< Object blocks view */ |
| 270 | #define FLAG_UNDEAD 36 /**< Monster is undead */ |
| 271 | #define FLAG_SCARED 37 /**< Monster is scared (mb player in future)*/ |
| 272 | #define FLAG_UNAGGRESSIVE 38 /**< Monster doesn't attack players */ |
| 273 | #define FLAG_REFL_MISSILE 39 /**< Arrows will reflect from object */ |
| 274 | |
| 275 | #define FLAG_REFL_SPELL 40 /**< Spells (some) will reflect from object */ |
| 276 | #define FLAG_NO_MAGIC 41 /**< Spells (some) can't pass this object */ |
| 277 | #define FLAG_NO_FIX_PLAYER 42 /**< fix_object() won't be called */ |
| 278 | #define FLAG_IS_LIGHTABLE 43 /**< object can be lit */ |
| 279 | #define FLAG_TEAR_DOWN 44 /**< at->faces[hp*animations/maxhp] at hit */ |
| 280 | #define FLAG_RUN_AWAY 45 /**< Object runs away from nearest player \ |
| 281 | but can still attack at a distance */ |
| 282 | /*#define FLAG_PASS_THRU 46*/ /* Objects with can_pass_thru can pass \ |
| 283 | thru this object as if it wasn't there */ |
| 284 | /*#define FLAG_CAN_PASS_THRU 47*/ /* Can pass thru... */ |
| 285 | |
| 286 | /*#define FLAG_PICK_UP 48*/ /* Can pick up */ |
| 287 | #define FLAG_UNIQUE 49 /**< Item is really unique (UNIQUE_ITEMS) */ |
| 288 | #define FLAG_NO_DROP 50 /**< Object can't be dropped */ |
| 289 | #define FLAG_WIZCAST 51 /**< The wizard can cast spells in no-magic area */ |
| 290 | #define FLAG_CAST_SPELL 52 /**< (Monster) can learn and cast spells */ |
| 291 | #define FLAG_USE_SCROLL 53 /**< (Monster) can read scroll */ |
| 292 | #define FLAG_USE_RANGE 54 /**< (Monster) can apply and use range items */ |
| 293 | #define FLAG_USE_BOW 55 /**< (Monster) can apply and fire bows */ |
| 294 | |
| 295 | #define FLAG_USE_ARMOUR 56 /**< (Monster) can wear armour/shield/helmet */ |
| 296 | #define FLAG_USE_WEAPON 57 /**< (Monster) can wield weapons */ |
| 297 | #define FLAG_USE_RING 58 /**< (Monster) can use rings, boots, gauntlets, etc */ |
| 298 | #define FLAG_READY_RANGE 59 /**< (Monster) has a range attack readied... 8) */ |
| 299 | #define FLAG_READY_BOW 60 /**< not implemented yet */ |
| 300 | #define FLAG_XRAYS 61 /**< X-ray vision */ |
| 301 | #define FLAG_NO_APPLY 62 /**< Avoids step_on/fly_on to this object */ |
| 302 | #define FLAG_IS_FLOOR 63 /**< Can't see what's underneath this object */ |
| 303 | |
| 304 | /* Start of values in flags[2] */ |
| 305 | #define FLAG_LIFESAVE 64 /**< Saves a players' life once, then destr. */ |
| 306 | #define FLAG_NO_STRENGTH 65 /**< Strength-bonus not added to wc/dam */ |
| 307 | #define FLAG_SLEEP 66 /**< NPC is sleeping */ |
| 308 | #define FLAG_STAND_STILL 67 /**< NPC will not (ever) move */ |
| 309 | #define FLAG_RANDOM_MOVE 68 /**< NPC will move randomly */ |
| 310 | #define FLAG_ONLY_ATTACK 69 /**< NPC will evaporate if there is no enemy */ |
| 311 | #define FLAG_CONFUSED 70 /**< Will also be unable to cast spells */ |
| 312 | #define FLAG_STEALTH 71 /**< Will wake monsters with less range */ |
| 313 | |
| 314 | #define FLAG_WIZPASS 72 /**< The wizard can go through walls */ |
| 315 | #define FLAG_IS_LINKED 73 /**< The object is linked with other objects */ |
| 316 | #define FLAG_CURSED 74 /**< The object is cursed */ |
| 317 | #define FLAG_DAMNED 75 /**< The object is _very_ cursed */ |
| 318 | #define FLAG_SEE_ANYWHERE 76 /**< The object will be visible behind walls */ |
| 319 | #define FLAG_KNOWN_MAGICAL 77 /**< The object is known to be magical */ |
| 320 | #define FLAG_KNOWN_CURSED 78 /**< The object is known to be cursed */ |
| 321 | #define FLAG_CAN_USE_SKILL 79 /**< The monster can use skills */ |
| 322 | |
| 323 | #define FLAG_BEEN_APPLIED 80 /**< The object has been applied */ |
| 324 | #define FLAG_READY_SCROLL 81 /**< monster has scroll in inv and can use it */ |
| 325 | /*#define FLAG_USE_ROD 82 unused (Monster) can apply and use rods */ |
| 326 | /*#define FLAG_READY_HORN 83 unused (Monster) has a horn readied */ |
| 327 | /*#define FLAG_USE_HORN 84 unused (Monster) can apply and use horns */ |
| 328 | #define FLAG_MAKE_INVIS 85 /**< (Item) gives invisibility when applied */ |
| 329 | #define FLAG_INV_LOCKED 86 /**< Item will not be dropped from inventory */ |
| 330 | #define FLAG_IS_WOODED 87 /**< Item is wooded terrain */ |
| 331 | |
| 332 | #define FLAG_IS_HILLY 88 /**< Item is hilly/mountain terrain */ |
| 333 | #define FLAG_READY_SKILL 89 /**< (Monster or Player) has a skill readied */ |
| 334 | #define FLAG_READY_WEAPON 90 /**< (Monster or Player) has a weapon readied */ |
| 335 | #define FLAG_NO_SKILL_IDENT 91 /**< If set, item cannot be identified w/ a skill */ |
| 336 | #define FLAG_BLIND 92 /**< If set, object cannot see (visually) */ |
| 337 | #define FLAG_SEE_IN_DARK 93 /**< if set ob not effected by darkness */ |
| 338 | #define FLAG_IS_CAULDRON 94 /**< container can make alchemical stuff */ |
| 339 | /*#define FLAG_DUST 95 *//* item is a 'powder', effects throwing */ |
| 340 | |
| 341 | /* Start of values in flags[3] */ |
| 342 | #define FLAG_NO_STEAL 96 /**< Item can't be stolen */ |
| 343 | #define FLAG_ONE_HIT 97 /**< Monster can only hit once before going |
| 344 | * away (replaces ghosthit) |
| 345 | */ |
| 346 | #define FLAG_CLIENT_SENT 98 /**< We use it to |
| 347 | * detect cases were the server is trying |
| 348 | * to send an upditem when we have not |
| 349 | * actually sent the item. |
| 350 | */ |
| 351 | |
| 352 | #define FLAG_BERSERK 99 /**< monster will attack closest living |
| 353 | * object */ |
| 354 | #define FLAG_NEUTRAL 100 /**< monster is from type neutral */ |
| 355 | #define FLAG_NO_ATTACK 101 /**< monster don't attack */ |
| 356 | #define FLAG_NO_DAMAGE 102 /**< monster can't be damaged */ |
| 357 | #define FLAG_OBJ_ORIGINAL 103 /**< NEVER SET THIS. Item was loaded by |
| 358 | * load_original_map() */ |
| 359 | /*#define FLAG_OBJ_SAVE_ON_OVL 104 *//* this object should be saved on |
| 360 | * the overlay, and is not subject to |
| 361 | * decay. */ |
| 362 | #define FLAG_ACTIVATE_ON_PUSH 105 /**< connected object is activated when 'pushed' */ |
| 363 | #define FLAG_ACTIVATE_ON_RELEASE 106 /**< connected object is activated when 'released' */ |
| 364 | #define FLAG_IS_WATER 107 |
| 365 | #define FLAG_CONTENT_ON_GEN 108 |
| 366 | #define FLAG_IS_A_TEMPLATE 109 /**< Object has no ingame life until instantiated*/ |
| 367 | #define FLAG_IS_BUILDABLE 110 /**< Can build on item */ |
| 368 | #define FLAG_AFK 111 /**< Player is AFK */ |
| 369 | #define FLAG_BLESSED 112 /**< Item has a blessing, opposite of cursed/damned. */ |
| 370 | #define FLAG_KNOWN_BLESSED 113 /**< Item is known to be blessed. */ |
| 371 | #define FLAG_PARALYZED 114 /**< Monster or player is paralyzed. |
| 372 | * Currently only used to display message to player |
| 373 | * of paralysis begin and end. */ |
| 374 | #define NUM_FLAGS 114 /**< Should always be equal to the last |
| 375 | * defined flag. If you change this, |
| 376 | * make sure you update the flag_links |
| 377 | * in common/loader.l |
| 378 | */ |
| 379 | |
| 380 | /*@}*/ |
| 381 | |
| 382 | /** |
| 383 | * @defgroup MOVE_xxx Movement types and related macros. |
| 384 | * |
| 385 | * Those flags are all possible movement types. |
| 386 | * |
| 387 | * If you add new movement types, you may need to update |
| 388 | * describe_item() so properly describe those types. |
| 389 | * change_abil() probably should be updated also. |
| 390 | */ |
| 391 | /*@{*/ |
| 392 | #define MOVE_WALK 0x1 /**< Object walks. */ |
| 393 | #define MOVE_FLY_LOW 0x2 /**< Low flying object. */ |
| 394 | #define MOVE_FLY_HIGH 0x4 /**< High flying object. */ |
| 395 | #define MOVE_FLYING 0x6 /**< Combo of fly_low and fly_high. */ |
| 396 | #define MOVE_SWIM 0x8 /**< Swimming object. */ |
| 397 | #define MOVE_BOAT 0x10 /**< Boats/sailing. */ |
| 398 | #define MOVE_ALL 0x1f /**< Mask of all movement types. */ |
| 399 | |
| 400 | /** |
| 401 | * The normal assumption is that objects are walking/flying. |
| 402 | * So often we don't want to block movement, but still don't want |
| 403 | * to allow all types (swimming is rather specialized) - I also |
| 404 | * expect as more movement types show up, this is likely to get |
| 405 | * updated. Basically, this is the default for spaces that allow |
| 406 | * movement - anything but swimming right now. If you really |
| 407 | * want nothing at all, then can always set move_block to 0 |
| 408 | */ |
| 409 | #define MOVE_BLOCK_DEFAULT MOVE_SWIM |
| 410 | |
| 411 | /** |
| 412 | * Typdef here to define type large enough to hold bitmask of |
| 413 | * all movement types. Make one declaration so easy to update. |
| 414 | * uint8_t is defined yet, so just use what that would define it |
| 415 | * at anyways. |
| 416 | */ |
| 417 | typedef unsigned char MoveType; |
| 418 | |
| 419 | /** |
| 420 | * Basic macro to see if ob2 blocks ob1 from moving onto this space. |
| 421 | * Basically, ob2 has to block all of ob1 movement types. |
| 422 | */ |
| 423 | #define OB_MOVE_BLOCK(ob1, ob2) \ |
| 424 | ((ob1->move_type&ob2->move_block) == ob1->move_type) |
| 425 | |
| 426 | /** |
| 427 | * Basic macro to see if if ob1 can not move onto a space based |
| 428 | * on the 'type' move_block parameter |
| 429 | * Add check - if type is 0, don't stop anything from moving |
| 430 | * onto it. |
| 431 | */ |
| 432 | #define OB_TYPE_MOVE_BLOCK(ob1, type) \ |
| 433 | ((type != 0) && (ob1->move_type&type) == ob1->move_type) |
| 434 | /*@}*/ |
| 435 | |
| 436 | #define GENERATE_TYPE(xyz) ((xyz)->stats.sp) |
| 437 | #define GENERATE_SPEED(xyz) ((xyz)->stats.maxsp) /* if(!RANDOM()%<speed>) */ |
| 438 | |
| 439 | #define EXIT_PATH(xyz) (xyz)->slaying |
| 440 | #define EXIT_LEVEL(xyz) (xyz)->stats.food |
| 441 | #define EXIT_X(xyz) (xyz)->stats.hp |
| 442 | #define EXIT_Y(xyz) (xyz)->stats.sp |
| 443 | #define EXIT_ALT_X(xyz) (xyz)->stats.maxhp |
| 444 | #define EXIT_ALT_Y(xyz) (xyz)->stats.maxsp |
| 445 | |
| 446 | /** |
| 447 | * Max radii for 'light' object, really large values allow objects that can |
| 448 | * slow down the game |
| 449 | */ |
| 450 | #define MAX_LIGHT_RADII 4 |
| 451 | /** |
| 452 | * Maximum map darkness, there is no practical reason to exceed this |
| 453 | **/ |
| 454 | #define MAX_DARKNESS 5 |
| 455 | |
| 456 | /** |
| 457 | * Maximum item power an item can have. If changed, check object::item_power for overflow issues. |
| 458 | */ |
| 459 | #define MAX_WEAPON_ITEM_POWER 100 |
| 460 | |
| 461 | static const int32_t MAX_FOOD = 999; |
| 462 | |
| 463 | #define DIRX(xyz) freearr_x[(xyz)->direction] |
| 464 | #define DIRY(xyz) freearr_y[(xyz)->direction] |
| 465 | |
| 466 | #define ARMOUR_SPEED(xyz) (xyz)->last_sp |
| 467 | #define ARMOUR_SPELLS(xyz) (xyz)->gen_sp_armour |
| 468 | #define WEAPON_SPEED(xyz) (xyz)->last_sp |
| 469 | |
| 470 | /** |
| 471 | * @defgroup MONSTER_MOVEMENT Monster movements |
| 472 | * @author [email protected] |
| 473 | * |
| 474 | * if your monsters start acting wierd, mail me. |
| 475 | */ |
| 476 | /*@{*/ |
| 477 | /* |
| 478 | * The following definitions are for the attack_movement variable in monsters. |
| 479 | * If the attack_variable movement is left out of the monster archetype, or is |
| 480 | * set to zero, the standard mode of movement from previous versions of |
| 481 | * Crossfire will be used. The upper four bits of movement data are not in |
| 482 | * effect when the monster has an enemy. These should only be used for non |
| 483 | * agressive monsters. To program a monsters movement add the attack movement |
| 484 | * numbers to the movement numbers example a monster that moves in a circle |
| 485 | * until attacked and then attacks from a distance: |
| 486 | * CIRCLE1 = 32 |
| 487 | * + DISTATT = 1 |
| 488 | * ------------------- |
| 489 | * attack_movement = 33 |
| 490 | */ |
| 491 | #define DISTATT 1 /**< Move toward a player if far, but maintain some space, |
| 492 | * attack from a distance - good for missile users only. */ |
| 493 | #define RUNATT 2 /**< Run but attack if player catches up to object. */ |
| 494 | #define HITRUN 3 /**< Run to then hit player then run away cyclicly. */ |
| 495 | #define WAITATT 4 /**< Wait for player to approach then hit, move if hit. */ |
| 496 | #define RUSH 5 /**< Rush toward player blindly, similiar to dumb monster. */ |
| 497 | #define ALLRUN 6 /**< Always run, never attack good for sim. of weak player.*/ |
| 498 | #define DISTHIT 7 /**< Attack from a distance if hit as recommended by Frank.*/ |
| 499 | #define WAIT2 8 /**< Monster does not try to move towards player if far. |
| 500 | * Maintains comfortable distance. */ |
| 501 | #define PETMOVE 16 /**< If the upper four bits of attack_movement |
| 502 | * are set to this number, the monster follows a player |
| 503 | * until the owner calls it back or off |
| 504 | * player followed denoted by ob->owner |
| 505 | * the monster will try to attack whatever the player is |
| 506 | * attacking, and will continue to do so until the |
| 507 | * calls off the monster - a key command will be |
| 508 | * inserted to do so. */ |
| 509 | #define CIRCLE1 32 /**< If the upper four bits of move_type / attack_movement |
| 510 | * are set to this number, the monster will move in a |
| 511 | * circle until it is attacked, or the enemy field is |
| 512 | * set, this is good for non-aggressive monsters and NPC. */ |
| 513 | #define CIRCLE2 48 /**< Same as ::CIRCLE1 but a larger circle is used. */ |
| 514 | #define PACEH 64 /**< The monster will pace back and forth until attacked. |
| 515 | * This is HORIZONTAL movement. */ |
| 516 | #define PACEH2 80 /**< The monster will pace as above but the length of the |
| 517 | * pace area is longer and the monster stops before |
| 518 | * changing directions. |
| 519 | * This is HORIZONTAL movement. */ |
| 520 | #define RANDO 96 /**< The monster will go in a random direction until |
| 521 | * it is stopped by an obstacle, then it chooses another |
| 522 | * direction. */ |
| 523 | #define RANDO2 112 /**< Constantly move in a different random direction. */ |
| 524 | #define PACEV 128 /**< The monster will pace back and forth until attacked. |
| 525 | * This is VERTICAL movement. */ |
| 526 | #define PACEV2 144 /**< The monster will pace as above but the length of the |
| 527 | * pace area is longer and the monster stops before |
| 528 | * changing directions. |
| 529 | * This is VERTICAL movement. */ |
| 530 | #define LO4 15 /**< bitmasks for upper and lower 4 bits from 8 bit fields */ |
| 531 | #define HI4 240 |
| 532 | /*@}*/ |
| 533 | |
| 534 | /** |
| 535 | * @defgroup ST_xxx Player state. |
| 536 | * Use of the state-variable in player objects. |
| 537 | * |
| 538 | * See the @ref page_connection "login process" page. |
| 539 | */ |
| 540 | /*@{*/ |
| 541 | #define ST_PLAYING 0 /**< Usual state. */ |
| 542 | #define ST_PLAY_AGAIN 1 /**< Player left through a bed of reality, and can login again. */ |
| 543 | #define ST_ROLL_STAT 2 /**< New character, rolling stats. */ |
| 544 | #define ST_CHANGE_CLASS 3 /**< New character, choosing class. */ |
| 545 | #define ST_CONFIRM_QUIT 4 /**< Player used the 'quit' command, make sure that's ok. */ |
| 546 | #define ST_GET_NAME 6 /**< Player just connected. */ |
| 547 | #define ST_GET_PASSWORD 7 /**< Name entered, now for password. */ |
| 548 | #define ST_CONFIRM_PASSWORD 8 /**< New character, confirm password. */ |
| 549 | #define ST_GET_PARTY_PASSWORD 10 /**< Player tried to join a password-protected party. */ |
| 550 | #define ST_CHANGE_PASSWORD_OLD 11 /**< Player is entering old password to change password */ |
| 551 | #define ST_CHANGE_PASSWORD_NEW 12 /**< Player is entering new password */ |
| 552 | #define ST_CHANGE_PASSWORD_CONFIRM 13 /**< Player is confirming new password */ |
| 553 | /*@}*/ |
| 554 | |
| 555 | #define BLANK_FACE_NAME "blank.111" |
| 556 | #define EMPTY_FACE_NAME "empty.111" |
| 557 | #define SMOOTH_FACE_NAME "default_smoothed.111" |
| 558 | |
| 559 | /* |
| 560 | * Defines for the luck/random functions to make things more readable |
| 561 | */ |
| 562 | |
| 563 | #define PREFER_HIGH 1 |
| 564 | #define PREFER_LOW 0 |
| 565 | |
| 566 | /** |
| 567 | * @defgroup AP_xxx Flags for apply_special(). |
| 568 | * |
| 569 | * Those flags correspond to the aflags parameter of the apply_special() function. |
| 570 | */ |
| 571 | /*@{*/ |
| 572 | /* Basic flags, always use one of these */ |
| 573 | #define AP_NULL 0 /**< Nothing specific. */ |
| 574 | #define AP_APPLY 1 /**< Item is to be applied. */ |
| 575 | #define AP_UNAPPLY 2 /**< Item is to be remvoed. */ |
| 576 | #define AP_OPEN 3 /**< Item is a container to be fully opened. */ |
| 577 | |
| 578 | #define AP_BASIC_FLAGS 15 |
| 579 | |
| 580 | /* Optional flags, for bitwise or with a basic flag */ |
| 581 | #define AP_NO_MERGE 16 /**< Don't try to merge object after (un)applying it. */ |
| 582 | #define AP_IGNORE_CURSE 32 /**< Apply/unapply regardless of cursed/damned status. */ |
| 583 | #define AP_PRINT 64 /**< Print what to do, don't actually do it |
| 584 | * Note this is supported in all the functions */ |
| 585 | #define AP_NOPRINT 128 /**< Don't print messages - caller will do that |
| 586 | * may be some that still print */ |
| 587 | /*@}*/ |
| 588 | |
| 589 | /** |
| 590 | * @defgroup AC_PLAYER_STAT for apply_changes_to_player() |
| 591 | * |
| 592 | * These flags determine what apply_changes_to_player() does for |
| 593 | * stat adjustment, if anything. |
| 594 | */ |
| 595 | #define AC_PLAYER_STAT_LIMIT 1 /** Limit stats to racial maximum */ |
| 596 | #define AC_PLAYER_STAT_NO_CHANGE 2 /** Do not make any stat adjustments */ |
| 597 | |
| 598 | |
| 599 | /** |
| 600 | * @defgroup CAN_APPLY_xxx Values returned by apply_can_apply_object(). |
| 601 | * |
| 602 | * Bitmask values for 'apply_can_apply_object()' return values. |
| 603 | * the CAN_APPLY_ prefix is to just note what function the |
| 604 | * are returned from. |
| 605 | * |
| 606 | * - CAN_APPLY_NEVER: who will never be able to use this - requires a body |
| 607 | * location who doesn't have. |
| 608 | * - CAN_APPLY_RESTRICTION: There is some restriction from using this item - |
| 609 | * this basically means one of the FLAGS are set saying you can't |
| 610 | * use this. |
| 611 | * - CAN_APPLY_NOT_MASK - this can be used to check the return value to see |
| 612 | * if this object can do anything to use this object. If the value |
| 613 | * returned from apply_can_apply_object() anded with the mask is non zero, |
| 614 | * then it is out of the control of this creature to use the item. |
| 615 | * otherwise it means that by unequipping stuff, they could apply the object |
| 616 | * - CAN_APPLY_UNAPPLY: Player needs to unapply something before applying |
| 617 | * this. |
| 618 | * - CAN_APPLY_UNAPPLY_MULT: There are multiple items that need to be |
| 619 | * unapplied before this can be applied. Think of switching to |
| 620 | * a bow but you have a sword & shield - both the sword and |
| 621 | * shield need to be uneqipped before you can do the bow. |
| 622 | * - CAN_APPLY_UNAPPLY_CHOICE: There is a choice of items to unapply before |
| 623 | * this one can be applied. Think of rings - human is wearing two |
| 624 | * rings and tries to apply one - there are two possible rings he |
| 625 | * could remove. |
| 626 | */ |
| 627 | /*@{*/ |
| 628 | #define CAN_APPLY_NEVER 0x1 |
| 629 | #define CAN_APPLY_RESTRICTION 0x2 |
| 630 | #define CAN_APPLY_NOT_MASK 0xf |
| 631 | #define CAN_APPLY_UNAPPLY 0x10 |
| 632 | #define CAN_APPLY_UNAPPLY_MULT 0x20 |
| 633 | #define CAN_APPLY_UNAPPLY_CHOICE 0x40 |
| 634 | /*@}*/ |
| 635 | |
| 636 | /** Cut off point of when an object is put on the active list or not */ |
| 637 | #define MIN_ACTIVE_SPEED 0.00001 |
| 638 | |
| 639 | uint32_t cf_random(void); |
| 640 | void cf_srandom(unsigned long seed); |
| 641 | |
| 642 | #define RANDOM() cf_random() |
| 643 | #define SRANDOM(seed) cf_srandom(seed) |
| 644 | |
| 645 | /** |
| 646 | * Returns the weight of the given object. Note: it does not take the number of |
| 647 | * items (nrof) into account. |
| 648 | */ |
| 649 | #define WEIGHT(op) (op->nrof ? op->weight : op->weight+op->carrying) |
| 650 | |
| 651 | /** |
| 652 | * Constructs a loop iterating over the inventory of an object. Example: |
| 653 | * <pre> |
| 654 | * FOR_INV_PREPARE(op, inv) |
| 655 | * LOG(llevInfo, "%s\n", inv->name); |
| 656 | * FOR_INV_FINISH(); |
| 657 | * </pre> |
| 658 | * or |
| 659 | * <pre> |
| 660 | * FOR_INV_PREPARE(op, inv) { |
| 661 | * LOG(llevInfo, "%s\n", inv->name); |
| 662 | * } FOR_INV_FINISH(); |
| 663 | * </pre> |
| 664 | * @param op_ the object to iterate over |
| 665 | * @param it_ a variable name that holds the inventory objects; a new variable |
| 666 | * will be declared; modifications do not affect the loop |
| 667 | */ |
| 668 | #define FOR_INV_PREPARE(op_, it_) \ |
| 669 | do { \ |
| 670 | object *it_ = (op_)->inv; \ |
| 671 | FOR_OB_AND_BELOW_PREPARE(it_); |
| 672 | /** |
| 673 | * Finishes #FOR_INV_PREPARE(). |
| 674 | */ |
| 675 | #define FOR_INV_FINISH() \ |
| 676 | FOR_OB_AND_BELOW_FINISH(); \ |
| 677 | } while(0) |
| 678 | |
| 679 | /** |
| 680 | * Constructs a loop iterating over all objects above an object. |
| 681 | * @param op_ the object to iterate over |
| 682 | * @param it_ a variable name that holds the inventory objects; a new variable |
| 683 | * will be declared; modifications do not affect the loop |
| 684 | */ |
| 685 | #define FOR_ABOVE_PREPARE(op_, it_) \ |
| 686 | do { \ |
| 687 | object *it_ = (op_)->above; \ |
| 688 | FOR_OB_AND_ABOVE_PREPARE(it_); |
| 689 | /** |
| 690 | * Finishes #FOR_ABOVE_PREPARE(). |
| 691 | */ |
| 692 | #define FOR_ABOVE_FINISH() \ |
| 693 | FOR_OB_AND_ABOVE_FINISH(); \ |
| 694 | } while(0) |
| 695 | |
| 696 | /** |
| 697 | * Constructs a loop iterating over all objects below an object. |
| 698 | * @param op_ the object to iterate over |
| 699 | * @param it_ a variable name that holds the inventory objects; a new variable |
| 700 | * will be declared; modifications do not affect the loop |
| 701 | */ |
| 702 | #define FOR_BELOW_PREPARE(op_, it_) \ |
| 703 | do { \ |
| 704 | object *it_ = (op_)->below; \ |
| 705 | FOR_OB_AND_BELOW_PREPARE(it_); |
| 706 | /** |
| 707 | * Finishes #FOR_BELOW_PREPARE(). |
| 708 | */ |
| 709 | #define FOR_BELOW_FINISH() \ |
| 710 | FOR_OB_AND_BELOW_FINISH(); \ |
| 711 | } while(0) |
| 712 | |
| 713 | /** |
| 714 | * Constructs a loop iterating over all objects of a map tile. |
| 715 | * @param map_ the map to iterate over |
| 716 | * @param mx_ the map's x-coordinate to iterate over |
| 717 | * @param my_ the map's y-coordinate to iterate over |
| 718 | * @param it_ a variable name that holds the inventory objects; a new variable |
| 719 | * will be declared; modifications do not affect the loop |
| 720 | */ |
| 721 | #define FOR_MAP_PREPARE(map_, mx_, my_, it_) \ |
| 722 | do { \ |
| 723 | object *it_ = GET_MAP_OB((map_), (mx_), (my_)); \ |
| 724 | FOR_OB_AND_ABOVE_PREPARE(it_); |
| 725 | /** |
| 726 | * Finishes #FOR_MAP_PREPARE(). |
| 727 | */ |
| 728 | #define FOR_MAP_FINISH() \ |
| 729 | FOR_OB_AND_ABOVE_FINISH(); \ |
| 730 | } while(0) |
| 731 | |
| 732 | /** |
| 733 | * Constructs a loop iterating over an object and all objects above it in the |
| 734 | * same pile. |
| 735 | * @param op_ the object to start with |
| 736 | */ |
| 737 | #define FOR_OB_AND_ABOVE_PREPARE(op_) FOR_OB_PREPARE(op_, above, __LINE__) |
| 738 | /** |
| 739 | * Finishes #FOR_OB_AND_ABOVE_PREPARE(). |
| 740 | */ |
| 741 | #define FOR_OB_AND_ABOVE_FINISH() FOR_OB_FINISH() |
| 742 | |
| 743 | /** |
| 744 | * Constructs a loop iterating over an object and all objects below it in the |
| 745 | * same pile. |
| 746 | * @param op_ the object to start with |
| 747 | */ |
| 748 | #define FOR_OB_AND_BELOW_PREPARE(op_) FOR_OB_PREPARE(op_, below, __LINE__) |
| 749 | /** |
| 750 | * Finishes #FOR_OB_AND_BELOW_PREPARE(). |
| 751 | */ |
| 752 | #define FOR_OB_AND_BELOW_FINISH() FOR_OB_FINISH() |
| 753 | |
| 754 | /** |
| 755 | * Constructs a loop iterating over a set of objects. This function should not |
| 756 | * be used directly in client code. |
| 757 | * @param op_ the object start start with |
| 758 | * @param field_ the field that holds the "next" pointer within op_ |
| 759 | * @param suffix_ a suffix for constructing unique variable names |
| 760 | */ |
| 761 | #define FOR_OB_PREPARE(op_, field_, suffix_) FOR_OB_PREPARE2(op_, field_, suffix_) |
| 762 | /** |
| 763 | * Constructs a loop iterating over a set of objects. This function should not |
| 764 | * be used at all. Use FOR_OB_PREPARE() instead. |
| 765 | * @param op_ the object start start with |
| 766 | * @param field_ the field that holds the "next" pointer within op_ |
| 767 | * @param suffix_ a suffix for constructing unique variable names |
| 768 | */ |
| 769 | #define FOR_OB_PREPARE2(op_, field_, suffix_) \ |
| 770 | do { \ |
| 771 | object *next##suffix_ = (op_); \ |
| 772 | tag_t next_tag##suffix_ = next##suffix_ == NULL ? 0 : next##suffix_->count;\ |
| 773 | while (((op_) = next##suffix_) != NULL) { \ |
| 774 | if (object_was_destroyed(next##suffix_, next_tag##suffix_)) {\ |
| 775 | break; \ |
| 776 | } \ |
| 777 | next##suffix_ = next##suffix_->field_; \ |
| 778 | next_tag##suffix_ = next##suffix_ == NULL ? 0 : next##suffix_->count; |
| 779 | /** |
| 780 | * Finishes #FOR_OB_PREPARE(). |
| 781 | */ |
| 782 | #define FOR_OB_FINISH() \ |
| 783 | } \ |
| 784 | } while(0) |
| 785 | |
| 786 | #endif /* DEFINE_H */ |