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