Home | History | Annotate | Line # | Download | only in huntd
hunt.h revision 1.3
      1 /*	$NetBSD: hunt.h,v 1.3 1998/01/09 08:03:41 perry 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 typedef struct sgttyb		TTYB;
    264 
    265 struct ident_def {
    266 	char	i_name[NAMELEN];
    267 	char	i_team;
    268 	long	i_machine;
    269 	long	i_uid;
    270 	float	i_kills;
    271 	int	i_entries;
    272 	float	i_score;
    273 	int	i_absorbed;
    274 	int	i_faced;
    275 	int	i_shot;
    276 	int	i_robbed;
    277 	int	i_slime;
    278 	int	i_missed;
    279 	int	i_ducked;
    280 	int	i_gkills, i_bkills, i_deaths, i_stillb, i_saved;
    281 	IDENT	*i_next;
    282 };
    283 
    284 struct player_def {
    285 	IDENT	*p_ident;
    286 	char	p_over;
    287 	int	p_face;
    288 	int	p_undershot;
    289 # ifdef	FLY
    290 	int	p_flying;
    291 	int	p_flyx, p_flyy;
    292 # endif
    293 # ifdef	BOOTS
    294 	int	p_nboots;
    295 # endif
    296 	FILE	*p_output;
    297 	int	p_fd;
    298 	int	p_mask;
    299 	int	p_damage;
    300 	int	p_damcap;
    301 	int	p_ammo;
    302 	int	p_ncshot;
    303 	int	p_scan;
    304 	int	p_cloak;
    305 	int	p_x, p_y;
    306 	int	p_ncount;
    307 	int	p_nexec;
    308 	long	p_nchar;
    309 	char	p_death[MSGLEN];
    310 	char	p_maze[HEIGHT][WIDTH2];
    311 	int	p_curx, p_cury;
    312 	int	p_lastx, p_lasty;
    313 	char	p_cbuf[BUFSIZ];
    314 };
    315 
    316 struct bullet_def {
    317 	int	b_x, b_y;
    318 	int	b_face;
    319 	int	b_charge;
    320 	char	b_type;
    321 	char	b_size;
    322 	char	b_over;
    323 	PLAYER	*b_owner;
    324 	IDENT	*b_score;
    325 	FLAG	b_expl;
    326 	BULLET	*b_next;
    327 };
    328 
    329 struct expl_def {
    330 	int	e_x, e_y;
    331 	char	e_char;
    332 	EXPL	*e_next;
    333 };
    334 
    335 struct regen_def {
    336 	int	r_x, r_y;
    337 	REGEN	*r_next;
    338 };
    339 
    340 /*
    341  * external variables
    342  */
    343 
    344 extern FLAG	Last_player;
    345 
    346 extern char	Buf[BUFSIZ], Maze[HEIGHT][WIDTH2], Orig_maze[HEIGHT][WIDTH2];
    347 
    348 extern char	*Sock_name, *Driver;
    349 
    350 extern int	errno, Nplayer, Num_fds, Socket, Status;
    351 extern fd_set	Fds_mask, Have_inp;
    352 
    353 # ifdef INTERNET
    354 extern u_short	Test_port;
    355 # else
    356 extern char	*Sock_name;
    357 # endif
    358 
    359 # ifdef VOLCANO
    360 extern int	volcano;
    361 # endif
    362 
    363 extern int	See_over[NASCII];
    364 
    365 extern BULLET	*Bullets;
    366 
    367 extern EXPL	*Expl[EXPLEN];
    368 extern EXPL	*Last_expl;
    369 
    370 extern IDENT	*Scores;
    371 
    372 extern PLAYER	Player[MAXPL], *End_player;
    373 # ifdef BOOTS
    374 extern PLAYER	Boot[NBOOTS];
    375 # endif
    376 
    377 # ifdef MONITOR
    378 extern FLAG	Am_monitor;
    379 extern PLAYER	Monitor[MAXMON], *End_monitor;
    380 # endif
    381 
    382 # ifdef INTERNET
    383 extern char	*Send_message;
    384 # endif
    385 
    386 extern char	map_key[256];
    387 extern FLAG	no_beep;
    388 
    389 /*
    390  * function types
    391  */
    392 
    393 void		add_shot __P((int, int, int, char, int, PLAYER *, int, char));
    394 int		answer __P((void));
    395 void		bad_con __P((void));
    396 void		bad_ver __P((void));
    397 int		broadcast_vec __P((int, struct	sockaddr **));
    398 void		ce __P((PLAYER *));
    399 void		cgoto __P((PLAYER *, int, int));
    400 void		check __P((PLAYER *, int, int));
    401 void		checkdam __P((PLAYER *, PLAYER *, IDENT *, int, char));
    402 void		clearwalls __P((void));
    403 void		clear_eol __P((void));
    404 void		clear_the_screen __P((void));
    405 void		clrscr __P((PLAYER *));
    406 BULLET	       *create_shot __P((int, int, int, char, int, int, PLAYER *,
    407 		    IDENT *, int, char));
    408 void		do_connect __P((char *, char, long));
    409 void		do_message __P((void));
    410 void		drawmaze __P((PLAYER *));
    411 void		drawplayer __P((PLAYER *, FLAG));
    412 void		drawstatus __P((PLAYER *));
    413 void		execute __P((PLAYER *));
    414 void		faketalk __P((void));
    415 void		find_driver __P((FLAG));
    416 void		fixshots __P((int, int, char));
    417 IDENT	       *get_ident __P((u_long, u_long, char *, char));
    418 void		get_local_name __P((char *));
    419 int		get_remote_name __P((char *));
    420 BULLET	       *is_bullet __P((int, int));
    421 void		look __P((PLAYER *));
    422 void		makemaze __P((void));
    423 void		message __P((PLAYER *, char *));
    424 void		mon_execute __P((PLAYER *));
    425 void		moveshots __P((void));
    426 void		open_ctl __P((void));
    427 int		opposite __P((int, char));
    428 void		otto __P((int, int, char));
    429 void		outch __P((PLAYER *, int));
    430 void		outstr __P((PLAYER *, char *, int));
    431 int		player_sym __P((PLAYER *, int, int));
    432 PLAYER	       *play_at __P((int, int));
    433 void		playit __P((void));
    434 void		put_ch __P((char));
    435 void		put_str __P((char *));
    436 int		quit __P((int));
    437 int		rand_dir __P((void));
    438 int		rand_num __P((int));
    439 void		redraw_screen __P((void));
    440 void		rmnl __P((char *));
    441 void		rollexpl __P((void));
    442 void		see __P((PLAYER *, int));
    443 void		sendcom __P((PLAYER *, int, ...));
    444 void		showexpl __P((int, int, char));
    445 void		showstat __P((PLAYER *));
    446 void		start_driver __P((void));
    447 void		stmonitor __P((PLAYER *));
    448 void		stplayer __P((PLAYER *, int));
    449 char		translate __P((char));
    450 SIGNAL_TYPE	cleanup __P((int));
    451 SIGNAL_TYPE	intr __P((int));
    452 SIGNAL_TYPE	sigalrm __P((int));
    453 SIGNAL_TYPE	sigemt __P((int));
    454 SIGNAL_TYPE	sigterm __P((int));
    455 SIGNAL_TYPE	tstp __P((int));
    456