1 /* NetHack 3.7	global.h	$NHDT-Date: 1612127119 2021/01/31 21:05:19 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.120 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Michael Allison, 2006. */
4 /* NetHack may be freely redistributed.  See license for details. */
5 
6 #ifndef GLOBAL_H
7 #define GLOBAL_H
8 
9 #include <stdio.h>
10 
11 /*
12  * Files expected to exist in the playground directory.
13  */
14 
15 #define RECORD "record"         /* file containing list of topscorers */
16 #define HELP "help"             /* file containing command descriptions */
17 #define SHELP "hh"              /* abbreviated form of the same */
18 #define KEYHELP "keyhelp"       /* explanatory text for 'whatdoes' command */
19 #define DEBUGHELP "wizhelp"     /* file containing debug mode cmds */
20 #define RUMORFILE "rumors"      /* file with fortune cookies */
21 #define ORACLEFILE "oracles"    /* file with oracular information */
22 #define DATAFILE "data"         /* file giving the meaning of symbols used */
23 #define CMDHELPFILE "cmdhelp"   /* file telling what commands do */
24 #define HISTORY "history"       /* file giving nethack's history */
25 #define LICENSE "license"       /* file with license information */
26 #define OPTIONFILE "opthelp"    /* file explaining runtime options */
27 #define OPTIONS_USED "options"  /* compile-time options, for #version */
28 #define SYMBOLS "symbols"       /* replacement symbol sets */
29 #define EPITAPHFILE "epitaph"   /* random epitaphs on graves */
30 #define ENGRAVEFILE "engrave"   /* random engravings on the floor */
31 #define BOGUSMONFILE "bogusmon" /* hallucinatory monsters */
32 #define SHIRTFILE "shirts"      /* T-shirt texts */
33 #define TRIBUTEFILE "tribute"   /* 3.6 tribute to Terry Pratchett */
34 #define LEV_EXT ".lua"          /* extension for special level files */
35 
36 /* Assorted definitions that may depend on selections in config.h. */
37 
38 /*
39  * for DUMB preprocessor and compiler, e.g., cpp and pcc supplied
40  * with Microport SysV/AT, which have small symbol tables;
41  * DUMB if needed is defined in CFLAGS
42  */
43 #ifdef DUMB
44 #ifdef BITFIELDS
45 #undef BITFIELDS
46 #endif
47 #ifndef STUPID
48 #define STUPID
49 #endif
50 #endif /* DUMB */
51 
52 /*
53  * type xchar: small integers (typedef'd as signed char,
54  * so in the range -127 - 127), usually coordinates.
55  */
56 typedef schar xchar;
57 
58 #ifdef __MINGW32__
59 /* Resolve conflict with Qt 5 and MinGW-w32 */
60 typedef unsigned char boolean; /* 0 or 1 */
61 #else
62 #ifndef SKIP_BOOLEAN
63 typedef xchar boolean; /* 0 or 1 */
64 #endif
65 #endif
66 
67 #ifndef TRUE /* defined in some systems' native include files */
68 #define TRUE ((boolean) 1)
69 #define FALSE ((boolean) 0)
70 #endif
71 
72 enum optchoice { opt_in, opt_out};
73 
74 /*
75  * type nhsym: loadable symbols go into this type
76  */
77 typedef uchar nhsym;
78 
79 #ifndef STRNCMPI
80 #ifndef __SASC_60 /* SAS/C already shifts to stricmp */
81 #define strcmpi(a, b) strncmpi((a), (b), -1)
82 #endif
83 #endif
84 
85 #if 0
86 /* comment out to test effects of each #define -- these will probably
87  * disappear eventually
88  */
89 #ifdef INTERNAL_COMP
90 #define RLECOMP  /* run-length compression of levl array - JLee */
91 #define ZEROCOMP /* zero-run compression of everything - Olaf Seibert */
92 #endif
93 #endif
94 
95 /* #define SPECIALIZATION */ /* do "specialized" version of new topology */
96 
97 #ifdef BITFIELDS
98 #define Bitfield(x, n) unsigned x : n
99 #else
100 #define Bitfield(x, n) uchar x
101 #endif
102 
103 #define SIZE(x) (int)(sizeof(x) / sizeof(x[0]))
104 
105 /* A limit for some NetHack int variables.  It need not, and for comparable
106  * scoring should not, depend on the actual limit on integers for a
107  * particular machine, although it is set to the minimum required maximum
108  * signed integer for C (2^15 -1).
109  */
110 #define LARGEST_INT 32767
111 
112 #include "coord.h"
113 
114 #if defined(CROSSCOMPILE)
115 struct cross_target_s {
116     const char *build_date;
117     const char *copyright_banner_c;
118     const char *git_sha;
119     const char *git_branch;
120     const char *version_string;
121     const char *version_id;
122     unsigned long version_number;
123     unsigned long version_features;
124     unsigned long ignored_features;
125     unsigned long version_sanity1;
126     unsigned long version_sanity2;
127     unsigned long version_sanity3;
128     unsigned long build_time;
129 };
130 extern struct cross_target_s cross_target;
131 #if defined(CROSSCOMPILE_TARGET) && !defined(MAKEDEFS_C)
132 #define BUILD_DATE cross_target.build_date        /* "Wed Apr 1 00:00:01 2020" */
133 #define COPYRIGHT_BANNER_C cross_target.copyright_banner_c
134 #define NETHACK_GIT_SHA cross_target.git_sha
135 #define NETHACK_GIT_BRANCH cross_target.git_branch
136 #define VERSION_ID cross_target.version_id
137 #define IGNORED_FEATURES cross_target.ignored_features
138 #define VERSION_FEATURES cross_target.version_features
139 #define VERSION_NUMBER cross_target.version_number
140 #define VERSION_SANITY1 cross_target.version_sanity1
141 #define VERSION_SANITY2 cross_target.version_sanity2
142 #define VERSION_SANITY3 cross_target.version_sanity3
143 #define VERSION_STRING cross_target.version_string
144 #define BUILD_TIME cross_target.build_time        /* (1574157640UL) */
145 #endif /* CROSSCOMPILE_TARGET && !MAKEDEFS_C */
146 #endif /* CROSSCOMPILE */
147 
148 /*
149  * Automatic inclusions for the subsidiary files.
150  * Please don't change the order.  It does matter.
151  */
152 
153 #ifdef VMS
154 #include "vmsconf.h"
155 #endif
156 
157 #ifdef UNIX
158 #include "unixconf.h"
159 #endif
160 
161 #ifdef MSDOS
162 #include "pcconf.h"
163 #endif
164 
165 #ifdef WIN32
166 #include "ntconf.h"
167 #endif
168 
169 #include "warnings.h"
170 
171 /* amiconf.h needs to be the last nested #include of config.h because
172    'make depend' will turn it into a comment, hiding anything after it */
173 #ifdef AMIGA
174 /*#include "amiconf.h"*/
175 #endif
176 
177 /* Displayable name of this port; don't redefine if defined in *conf.h */
178 #ifndef PORT_ID
179 #ifdef AMIGA
180 #define PORT_ID "Amiga"
181 #endif
182 #ifdef MAC
183 #define PORT_ID "Mac"
184 #endif
185 #ifdef __APPLE__
186 #define PORT_ID "MacOSX"
187 #endif
188 #ifdef MSDOS
189 #ifdef PC9800
190 #define PORT_ID "PC-9800"
191 #else
192 #define PORT_ID "PC"
193 #endif
194 #ifdef DJGPP
195 #define PORT_SUB_ID "djgpp"
196 #else
197 #ifdef OVERLAY
198 #define PORT_SUB_ID "overlaid"
199 #else
200 #define PORT_SUB_ID "non-overlaid"
201 #endif
202 #endif
203 #endif
204 #ifdef OS2
205 #define PORT_ID "OS/2"
206 #endif
207 #ifdef TOS
208 #define PORT_ID "ST"
209 #endif
210 /* Check again in case something more specific has been defined above. */
211 #ifndef PORT_ID
212 #ifdef UNIX
213 #define PORT_ID "Unix"
214 #endif
215 #endif
216 #ifdef VMS
217 #define PORT_ID "VMS"
218 #endif
219 #ifdef WIN32
220 #define PORT_ID "Windows"
221 #endif
222 #endif
223 
224 #if !defined(CROSSCOMPILE)
225 #if defined(MICRO)
226 #if !defined(AMIGA) && !defined(TOS) && !defined(OS2_HPFS)
227 #define SHORT_FILENAMES /* filenames are 8.3 */
228 #endif
229 #endif
230 #endif
231 
232 #include "fnamesiz.h" /* file sizes shared between nethack and recover */
233 
234 #ifdef VMS
235 /* vms_exit() (sys/vms/vmsmisc.c) expects the non-VMS EXIT_xxx values below.
236  * these definitions allow all systems to be treated uniformly, provided
237  * main() routines do not terminate with return(), whose value is not
238  * so massaged.
239  */
240 #ifdef EXIT_SUCCESS
241 #undef EXIT_SUCCESS
242 #endif
243 #ifdef EXIT_FAILURE
244 #undef EXIT_FAILURE
245 #endif
246 #endif
247 
248 #ifndef EXIT_SUCCESS
249 #define EXIT_SUCCESS 0
250 #endif
251 #ifndef EXIT_FAILURE
252 #define EXIT_FAILURE 1
253 #endif
254 
255 #if defined(X11_GRAPHICS) || defined(QT_GRAPHICS) || defined(GNOME_GRAPHICS) \
256     || defined(WIN32)
257 #ifndef USE_TILES
258 #define USE_TILES /* glyph2tile[] will be available */
259 #endif
260 #endif
261 #if defined(AMII_GRAPHICS) || defined(GEM_GRAPHICS)
262 #ifndef USE_TILES
263 #define USE_TILES
264 #endif
265 #endif
266 
267 #if defined(UNIX) || defined(VMS) || defined(__EMX__) || defined(WIN32)
268 #define HANGUPHANDLING
269 #endif
270 #if defined(SAFERHANGUP) \
271     && (defined(NOSAVEONHANGUP) || !defined(HANGUPHANDLING))
272 #undef SAFERHANGUP
273 #endif
274 
275 #define Sprintf (void) sprintf
276 #define Strcat (void) strcat
277 #define Strcpy (void) strcpy
278 #ifdef NEED_VARARGS
279 #define Vprintf (void) vprintf
280 #define Vfprintf (void) vfprintf
281 #define Vsprintf (void) vsprintf
282 #endif
283 
284 /*
285  *  Memory allocation.  Functions are declared here rather than in
286  *  extern.h so that source files which use config.h instead of hack.h
287  *  will see the declarations.
288  *
289  *  NetHack does not use malloc() [except to implement alloc() in alloc.c]
290  *  or realloc() or calloc().  They return Null if memory runs out and
291  *  nethack's code relies on alloc() to intercept that so that a zillion
292  *  callers don't need to test for Null result.  alloc() never returns
293  *  Null; if memory runs out, it calls panic() and does not return at all.
294  */
295 
296 /* dupstr() is unconditional in alloc.c but not used when MONITOR_HEAP
297    is enabled; some utility programs link with alloc.{o,obj} and need it
298    if nethack is built with MONITOR_HEAP enabled and they aren't; this
299    declaration has been moved out of the '#else' below to avoid getting
300    a complaint from -Wmissing-prototypes when building with MONITOR_HEAP */
301 extern char *dupstr(const char *);
302 
303 /*
304  * MONITOR_HEAP is conditionally used for primitive memory leak debugging.
305  * When enabled, NH_HEAPLOG (if defined in the environment) is used as the
306  * name of a log file to create for capturing allocations and releases.
307  * [The 'heaputil' program to analyze that file isn't included in releases.]
308  *
309  * See alloc.c.
310  */
311 #ifdef MONITOR_HEAP
312 /* plain alloc() is not declared except in alloc.c */
313 extern long *nhalloc(unsigned int, const char *, int);
314 extern void nhfree(genericptr_t, const char *, int);
315 extern char *nhdupstr(const char *, const char *, int);
316 /* this predates C99's __func__; that is trickier to use conditionally
317    because it is not implemented as a preprocessor macro; MONITOR_HEAP
318    wouldn't gain much benefit from it anyway so continue to live without it;
319    if func's caller were accessible, that would be a very different issue */
320 #ifndef __FILE__
321 #define __FILE__ ""
322 #endif
323 #ifndef __LINE__
324 #define __LINE__ 0
325 #endif
326 #define alloc(a) nhalloc(a, __FILE__, (int) __LINE__)
327 #define free(a) nhfree(a, __FILE__, (int) __LINE__)
328 #define dupstr(s) nhdupstr(s, __FILE__, (int) __LINE__)
329 #else /* !MONITOR_HEAP */
330 /* declare alloc.c's alloc(); allocations made with it use ordinary free() */
331 extern long *alloc(unsigned int);  /* alloc.c */
332 #endif /* ?MONITOR_HEAP */
333 
334 /* Used for consistency checks of various data files; declare it here so
335    that utility programs which include config.h but not hack.h can see it. */
336 struct version_info {
337     unsigned long incarnation;   /* actual version number */
338     unsigned long feature_set;   /* bitmask of config settings */
339     unsigned long entity_count;  /* # of monsters and objects */
340     unsigned long struct_sizes1; /* size of key structs */
341     unsigned long struct_sizes2; /* size of more key structs */
342 };
343 
344 struct savefile_info {
345     unsigned long sfi1; /* compression etc. */
346     unsigned long sfi2; /* miscellaneous */
347     unsigned long sfi3; /* thirdparty */
348 };
349 #ifdef NHSTDC
350 #define SFI1_EXTERNALCOMP (1UL)
351 #define SFI1_RLECOMP (1UL << 1)
352 #define SFI1_ZEROCOMP (1UL << 2)
353 #else
354 #define SFI1_EXTERNALCOMP (1L)
355 #define SFI1_RLECOMP (1L << 1)
356 #define SFI1_ZEROCOMP (1L << 2)
357 #endif
358 
359 /*
360  * Configurable internal parameters.
361  *
362  * Please be very careful if you are going to change one of these.  Any
363  * changes in these parameters, unless properly done, can render the
364  * executable inoperative.
365  */
366 
367 /* size of terminal screen is (at least) (ROWNO+3) by COLNO */
368 #define COLNO 80
369 #define ROWNO 21
370 
371 #define MAXNROFROOMS 40 /* max number of rooms per level */
372 #define MAX_SUBROOMS 24 /* max # of subrooms in a given room */
373 #define DOORMAX 120     /* max number of doors per level */
374 
375 #define BUFSZ 256  /* for getlin buffers */
376 #define QBUFSZ 128 /* for building question text */
377 #define TBUFSZ 300 /* g.toplines[] buffer max msg: 3 81char names */
378 /* plus longest prefix plus a few extra words */
379 
380 /* COLBUFSZ is the larger of BUFSZ and COLNO */
381 #if BUFSZ > COLNO
382 #define COLBUFSZ BUFSZ
383 #else
384 #define COLBUFSZ COLNO
385 #endif
386 
387 #define PL_NSIZ 32 /* name of player, ghost, shopkeeper */
388 #define PL_CSIZ 32 /* sizeof pl_character */
389 #define PL_FSIZ 32 /* fruit name */
390 #define PL_PSIZ 63 /* player-given names for pets, other monsters, objects */
391 
392 #define MAXDUNGEON 16 /* current maximum number of dungeons */
393 #define MAXLEVEL 32   /* max number of levels in one dungeon */
394 #define MAXSTAIRS 1   /* max # of special stairways in a dungeon */
395 #define ALIGNWEIGHT 4 /* generation weight of alignment */
396 
397 #define MAXULEV 30 /* max character experience level */
398 
399 #define MAXMONNO 120 /* extinct monst after this number created */
400 #define MHPMAX 500   /* maximum monster hp */
401 
402 /*
403  * Version 3.7.x has aspirations of portable file formats. We
404  * make a distinction between MAIL functionality and MAIL_STRUCTURES
405  * so that the underlying structures are consistent, whether MAIL is
406  * defined or not.
407  */
408 #define MAIL_STRUCTURES
409 
410 /* PANICTRACE: Always defined for NH_DEVEL_STATUS != NH_STATUS_RELEASED
411    but only for supported platforms. */
412 #ifdef UNIX
413 #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
414 /* see end.c */
415 #if !defined(CROSS_TO_WASM)
416 #ifndef PANICTRACE
417 #define PANICTRACE
418 #endif  /* PANICTRACE */
419 #endif  /* CROSS_TO_WASM */
420 #endif  /* NH_DEVEL_STATUS != NH_STATUS_RELEASED */
421 #endif  /* UNIX */
422 
423 /* The following are meaningless if PANICTRACE is not defined: */
424 #if defined(__linux__) && defined(__GLIBC__) && (__GLIBC__ >= 2)
425 #define PANICTRACE_LIBC
426 #endif
427 #if defined(MACOSX)
428 #define PANICTRACE_LIBC
429 #endif
430 #ifdef UNIX
431 #if !defined(CROSS_TO_WASM) /* no popen in WASM */
432 #define PANICTRACE_GDB
433 #endif
434 #endif
435 
436 /* Supply nethack_enter macro if not supplied by port */
437 #ifndef nethack_enter
438 #define nethack_enter(argc, argv) ((void) 0)
439 #endif
440 
441 /* Supply nhassert macro if not supplied by port */
442 #ifndef nhassert
443 #define nhassert(expression) (void)((!!(expression)) || \
444         (nhassert_failed(#expression, __FILE__, __LINE__), 0))
445 #endif
446 
447 /* LIVELOG message type flags */
448 #define LL_WISH       0x0001 /* Report stuff people type at the wish prompt. */
449 #define LL_ACHIEVE    0x0002 /* Achievements bitfield + invocation, planes */
450 #define LL_UMONST     0x0004 /* Kill, Bribe or otherwise dispatch unique monsters */
451 #define LL_DIVINEGIFT 0x0008 /* Sacrifice gifts, crowning */
452 #define LL_LIFESAVE   0x0010 /* Use up amulet of lifesaving */
453 #define LL_CONDUCT    0x0020 /* Break conduct - not reported early-game */
454 #define LL_ARTIFACT   0x0040 /* Excalibur, Sting, Orcrist, plus sac gifts and artwishes */
455 #define LL_GENOCIDE   0x0080 /* Logging of genocides */
456 #define LL_KILLEDPET  0x0100 /* Killed a tame monster */
457 #define LL_ALIGNMENT  0x0200 /* changed alignment temporarily or permanently */
458 #define LL_DUMP_ASC   0x0400 /* Log URL for dumplog if ascended */
459 #define LL_DUMP_ALL   0x0800 /* Log dumplog url for all games */
460 #define LL_MINORAC    0x1000 /* Log 'minor' achievements - can be spammy */
461 #define LL_DEBUG      0x8000 /* For debugging messages and other spam */
462 
463 /* Macros for meta and ctrl modifiers:
464  *   M and C return the meta/ctrl code for the given character;
465  *     e.g., (C('c') is ctrl-c
466  */
467 #ifndef M
468 #ifndef NHSTDC
469 #define M(c) (0x80 | (c))
470 #else
471 #define M(c) ((c) - 128)
472 #endif /* NHSTDC */
473 #endif
474 
475 #ifndef C
476 #define C(c) (0x1f & (c))
477 #endif
478 
479 #define unctrl(c) ((c) <= C('z') ? (0x60 | (c)) : (c))
480 #define unmeta(c) (0x7f & (c))
481 
482 #endif /* GLOBAL_H */
483