xref: /netbsd/games/hunt/huntd/hunt.h (revision bf9ec67e)
1 /*	$NetBSD: hunt.h,v 1.6 2000/01/21 17:08:34 mycroft Exp $	*/
2 
3 /*
4  *  Hunt
5  *  Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
6  *  San Francisco, California
7  */
8 
9 # include "bsd.h"
10 
11 # include	<stdio.h>
12 # include	<string.h>
13 # ifdef LOG
14 # include	<syslog.h>
15 # endif
16 # if !defined(TERMINFO) && BSD_RELEASE < 44
17 # include	<sgtty.h>
18 # else
19 # include	<sys/ioctl.h>
20 # endif
21 # include	<sys/types.h>
22 # include	<sys/uio.h>
23 # include	<sys/socket.h>
24 # ifdef	INTERNET
25 # include	<netinet/in.h>
26 # include	<netdb.h>
27 # include	<arpa/inet.h>
28 # ifdef BROADCAST
29 # include	<net/if.h>
30 # endif
31 # else
32 # include	<sys/un.h>
33 # endif
34 
35 # ifdef	INTERNET
36 # define	SOCK_FAMILY	AF_INET
37 # else
38 # define	SOCK_FAMILY	AF_UNIX
39 # define	AF_UNIX_HACK		/* 4.2 hack; leaves files around */
40 # endif
41 
42 /*
43  * Preprocessor define dependencies
44  */
45 # if defined(VOLCANO) && !defined(OOZE)
46 # define OOZE
47 # endif
48 # if defined(BOOTS) && !defined(FLY)
49 # define FLY
50 # endif
51 # if !defined(REFLECT) && !defined(RANDOM)
52 # define RANDOM
53 # endif
54 # ifdef TERMINFO
55 /* mvcur() in terminfo needs the curses library to be initialized to not
56  * coredump, so give up and use it. */
57 # define USE_CURSES
58 # endif
59 
60 /* decrement version number for each change in startup protocol */
61 # define	HUNT_VERSION		-1
62 
63 # define	ADDCH		('a' | 0200)
64 # define	MOVE		('m' | 0200)
65 # define	REFRESH		('r' | 0200)
66 # define	CLRTOEOL	('c' | 0200)
67 # define	ENDWIN		('e' | 0200)
68 # define	CLEAR		('C' | 0200)
69 # define	REDRAW		('R' | 0200)
70 # define	LAST_PLAYER	('l' | 0200)
71 # define	BELL		('b' | 0200)
72 # define	READY		('g' | 0200)
73 
74 /*
75  * Choose MAXPL and MAXMON carefully.  The screen is assumed to be
76  * 23 lines high and will only tolerate (MAXPL == 17 && MAXMON == 0)
77  * or (MAXPL + MAXMON <= 16).
78  */
79 # ifdef MONITOR
80 # define	MAXPL		15
81 # define	MAXMON		1
82 # else
83 # define	MAXPL		17
84 # endif
85 # define	SHORTLEN	2		/* sizeof (network short) */
86 # define	LONGLEN		4		/* sizeof (network long) */
87 # define	NAMELEN		20
88 # define	MSGLEN		SCREEN_WIDTH
89 # define	DECAY		50.0
90 
91 # define	NASCII		128
92 
93 # define	WIDTH	51
94 # define	WIDTH2	64	/* Next power of 2 >= WIDTH (for fast access) */
95 # define	HEIGHT	23
96 # define	UBOUND	1
97 # define	DBOUND	(HEIGHT - 1)
98 # define	LBOUND	1
99 # define	RBOUND	(WIDTH - 1)
100 
101 # define	SCREEN_HEIGHT	24
102 # define	SCREEN_WIDTH	80
103 # define	SCREEN_WIDTH2	128	/* Next power of 2 >= SCREEN_WIDTH */
104 
105 # define	STAT_LABEL_COL	60
106 # define	STAT_VALUE_COL	74
107 # define	STAT_NAME_COL	61
108 # define	STAT_SCAN_COL	(STAT_NAME_COL + 5)
109 # define	STAT_AMMO_ROW	0
110 # define	STAT_GUN_ROW	1
111 # define	STAT_DAM_ROW	2
112 # define	STAT_KILL_ROW	3
113 # define	STAT_PLAY_ROW	5
114 # ifdef MONITOR
115 # define	STAT_MON_ROW	(STAT_PLAY_ROW + MAXPL + 1)
116 # endif
117 # define	STAT_NAME_LEN	18
118 
119 # define	DOOR	'#'
120 # define	WALL1	'-'
121 # define	WALL2	'|'
122 # define	WALL3	'+'
123 # ifdef REFLECT
124 # define	WALL4	'/'
125 # define	WALL5	'\\'
126 # endif
127 # define	KNIFE	'K'
128 # define	SHOT	':'
129 # define	GRENADE	'o'
130 # define	SATCHEL	'O'
131 # define	BOMB	'@'
132 # define	MINE	';'
133 # define	GMINE	'g'
134 # ifdef	OOZE
135 # define	SLIME	'$'
136 # endif
137 # ifdef	VOLCANO
138 # define	LAVA	'~'
139 # endif
140 # ifdef DRONE
141 # define	DSHOT	'?'
142 # endif
143 # ifdef FLY
144 # define	FALL	'F'
145 # endif
146 # ifdef BOOTS
147 # define	NBOOTS		2
148 # define	BOOT		'b'
149 # define	BOOT_PAIR	'B'
150 # endif
151 # define	SPACE	' '
152 
153 # define	ABOVE	'i'
154 # define	BELOW	'!'
155 # define	RIGHT	'}'
156 # define	LEFTS	'{'
157 # ifdef FLY
158 # define	FLYER	'&'
159 # define	isplayer(c)	(c == LEFTS || c == RIGHT ||\
160 				c == ABOVE || c == BELOW || c == FLYER)
161 # else
162 # define	isplayer(c)	(c == LEFTS || c == RIGHT ||\
163 				c == ABOVE || c == BELOW)
164 # endif
165 
166 # define	NORTH	01
167 # define	SOUTH	02
168 # define	EAST	010
169 # define	WEST	020
170 
171 # ifndef TRUE
172 # define	TRUE	1
173 # define	FALSE	0
174 # endif
175 # undef CTRL
176 # define	CTRL(x)	((x) & 037)
177 
178 # define	BULSPD		5		/* bullets movement speed */
179 # define	ISHOTS		15
180 # define	NSHOTS		5
181 # define	MAXNCSHOT	2
182 # define	MAXDAM		10
183 # define	MINDAM		5
184 # define	STABDAM		2
185 
186 # define	BULREQ		1
187 # define	GRENREQ		9
188 # define	SATREQ		25
189 # define	BOMB7REQ	49
190 # define	BOMB9REQ	81
191 # define	BOMB11REQ	121
192 # define	BOMB13REQ	169
193 # define	BOMB15REQ	225
194 # define	BOMB17REQ	289
195 # define	BOMB19REQ	361
196 # define	BOMB21REQ	441
197 # define	MAXBOMB		11
198 # ifdef DRONE
199 # define	MINDSHOT	2	/* At least a satchel bomb */
200 # endif
201 extern int	shot_req[];
202 extern int	shot_type[];
203 # ifdef	OOZE
204 # define	SLIME_FACTOR	3
205 # define	SLIMEREQ	5
206 # define	SSLIMEREQ	10
207 # define	SLIME2REQ	15
208 # define	SLIME3REQ	20
209 # define	MAXSLIME	4
210 # define	SLIMESPEED	5
211 extern int	slime_req[];
212 # endif
213 # ifdef	VOLCANO
214 # define	LAVASPEED	1
215 # endif
216 
217 # define	CLOAKLEN	20
218 # define	SCANLEN		(Nplayer * 20)
219 # define	EXPLEN		4
220 
221 # define	Q_QUIT		0
222 # define	Q_CLOAK		1
223 # define	Q_FLY		2
224 # define	Q_SCAN		3
225 # define	Q_MESSAGE	4
226 
227 # define	C_PLAYER	0
228 # define	C_MONITOR	1
229 # define	C_MESSAGE	2
230 # define	C_SCORES	3
231 
232 # ifdef MONITOR
233 # define	C_TESTMSG()	(Query_driver ? C_MESSAGE :\
234 				(Show_scores ? C_SCORES :\
235 				(Am_monitor ? C_MONITOR :\
236 				C_PLAYER)))
237 # else
238 # define	C_TESTMSG()	(Show_scores ? C_SCORES :\
239 				(Query_driver ? C_MESSAGE :\
240 				C_PLAYER))
241 # endif
242 
243 # ifdef FLY
244 # define	_scan_char(pp)	(((pp)->p_scan < 0) ? ' ' : '*')
245 # define	_cloak_char(pp)	(((pp)->p_cloak < 0) ? _scan_char(pp) : '+')
246 # define	stat_char(pp)	(((pp)->p_flying < 0) ? _cloak_char(pp) : FLYER)
247 # else
248 # define	_scan_char(pp)	(((pp)->p_scan < 0) ? ' ' : '*')
249 # define	stat_char(pp)	(((pp)->p_cloak < 0) ? _scan_char(pp) : '+')
250 # endif
251 
252 typedef int			FLAG;
253 typedef struct bullet_def	BULLET;
254 typedef struct expl_def		EXPL;
255 typedef struct player_def	PLAYER;
256 typedef struct ident_def	IDENT;
257 typedef struct regen_def	REGEN;
258 # ifdef	INTERNET
259 typedef struct sockaddr_in	SOCKET;
260 # else
261 typedef struct sockaddr_un	SOCKET;
262 # endif
263 
264 struct ident_def {
265 	char	i_name[NAMELEN];
266 	char	i_team;
267 	long	i_machine;
268 	long	i_uid;
269 	float	i_kills;
270 	int	i_entries;
271 	float	i_score;
272 	int	i_absorbed;
273 	int	i_faced;
274 	int	i_shot;
275 	int	i_robbed;
276 	int	i_slime;
277 	int	i_missed;
278 	int	i_ducked;
279 	int	i_gkills, i_bkills, i_deaths, i_stillb, i_saved;
280 	IDENT	*i_next;
281 };
282 
283 struct player_def {
284 	IDENT	*p_ident;
285 	char	p_over;
286 	int	p_face;
287 	int	p_undershot;
288 # ifdef	FLY
289 	int	p_flying;
290 	int	p_flyx, p_flyy;
291 # endif
292 # ifdef	BOOTS
293 	int	p_nboots;
294 # endif
295 	FILE	*p_output;
296 	int	p_fd;
297 	int	p_mask;
298 	int	p_damage;
299 	int	p_damcap;
300 	int	p_ammo;
301 	int	p_ncshot;
302 	int	p_scan;
303 	int	p_cloak;
304 	int	p_x, p_y;
305 	int	p_ncount;
306 	int	p_nexec;
307 	long	p_nchar;
308 	char	p_death[MSGLEN];
309 	char	p_maze[HEIGHT][WIDTH2];
310 	int	p_curx, p_cury;
311 	int	p_lastx, p_lasty;
312 	char	p_cbuf[BUFSIZ];
313 };
314 
315 struct bullet_def {
316 	int	b_x, b_y;
317 	int	b_face;
318 	int	b_charge;
319 	char	b_type;
320 	char	b_size;
321 	char	b_over;
322 	PLAYER	*b_owner;
323 	IDENT	*b_score;
324 	FLAG	b_expl;
325 	BULLET	*b_next;
326 };
327 
328 struct expl_def {
329 	int	e_x, e_y;
330 	char	e_char;
331 	EXPL	*e_next;
332 };
333 
334 struct regen_def {
335 	int	r_x, r_y;
336 	REGEN	*r_next;
337 };
338 
339 /*
340  * external variables
341  */
342 
343 extern FLAG	Last_player;
344 
345 extern char	Buf[BUFSIZ], Maze[HEIGHT][WIDTH2], Orig_maze[HEIGHT][WIDTH2];
346 
347 extern char	*Sock_name, *Driver;
348 
349 extern int	Nplayer, Num_fds, Socket, Status;
350 extern fd_set	Fds_mask, Have_inp;
351 
352 # ifdef INTERNET
353 extern u_short	Test_port;
354 # else
355 extern char	*Sock_name;
356 # endif
357 
358 # ifdef VOLCANO
359 extern int	volcano;
360 # endif
361 
362 extern int	See_over[NASCII];
363 
364 extern BULLET	*Bullets;
365 
366 extern EXPL	*Expl[EXPLEN];
367 extern EXPL	*Last_expl;
368 
369 extern IDENT	*Scores;
370 
371 extern PLAYER	Player[MAXPL], *End_player;
372 # ifdef BOOTS
373 extern PLAYER	Boot[NBOOTS];
374 # endif
375 
376 # ifdef MONITOR
377 extern FLAG	Am_monitor;
378 extern PLAYER	Monitor[MAXMON], *End_monitor;
379 # endif
380 
381 # ifdef INTERNET
382 extern char	*Send_message;
383 # endif
384 
385 extern char	map_key[256];
386 extern FLAG	no_beep;
387 
388 /*
389  * function types
390  */
391 
392 void		add_shot __P((int, int, int, char, int, PLAYER *, int, char));
393 int		answer __P((void));
394 void		bad_con __P((void));
395 void		bad_ver __P((void));
396 int		broadcast_vec __P((int, struct	sockaddr **));
397 void		ce __P((PLAYER *));
398 void		cgoto __P((PLAYER *, int, int));
399 void		check __P((PLAYER *, int, int));
400 void		checkdam __P((PLAYER *, PLAYER *, IDENT *, int, char));
401 void		clearwalls __P((void));
402 void		clear_eol __P((void));
403 void		clear_the_screen __P((void));
404 void		clrscr __P((PLAYER *));
405 BULLET	       *create_shot __P((int, int, int, char, int, int, PLAYER *,
406 		    IDENT *, int, char));
407 void		do_connect __P((char *, char, long));
408 void		do_message __P((void));
409 void		drawmaze __P((PLAYER *));
410 void		drawplayer __P((PLAYER *, FLAG));
411 void		drawstatus __P((PLAYER *));
412 void		execute __P((PLAYER *));
413 void		faketalk __P((void));
414 void		find_driver __P((FLAG));
415 void		fixshots __P((int, int, char));
416 IDENT	       *get_ident __P((u_long, u_long, char *, char));
417 void		get_local_name __P((char *));
418 int		get_remote_name __P((char *));
419 BULLET	       *is_bullet __P((int, int));
420 void		look __P((PLAYER *));
421 void		makemaze __P((void));
422 void		message __P((PLAYER *, char *));
423 void		mon_execute __P((PLAYER *));
424 void		moveshots __P((void));
425 void		open_ctl __P((void));
426 int		opposite __P((int, char));
427 void		otto __P((int, int, char));
428 void		outch __P((PLAYER *, int));
429 void		outstr __P((PLAYER *, char *, int));
430 int		player_sym __P((PLAYER *, int, int));
431 PLAYER	       *play_at __P((int, int));
432 void		playit __P((void));
433 void		put_ch __P((char));
434 void		put_str __P((char *));
435 int		quit __P((int));
436 int		rand_dir __P((void));
437 int		rand_num __P((int));
438 void		redraw_screen __P((void));
439 void		rmnl __P((char *));
440 void		rollexpl __P((void));
441 void		see __P((PLAYER *, int));
442 void		sendcom __P((PLAYER *, int, ...));
443 void		showexpl __P((int, int, char));
444 void		showstat __P((PLAYER *));
445 void		start_driver __P((void));
446 void		stmonitor __P((PLAYER *));
447 void		stplayer __P((PLAYER *, int));
448 char		translate __P((char));
449 SIGNAL_TYPE	cleanup __P((int)) __attribute__((__noreturn__));
450 SIGNAL_TYPE	intr __P((int));
451 SIGNAL_TYPE	sigalrm __P((int));
452 SIGNAL_TYPE	sigemt __P((int));
453 SIGNAL_TYPE	sigterm __P((int));
454 SIGNAL_TYPE	tstp __P((int));
455