1 /**
2  * @file
3  * @brief Precompiled header used by Crawl.
4  *
5  * CodeWarrior and MSVC both support precompiled headers which can
6  * significantly speed up compiles. Unlike CodeWarrior MSVC imposes
7  * some annoying restrictions on precompiled headers: the precompiled
8  * header *must* be the first include in all cc files. Any includes or
9  * other statements that occur before the pch include are ignored. This
10  * is really stupid and can lead to bizarre errors, but it does mean
11  * that we shouldn't run into any problems on systems without precompiled
12  * headers.
13 **/
14 
15 
16 #pragma once
17 
18 /* Fix annoying precompiled header compile errors caused by unused Objective-C variant. */
19 #if !defined(__OBJC__)
20 
21 #include "platform.h"
22 #include <stdint.h>
23 
24 // Define COMPILE_CHECK before including any of our headers, so even things
25 // like externs.h can use it. platform.h a few lines up is standalone, so
26 // doesn't count.
27 #include "macros.h"
28 
29 #ifdef __sun
30 // Solaris libc has ambiguous overloads for float, double, long float, so
31 // we need to upgrade ints explicitly:
32 #include <math.h>
sqrt(int x)33 static inline double sqrt(int x) { return sqrt((double)x); }
atan2(int x,int y)34 static inline double atan2(int x, int y) { return atan2((double)x, (double)y); }
pow(int x,int y)35 static inline double pow(int x, int y) { return std::pow((double)x, y); }
pow(int x,double y)36 static inline double pow(int x, double y) { return std::pow((double)x, y); }
37 #endif
38 
39 /**
40  * The maximum total memory that the user-script Lua interpreter is
41  * allowed to allocate, in kilobytes. This limit is enforced to prevent
42  * badly-written or malicious user scripts from consuming too much memory.
43  */
44 #define CLUA_MAX_MEMORY_USE (16 * 1024)
45 
46 // Uncomment to prevent Crawl from looking for a list of saves when
47 // asking the player to enter a name. This can speed up startup
48 // considerably if you have a lot of saves lying around.
49 //
50 // #define DISABLE_SAVEGAME_LISTS
51 
52 // Uncomment to prevent Crawl from remembering startup preferences.
53 //
54 // #define DISABLE_STICKY_STARTUP_OPTIONS
55 
56 // Uncomment to let valgrind debug unitialized uses of global classes
57 // (you, env, clua, dlua, crawl_state).
58 //
59 // #define DEBUG_GLOBALS
60 
61 //
62 // Define 'UNIX' if the target OS is UNIX-like.
63 // Unknown OSes are assumed to be here.
64 //
65 #if defined(TARGET_OS_MACOSX) || defined(TARGET_OS_LINUX) || \
66     defined(TARGET_OS_FREEBSD) || defined(TARGET_OS_NETBSD) || \
67     defined(TARGET_OS_OPENBSD) || defined(TARGET_OS_CYGWIN) || \
68     defined(TARGET_OS_SOLARIS) || defined(TARGET_OS_UNKNOWN)
69     #ifndef UNIX
70     #define UNIX
71     #endif
72 #endif
73 
74 //
75 // MinGW
76 //
77 #if defined(TARGET_COMPILER_MINGW)
78     #ifndef REGEX_PCRE
79     #define REGEX_PCRE
80     #endif
81 #endif
82 
83 // =========================================================================
84 //  System Defines
85 // =========================================================================
86 
87 #ifdef UNIX
88     // Uncomment if you're running Crawl with dgamelaunch and have
89     // problems viewing games in progress. This affects how Crawl
90     // clears the screen (see DGL_CLEAR_SCREEN) below.
91     //
92     // #define DGAMELAUNCH
93 
94     #define USE_UNIX_SIGNALS
95 
96     #define FILE_SEPARATOR '/'
97 
98     // More sophisticated character handling
99     #define CURSES_USE_KEYPAD
100 
101     // How long (milliseconds) curses should wait for additional characters
102     // after seeing an Escape (0x1b) keypress. May not be available on all
103     // curses implementations.
104     #define CURSES_SET_ESCDELAY 20
105 
106     // Have the utimes function to set access and modification time on
107     // a file.
108     #define HAVE_UTIMES
109 
110     // Use POSIX regular expressions
111 #ifndef REGEX_PCRE
112     #define REGEX_POSIX
113 #endif
114 
115     // If you have libpcre, you can use that instead of POSIX regexes -
116     // uncomment the line below and add -lpcre to your makefile.
117     // #define REGEX_PCRE
118 
119     #include "libunix.h"
120 
121 #elif defined(TARGET_OS_WINDOWS)
122     #if defined(TARGET_COMPILER_MINGW)
123         #define USE_UNIX_SIGNALS
124     #endif
125 
126     // TODO: libw32c.h still contains an #ifdef USE_TILE_WEB
127     #include "libw32c.h"
128 
129     // NT and better are happy with /; I'm not sure how 9x reacts.
130     #define FILE_SEPARATOR '/'
131     #define ALT_FILE_SEPARATOR '\\'
132 
133     // Use Perl-compatible regular expressions. libpcre must be available and
134     // linked in. Required in the absence of POSIX regexes.
135     #ifndef REGEX_PCRE
136     #define REGEX_PCRE
137     #endif
138 #else
139     #error Missing platform #define or unsupported compiler.
140 #endif
141 
142 #ifndef _WIN32_WINNT
143 // Allow using Win2000 syscalls.
144 # define _WIN32_WINNT 0x501
145 #endif
146 
147 // /usr/bin is not writable on OSX 10.11+ due to System Integrity Protection
148 #ifdef TARGET_OS_MACOSX
149 # define GDB_PATH "/usr/local/bin/gdb"
150 #else
151 # define GDB_PATH "/usr/bin/gdb"
152 #endif
153 
154 
155 // =========================================================================
156 //  Defines for dgamelaunch-specific things.
157 // =========================================================================
158 
159 #ifdef DGAMELAUNCH
160     // DGL_CLEAR_SCREEN specifies the escape sequence to use to clear
161     // the screen (used only when DGAMELAUNCH is defined). We make no
162     // attempt to discover an appropriate escape sequence for the
163     // term, assuming that dgamelaunch admins can adjust this as
164     // needed.
165     //
166     // Why this is necessary: dgamelaunch's ttyplay initialises
167     // playback by jumping to the last screen clear and playing back
168     // from there. For that to work, ttyplay must be able to recognise
169     // the clear screen sequence, and ncurses clear()+refresh()
170     // doesn't do the trick.
171     //
172     #define DGL_CLEAR_SCREEN "\033[2J"
173 
174     // Create .des and database cache files in a directory named with the
175     // game version so that multiple save-compatible Crawl versions can
176     // share the same savedir.
177     #define VERSIONED_CACHE_DIR
178 
179     // Update (text) database files safely; when a Crawl process
180     // starts up and notices that a db file is out-of-date, it updates
181     // it in-place, instead of torching the old file.
182     #define DGL_REWRITE_PROTECT_DB_FILES
183 
184     // Startup preferences are saved by player name rather than uid,
185     // since all players use the same uid in dgamelaunch.
186     #ifndef DGL_NO_STARTUP_PREFS_BY_NAME
187     #define DGL_STARTUP_PREFS_BY_NAME
188     #endif
189 
190     // Increase the size of the topscores file for public servers.
191     #ifndef SCORE_FILE_ENTRIES
192     #define SCORE_FILE_ENTRIES 1000
193     #endif
194 
195     // If defined, the hiscores code dumps preformatted verbose and terse
196     // death message strings in the logfile for the convenience of logfile
197     // parsers.
198     #define DGL_EXTENDED_LOGFILES
199 
200     // Basic messaging for dgamelaunch, based on SIMPLE_MAIL for
201     // NetHack and Slash'EM. I'm calling this "messaging" because that's
202     // closer to reality.
203     #define DGL_SIMPLE_MESSAGING
204 
205     // How often we check for messages. This is not once per turn, but once
206     // per player-input. Message checks are not performed if the keyboard
207     // buffer is full, so messages should not interrupt macros.
208     #define DGL_MESSAGE_CHECK_INTERVAL 1
209 
210     // Record game milestones in an xlogfile.
211     #define DGL_MILESTONES
212 
213     // Save a timestamp every 100 turns so that external tools can seek in
214     // game recordings more easily.
215     #define DGL_TURN_TIMESTAMPS
216 
217     // Record where players are currently.
218     #define DGL_WHEREIS
219 
220     // Uses <playername>-macro.txt as the macro file if uncommented.
221     // #define DGL_NAMED_MACRO_FILE
222 
223     // Uses Options.macro_dir as the full path to the macro file. Mutually
224     // exclusive with DGL_NAMED_MACRO_FILE.
225     #define DGL_MACRO_ABSOLUTE_PATH
226 
227     // Makes the game ask the user to hit Enter after bailing out with
228     // an error message.
229     #define DGL_PAUSE_AFTER_ERROR
230 
231     // Enable core dumps. Note that this will not create core dumps if
232     // Crawl is installed setuid or setgid, but dgamelaunch installs should
233     // not be installing Crawl set[ug]id anyway.
234     #define DGL_ENABLE_CORE_DUMP
235 
236     // Use UTC for dgamelaunch servers.
237     #define TIME_FN gmtime
238 
239     // Outside DGL, there's a local player who can kill the game himself, so
240     // there are no false positives.
241     // (A false positive would be possible with wizmode shenanigans.)
242     #define WATCHDOG
243 #endif
244 
245 // legacy name
246 #ifdef DGL_VERSIONED_CACHE_DIR
247     #define VERSIONED_CACHE_DIR
248 #endif
249 
250 #ifndef TIME_FN
251 #define TIME_FN localtime
252 #endif
253 
254 #if defined(REGEX_POSIX) && defined(REGEX_PCRE)
255 #error You can use either REGEX_POSIX or REGEX_PCRE, or neither, but not both.
256 #endif
257 
258 #include "debug-defines.h"
259 
260 // =========================================================================
261 //  Lua user scripts (NOTE: this may also be enabled in your makefile!)
262 // =========================================================================
263 //
264 // Enables Crawl's Lua bindings for user scripts. See the section on
265 // Lua in INSTALL for more information. NOTE: CLUA_BINDINGS is enabled
266 // by default in all standard makefiles. Commenting it out here may
267 // not be sufficient to disable user-Lua - you must also check your
268 // makefile and remove -DCLUA_BINDINGS. You can use V in-game to check
269 // whether user-scripts are enabled.
270 //
271 // #define CLUA_BINDINGS
272 
273 // =========================================================================
274 //  Game Play Defines
275 // =========================================================================
276 
277 // Current TAG_MAJOR_VERSION
278 #include "tag-version.h"
279 
280 // number of older messages stored during play and in save files
281 #define NUM_STORED_MESSAGES   1000
282 
283 // clamp time between command inputs at 30 seconds when reporting play time.
284 // Anything longer means you do something other than playing -- heck, even 30s
285 // is too long as when thinking in a tight spot people re-read the inventory,
286 // check monsters, etc.
287 #define IDLE_TIME_CLAMP  30
288 
289 // Number of top scores to keep. See above for the dgamelaunch setting.
290 #ifndef SCORE_FILE_ENTRIES
291 #define SCORE_FILE_ENTRIES      100
292 #endif
293 
294 // Option to allow scoring of wizard characters. Note that even if
295 // you define this option, wizard characters are still tagged as such
296 // in the score file.
297 // #define SCORE_WIZARD_CHARACTERS
298 
299 #define SAVE_SUFFIX ".cs"
300 
301 // If you are installing Crawl for multiple users, define SAVE_DIR
302 // to the directory where saves, bones, and score file will go...
303 // end it with a '/'. Only one system user should be able to access
304 // these -- usually this means you should place them in ~/.crawl/
305 // unless it's a DGL build.
306 
307 #if !defined(DB_NDBM) && !defined(DB_DBH) && !defined(USE_SQLITE_DBM)
308 #define USE_SQLITE_DBM
309 #endif
310 
311 // Uncomment these if you can't find these functions on your system
312 // #define NEED_USLEEP
313 
314 // And now headers we want precompiled
315 #ifdef TARGET_COMPILER_VC
316 # include "msvc.h"
317 #endif
318 
319 #include "debug.h"
320 #include "externs.h"
321 
322 #ifdef TARGET_COMPILER_VC
323 # include "libw32c.h"
324 #endif
325 
326 #ifdef __cplusplus
327 # include "tiles.h"
328 #endif
329 
330 #include "libconsole.h"
331 
332 #endif // !defined __OBJC__
333