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