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