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