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