49 #if !defined(__STDC__)
53 error - Your ANSI C compiler should be defining
__STDC__;
61 #define FABS(x) ((x) < 0 ? -(x) : (x))
64 #include <sys/param.h>
67 #define MIN(x, y) ((x) < (y) ? (x) : (y))
70 #define MAX(x, y) ((x) > (y) ? (x) : (y))
82 #define VERY_BIG_BUF 1024
85 #define MAX_ANIMATIONS 256
94 #define OUT_OF_MEMORY 0
96 #define ARCHTABLE_TOO_SMALL 2
132 #define LOCKED_DOOR 20
133 #define SPECIAL_KEY 21
138 #define TIMED_GATE 26
140 #define GRIMREAPER 28
142 #define TRIGGER_BUTTON 30
143 #define TRIGGER_ALTAR 31
144 #define TRIGGER_PEDESTAL 32
153 #define PLAYERMOVER 40
154 #define TELEPORTER 41
157 #define EXPERIENCE 44
165 #define THROWN_OBJ 48
173 #define TRIGGER_MARKER 52
176 #define DEAD_OBJECT 53
181 #define HOLY_ALTAR 56
182 #define PLAYER_CHANGER 57
183 #define BATTLEGROUND 58
185 #define PEACEMAKER 59
193 #define MOOD_FLOOR 65
206 #define SHOP_FLOOR 68
212 #define SKILL_TOOL 74
223 #define MISC_OBJECT 79
233 #define DUPLICATOR 83
253 #define SPELL_EFFECT 102
254 #define CONVERTER 103
256 #define POISONING 105
266 #define POTION_EFFECT 115
268 #define EVENT_CONNECTOR 116
270 #define CLOSE_CON 121
272 #define CONTAINER 122
273 #define ARMOUR_IMPROVER 123
274 #define WEAPON_IMPROVER 124
279 #define SKILLSCROLL 130
281 #define DEEP_SWAMP 138
282 #define IDENTIFY_ALTAR 139
284 #define SHOP_INVENTORY 150
292 #define POWER_CRYSTAL 156
302 #define OBJECT_TYPE_MAX 162
310 #define ST_BD_BUILD 1
311 #define ST_BD_REMOVE 2
318 #define ST_MAT_FLOOR 1
319 #define ST_MAT_WALL 2
320 #define ST_MAT_ITEM 3
321 #define ST_MAT_WINDOW 4
330 #define WEAP_PIERCE 2
331 #define WEAP_CLEAVE 3
357 #define PU_NOTHING 0x00000000
359 #define PU_DEBUG 0x10000000
360 #define PU_INHIBIT 0x20000000
361 #define PU_STOP 0x40000000
362 #define PU_NEWMODE 0x80000000
364 #define PU_RATIO 0x0000000F
366 #define PU_FOOD 0x00000010
367 #define PU_DRINK 0x00000020
368 #define PU_VALUABLES 0x00000040
369 #define PU_BOW 0x00000080
371 #define PU_ARROW 0x00000100
372 #define PU_HELMET 0x00000200
373 #define PU_SHIELD 0x00000400
374 #define PU_ARMOUR 0x00000800
376 #define PU_BOOTS 0x00001000
377 #define PU_GLOVES 0x00002000
378 #define PU_CLOAK 0x00004000
379 #define PU_KEY 0x00008000
381 #define PU_MISSILEWEAPON 0x00010000
382 #define PU_ALLWEAPON 0x00020000
383 #define PU_MAGICAL 0x00040000
384 #define PU_POTION 0x00080000
386 #define PU_SPELLBOOK 0x00100000
387 #define PU_SKILLSCROLL 0x00200000
388 #define PU_READABLES 0x00400000
389 #define PU_MAGIC_DEVICE 0x00800000
391 #define PU_NOT_CURSED 0x01000000
392 #define PU_JEWELS 0x02000000
393 #define PU_FLESH 0x04000000
402 #define SIZEOFFREE1 8
403 #define SIZEOFFREE2 24
404 #define SIZEOFFREE 49
406 #define NROF_SOUNDS (23+NROFREALSPELLS)
412 #define IS_WEAPON(op) \
413 (op->type == ARROW || op->type == BOW || op->type == WEAPON)
415 #define IS_ARMOR(op) \
416 (op->type == ARMOUR || op->type == HELMET || \
417 op->type == BOOTS || op->type == GLOVES)
419 #define IS_SHIELD(op) \
422 #define IS_LIVE(op) \
423 ((op->type == PLAYER || QUERY_FLAG(op, FLAG_MONSTER) || \
424 (QUERY_FLAG(op, FLAG_ALIVE) && !QUERY_FLAG(op, FLAG_GENERATOR) && \
425 !op->type == DOOR)) && (!QUERY_FLAG(op, FLAG_IS_A_TEMPLATE)))
427 #define IS_ARROW(op) \
428 (op->type == ARROW || \
429 (op->type == SPELL_EFFECT && (op->subtype == SP_BULLET || op->subtype == SP_MAGIC_MISSILE)))
433 #define HAS_RANDOM_ITEMS(op) (op->randomitems && (!QUERY_FLAG(op, FLAG_IS_A_TEMPLATE)))
473 #define SET_FLAG(xyz, p) \
474 ((xyz)->flags[p/32] |= (1U<<(p%32)))
475 #define CLEAR_FLAG(xyz, p) \
476 ((xyz)->flags[p/32] &= ~(1U<<(p%32)))
477 #define QUERY_FLAG(xyz, p) \
478 ((xyz)->flags[p/32]&(1U<<(p%32)))
479 #define COMPARE_FLAGS(p, q) \
481 ((p)->flags[0] == (q)->flags[0]) && \
482 ((p)->flags[1] == (q)->flags[1]) && \
483 ((p)->flags[2] == (q)->flags[2]) && \
484 ((p)->flags[3] == (q)->flags[3]) \
491 #define FLAG_REMOVED 2
493 #define FLAG_WAS_WIZ 4
494 #define FLAG_APPLIED 5
495 #define FLAG_UNPAID 6
496 #define FLAG_USE_SHIELD 7
498 #define FLAG_NO_PICK 8
499 #define FLAG_CLIENT_ANIM_SYNC 9
500 #define FLAG_CLIENT_ANIM_RANDOM 10
501 #define FLAG_ANIMATE 11
502 #define FLAG_DIALOG_PARSED 12
504 #define FLAG_MONSTER 14
505 #define FLAG_FRIENDLY 15
507 #define FLAG_GENERATOR 16
508 #define FLAG_IS_THROWN 17
509 #define FLAG_AUTO_APPLY 18
510 #define FLAG_TREASURE 19
511 #define FLAG_PLAYER_SOLD 20
512 #define FLAG_SEE_INVISIBLE 21
513 #define FLAG_CAN_ROLL 22
514 #define FLAG_OVERLAY_FLOOR 23
515 #define FLAG_IS_TURNABLE 24
519 #define FLAG_IS_USED_UP 28
520 #define FLAG_IDENTIFIED 29
521 #define FLAG_REFLECTING 30
522 #define FLAG_CHANGING 31
525 #define FLAG_SPLITTING 32
526 #define FLAG_HITBACK 33
527 #define FLAG_STARTEQUIP 34
528 #define FLAG_BLOCKSVIEW 35
529 #define FLAG_UNDEAD 36
530 #define FLAG_SCARED 37
531 #define FLAG_UNAGGRESSIVE 38
532 #define FLAG_REFL_MISSILE 39
534 #define FLAG_REFL_SPELL 40
535 #define FLAG_NO_MAGIC 41
536 #define FLAG_NO_FIX_PLAYER 42
537 #define FLAG_IS_LIGHTABLE 43
538 #define FLAG_TEAR_DOWN 44
539 #define FLAG_RUN_AWAY 45
546 #define FLAG_UNIQUE 49
547 #define FLAG_NO_DROP 50
548 #define FLAG_WIZCAST 51
549 #define FLAG_CAST_SPELL 52
550 #define FLAG_USE_SCROLL 53
551 #define FLAG_USE_RANGE 54
552 #define FLAG_USE_BOW 55
554 #define FLAG_USE_ARMOUR 56
555 #define FLAG_USE_WEAPON 57
556 #define FLAG_USE_RING 58
557 #define FLAG_READY_RANGE 59
558 #define FLAG_READY_BOW 60
559 #define FLAG_XRAYS 61
560 #define FLAG_NO_APPLY 62
561 #define FLAG_IS_FLOOR 63
564 #define FLAG_LIFESAVE 64
565 #define FLAG_NO_STRENGTH 65
566 #define FLAG_SLEEP 66
567 #define FLAG_STAND_STILL 67
568 #define FLAG_RANDOM_MOVE 68
569 #define FLAG_ONLY_ATTACK 69
570 #define FLAG_CONFUSED 70
571 #define FLAG_STEALTH 71
573 #define FLAG_WIZPASS 72
574 #define FLAG_IS_LINKED 73
575 #define FLAG_CURSED 74
576 #define FLAG_DAMNED 75
577 #define FLAG_SEE_ANYWHERE 76
578 #define FLAG_KNOWN_MAGICAL 77
579 #define FLAG_KNOWN_CURSED 78
580 #define FLAG_CAN_USE_SKILL 79
582 #define FLAG_BEEN_APPLIED 80
583 #define FLAG_READY_SCROLL 81
584 #define FLAG_USE_ROD 82
586 #define FLAG_USE_HORN 84
587 #define FLAG_MAKE_INVIS 85
588 #define FLAG_INV_LOCKED 86
589 #define FLAG_IS_WOODED 87
591 #define FLAG_IS_HILLY 88
592 #define FLAG_READY_SKILL 89
593 #define FLAG_READY_WEAPON 90
594 #define FLAG_NO_SKILL_IDENT 91
595 #define FLAG_BLIND 92
596 #define FLAG_SEE_IN_DARK 93
597 #define FLAG_IS_CAULDRON 94
601 #define FLAG_NO_STEAL 96
602 #define FLAG_ONE_HIT 97
605 #define FLAG_CLIENT_SENT 98
611 #define FLAG_BERSERK 99
613 #define FLAG_NEUTRAL 100
614 #define FLAG_NO_ATTACK 101
615 #define FLAG_NO_DAMAGE 102
616 #define FLAG_OBJ_ORIGINAL 103
621 #define FLAG_ACTIVATE_ON_PUSH 105
622 #define FLAG_ACTIVATE_ON_RELEASE 106
623 #define FLAG_IS_WATER 107
624 #define FLAG_CONTENT_ON_GEN 108
625 #define FLAG_IS_A_TEMPLATE 109
626 #define FLAG_IS_BUILDABLE 110
628 #define FLAG_BLESSED 112
629 #define FLAG_KNOWN_BLESSED 113
630 #define NUM_FLAGS 113
638 #define NROFNEWOBJS(xyz) ((xyz)->stats.food)
650 #define MOVE_WALK 0x1
651 #define MOVE_FLY_LOW 0x2
652 #define MOVE_FLY_HIGH 0x4
653 #define MOVE_FLYING 0x6
654 #define MOVE_SWIM 0x8
655 #define MOVE_BOAT 0x10
656 #define MOVE_ALL 0x1f
667 #define MOVE_BLOCK_DEFAULT MOVE_SWIM
681 #define OB_MOVE_BLOCK(ob1, ob2) \
682 ((ob1->move_type&ob2->move_block) == ob1->move_type)
690 #define OB_TYPE_MOVE_BLOCK(ob1, type) \
691 ((type != 0) && (ob1->move_type&type) == ob1->move_type)
694 #define SET_GENERATE_TYPE(xyz, va) (xyz)->stats.sp = (va)
695 #define GENERATE_TYPE(xyz) ((xyz)->stats.sp)
696 #define GENERATE_SPEED(xyz) ((xyz)->stats.maxsp)
698 #define EXIT_PATH(xyz) (xyz)->slaying
699 #define EXIT_LEVEL(xyz) (xyz)->stats.food
700 #define EXIT_X(xyz) (xyz)->stats.hp
701 #define EXIT_Y(xyz) (xyz)->stats.sp
702 #define EXIT_ALT_X(xyz) (xyz)->stats.maxhp
703 #define EXIT_ALT_Y(xyz) (xyz)->stats.maxsp
709 #define MAX_LIGHT_RADII 4
713 #define MAX_DARKNESS 5
718 #define MAX_WEAPON_ITEM_POWER 100
728 #define F_NO_BARGAIN 4
729 #define F_IDENTIFIED 8
730 #define F_NOT_CURSED 16
735 #define DIRX(xyz) freearr_x[(xyz)->direction]
736 #define DIRY(xyz) freearr_y[(xyz)->direction]
738 #define ARMOUR_SPEED(xyz) (xyz)->last_sp
739 #define ARMOUR_SPELLS(xyz) (xyz)->gen_sp_armour
740 #define WEAPON_SPEED(xyz) (xyz)->last_sp
815 #define ST_PLAY_AGAIN 1
816 #define ST_ROLL_STAT 2
817 #define ST_CHANGE_CLASS 3
818 #define ST_CONFIRM_QUIT 4
819 #define ST_GET_NAME 6
820 #define ST_GET_PASSWORD 7
821 #define ST_CONFIRM_PASSWORD 8
822 #define ST_GET_PARTY_PASSWORD 10
823 #define ST_CHANGE_PASSWORD_OLD 11
824 #define ST_CHANGE_PASSWORD_NEW 12
825 #define ST_CHANGE_PASSWORD_CONFIRM 13
828 #define BLANK_FACE_NAME "blank.111"
829 #define EMPTY_FACE_NAME "empty.111"
830 #define SMOOTH_FACE_NAME "default_smoothed.111"
836 #define PREFER_HIGH 1
852 static inline void safe_strcat(
char *dest,
const char *orig,
size_t *curlen,
size_t maxlen) {
853 if (*curlen == (maxlen-1))
855 strncpy(dest+*curlen, orig, maxlen-*curlen-1);
857 *curlen += strlen(orig);
858 if (*curlen > (maxlen-1))
867 #define DESCRIBE_ABILITY_SAFE(retbuf, variable, name, len, maxlen) \
870 safe_strcat(retbuf, "(" name ": ", len, maxlen); \
871 for (i = 0; i < NROFATTACKS; i++) \
872 if (variable&(1<<i)) { \
874 safe_strcat(retbuf, ", ", len, maxlen); \
877 safe_strcat(retbuf, attacks[i], len, maxlen); \
879 safe_strcat(retbuf, ")", len, maxlen); \
884 #define DESCRIBE_ABILITY(retbuf, variable, name) \
887 strcat(retbuf, "(" name ": "); \
888 for (i = 0; i < NROFATTACKS; i++) \
889 if (variable&(1<<i)) { \
891 strcat(retbuf, ", "); \
894 strcat(retbuf, attacks[i]); \
896 strcat(retbuf, ")"); \
899 #define DESCRIBE_PATH(retbuf, variable, name) \
902 strcat(retbuf, "(" name ": "); \
903 for (i = 0; i < NRSPELLPATHS; i++) \
904 if (variable&(1<<i)) { \
906 strcat(retbuf, ", "); \
909 strcat(retbuf, spellpathnames[i]); \
911 strcat(retbuf, ")"); \
914 #define DESCRIBE_PATH_SAFE(retbuf, variable, name, len, maxlen) \
917 safe_strcat(retbuf, "(" name ": ", len, maxlen); \
918 for (i = 0; i < NRSPELLPATHS; i++) \
919 if (variable&(1<<i)) { \
921 safe_strcat(retbuf, ", ", len, maxlen); \
924 safe_strcat(retbuf, spellpathnames[i], len, maxlen); \
926 safe_strcat(retbuf, ")", len, maxlen); \
940 #define AP_BASIC_FLAGS 15
943 #define AP_NO_MERGE 16
944 #define AP_IGNORE_CURSE 32
947 #define AP_NOPRINT 128
980 #define CAN_APPLY_NEVER 0x1
981 #define CAN_APPLY_RESTRICTION 0x2
982 #define CAN_APPLY_NOT_MASK 0xf
983 #define CAN_APPLY_UNAPPLY 0x10
984 #define CAN_APPLY_UNAPPLY_MULT 0x20
985 #define CAN_APPLY_UNAPPLY_CHOICE 0x40
989 #define MIN_ACTIVE_SPEED 0.00001
1004 #define RANDOM() random()
1005 #define SRANDOM(xyz) srandom(xyz)
1007 # ifdef HAVE_SRAND48
1008 # define RANDOM() lrand48()
1009 # define SRANDOM(xyz) srand48(xyz)
1012 # define RANDOM() rand()
1013 # define SRANDOM(xyz) srand(xyz)
1015 # error "Could not find a usable random routine"
1024 #define WEIGHT(op) (op->nrof ? op->weight : op->weight+op->carrying)
1039 #define PREPARE_FASTCAT(buf__) buf__+strlen(buf__)
1040 #define FAST_STRNCAT(buf__, buf2__, size__) { memcpy(buf__, buf2__, size__); buf__ += size__; }
1041 #define FAST_STRCAT(buf__, buf2__) { memcpy(buf__, buf2__, strlen(buf2__)); buf__ += strlen(buf2__); }
1042 #define FINISH_FASTCAT(buf__) buf__[0] = '\0';
static void safe_strcat(char *dest, const char *orig, size_t *curlen, size_t maxlen)
error Your ANSI C compiler should be defining __STDC__