OSDN Git Service

fix #42547
[jnethack/source.git] / include / hack.h
1 /* NetHack 3.6  hack.h  $NHDT-Date: 1561019041 2019/06/20 08:24:01 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.106 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Pasi Kallinen, 2017. */
4 /* NetHack may be freely redistributed.  See license for details. */
5
6 #ifndef HACK_H
7 #define HACK_H
8
9 #ifndef CONFIG_H
10 #include "config.h"
11 #endif
12 #include "lint.h"
13
14 #define TELL 1
15 #define NOTELL 0
16 #define ON 1
17 #define OFF 0
18 #define BOLT_LIM 8        /* from this distance ranged attacks will be made */
19 #define MAX_CARR_CAP 1000 /* so that boulders can be heavier */
20 #define DUMMY { 0 }       /* array initializer, letting [1..N-1] default */
21
22 /* symbolic names for capacity levels */
23 enum encumbrance_types {
24     UNENCUMBERED = 0,
25     SLT_ENCUMBER = 1, /* Burdened */
26     MOD_ENCUMBER = 2, /* Stressed */
27     HVY_ENCUMBER = 3, /* Strained */
28     EXT_ENCUMBER = 4, /* Overtaxed */
29     OVERLOADED   = 5  /* Overloaded */
30 };
31
32 /* weight increment of heavy iron ball */
33 #define IRON_BALL_W_INCR 160
34
35 /* number of turns it takes for vault guard to show up */
36 #define VAULT_GUARD_TIME 30
37
38 #define SHOP_DOOR_COST 400L /* cost of a destroyed shop door */
39 #define SHOP_BARS_COST 300L /* cost of iron bars */
40 #define SHOP_HOLE_COST 200L /* cost of making hole/trapdoor */
41 #define SHOP_WALL_COST 200L /* cost of destroying a wall */
42 #define SHOP_WALL_DMG  (10L * ACURRSTR) /* damaging a wall */
43
44 /* hunger states - see hu_stat in eat.c */
45 enum hunger_state_types {
46     SATIATED   = 0,
47     NOT_HUNGRY = 1,
48     HUNGRY     = 2,
49     WEAK       = 3,
50     FAINTING   = 4,
51     FAINTED    = 5,
52     STARVED    = 6
53 };
54
55 /* Macros for how a rumor was delivered in outrumor() */
56 #define BY_ORACLE 0
57 #define BY_COOKIE 1
58 #define BY_PAPER 2
59 #define BY_OTHER 9
60
61 /* Macros for why you are no longer riding */
62 enum dismount_types {
63     DISMOUNT_GENERIC  = 0,
64     DISMOUNT_FELL     = 1,
65     DISMOUNT_THROWN   = 2,
66     DISMOUNT_POLY     = 3,
67     DISMOUNT_ENGULFED = 4,
68     DISMOUNT_BONES    = 5,
69     DISMOUNT_BYCHOICE = 6
70 };
71
72 /* mgflags for mapglyph() */
73 #define MG_FLAG_NORMAL     0x00
74 #define MG_FLAG_NOOVERRIDE 0x01
75
76 /* Special returns from mapglyph() */
77 #define MG_CORPSE  0x01
78 #define MG_INVIS   0x02
79 #define MG_DETECT  0x04
80 #define MG_PET     0x08
81 #define MG_RIDDEN  0x10
82 #define MG_STATUE  0x20
83 #define MG_OBJPILE 0x40  /* more than one stack of objects */
84 #define MG_BW_LAVA 0x80  /* 'black & white lava': highlight lava if it
85                             can't be distringuished from water by color */
86
87 /* sellobj_state() states */
88 #define SELL_NORMAL (0)
89 #define SELL_DELIBERATE (1)
90 #define SELL_DONTSELL (2)
91
92 /* alteration types--keep in synch with costly_alteration(mkobj.c) */
93 enum cost_alteration_types {
94     COST_CANCEL  =  0, /* standard cancellation */
95     COST_DRAIN   =  1, /* drain life upon an object */
96     COST_UNCHRG  =  2, /* cursed charging */
97     COST_UNBLSS  =  3, /* unbless (devalues holy water) */
98     COST_UNCURS  =  4, /* uncurse (devalues unholy water) */
99     COST_DECHNT  =  5, /* disenchant weapons or armor */
100     COST_DEGRD   =  6, /* removal of rustproofing, dulling via engraving */
101     COST_DILUTE  =  7, /* potion dilution */
102     COST_ERASE   =  8, /* scroll or spellbook blanking */
103     COST_BURN    =  9, /* dipped into flaming oil */
104     COST_NUTRLZ  = 10, /* neutralized via unicorn horn */
105     COST_DSTROY  = 11, /* wand breaking (bill first, useup later) */
106     COST_SPLAT   = 12, /* cream pie to own face (ditto) */
107     COST_BITE    = 13, /* start eating food */
108     COST_OPEN    = 14, /* open tin */
109     COST_BRKLCK  = 15, /* break box/chest's lock */
110     COST_RUST    = 16, /* rust damage */
111     COST_ROT     = 17, /* rotting attack */
112     COST_CORRODE = 18 /* acid damage */
113 };
114
115 /* bitmask flags for corpse_xname();
116    PFX_THE takes precedence over ARTICLE, NO_PFX takes precedence over both */
117 #define CXN_NORMAL 0    /* no special handling */
118 #define CXN_SINGULAR 1  /* override quantity if greather than 1 */
119 #define CXN_NO_PFX 2    /* suppress "the" from "the Unique Monst */
120 #define CXN_PFX_THE 4   /* prefix with "the " (unless pname) */
121 #define CXN_ARTICLE 8   /* include a/an/the prefix */
122 #define CXN_NOCORPSE 16 /* suppress " corpse" suffix */
123
124 /* getpos() return values */
125 enum getpos_retval {
126     LOOK_TRADITIONAL = 0, /* '.' -- ask about "more info?" */
127     LOOK_QUICK       = 1, /* ',' -- skip "more info?" */
128     LOOK_ONCE        = 2, /* ';' -- skip and stop looping */
129     LOOK_VERBOSE     = 3  /* ':' -- show more info w/o asking */
130 };
131
132 /*
133  * This is the way the game ends.  If these are rearranged, the arrays
134  * in end.c and topten.c will need to be changed.  Some parts of the
135  * code assume that PANIC separates the deaths from the non-deaths.
136  */
137 enum game_end_types {
138     DIED         =  0,
139     CHOKING      =  1,
140     POISONING    =  2,
141     STARVING     =  3,
142     DROWNING     =  4,
143     BURNING      =  5,
144     DISSOLVED    =  6,
145     CRUSHING     =  7,
146     STONING      =  8,
147     TURNED_SLIME =  9,
148     GENOCIDED    = 10,
149     PANICKED     = 11,
150     TRICKED      = 12,
151     QUIT         = 13,
152     ESCAPED      = 14,
153     ASCENDED     = 15
154 };
155
156 typedef struct strbuf {
157     int    len;
158     char * str;
159     char   buf[256];
160 } strbuf_t;
161
162 #include "align.h"
163 #include "dungeon.h"
164 #include "monsym.h"
165 #include "mkroom.h"
166 #include "objclass.h"
167 #include "youprop.h"
168 #include "wintype.h"
169 #include "context.h"
170 #include "decl.h"
171 #include "timeout.h"
172
173 NEARDATA extern coord bhitpos; /* place where throw or zap hits or stops */
174
175 /* types of calls to bhit() */
176 enum bhit_call_types {
177     ZAPPED_WAND   = 0,
178     THROWN_WEAPON = 1,
179     THROWN_TETHERED_WEAPON = 2,
180     KICKED_WEAPON = 3,
181     FLASHED_LIGHT = 4,
182     INVIS_BEAM    = 5
183 };
184
185 /* attack mode for hmon() */
186 enum hmon_atkmode_types {
187     HMON_MELEE   = 0, /* hand-to-hand */
188     HMON_THROWN  = 1, /* normal ranged (or spitting while poly'd) */
189     HMON_KICKED  = 2, /* alternate ranged */
190     HMON_APPLIED = 3, /* polearm, treated as ranged */
191     HMON_DRAGGED = 4  /* attached iron ball, pulled into mon */
192 };
193
194 /* sortloot() return type; needed before extern.h */
195 struct sortloot_item {
196     struct obj *obj;
197     char *str; /* result of loot_xname(obj) in some cases, otherwise null */
198     int indx; /* signed int, because sortloot()'s qsort comparison routine
199                  assumes (a->indx - b->indx) might yield a negative result */
200     xchar orderclass; /* order rather than object class; 0 => not yet init'd */
201     xchar subclass; /* subclass for some classes */
202     xchar disco; /* discovery status */
203 };
204 typedef struct sortloot_item Loot;
205
206 #define MATCH_WARN_OF_MON(mon)                                               \
207     (Warn_of_mon && ((context.warntype.obj                                   \
208                       && (context.warntype.obj & (mon)->data->mflags2))      \
209                      || (context.warntype.polyd                              \
210                          && (context.warntype.polyd & (mon)->data->mflags2)) \
211                      || (context.warntype.species                            \
212                          && (context.warntype.species == (mon)->data))))
213
214 #include "trap.h"
215 #include "flag.h"
216 #include "rm.h"
217 #include "vision.h"
218 #include "display.h"
219 #include "engrave.h"
220 #include "rect.h"
221 #include "region.h"
222
223 /* Symbol offsets */
224 #define SYM_OFF_P (0)
225 #define SYM_OFF_O (SYM_OFF_P + MAXPCHARS)
226 #define SYM_OFF_M (SYM_OFF_O + MAXOCLASSES)
227 #define SYM_OFF_W (SYM_OFF_M + MAXMCLASSES)
228 #define SYM_OFF_X (SYM_OFF_W + WARNCOUNT)
229 #define SYM_MAX (SYM_OFF_X + MAXOTHER)
230
231 #ifdef USE_TRAMPOLI /* this doesn't belong here, but we have little choice */
232 #undef NDECL
233 #define NDECL(f) f()
234 #endif
235
236 #include "extern.h"
237 #include "winprocs.h"
238 #include "sys.h"
239
240 #ifdef USE_TRAMPOLI
241 #include "wintty.h"
242 #undef WINTTY_H
243 #include "trampoli.h"
244 #undef EXTERN_H
245 #include "extern.h"
246 #endif /* USE_TRAMPOLI */
247
248 /* flags to control makemon(); goodpos() uses some plus has some of its own */
249 #define NO_MM_FLAGS 0x00000 /* use this rather than plain 0 */
250 #define NO_MINVENT  0x00001 /* suppress minvent when creating mon */
251 #define MM_NOWAIT   0x00002 /* don't set STRAT_WAITMASK flags */
252 #define MM_NOCOUNTBIRTH 0x00004 /* don't increment born count (for revival) */
253 #define MM_IGNOREWATER  0x00008 /* ignore water when positioning */
254 #define MM_ADJACENTOK   0x00010 /* acceptable to use adjacent coordinates */
255 #define MM_ANGRY    0x00020 /* monster is created angry */
256 #define MM_NONAME   0x00040 /* monster is not christened */
257 #define MM_EGD      0x00100 /* add egd structure */
258 #define MM_EPRI     0x00200 /* add epri structure */
259 #define MM_ESHK     0x00400 /* add eshk structure */
260 #define MM_EMIN     0x00800 /* add emin structure */
261 #define MM_EDOG     0x01000 /* add edog structure */
262 #define MM_ASLEEP   0x02000 /* monsters should be generated asleep */
263 #define MM_NOGRP    0x04000 /* suppress creation of monster groups */
264 /* if more MM_ flag masks are added, skip or renumber the GP_ one(s) */
265 #define GP_ALLOW_XY 0x08000 /* [actually used by enexto() to decide whether
266                              * to make an extra call to goodpos()]          */
267
268 /* flags for make_corpse() and mkcorpstat() */
269 #define CORPSTAT_NONE 0x00
270 #define CORPSTAT_INIT 0x01   /* pass init flag to mkcorpstat */
271 #define CORPSTAT_BURIED 0x02 /* bury the corpse or statue */
272
273 /* flags for decide_to_shift() */
274 #define SHIFT_SEENMSG 0x01 /* put out a message if in sight */
275 #define SHIFT_MSG 0x02     /* always put out a message */
276
277 /* flags for deliver_obj_to_mon */
278 #define DF_NONE     0x00
279 #define DF_RANDOM   0x01
280 #define DF_ALL      0x04
281
282 /* special mhpmax value when loading bones monster to flag as extinct or
283  * genocided */
284 #define DEFUNCT_MONSTER (-100)
285
286 /* macro form of adjustments of physical damage based on Half_physical_damage.
287  * Can be used on-the-fly with the 1st parameter to losehp() if you don't
288  * need to retain the dmg value beyond that call scope.
289  * Take care to ensure it doesn't get used more than once in other instances.
290  */
291 #define Maybe_Half_Phys(dmg) \
292     ((Half_physical_damage) ? (((dmg) + 1) / 2) : (dmg))
293
294 /* flags for special ggetobj status returns */
295 #define ALL_FINISHED 0x01 /* called routine already finished the job */
296
297 /* flags to control query_objlist() */
298 #define BY_NEXTHERE     0x01   /* follow objlist by nexthere field */
299 #define AUTOSELECT_SINGLE 0x02 /* if only 1 object, don't ask */
300 #define USE_INVLET      0x04   /* use object's invlet */
301 #define INVORDER_SORT   0x08   /* sort objects by packorder */
302 #define SIGNAL_NOMENU   0x10   /* return -1 rather than 0 if none allowed */
303 #define SIGNAL_ESCAPE   0x20   /* return -2 rather than 0 for ESC */
304 #define FEEL_COCKATRICE 0x40   /* engage cockatrice checks and react */
305 #define INCLUDE_HERO    0x80   /* show hero among engulfer's inventory */
306
307 /* Flags to control query_category() */
308 /* BY_NEXTHERE used by query_category() too, so skip 0x01 */
309 #define UNPAID_TYPES 0x002
310 #define GOLD_TYPES   0x004
311 #define WORN_TYPES   0x008
312 #define ALL_TYPES    0x010
313 #define BILLED_TYPES 0x020
314 #define CHOOSE_ALL   0x040
315 #define BUC_BLESSED  0x080
316 #define BUC_CURSED   0x100
317 #define BUC_UNCURSED 0x200
318 #define BUC_UNKNOWN  0x400
319 #define BUC_ALLBKNOWN (BUC_BLESSED | BUC_CURSED | BUC_UNCURSED)
320 #define BUCX_TYPES (BUC_ALLBKNOWN | BUC_UNKNOWN)
321 #define ALL_TYPES_SELECTED -2
322
323 /* Flags to control find_mid() */
324 #define FM_FMON 0x01    /* search the fmon chain */
325 #define FM_MIGRATE 0x02 /* search the migrating monster chain */
326 #define FM_MYDOGS 0x04  /* search mydogs */
327 #define FM_EVERYWHERE (FM_FMON | FM_MIGRATE | FM_MYDOGS)
328
329 /* Flags to control pick_[race,role,gend,align] routines in role.c */
330 #define PICK_RANDOM 0
331 #define PICK_RIGID 1
332
333 /* Flags to control dotrap() in trap.c */
334 #define FORCETRAP 0x01     /* triggering not left to chance */
335 #define NOWEBMSG 0x02      /* suppress stumble into web message */
336 #define FORCEBUNGLE 0x04   /* adjustments appropriate for bungling */
337 #define RECURSIVETRAP 0x08 /* trap changed into another type this same turn */
338 #define TOOKPLUNGE 0x10    /* used '>' to enter pit below you */
339 #define VIASITTING 0x20    /* #sit while at trap location (affects message) */
340 #define FAILEDUNTRAP 0x40  /* trap activated by failed untrap attempt */
341
342 /* Flags to control test_move in hack.c */
343 #define DO_MOVE 0   /* really doing the move */
344 #define TEST_MOVE 1 /* test a normal move (move there next) */
345 #define TEST_TRAV 2 /* test a future travel location */
346 #define TEST_TRAP 3 /* check if a future travel loc is a trap */
347
348 /*** some utility macros ***/
349 #define yn(query) yn_function(query, ynchars, 'n')
350 #define ynq(query) yn_function(query, ynqchars, 'q')
351 #define ynaq(query) yn_function(query, ynaqchars, 'y')
352 #define nyaq(query) yn_function(query, ynaqchars, 'n')
353 #define nyNaq(query) yn_function(query, ynNaqchars, 'n')
354 #define ynNaq(query) yn_function(query, ynNaqchars, 'y')
355
356 /* Macros for scatter */
357 #define VIS_EFFECTS 0x01 /* display visual effects */
358 #define MAY_HITMON 0x02  /* objects may hit monsters */
359 #define MAY_HITYOU 0x04  /* objects may hit you */
360 #define MAY_HIT (MAY_HITMON | MAY_HITYOU)
361 #define MAY_DESTROY 0x08  /* objects may be destroyed at random */
362 #define MAY_FRACTURE 0x10 /* boulders & statues may fracture */
363
364 /* Macros for launching objects */
365 #define ROLL 0x01          /* the object is rolling */
366 #define FLING 0x02         /* the object is flying thru the air */
367 #define LAUNCH_UNSEEN 0x40 /* hero neither caused nor saw it */
368 #define LAUNCH_KNOWN 0x80  /* the hero caused this by explicit action */
369
370 /* Macros for explosion types */
371 enum explosion_types {
372     EXPL_DARK    = 0,
373     EXPL_NOXIOUS = 1,
374     EXPL_MUDDY   = 2,
375     EXPL_WET     = 3,
376     EXPL_MAGICAL = 4,
377     EXPL_FIERY   = 5,
378     EXPL_FROSTY  = 6,
379     EXPL_MAX     = 7
380 };
381
382 /* enlightenment control flags */
383 #define BASICENLIGHTENMENT 1 /* show mundane stuff */
384 #define MAGICENLIGHTENMENT 2 /* show intrinsics and such */
385 #define ENL_GAMEINPROGRESS 0
386 #define ENL_GAMEOVERALIVE  1 /* ascension, escape, quit, trickery */
387 #define ENL_GAMEOVERDEAD   2
388
389 /* control flags for sortloot() */
390 #define SORTLOOT_PACK   0x01
391 #define SORTLOOT_INVLET 0x02
392 #define SORTLOOT_LOOT   0x04
393 #define SORTLOOT_PETRIFY 0x20 /* override filter func for c-trice corpses */
394
395 /* flags for xkilled() [note: meaning of first bit used to be reversed,
396    1 to give message and 0 to suppress] */
397 #define XKILL_GIVEMSG   0
398 #define XKILL_NOMSG     1
399 #define XKILL_NOCORPSE  2
400 #define XKILL_NOCONDUCT 4
401
402 /* pline_flags; mask values for custompline()'s first argument */
403 /* #define PLINE_ORDINARY 0 */
404 #define PLINE_NOREPEAT   1
405 #define OVERRIDE_MSGTYPE 2
406 #define SUPPRESS_HISTORY 4
407 #define URGENT_MESSAGE   8
408
409 /* Macros for messages referring to hands, eyes, feet, etc... */
410 enum bodypart_types {
411     ARM       =  0,
412     EYE       =  1,
413     FACE      =  2,
414     FINGER    =  3,
415     FINGERTIP =  4,
416     FOOT      =  5,
417     HAND      =  6,
418     HANDED    =  7,
419     HEAD      =  8,
420     LEG       =  9,
421     LIGHT_HEADED = 10,
422     NECK      = 11,
423     SPINE     = 12,
424     TOE       = 13,
425     HAIR      = 14,
426     BLOOD     = 15,
427     LUNG      = 16,
428     NOSE      = 17,
429     STOMACH   = 18
430 };
431
432 /* indices for some special tin types */
433 #define ROTTEN_TIN 0
434 #define HOMEMADE_TIN 1
435 #define SPINACH_TIN (-1)
436 #define RANDOM_TIN (-2)
437 #define HEALTHY_TIN (-3)
438
439 /* Some misc definitions */
440 #define POTION_OCCUPANT_CHANCE(n) (13 + 2 * (n))
441 #define WAND_BACKFIRE_CHANCE 100
442 #define BALL_IN_MON (u.uswallow && uball && uball->where == OBJ_FREE)
443 #define CHAIN_IN_MON (u.uswallow && uchain && uchain->where == OBJ_FREE)
444 #define NODIAG(monnum) ((monnum) == PM_GRID_BUG)
445
446 /* Flags to control menus */
447 #define MENUTYPELEN sizeof("traditional ")
448 #define MENU_TRADITIONAL 0
449 #define MENU_COMBINATION 1
450 #define MENU_FULL 2
451 #define MENU_PARTIAL 3
452
453 #define MENU_SELECTED TRUE
454 #define MENU_UNSELECTED FALSE
455
456 /*
457  * Option flags
458  * Each higher number includes the characteristics of the numbers
459  * below it.
460  */
461 /* XXX This should be replaced with a bitmap. */
462 #define SET_IN_SYS 0   /* system config file option only */
463 #define SET_IN_FILE 1  /* config file option only */
464 #define SET_VIA_PROG 2 /* may be set via extern program, not seen in game */
465 #define DISP_IN_GAME 3 /* may be set via extern program, displayed in game \
466                           */
467 #define SET_IN_GAME 4  /* may be set via extern program or set in the game */
468 #define SET_IN_WIZGAME 5  /* may be set set in the game if wizmode */
469 #define SET__IS_VALUE_VALID(s) ((s < SET_IN_SYS) || (s > SET_IN_WIZGAME))
470
471 #define FEATURE_NOTICE_VER(major, minor, patch)                    \
472     (((unsigned long) major << 24) | ((unsigned long) minor << 16) \
473      | ((unsigned long) patch << 8) | ((unsigned long) 0))
474
475 #define FEATURE_NOTICE_VER_MAJ (flags.suppress_alert >> 24)
476 #define FEATURE_NOTICE_VER_MIN \
477     (((unsigned long) (0x0000000000FF0000L & flags.suppress_alert)) >> 16)
478 #define FEATURE_NOTICE_VER_PATCH \
479     (((unsigned long) (0x000000000000FF00L & flags.suppress_alert)) >> 8)
480
481 #ifndef max
482 #define max(a, b) ((a) > (b) ? (a) : (b))
483 #endif
484 #ifndef min
485 #define min(x, y) ((x) < (y) ? (x) : (y))
486 #endif
487 #define plur(x) (((x) == 1) ? "" : "s")
488
489 #define ARM_BONUS(obj)                      \
490     (objects[(obj)->otyp].a_ac + (obj)->spe \
491      - min((int) greatest_erosion(obj), objects[(obj)->otyp].a_ac))
492
493 #define makeknown(x) discover_object((x), TRUE, TRUE)
494 #define distu(xx, yy) dist2((int)(xx), (int)(yy), (int) u.ux, (int) u.uy)
495 #define onlineu(xx, yy) online2((int)(xx), (int)(yy), (int) u.ux, (int) u.uy)
496
497 #define rn1(x, y) (rn2(x) + (y))
498
499 /* negative armor class is randomly weakened to prevent invulnerability */
500 #define AC_VALUE(AC) ((AC) >= 0 ? (AC) : -rnd(-(AC)))
501
502 #if defined(MICRO) && !defined(__DJGPP__)
503 #define getuid() 1
504 #define getlogin() ((char *) 0)
505 #endif /* MICRO */
506
507 #if defined(OVERLAY)
508 #define USE_OVLx
509 #define STATIC_DCL extern
510 #define STATIC_OVL
511 #define STATIC_VAR
512
513 #else /* !OVERLAY */
514
515 #define STATIC_DCL static
516 #define STATIC_OVL static
517 #define STATIC_VAR static
518
519 #endif /* OVERLAY */
520
521 /* Macro for a few items that are only static if we're not overlaid.... */
522 #if defined(USE_TRAMPOLI) || defined(USE_OVLx)
523 #define STATIC_PTR
524 #else
525 #define STATIC_PTR static
526 #endif
527
528 /* The function argument to qsort() requires a particular
529  * calling convention under WINCE which is not the default
530  * in that environment.
531  */
532 #if defined(WIN_CE)
533 #define CFDECLSPEC __cdecl
534 #else
535 #define CFDECLSPEC
536 #endif
537
538 #define DEVTEAM_EMAIL "devteam@nethack.org"
539 #define DEVTEAM_URL "https://www.nethack.org/"
540
541 #endif /* HACK_H */