Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / games / hunt / huntd / hunt.h
blob3d920ff2e89e8b9bfc08bd3fb028bc52021504ce
1 /* $NetBSD: hunt.h,v 1.18 2009/07/04 07:51:35 dholland Exp $ */
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:
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.
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.
34 #include "bsd.h"
36 #include <stdio.h>
37 #include <string.h>
39 #ifdef LOG
40 #include <syslog.h>
41 #endif
43 #include <sys/ioctl.h>
44 #include <sys/types.h>
45 #include <sys/uio.h>
46 #include <sys/poll.h>
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
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
65 * Preprocessor define dependencies
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
77 /* decrement version number for each change in startup protocol */
78 #define HUNT_VERSION -1
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)
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).
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
109 #define NASCII 128
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)
119 #define SCREEN_HEIGHT 24
120 #define SCREEN_WIDTH 80
121 #define SCREEN_WIDTH2 128 /* Next power of 2 >= SCREEN_WIDTH */
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
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 ' '
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
184 #define NORTH 01
185 #define SOUTH 02
186 #define EAST 010
187 #define WEST 020
189 #ifndef TRUE
190 #define TRUE 1
191 #define FALSE 0
192 #endif
194 #undef CTRL
195 #define CTRL(x) ((x) & 037)
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
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
220 extern int shot_req[];
221 extern 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
230 extern int slime_req[];
231 #endif
232 #ifdef VOLCANO
233 #define LAVASPEED 1
234 #endif
236 #define CLOAKLEN 20
237 #define SCANLEN (Nplayer * 20)
238 #define EXPLEN 4
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
246 #define C_PLAYER 0
247 #define C_MONITOR 1
248 #define C_MESSAGE 2
249 #define C_SCORES 3
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
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
271 typedef int FLAG;
272 typedef struct bullet_def BULLET;
273 typedef struct expl_def EXPL;
274 typedef struct player_def PLAYER;
275 typedef struct ident_def IDENT;
276 typedef struct regen_def REGEN;
277 #ifdef INTERNET
278 typedef struct sockaddr_in SOCKET;
279 #else
280 typedef struct sockaddr_un SOCKET;
281 #endif
283 struct 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;
302 struct 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];
334 struct 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;
347 struct expl_def {
348 int e_x, e_y;
349 char e_char;
350 EXPL *e_next;
353 struct regen_def {
354 int r_x, r_y;
355 REGEN *r_next;
359 * external variables
362 extern FLAG Last_player;
364 extern char Buf[BUFSIZ], Maze[HEIGHT][WIDTH2], Orig_maze[HEIGHT][WIDTH2];
366 extern const char *Driver;
368 extern int Nplayer, Socket, Status;
369 extern struct pollfd fdset[];
371 #ifdef INTERNET
372 extern u_short Test_port;
373 #else
374 extern char *Sock_name, *Stat_name;
375 #endif
377 #ifdef VOLCANO
378 extern int volcano;
379 #endif
381 extern int See_over[NASCII];
383 extern BULLET *Bullets;
385 extern EXPL *Expl[EXPLEN];
386 extern EXPL *Last_expl;
388 extern IDENT *Scores;
390 extern PLAYER Player[MAXPL], *End_player;
391 #ifdef BOOTS
392 extern PLAYER Boot[NBOOTS];
393 #endif
395 #ifdef MONITOR
396 extern FLAG Am_monitor;
397 extern PLAYER Monitor[MAXMON], *End_monitor;
398 #endif
400 #ifdef INTERNET
401 extern char *Send_message;
402 #endif
404 extern char map_key[256];
405 extern FLAG no_beep;
408 * function types
411 void add_shot(int, int, int, char, int, PLAYER *, int, char);
412 int answer(void);
413 void bad_con(void) __dead;
414 void bad_ver(void) __dead;
415 void ce(PLAYER *);
416 void cgoto(PLAYER *, int, int);
417 void check(PLAYER *, int, int);
418 void checkdam(PLAYER *, PLAYER *, IDENT *, int, char);
419 void clearwalls(void);
420 void clear_eol(void);
421 void clear_the_screen(void);
422 void clrscr(PLAYER *);
423 BULLET *create_shot(int, int, int, char, int, int, PLAYER *,
424 IDENT *, int, char);
425 void do_connect(char *, char, long);
426 void do_message(void);
427 void drawmaze(PLAYER *);
428 void drawplayer(PLAYER *, FLAG);
429 void execute(PLAYER *);
430 void faketalk(void);
431 void fixshots(int, int, char);
432 void get_local_name(char *);
433 int get_remote_name(char *);
434 BULLET *is_bullet(int, int);
435 void look(PLAYER *);
436 void makemaze(void);
437 void message(PLAYER *, const char *);
438 void mon_execute(PLAYER *);
439 void moveshots(void);
440 void open_ctl(void);
441 int opposite(int, char);
442 void otto(int, int, char);
443 void outch(PLAYER *, int);
444 void outstr(PLAYER *, const char *, int);
445 PLAYER *play_at(int, int);
446 void playit(void);
447 void put_ch(char);
448 void put_str(char *);
449 int quit(int);
450 int rand_dir(void);
451 int rand_num(int);
452 void rollexpl(void);
453 void sendcom(PLAYER *, int, ...);
454 void showexpl(int, int, char);
455 void showstat(PLAYER *);
456 void cleanup(int) __dead;
457 void intr(int);
458 void tstp(int);