xref: /netbsd-src/games/warp/warp.h (revision 2fa7e14158d403140e8fb3c233c9e17417a69d87)
1 /* Header: warp.h,v 7.0.1.2 86/12/12 17:08:42 lwall Exp */
2 
3 /* Log:	warp.h,v
4  * Revision 7.0.1.2  86/12/12  17:08:42  lwall
5  * Baseline for net release.
6  *
7  * Revision 7.0.1.1  86/10/16  10:54:26  lwall
8  * Added Damage.  Fixed random bugs.
9  *
10  * Revision 7.0  86/10/08  15:17:55  lwall
11  * Split into separate files.  Added amoebas and pirates.
12  *
13  */
14 
15 #ifndef WARP_H
16 #define WARP_H
17 
18 #include "config.h"	/* generated by Configure script */
19 
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <sys/param.h>
23 #include <sys/ioctl.h>
24 
25 #include <term.h>
26 #include <math.h>
27 #include <stdio.h>
28 #include <signal.h>
29 #include <fcntl.h>
30 #include <ctype.h>
31 #include <errno.h>
32 #include <stdbool.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <unistd.h>
36 
37 /* WARPLIB must be readable and writeable by warp, but not by anyone who you
38  * don't trust.  In other words, to set up warp so everyone can play and
39  * no one can cheat, give warp a uid of its own and make warp setuid to
40  * that uid.  WARPLIB must then NOT be made writeable by the world,
41  * since no attempt is made to encrypt saved games or anything.
42  * (It must be readable by the world, however, due to a strangeness in
43  * access.)
44  */
45 
46 #define SAVEDIR "/var/games/warp"
47 #define NEWSFILE "warp.news"
48 #define HELPFILE "warp.doc"
49 #define LOCKFILE ".warp.lock"
50 #define LOGFILE "warp.log"
51 #define SCOREBOARD "warp.top"
52 #define LSCOREBOARD "warp.lowtop"
53 #define FSCOREBOARD "warp.funtop"
54 #define TMPSCOREBOARD "warp.topnew"
55 #define WARPMACRO "%X/Kbmap.%{TERM}"
56 
57 /* warp library */
58 #ifndef WARPLIB		/* ~ and %l only ("~%l" is permissible) */
59 #   ifdef PRIVLIB
60 #	define WARPLIB PRIVLIB
61 #   else
62 #	define WARPLIB "/usr/games/warp"
63 #   endif
64 #endif
65 
66 EXT char *warplib;
67 
68 #define PERMMAPS 8	/* how many starmaps are permanent */
69 #define MAPS 20		/* how many starmaps to choose from */
70 			/* (MAPS - PERMMAPS is # of half-gone universes) */
71 
72 /*
73  * Screen size info, minimum screen size is 23x40 (actually 24x80).
74  * YSIZE and XSIZE should be relatively prime so that a torpedo launched
75  * at an angle will eventually cover the whole screen.
76  * To calculate a new position for something:
77  * new_position = (current_position + delta + ?SIZE00) % ?SIZE
78  * This allows for negative deltas of up to ?SIZE00 (% doesn't work right
79  * on negative numbers).
80  * ?SIZE01, etc. are fudges for efficiency--they already include a delta.
81  */
82 
83 #define XYSIZE 920
84 #define XYSIZEx4 3680
85 
86 #define YSIZE   23
87 #define YSIZE00 2300
88 #define YSIZE01 2301
89 #define YSIZE99 2299
90 
91 #define XSIZE   40
92 #define XSIZE00 4000
93 #define XSIZE01 4001
94 #define XSIZE99 3999
95 #define XSIZE02 4002
96 #define XSIZE98 3998
97 #define XSIZE03 4003
98 #define XSIZE97 3997
99 #define XSIZE08 4008
100 #define XSIZE92 3992
101 
102 EXT char amb[YSIZE][XSIZE];
103 
104 #ifdef WHOAMI
105 #    include <whoami.h>
106 #endif
107 
108 #ifndef isalnum
109 #   define isalnum(c) (isalpha(c) || isdigit(c))
110 #endif
111 
112 #ifdef TERMIO
113 #   include <termio.h>
114 #elif defined TERMIOS
115 #   include <termios.h>
116 #else
117 #   include <sgtty.h>
118 #endif
119 
120 #include <sys/timeb.h>
121 
122 #   include <pwd.h>
123 
124 #define BITSPERBYTE 8
125 #define LBUFLEN 512	/* line buffer length */
126 
127 #ifdef pdp11
128 #   define CBUFLEN 256	/* command buffer length */
129 #   define PUSHSIZE 128
130 #else
131 #   define CBUFLEN 512	/* command buffer length */
132 #   define PUSHSIZE 256
133 #endif
134 #ifdef pdp11
135 #   define MAXFILENAME 128
136 #else
137 #   define MAXFILENAME 512
138 #endif
139 #define FINISHCMD 0177
140 
141 /* some handy defs */
142 
143 #define Ctl(ch) (ch & 037)
144 
145 #define strNE(s1,s2) (strcmp(s1,s2))
146 #define strEQ(s1,s2) (!strcmp(s1,s2))
147 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
148 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
149 
150 #define sgn(x) ((x) < 0 ? -1 : (x) > 0)
151 
152 /* Things we can figure out ourselves */
153 
154 #ifdef SIGPROF
155 #   define BSD42		/* do we have Berkeley 4.2? */
156 #endif
157 
158 #ifdef FIONREAD
159 #   define PENDING
160 #else
161 #   ifdef O_NDELAY
162 #	define PENDING
163 #   else
164 #	ifdef RDCHK
165 #	    define PENDING
166 #	endif
167 #   endif
168 #endif
169 
170 #define UNLINK(victim) unlink(victim)
171 
172 /* Valid substitutions for strings marked with % comment are:
173  *	%H	Host name (yours)
174  *	%L	Login name (yours)
175  *	%N	Full name (yours)
176  *	%O	Original working directory (where you ran warp from)
177  *	%X	Warp library directory
178  *	%~	Home directory
179  *	%.	Directory containing . files
180  *	%$	current process number
181  *	%{name} Environment variable "name".  %{name-default} form allowed.
182  *	%"prompt"
183  *		Print prompt and insert what is typed.
184  *	%`command`
185  *		Insert output of command.
186  *	%(test_text=pattern?if_text:else_text)
187  *		Substitute if_text if test_text matches pattern, otherwise
188  *		substitute else_text.  Use != for negated match.
189  *		% substitutions are done on test_text, if_text, and else_text.
190  *		(Note: %() only works if CONDSUB defined.)
191  */
192 
193 /* *** System Dependent Stuff *** */
194 
195 /* NOTE: many of these are defined in the config.h file */
196 
197 #ifndef ROOTID
198 #   define ROOTID 0        /* uid of superuser */
199 #endif
200 
201 #   define sigset signal
202 #   define sigignore(sig) signal(sig,SIG_IGN)
203 
204 #ifndef LOGDIRFIELD
205 #   define LOGDIRFIELD 6		/* Which field (origin 1) is the */
206 					/* login directory in /etc/passwd? */
207 					/* (If it is not kept in passwd, */
208 					/* but getpwnam() returns it, */
209 					/* define the symbol GETPWENT) */
210 #endif
211 #ifndef GCOSFIELD
212 #   define GCOSFIELD 5
213 #endif
214 
215 /* Undefine any of the following features to save both I and D space */
216 /* In general, earlier ones are easier to get along without */
217 /* Pdp11's without split I and D may have to undefine them all */
218 #define DEBUGGING	/* include debugging code */
219 #define PUSHBACK	/* macros and keymaps using pushback buffer */
220 #define CONDSUB		/* allow %(cond?text:text) */
221 #define BACKTICK	/* allow %`command` */
222 #define PROMPTTTY	/* allow %"prompt" */
223 #define GETLOGIN	/* use getlogin() routine as backup to environment */
224 			/* variables USER or LOGNAME */
225 #define TILDENAME	/* allow ~logname expansion */
226 #define GETWD		/* use our getwd() instead of piped in pwd */
227 #define SETUIDGID	/* substitute eaccess() for access() so that rn */
228 			/* can run setuid or setgid */
229 			/* if not setuid or setgid, you don't need it */
230 #define VERBOSE		/* compile in more informative messages */
231 #define TERSE		/* compile in shorter messages */
232 
233 /* some dependencies among options */
234 
235 #ifndef SETUIDGID
236 #   define eaccess access
237 #endif
238 
239 #ifdef VERBOSE
240 #   ifdef TERSE
241 #	define IF(c) if (c)
242 #	define ELSE else
243 #   else /* !TERSE */
244 #	define IF(c)
245 #	define ELSE
246 #   endif
247 #else /* !VERBOSE */
248 #   ifndef TERSE
249 #	define TERSE
250 #   endif
251 #   define IF(c) "IF" outside of VERBOSE???
252 #   define ELSE "ELSE" outside of VERBOSE???
253 #endif
254 
255 #ifdef DEBUGGING
256 #   define assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\r\n", __FILE__, __LINE__);sig_catcher(0);}}
257 #else
258 #   define assert(ex) ;
259 #endif
260 
261 #define TCSIZE 512	/* capacity for termcap strings */
262 
263 /* End of Space Conservation Section */
264 
265 /* More System Dependencies */
266 
267 /* preferred shell for use in doshell routine */
268 /*  ksh or sh would be okay here */
269 #ifndef PREFSHELL
270 #   define PREFSHELL "/bin/csh"
271 #endif
272 
273 /* path to fastest starting shell */
274 #ifndef SH
275 #   define SH "/bin/sh"
276 #endif
277 
278 /* location of macro file */
279 #ifndef WARPMACRO
280 #   ifdef PUSHBACK
281 #	define WARPMACRO "%./.warpmac"
282 #   endif
283 #endif
284 
285 /* location of full name */
286 #ifndef FULLNAMEFILE
287 #   ifndef PASSNAMES
288 #	define FULLNAMEFILE "%./.fullname"
289 #   endif
290 #endif
291 
292 /* a motd-like file for warp */
293 #ifndef WARPNEWSNAME		/* % and ~ */
294 #   define WARPNEWSNAME "%X/warp.news"
295 #endif
296 
297 /* typedefs */
298 
299 /* *** end of the machine dependent stuff *** */
300 
301 /* GLOBAL THINGS */
302 
303 /* file statistics area */
304 
305 EXT struct stat filestat;
306 
307 /* various things of type char */
308 
309 EXT char buf[LBUFLEN+1];	/* general purpose line buffer */
310 
311 EXT char *cwd INIT(NULL);		/* current working directory */
312 
313 /* switches */
314 
315 #ifdef DEBUGGING
316     EXT int debug INIT(0);				/* -D */
317 #   define DEB_FILEXP 64
318 #endif
319 
320 #ifdef VERBOSE
321 #   ifdef TERSE
322 	EXT bool verbose INIT(true);			/* +t */
323 #   endif
324 #endif
325 
326 /* miscellania */
327 
328 EXT FILE *tmpfp INIT(NULL);	/* scratch fp */
329 
330 #define NOMARKING 0
331 #define STANDOUT 1
332 #define UNDERLINE 2
333 
334 /* Factored strings */
335 
336 EXT char nullstr[] INIT("");
337 EXT char readerr[] INIT("warp read error");
338 EXT char cantopen[] INIT("Can't open %s\r\n");
339 
340 #ifdef VERBOSE
341 #define NOCD "Can't chdir to directory %s\r\n"
342 #else
343 #define NOCD "Can't find %s\r\n"
344 #endif
345 
346 EXT bool justonemoretime INIT(true);
347 EXT bool keepgoing INIT(true);
348 
349 EXT bool friendspec INIT(false);
350 EXT bool piratespec INIT(false);
351 EXT bool amoebaspec INIT(false);
352 EXT bool starspec INIT(false);
353 EXT bool klingspec INIT(false);
354 EXT bool apolspec INIT(false);
355 EXT bool crushspec INIT(false);
356 EXT bool romspec INIT(false);
357 EXT bool prespec INIT(false);
358 EXT bool tholspec INIT(false);
359 EXT bool gornspec INIT(false);
360 EXT bool beginner INIT(false);
361 EXT bool massacre INIT(false);
362 EXT bool lowspeed INIT(false);
363 EXT bool debugging INIT(false);
364 EXT bool didkill INIT(false);
365 EXT bool experimenting INIT(false);
366 EXT bool scorespec INIT(false);
367 EXT bool metakey INIT(false);
368 
369 EXT bool bombed_out;
370 EXT int panic INIT(0);
371 EXT bool madgorns;
372 
373 EXT int madfriends;
374 
375 EXT int inumpirates;
376 EXT int numpirates;
377 EXT int inumfriends;
378 EXT int numfriends;
379 EXT int inumamoebas;
380 EXT int numamoebas;
381 EXT int inumstars;
382 EXT int numstars;
383 EXT int inumenemies;
384 EXT int numenemies;
385 EXT int inumroms;
386 EXT int inumthols;
387 EXT int inumapollos;
388 EXT int numapollos;
389 EXT int apolloflag;
390 EXT int inumcrushes;
391 EXT int numcrushes;
392 EXT int inumgorns;
393 EXT int numgorns;
394 EXT int deados;
395 EXT int deadmudds;
396 EXT int smarts;
397 EXT int ismarts INIT(0);
398 EXT int numos INIT(0);
399 EXT int numxes INIT(0);
400 EXT int ient;
401 EXT int numents;
402 EXT int ibase;
403 EXT int numbases;
404 EXT int inuminhab;
405 EXT int numinhab;
406 EXT int wave;
407 EXT int cumsmarts;
408 EXT int prescene INIT(-1);
409 EXT int scandist;
410 EXT int antibase;
411 EXT int sm35;
412 EXT int sm45;
413 EXT int sm50;
414 EXT int sm55;
415 EXT int sm80;
416 EXT int sm95;
417 EXT int entmax;
418 EXT int basemax;
419 EXT int enemshields;
420 EXT int super;
421 EXT int whenok;
422 EXT int yamblast;
423 EXT int xamblast;
424 EXT int ambsize;
425 
426 EXT char spbuf[1024];
427 
428 #endif
429