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