xref: /dragonfly/games/hunt/huntd/server.h (revision 25a2db75)
1 /*-
2  * Copyright (c) 1983-2003, Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the University of California, San Francisco nor
15  *    the names of its contributors may be used to endorse or promote
16  *    products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $OpenBSD: server.h,v 1.9 2004/01/16 00:13:19 espie Exp $
32  * $NetBSD: hunt.h,v 1.5 1998/09/13 15:27:28 hubertf Exp $
33  * $DragonFly: src/games/hunt/huntd/server.h,v 1.1 2008/09/02 21:50:21 dillon Exp $
34  */
35 
36 
37 #include <stdio.h>
38 #include <sys/socket.h>
39 #include <sys/types.h>
40 
41 #ifndef __GNUC__
42 #define __attribute__(x)
43 #endif
44 
45 /*
46  * Choose MAXPL and MAXMON carefully.  The screen is assumed to be
47  * 23 lines high and will only tolerate (MAXPL == 17 && MAXMON == 0)
48  * or (MAXPL + MAXMON <= 16).
49  */
50 #define MAXPL		14
51 #define MAXMON		2
52 #if (MAXPL + MAXMON > 16)
53 #warning "MAXPL + MAXMON is excessive"
54 #endif
55 
56 #define MSGLEN		SCREEN_WIDTH
57 
58 #define UBOUND		1
59 #define DBOUND		(HEIGHT - 1)
60 #define LBOUND		1
61 #define RBOUND		(WIDTH - 1)
62 
63 #define NASCII		128
64 
65 /* Layout of the scoreboard: */
66 #define STAT_LABEL_COL	60
67 #define STAT_VALUE_COL	74
68 #define STAT_NAME_COL	61
69 #define STAT_SCAN_COL	(STAT_NAME_COL + 5)
70 #define STAT_AMMO_ROW	0
71 #define STAT_GUN_ROW	1
72 #define STAT_DAM_ROW	2
73 #define STAT_KILL_ROW	3
74 #define STAT_PLAY_ROW	5
75 #define STAT_MON_ROW	(STAT_PLAY_ROW + MAXPL + 1)
76 #define STAT_NAME_LEN	18
77 
78 /* Number of boots: */
79 #define NBOOTS		2
80 
81 /* Bitmask of directions */
82 #define NORTH		01
83 #define SOUTH		02
84 #define EAST		010
85 #define WEST		020
86 
87 # undef CTRL
88 #define CTRL(x)	((x) & 037)
89 
90 #define BULREQ		1		/* 0 */
91 #define GRENREQ		9		/* 1 */
92 #define SATREQ		25		/* 2 */
93 #define BOMB7REQ	49		/* 3 */
94 #define BOMB9REQ	81		/* 4 */
95 #define BOMB11REQ	121		/* 5 */
96 #define BOMB13REQ	169		/* 6 */
97 #define BOMB15REQ	225		/* 7 */
98 #define BOMB17REQ	289		/* 8 */
99 #define BOMB19REQ	361		/* 9 */
100 #define BOMB21REQ	441		/* 10 */
101 #define MAXBOMB				   11
102 
103 #define SLIMEREQ	5		/* 0 */
104 #define SSLIMEREQ	10		/* 1 */
105 #define SLIME2REQ	15		/* 2 */
106 #define SLIME3REQ	20		/* 3 */
107 #define MAXSLIME			   4
108 
109 #define EXPLEN		16
110 
111 #define _scan_char(pp)	(((pp)->p_scan < 0) ? ' ' : '*')
112 #define _cloak_char(pp)	(((pp)->p_cloak < 0) ? _scan_char(pp) : '+')
113 #define stat_char(pp)	(((pp)->p_flying < 0) ? _cloak_char(pp) : FLYER)
114 
115 typedef struct bullet_def	BULLET;
116 typedef struct expl_def		EXPL;
117 typedef struct player_def	PLAYER;
118 typedef struct ident_def	IDENT;
119 typedef struct regen_def	REGEN;
120 
121 #define	ALL_PLAYERS		((PLAYER *)1)
122 
123 struct ident_def {
124 	char	i_name[NAMELEN];
125 	char	i_team;
126 	u_int32_t i_machine;
127 	uid_t	i_uid;
128 	float	i_kills;
129 	int	i_entries;
130 	float	i_score;
131 	int	i_absorbed;
132 	int	i_faced;
133 	int	i_shot;
134 	int	i_robbed;
135 	int	i_slime;
136 	int	i_missed;
137 	int	i_ducked;
138 	int	i_gkills, i_bkills, i_deaths, i_stillb, i_saved;
139 	IDENT	*i_next;
140 };
141 
142 struct player_def {
143 	IDENT	*p_ident;
144 	char	p_over;
145 	int	p_face;
146 	int	p_undershot;
147 	int	p_flying;
148 	int	p_flyx, p_flyy;
149 	int	p_nboots;
150 	FILE	*p_output;
151 	int	p_fd;
152 	int	p_mask;
153 	int	p_damage;
154 	int	p_damcap;
155 	int	p_ammo;
156 	int	p_ncshot;
157 	int	p_scan;
158 	int	p_cloak;
159 	int	p_x, p_y;
160 	int	p_ncount;
161 	int	p_nexec;
162 	long	p_nchar;
163 	char	p_death[MSGLEN];
164 	char	p_maze[HEIGHT][WIDTH2];
165 	int	p_curx, p_cury;
166 	int	p_lastx, p_lasty;
167 	char	p_cbuf[BUFSIZ];
168 };
169 
170 struct bullet_def {
171 	int	b_x, b_y;
172 	int	b_face;
173 	int	b_charge;
174 	char	b_type;
175 	char	b_size;
176 	char	b_over;
177 	PLAYER	*b_owner;
178 	IDENT	*b_score;
179 	FLAG	b_expl;
180 	BULLET	*b_next;
181 };
182 
183 struct expl_def {
184 	int	e_x, e_y;
185 	char	e_char;
186 	EXPL	*e_next;
187 };
188 
189 struct regen_def {
190 	int	r_x, r_y;
191 	REGEN	*r_next;
192 };
193 
194 struct spawn {
195 	int		fd;
196 	int		reading_msg;
197 	struct sockaddr source;
198 	socklen_t	sourcelen;
199 	uid_t		uid;
200 	char		name[NAMELEN+1];
201 	u_int8_t	team;
202 	u_int32_t	enter_status;
203 	char		ttyname[NAMELEN];
204 	u_int32_t	mode;
205 	char		msg[BUFSIZ];
206 	int		msglen;
207 	struct spawn *	next;
208 	struct spawn **	prevnext;
209 	int		inlen;
210 	char		inbuf[ sizeof (u_int32_t) + NAMELEN +
211 			       sizeof (u_int8_t) + sizeof (u_int32_t) +
212 			       NAMELEN + sizeof (u_int32_t) ];
213 };
214 
215 extern struct spawn *	Spawn;
216 
217 extern int	Socket;
218 
219 /* answer.c */
220 void	answer_first(void);
221 int	answer_next(struct spawn *);
222 int	rand_dir(void);
223 void	answer_info(FILE *);
224 
225 /* draw.c */
226 void	drawmaze(PLAYER *);
227 void	look(PLAYER *);
228 void	check(PLAYER *, int, int);
229 void	showstat(PLAYER *);
230 void	drawplayer(PLAYER *, FLAG);
231 void	message(PLAYER *, const char *);
232 
233 /* driver.c */
234 int	rand_num(int);
235 void	checkdam(PLAYER *, PLAYER *, IDENT *, int, char);
236 void	cleanup(int);
237 
238 /* execute.c */
239 void	mon_execute(PLAYER *);
240 void	execute(PLAYER *);
241 void	add_shot(int, int, int, char, int, PLAYER *, int, char);
242 BULLET *create_shot(int, int, int, char, int, int, PLAYER *, IDENT *,
243 	    int, char);
244 void	ammo_update(PLAYER *);
245 
246 /* expl.c */
247 void	showexpl(int, int, char);
248 void	rollexpl(void);
249 void	clearwalls(void);
250 int	can_rollexpl(void);
251 
252 /* makemaze.c */
253 void	makemaze(void);
254 
255 /* shots.c */
256 int	can_moveshots(void);
257 void	moveshots(void);
258 PLAYER *play_at(int, int);
259 int	opposite(int, char);
260 BULLET *is_bullet(int, int);
261 void	fixshots(int, int, char);
262 
263 /* terminal.c */
264 void	cgoto(PLAYER *, int, int);
265 void	outch(PLAYER *, char);
266 void	outstr(PLAYER *, const char *, int);
267 void	outyx(PLAYER *, int, int, const char *, ...)
268 			__attribute__((format (printf, 4, 5)));
269 void	clrscr(PLAYER *);
270 void	ce(PLAYER *);
271 void	sendcom(PLAYER *, int, ...);
272 void	flush(PLAYER *);
273 void	logit(int, const char *, ...)
274 			__attribute__((format (printf, 2, 3)));
275 void	logx(int, const char *, ...)
276 			__attribute__((format (printf, 2, 3)));
277 
278 /* extern.c */
279 extern FLAG	Am_monitor;
280 extern char	Buf[BUFSIZ];
281 extern char	Maze[HEIGHT][WIDTH2];
282 extern char	Orig_maze[HEIGHT][WIDTH2];
283 extern fd_set	Fds_mask;
284 extern fd_set	Have_inp;
285 extern int	Nplayer;
286 extern int	Num_fds;
287 extern int	Status;
288 extern int	See_over[NASCII];
289 extern BULLET *	Bullets;
290 extern EXPL *	Expl[EXPLEN];
291 extern EXPL *	Last_expl;
292 extern PLAYER	Player[MAXPL];
293 extern PLAYER *	End_player;
294 extern PLAYER	Boot[NBOOTS];
295 extern IDENT *	Scores;
296 extern PLAYER	Monitor[MAXMON];
297 extern PLAYER *	End_monitor;
298 extern int	volcano;
299 extern int	shot_req[MAXBOMB];
300 extern int	shot_type[MAXBOMB];
301 extern int	slime_req[MAXSLIME];
302