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