extern.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /* $NetBSD: extern.h,v 1.27 2004/02/08 00:32:48 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1983, 1993
  4. * The Regents of the University of California. 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
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * @(#)externs.h 8.1 (Berkeley) 5/31/93
  31. */
  32. #include <sys/types.h>
  33. #include "machdep.h"
  34. /* program mode */
  35. extern int mode;
  36. #define MODE_PLAYER 1
  37. #define MODE_DRIVER 2
  38. #define MODE_LOGGER 3
  39. /* command line flags */
  40. extern int randomize; /* -x, give first available ship */
  41. extern int longfmt; /* -l, print score in long format */
  42. extern int nobells; /* -b, don't ring bell before Signal */
  43. /* other initial modes */
  44. extern gid_t gid;
  45. extern gid_t egid;
  46. #define dieroll() ((random()) % 6 + 1)
  47. #define sqr(a) ((a) * (a))
  48. #define min(a,b) ((a) < (b) ? (a) : (b))
  49. #define grappled(a) ((a)->file->ngrap)
  50. #define fouled(a) ((a)->file->nfoul)
  51. #define snagged(a) (grappled(a) + fouled(a))
  52. #define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count)
  53. #define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count)
  54. #define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
  55. #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
  56. #define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
  57. #define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b))
  58. #define cleangrapple(a, b, c) Cleansnag(a, b, c, 1)
  59. #define cleanfoul(a, b, c) Cleansnag(a, b, c, 2)
  60. #define cleansnag(a, b, c) Cleansnag(a, b, c, 3)
  61. #define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
  62. #define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir])
  63. #define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir])
  64. #define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp))
  65. #define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
  66. /* loadL and loadR, should match loadname[] */
  67. #define L_EMPTY 0 /* should be 0, don't change */
  68. #define L_GRAPE 1
  69. #define L_CHAIN 2
  70. #define L_ROUND 3
  71. #define L_DOUBLE 4
  72. #define L_EXPLODE 5
  73. /*
  74. * readyL and readyR, these are bits, except R_EMPTY
  75. */
  76. #define R_EMPTY 0 /* not loaded and not loading */
  77. #define R_LOADING 1 /* loading */
  78. #define R_DOUBLE 2 /* loading double */
  79. #define R_LOADED 4 /* loaded */
  80. #define R_INITIAL 8 /* loaded initial */
  81. #define HULL 0
  82. #define RIGGING 1
  83. #define W_CAPTAIN 1
  84. #define W_CAPTURED 2
  85. #define W_CLASS 3
  86. #define W_CREW 4
  87. #define W_DBP 5
  88. #define W_DRIFT 6
  89. #define W_EXPLODE 7
  90. #define W_FILE 8
  91. #define W_FOUL 9
  92. #define W_GUNL 10
  93. #define W_GUNR 11
  94. #define W_HULL 12
  95. #define W_MOVE 13
  96. #define W_OBP 14
  97. #define W_PCREW 15
  98. #define W_UNFOUL 16
  99. #define W_POINTS 17
  100. #define W_QUAL 18
  101. #define W_UNGRAP 19
  102. #define W_RIGG 20
  103. #define W_COL 21
  104. #define W_DIR 22
  105. #define W_ROW 23
  106. #define W_SIGNAL 24
  107. #define W_SINK 25
  108. #define W_STRUCK 26
  109. #define W_TA 27
  110. #define W_ALIVE 28
  111. #define W_TURN 29
  112. #define W_WIND 30
  113. #define W_FS 31
  114. #define W_GRAP 32
  115. #define W_RIG1 33
  116. #define W_RIG2 34
  117. #define W_RIG3 35
  118. #define W_RIG4 36
  119. #define W_BEGIN 37
  120. #define W_END 38
  121. #define W_DDEAD 39
  122. #define NLOG 10
  123. struct logs {
  124. char l_name[20];
  125. int l_uid;
  126. int l_shipnum;
  127. int l_gamenum;
  128. int l_netpoints;
  129. };
  130. struct BP {
  131. short turnsent;
  132. struct ship *toship;
  133. short mensent;
  134. };
  135. struct snag {
  136. short sn_count;
  137. short sn_turn;
  138. };
  139. #define NSCENE nscene
  140. #define NSHIP 10
  141. #define NBP 3
  142. #define NNATION 8
  143. #define N_A 0
  144. #define N_B 1
  145. #define N_S 2
  146. #define N_F 3
  147. #define N_J 4
  148. #define N_D 5
  149. #define N_K 6
  150. #define N_O 7
  151. struct File {
  152. int index;
  153. char captain[20]; /* 0 */
  154. short points; /* 20 */
  155. unsigned char loadL; /* 22 */
  156. unsigned char loadR; /* 24 */
  157. unsigned char readyL; /* 26 */
  158. unsigned char readyR; /* 28 */
  159. struct BP OBP[NBP]; /* 30 */
  160. struct BP DBP[NBP]; /* 48 */
  161. char struck; /* 66 */
  162. struct ship *captured; /* 68 */
  163. short pcrew; /* 70 */
  164. char movebuf[10]; /* 72 */
  165. char drift; /* 82 */
  166. short nfoul;
  167. short ngrap;
  168. struct snag foul[NSHIP]; /* 84 */
  169. struct snag grap[NSHIP]; /* 124 */
  170. char RH; /* 224 */
  171. char RG; /* 226 */
  172. char RR; /* 228 */
  173. char FS; /* 230 */
  174. char explode; /* 232 */
  175. char sink; /* 234 */
  176. unsigned char dir;
  177. short col;
  178. short row;
  179. char loadwith;
  180. char stern;
  181. };
  182. struct ship {
  183. const char *shipname; /* 0 */
  184. struct shipspecs *specs; /* 2 */
  185. unsigned char nationality; /* 4 */
  186. short shiprow; /* 6 */
  187. short shipcol; /* 8 */
  188. char shipdir; /* 10 */
  189. struct File *file; /* 12 */
  190. };
  191. struct scenario {
  192. char winddir; /* 0 */
  193. char windspeed; /* 2 */
  194. char windchange; /* 4 */
  195. unsigned char vessels; /* 12 */
  196. const char *name; /* 14 */
  197. struct ship ship[NSHIP]; /* 16 */
  198. };
  199. extern struct scenario scene[];
  200. extern int nscene;
  201. struct shipspecs {
  202. char bs;
  203. char fs;
  204. char ta;
  205. short guns;
  206. unsigned char class;
  207. char hull;
  208. unsigned char qual;
  209. char crew1;
  210. char crew2;
  211. char crew3;
  212. char gunL;
  213. char gunR;
  214. char carL;
  215. char carR;
  216. int rig1;
  217. int rig2;
  218. int rig3;
  219. int rig4;
  220. short pts;
  221. };
  222. extern struct shipspecs specs[];
  223. extern struct scenario *cc; /* the current scenario */
  224. extern struct ship *ls; /* &cc->ship[cc->vessels] */
  225. #define SHIP(s) (&cc->ship[s])
  226. #define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++)
  227. struct windeffects {
  228. char A, B, C, D;
  229. };
  230. extern const struct windeffects WET[7][6];
  231. struct Tables {
  232. char H, G, C, R;
  233. };
  234. extern const struct Tables RigTable[11][6];
  235. extern const struct Tables HullTable[11][6];
  236. extern const char AMMO[9][4];
  237. extern const char HDT[9][10];
  238. extern const char HDTrake[9][10];
  239. extern const char QUAL[9][5];
  240. extern const char MT[9][3];
  241. extern const char *const countryname[];
  242. extern const char *const classname[];
  243. extern const char *const directionname[];
  244. extern const char *const qualname[];
  245. extern const char loadname[];
  246. extern const char rangeofshot[];
  247. extern const char dr[], dc[];
  248. extern int winddir;
  249. extern int windspeed;
  250. extern int turn;
  251. extern int game;
  252. extern int alive;
  253. extern int people;
  254. extern int hasdriver;
  255. /* assorted.c */
  256. void table (struct ship *, struct ship *, int, int, int, int);
  257. void Cleansnag (struct ship *, struct ship *, int, int);
  258. /* dr_1.c */
  259. void unfoul (void);
  260. void boardcomp (void);
  261. void resolve (void);
  262. void compcombat (void);
  263. int next (void);
  264. /* dr_2.c */
  265. void thinkofgrapples (void);
  266. void checkup (void);
  267. void prizecheck (void);
  268. void closeon (struct ship *, struct ship *, char *, int, int, int);
  269. /* dr_3.c */
  270. void moveall (void);
  271. void sendbp (struct ship *, struct ship *, int, int);
  272. int is_toughmelee (struct ship *, struct ship *, int, int);
  273. void reload (void);
  274. void checksails (void);
  275. /* dr_4.c */
  276. void ungrap (struct ship *, struct ship *);
  277. void grap (struct ship *, struct ship *);
  278. /* dr_5.c */
  279. void subtract (struct ship *, struct ship *, int, int [3], int);
  280. int mensent (struct ship *, struct ship *, int[3], struct ship **, int *,
  281. int);
  282. /* dr_main.c */
  283. int dr_main (void);
  284. /* game.c */
  285. int maxturns (struct ship *, char *);
  286. int maxmove (struct ship *, int, int);
  287. /* lo_main.c */
  288. int lo_main (void);
  289. /* misc.c */
  290. int range (struct ship *, struct ship *);
  291. struct ship *closestenemy (struct ship *, int, int);
  292. int gunsbear (struct ship *, struct ship *);
  293. int portside (struct ship *, struct ship *, int);
  294. int colours (struct ship *);
  295. void logger (struct ship *);
  296. /* parties.c */
  297. int meleeing (struct ship *, struct ship *);
  298. int boarding (struct ship *, int);
  299. void unboard (struct ship *, struct ship *, int);
  300. /* pl_1.c */
  301. void leave (int) __attribute__((__noreturn__));
  302. void choke (int) __attribute__((__noreturn__));
  303. void child (int);
  304. /* pl_2.c */
  305. void play (void) __attribute__((__noreturn__));
  306. /* pl_3.c */
  307. void acceptcombat (void);
  308. void grapungrap (void);
  309. void unfoulplayer (void);
  310. /* pl_4.c */
  311. void changesail (void);
  312. void acceptsignal (void);
  313. void lookout (void);
  314. const char *saywhat (struct ship *, int);
  315. void eyeball (struct ship *);
  316. /* pl_5.c */
  317. void acceptmove (void);
  318. void acceptboard (void);
  319. /* pl_6.c */
  320. void repair (void);
  321. void loadplayer (void);
  322. /* pl_7.c */
  323. void initscreen (void);
  324. void cleanupscreen (void);
  325. void newturn (int);
  326. void Signal (const char *, struct ship *, ...)
  327. __attribute__((__format__(__printf__,1,3)));
  328. void Msg (const char *, ...)
  329. __attribute__((__format__(__printf__,1,2)));
  330. void prompt (const char *, struct ship *);
  331. int sgetch (const char *, struct ship *, int);
  332. void sgetstr (const char *, char *, int);
  333. void draw_screen (void);
  334. void draw_view (void);
  335. void draw_turn (void);
  336. void draw_stat (void);
  337. void draw_slot (void);
  338. void draw_board (void);
  339. void centerview (void);
  340. void upview (void);
  341. void downview (void);
  342. void leftview (void);
  343. void rightview (void);
  344. /* pl_main.c */
  345. int pl_main (void);
  346. /* sync.c */
  347. void fmtship (char *, size_t, const char *, struct ship *);
  348. void makesignal (struct ship *, const char *, struct ship *, ...)
  349. __attribute__((__format__(__printf__,2,4)));
  350. void makemsg (struct ship *, const char *, ...)
  351. __attribute__((__format__(__printf__,2,3)));
  352. int sync_exists (int);
  353. int sync_open (void);
  354. void sync_close (int);
  355. void Write (int, struct ship *, long, long, long, long);
  356. void Writestr (int, struct ship *, const char *);
  357. int Sync (void);