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