1 /* $NetBSD: extern.h,v 1.35 2009/08/12 09:05:08 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 NLOG 10 105 struct logs { 106 char l_name[20]; 107 int l_uid; 108 int l_shipnum; 109 int l_gamenum; 110 int l_netpoints; 111 }; 112 113 struct BP { 114 struct ship *toship; 115 short turnsent; 116 short mensent; 117 }; 118 119 struct snag { 120 short sn_count; 121 short sn_turn; 122 }; 123 124 #define NSCENE nscene 125 #define NSHIP 10 126 #define NBP 3 127 128 #define NNATION 8 129 #define N_A 0 130 #define N_B 1 131 #define N_S 2 132 #define N_F 3 133 #define N_J 4 134 #define N_D 5 135 #define N_K 6 136 #define N_O 7 137 138 struct File { 139 int index; 140 char captain[20]; /* 0 */ 141 short points; /* 20 */ 142 unsigned char loadL; /* 22 */ 143 unsigned char loadR; /* 24 */ 144 unsigned char readyL; /* 26 */ 145 unsigned char readyR; /* 28 */ 146 struct BP OBP[NBP]; /* 30 */ 147 struct BP DBP[NBP]; /* 48 */ 148 char struck; /* 66 */ 149 struct ship *captured; /* 68 */ 150 short pcrew; /* 70 */ 151 char movebuf[10]; /* 72 */ 152 char drift; /* 82 */ 153 short nfoul; 154 short ngrap; 155 struct snag foul[NSHIP]; /* 84 */ 156 struct snag grap[NSHIP]; /* 124 */ 157 char RH; /* 224 */ 158 char RG; /* 226 */ 159 char RR; /* 228 */ 160 char FS; /* 230 */ 161 char explode; /* 232 */ 162 char sink; /* 234 */ 163 unsigned char dir; 164 short col; 165 short row; 166 char loadwith; 167 char stern; 168 }; 169 170 struct ship { 171 const char *shipname; /* 0 */ 172 struct shipspecs *specs; /* 2 */ 173 unsigned char nationality; /* 4 */ 174 short shiprow; /* 6 */ 175 short shipcol; /* 8 */ 176 char shipdir; /* 10 */ 177 struct File *file; /* 12 */ 178 }; 179 180 struct scenario { 181 char winddir; /* 0 */ 182 char windspeed; /* 2 */ 183 char windchange; /* 4 */ 184 unsigned char vessels; /* 12 */ 185 const char *name; /* 14 */ 186 struct ship ship[NSHIP]; /* 16 */ 187 }; 188 extern struct scenario scene[]; 189 extern int nscene; 190 191 struct shipspecs { 192 char bs; 193 char fs; 194 char ta; 195 short guns; 196 unsigned char class; 197 char hull; 198 unsigned char qual; 199 char crew1; 200 char crew2; 201 char crew3; 202 char gunL; 203 char gunR; 204 char carL; 205 char carR; 206 int rig1; 207 int rig2; 208 int rig3; 209 int rig4; 210 short pts; 211 }; 212 213 extern struct scenario *cc; /* the current scenario */ 214 extern struct ship *ls; /* &cc->ship[cc->vessels] */ 215 216 #define SHIP(s) (&cc->ship[s]) 217 #define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++) 218 219 struct windeffects { 220 char A, B, C, D; 221 }; 222 extern const struct windeffects WET[7][6]; 223 224 struct Tables { 225 char H, G, C, R; 226 }; 227 extern const struct Tables RigTable[11][6]; 228 extern const struct Tables HullTable[11][6]; 229 230 extern const char AMMO[9][4]; 231 extern const char HDT[9][10]; 232 extern const char HDTrake[9][10]; 233 extern const char QUAL[9][5]; 234 extern const char MT[9][3]; 235 236 extern const char *const countryname[]; 237 extern const char *const classname[]; 238 extern const char *const directionname[]; 239 extern const char *const qualname[]; 240 extern const char loadname[]; 241 242 extern const char rangeofshot[]; 243 244 extern const char dr[], dc[]; 245 246 extern int winddir; 247 extern int windspeed; 248 extern int turn; 249 extern int game; 250 extern int alive; 251 extern int people; 252 extern int hasdriver; 253 254 /* assorted.c */ 255 void table(struct ship *, struct ship *, int, int, int, int); 256 void Cleansnag(struct ship *, struct ship *, int, int); 257 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 265 /* dr_2.c */ 266 void thinkofgrapples(void); 267 void checkup(void); 268 void prizecheck(void); 269 void closeon(struct ship *, struct ship *, char *, size_t, int, int, bool); 270 271 /* dr_3.c */ 272 void moveall(void); 273 void sendbp(struct ship *, struct ship *, int, int); 274 int is_toughmelee(struct ship *, struct ship *, int, int); 275 void reload(void); 276 void checksails(void); 277 278 /* dr_4.c */ 279 void ungrap(struct ship *, struct ship *); 280 void grap(struct ship *, struct ship *); 281 282 /* dr_5.c */ 283 void subtract(struct ship *, struct ship *, int, int [3], int); 284 int mensent(struct ship *, struct ship *, int[3], struct ship **, int *, int); 285 286 /* dr_main.c */ 287 int dr_main(void); 288 289 /* game.c */ 290 int maxturns(struct ship *, bool *); 291 int maxmove(struct ship *, int, int); 292 293 /* lo_main.c */ 294 int lo_main(void); 295 296 /* misc.c */ 297 int range(struct ship *, struct ship *); 298 struct ship *closestenemy(struct ship *, int, int); 299 int gunsbear(struct ship *, struct ship *); 300 int portside(struct ship *, struct ship *, int); 301 int colours(struct ship *); 302 void logger(struct ship *); 303 304 /* parties.c */ 305 int meleeing(struct ship *, struct ship *); 306 int boarding(struct ship *, int); 307 void unboard(struct ship *, struct ship *, int); 308 309 /* pl_1.c */ 310 void leave(int) __attribute__((__noreturn__)); 311 void choke(int) __attribute__((__noreturn__)); 312 void child(int); 313 314 /* pl_2.c */ 315 void newturn(int); 316 void play(void) __attribute__((__noreturn__)); 317 318 /* pl_3.c */ 319 void acceptcombat(void); 320 void grapungrap(void); 321 void unfoulplayer(void); 322 323 /* pl_4.c */ 324 void changesail(void); 325 void acceptsignal(void); 326 void lookout(void); 327 const char *saywhat(struct ship *, int); 328 void eyeball(struct ship *); 329 330 /* pl_5.c */ 331 void acceptmove(void); 332 void acceptboard(void); 333 334 /* pl_6.c */ 335 void repair(void); 336 void loadplayer(void); 337 338 /* pl_7.c */ 339 void initscreen(void); 340 void cleanupscreen(void); 341 void Signal(const char *, struct ship *, ...) 342 __attribute__((__format__(__printf__,1,3))); 343 void Msg(const char *, ...) 344 __attribute__((__format__(__printf__,1,2))); 345 int sgetch(const char *, struct ship *, int); 346 void sgetstr(const char *, char *, int); 347 void centerview(void); 348 void upview(void); 349 void downview(void); 350 void leftview(void); 351 void rightview(void); 352 353 /* pl_main.c */ 354 int pl_main(void); 355 356 /* sync.c */ 357 void fmtship(char *, size_t, const char *, struct ship *); 358 void makesignal(struct ship *, const char *, struct ship *, ...) 359 __attribute__((__format__(__printf__,2,4))); 360 void makemsg(struct ship *, const char *, ...) 361 __attribute__((__format__(__printf__,2,3))); 362 int sync_exists(int); 363 int sync_open(void); 364 void sync_close(int); 365 int Sync(void); 366 367 void send_captain(struct ship *ship, const char *astr); 368 void send_captured(struct ship *ship, long a); 369 void send_class(struct ship *ship, long a); 370 void send_crew(struct ship *ship, long a, long b, long c); 371 void send_dbp(struct ship *ship, long a, long b, long c, long d); 372 void send_drift(struct ship *ship, long a); 373 void send_explode(struct ship *ship, long a); 374 void send_foul(struct ship *ship, long a); 375 void send_gunl(struct ship *ship, long a, long b); 376 void send_gunr(struct ship *ship, long a, long b); 377 void send_hull(struct ship *ship, long a); 378 void send_move(struct ship *ship, const char *astr); 379 void send_obp(struct ship *ship, long a, long b, long c, long d); 380 void send_pcrew(struct ship *ship, long a); 381 void send_unfoul(struct ship *ship, long a, long b); 382 void send_points(struct ship *ship, long a); 383 void send_qual(struct ship *ship, long a); 384 void send_ungrap(struct ship *ship, long a, long b); 385 void send_rigg(struct ship *ship, long a, long b, long c, long d); 386 void send_col(struct ship *ship, long a); 387 void send_dir(struct ship *ship, long a); 388 void send_row(struct ship *ship, long a); 389 void send_signal(struct ship *ship, const char *astr); 390 void send_sink(struct ship *ship, long a); 391 void send_struck(struct ship *ship, long a); 392 void send_ta(struct ship *ship, long a); 393 void send_alive(void); 394 void send_turn(long a); 395 void send_wind(long a, long b); 396 void send_fs(struct ship *ship, long a); 397 void send_grap(struct ship *ship, long a); 398 void send_rig1(struct ship *ship, long a); 399 void send_rig2(struct ship *ship, long a); 400 void send_rig3(struct ship *ship, long a); 401 void send_rig4(struct ship *ship, long a); 402 void send_begin(struct ship *ship); 403 void send_end(struct ship *ship); 404 void send_ddead(void); 405