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