hunt.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /* $NetBSD: hunt.h,v 1.11 2004/02/08 22:23:50 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1983-2003, Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * + Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * + Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * + Neither the name of the University of California, San Francisco nor
  16. * the names of its contributors may be used to endorse or promote
  17. * products derived from this software without specific prior written
  18. * permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  23. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. # include "bsd.h"
  33. # include <errno.h>
  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/poll.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. # ifdef INTERNET
  58. # define SOCK_FAMILY AF_INET
  59. # else
  60. # define SOCK_FAMILY AF_UNIX
  61. # define AF_UNIX_HACK /* 4.2 hack; leaves files around */
  62. # endif
  63. /*
  64. * Preprocessor define dependencies
  65. */
  66. # if defined(VOLCANO) && !defined(OOZE)
  67. # define OOZE
  68. # endif
  69. # if defined(BOOTS) && !defined(FLY)
  70. # define FLY
  71. # endif
  72. # if !defined(REFLECT) && !defined(RANDOM)
  73. # define RANDOM
  74. # endif
  75. # ifdef TERMINFO
  76. /* mvcur() in terminfo needs the curses library to be initialized to not
  77. * coredump, so give up and use it. */
  78. # define USE_CURSES
  79. # endif
  80. /* decrement version number for each change in startup protocol */
  81. # define HUNT_VERSION -1
  82. # define ADDCH ('a' | 0200)
  83. # define MOVE ('m' | 0200)
  84. # define REFRESH ('r' | 0200)
  85. # define CLRTOEOL ('c' | 0200)
  86. # define ENDWIN ('e' | 0200)
  87. # define CLEAR ('C' | 0200)
  88. # define REDRAW ('R' | 0200)
  89. # define LAST_PLAYER ('l' | 0200)
  90. # define BELL ('b' | 0200)
  91. # define READY ('g' | 0200)
  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. # define NASCII 128
  110. # define WIDTH 51
  111. # define WIDTH2 64 /* Next power of 2 >= WIDTH (for fast access) */
  112. # define HEIGHT 23
  113. # define UBOUND 1
  114. # define DBOUND (HEIGHT - 1)
  115. # define LBOUND 1
  116. # define RBOUND (WIDTH - 1)
  117. # define SCREEN_HEIGHT 24
  118. # define SCREEN_WIDTH 80
  119. # define SCREEN_WIDTH2 128 /* Next power of 2 >= SCREEN_WIDTH */
  120. # define STAT_LABEL_COL 60
  121. # define STAT_VALUE_COL 74
  122. # define STAT_NAME_COL 61
  123. # define STAT_SCAN_COL (STAT_NAME_COL + 5)
  124. # define STAT_AMMO_ROW 0
  125. # define STAT_GUN_ROW 1
  126. # define STAT_DAM_ROW 2
  127. # define STAT_KILL_ROW 3
  128. # define STAT_PLAY_ROW 5
  129. # ifdef MONITOR
  130. # define STAT_MON_ROW (STAT_PLAY_ROW + MAXPL + 1)
  131. # endif
  132. # define STAT_NAME_LEN 18
  133. # define DOOR '#'
  134. # define WALL1 '-'
  135. # define WALL2 '|'
  136. # define WALL3 '+'
  137. # ifdef REFLECT
  138. # define WALL4 '/'
  139. # define WALL5 '\\'
  140. # endif
  141. # define KNIFE 'K'
  142. # define SHOT ':'
  143. # define GRENADE 'o'
  144. # define SATCHEL 'O'
  145. # define BOMB '@'
  146. # define MINE ';'
  147. # define GMINE 'g'
  148. # ifdef OOZE
  149. # define SLIME '$'
  150. # endif
  151. # ifdef VOLCANO
  152. # define LAVA '~'
  153. # endif
  154. # ifdef DRONE
  155. # define DSHOT '?'
  156. # endif
  157. # ifdef FLY
  158. # define FALL 'F'
  159. # endif
  160. # ifdef BOOTS
  161. # define NBOOTS 2
  162. # define BOOT 'b'
  163. # define BOOT_PAIR 'B'
  164. # endif
  165. # define SPACE ' '
  166. # define ABOVE 'i'
  167. # define BELOW '!'
  168. # define RIGHT '}'
  169. # define LEFTS '{'
  170. # ifdef FLY
  171. # define FLYER '&'
  172. # define is_player(c) (c == LEFTS || c == RIGHT ||\
  173. c == ABOVE || c == BELOW || c == FLYER)
  174. # else
  175. # define is_player(c) (c == LEFTS || c == RIGHT ||\
  176. c == ABOVE || c == BELOW)
  177. # endif
  178. # define NORTH 01
  179. # define SOUTH 02
  180. # define EAST 010
  181. # define WEST 020
  182. # ifndef TRUE
  183. # define TRUE 1
  184. # define FALSE 0
  185. # endif
  186. # undef CTRL
  187. # define CTRL(x) ((x) & 037)
  188. # define BULSPD 5 /* bullets movement speed */
  189. # define ISHOTS 15
  190. # define NSHOTS 5
  191. # define MAXNCSHOT 2
  192. # define MAXDAM 10
  193. # define MINDAM 5
  194. # define STABDAM 2
  195. # define BULREQ 1
  196. # define GRENREQ 9
  197. # define SATREQ 25
  198. # define BOMB7REQ 49
  199. # define BOMB9REQ 81
  200. # define BOMB11REQ 121
  201. # define BOMB13REQ 169
  202. # define BOMB15REQ 225
  203. # define BOMB17REQ 289
  204. # define BOMB19REQ 361
  205. # define BOMB21REQ 441
  206. # define MAXBOMB 11
  207. # ifdef DRONE
  208. # define MINDSHOT 2 /* At least a satchel bomb */
  209. # endif
  210. extern int shot_req[];
  211. extern int shot_type[];
  212. # ifdef OOZE
  213. # define SLIME_FACTOR 3
  214. # define SLIMEREQ 5
  215. # define SSLIMEREQ 10
  216. # define SLIME2REQ 15
  217. # define SLIME3REQ 20
  218. # define MAXSLIME 4
  219. # define SLIMESPEED 5
  220. extern int slime_req[];
  221. # endif
  222. # ifdef VOLCANO
  223. # define LAVASPEED 1
  224. # endif
  225. # define CLOAKLEN 20
  226. # define SCANLEN (Nplayer * 20)
  227. # define EXPLEN 4
  228. # define Q_QUIT 0
  229. # define Q_CLOAK 1
  230. # define Q_FLY 2
  231. # define Q_SCAN 3
  232. # define Q_MESSAGE 4
  233. # define C_PLAYER 0
  234. # define C_MONITOR 1
  235. # define C_MESSAGE 2
  236. # define C_SCORES 3
  237. # ifdef MONITOR
  238. # define C_TESTMSG() (Query_driver ? C_MESSAGE :\
  239. (Show_scores ? C_SCORES :\
  240. (Am_monitor ? C_MONITOR :\
  241. C_PLAYER)))
  242. # else
  243. # define C_TESTMSG() (Show_scores ? C_SCORES :\
  244. (Query_driver ? C_MESSAGE :\
  245. C_PLAYER))
  246. # endif
  247. # ifdef FLY
  248. # define _scan_char(pp) (((pp)->p_scan < 0) ? ' ' : '*')
  249. # define _cloak_char(pp) (((pp)->p_cloak < 0) ? _scan_char(pp) : '+')
  250. # define stat_char(pp) (((pp)->p_flying < 0) ? _cloak_char(pp) : FLYER)
  251. # else
  252. # define _scan_char(pp) (((pp)->p_scan < 0) ? ' ' : '*')
  253. # define stat_char(pp) (((pp)->p_cloak < 0) ? _scan_char(pp) : '+')
  254. # endif
  255. typedef int FLAG;
  256. typedef struct bullet_def BULLET;
  257. typedef struct expl_def EXPL;
  258. typedef struct player_def PLAYER;
  259. typedef struct ident_def IDENT;
  260. typedef struct regen_def REGEN;
  261. # ifdef INTERNET
  262. typedef struct sockaddr_in SOCKET;
  263. # else
  264. typedef struct sockaddr_un SOCKET;
  265. # endif
  266. struct ident_def {
  267. char i_name[NAMELEN];
  268. char i_team;
  269. long i_machine;
  270. long i_uid;
  271. float i_kills;
  272. int i_entries;
  273. float i_score;
  274. int i_absorbed;
  275. int i_faced;
  276. int i_shot;
  277. int i_robbed;
  278. int i_slime;
  279. int i_missed;
  280. int i_ducked;
  281. int i_gkills, i_bkills, i_deaths, i_stillb, i_saved;
  282. IDENT *i_next;
  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. struct bullet_def {
  316. int b_x, b_y;
  317. int b_face;
  318. int b_charge;
  319. char b_type;
  320. char b_size;
  321. char b_over;
  322. PLAYER *b_owner;
  323. IDENT *b_score;
  324. FLAG b_expl;
  325. BULLET *b_next;
  326. };
  327. struct expl_def {
  328. int e_x, e_y;
  329. char e_char;
  330. EXPL *e_next;
  331. };
  332. struct regen_def {
  333. int r_x, r_y;
  334. REGEN *r_next;
  335. };
  336. /*
  337. * external variables
  338. */
  339. extern FLAG Last_player;
  340. extern char Buf[BUFSIZ], Maze[HEIGHT][WIDTH2], Orig_maze[HEIGHT][WIDTH2];
  341. extern const char *Driver;
  342. extern int Nplayer, Socket, Status;
  343. extern struct pollfd fdset[];
  344. # ifdef INTERNET
  345. extern u_short Test_port;
  346. # else
  347. extern char *Sock_name, *Stat_name;
  348. # endif
  349. # ifdef VOLCANO
  350. extern int volcano;
  351. # endif
  352. extern int See_over[NASCII];
  353. extern BULLET *Bullets;
  354. extern EXPL *Expl[EXPLEN];
  355. extern EXPL *Last_expl;
  356. extern IDENT *Scores;
  357. extern PLAYER Player[MAXPL], *End_player;
  358. # ifdef BOOTS
  359. extern PLAYER Boot[NBOOTS];
  360. # endif
  361. # ifdef MONITOR
  362. extern FLAG Am_monitor;
  363. extern PLAYER Monitor[MAXMON], *End_monitor;
  364. # endif
  365. # ifdef INTERNET
  366. extern char *Send_message;
  367. # endif
  368. extern char map_key[256];
  369. extern FLAG no_beep;
  370. /*
  371. * function types
  372. */
  373. void add_shot(int, int, int, char, int, PLAYER *, int, char);
  374. int answer(void);
  375. void bad_con(void) __attribute__((__noreturn__));
  376. void bad_ver(void) __attribute__((__noreturn__));
  377. int broadcast_vec(int, struct sockaddr **);
  378. void ce(PLAYER *);
  379. void cgoto(PLAYER *, int, int);
  380. void check(PLAYER *, int, int);
  381. void checkdam(PLAYER *, PLAYER *, IDENT *, int, char);
  382. void clearwalls(void);
  383. void clear_eol(void);
  384. void clear_the_screen(void);
  385. void clrscr(PLAYER *);
  386. BULLET *create_shot(int, int, int, char, int, int, PLAYER *,
  387. IDENT *, int, char);
  388. void do_connect(const char *, char, long);
  389. void do_message(void);
  390. void drawmaze(PLAYER *);
  391. void drawplayer(PLAYER *, FLAG);
  392. void drawstatus(PLAYER *);
  393. void execute(PLAYER *);
  394. void faketalk(void);
  395. void find_driver(FLAG);
  396. void fixshots(int, int, char);
  397. IDENT *get_ident(u_long, u_long, const char *, char);
  398. void get_local_name(const char *);
  399. int get_remote_name(char *);
  400. BULLET *is_bullet(int, int);
  401. void look(PLAYER *);
  402. void makemaze(void);
  403. void message(PLAYER *, const char *);
  404. void mon_execute(PLAYER *);
  405. void moveshots(void);
  406. void open_ctl(void);
  407. int opposite(int, char);
  408. void otto(int, int, char);
  409. void outch(PLAYER *, int);
  410. void outstr(PLAYER *, const char *, int);
  411. int player_sym(const PLAYER *, int, int);
  412. PLAYER *play_at(int, int);
  413. void playit(void);
  414. void put_ch(char);
  415. # ifndef USE_CURSES
  416. void put_str(const char *);
  417. # endif
  418. int quit(int);
  419. int rand_dir(void);
  420. int rand_num(int);
  421. void redraw_screen(void);
  422. void rmnl(char *);
  423. void rollexpl(void);
  424. void see(PLAYER *, int);
  425. void sendcom(PLAYER *, int, ...);
  426. void showexpl(int, int, char);
  427. void showstat(PLAYER *);
  428. void start_driver(void);
  429. void stmonitor(PLAYER *);
  430. void stplayer(PLAYER *, int);
  431. char translate(char);
  432. SIGNAL_TYPE cleanup(int) __attribute__((__noreturn__));
  433. SIGNAL_TYPE intr(int);
  434. SIGNAL_TYPE sigalrm(int);
  435. SIGNAL_TYPE sigemt(int) __attribute__((__noreturn__));
  436. SIGNAL_TYPE sigterm(int) __attribute__((__noreturn__));
  437. SIGNAL_TYPE sigusr1(int) __attribute__((__noreturn__));
  438. SIGNAL_TYPE tstp(int);