1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 * 12 * @(#)extern.h 5.2 (Berkeley) 03/09/88 13 */ 14 15 #include <stdio.h> 16 #include <signal.h> 17 #include <ctype.h> 18 #include <setjmp.h> 19 #include "machdep.h" 20 21 /* program mode */ 22 int mode; 23 jmp_buf restart; 24 #define MODE_PLAYER 1 25 #define MODE_DRIVER 2 26 #define MODE_LOGGER 3 27 28 /* command line flags */ 29 char debug; /* -D */ 30 char randomize; /* -x, give first available ship */ 31 char longfmt; /* -l, print score in long format */ 32 char nobells; /* -b, don't ring bell before Signal */ 33 34 /* other initial modes */ 35 char issetuid; /* running setuid */ 36 37 #define die() ((rand() >> 3) % 6 + 1) 38 #define sqr(a) ((a) * (a)) 39 #define abs(a) ((a) > 0 ? (a) : -(a)) 40 #define min(a,b) ((a) < (b) ? (a) : (b)) 41 42 #define grappled(a) ((a)->file->ngrap) 43 #define fouled(a) ((a)->file->nfoul) 44 #define snagged(a) (grappled(a) + fouled(a)) 45 46 #define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count) 47 #define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count) 48 #define snagged2(a, b) (grappled2(a, b) + fouled2(a, b)) 49 50 #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0) 51 #define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0) 52 #define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b)) 53 54 #define cleangrapple(a, b, c) Cleansnag(a, b, c, 1) 55 #define cleanfoul(a, b, c) Cleansnag(a, b, c, 2) 56 #define cleansnag(a, b, c) Cleansnag(a, b, c, 3) 57 58 #define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0)) 59 #define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir]) 60 #define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir]) 61 62 #define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp)) 63 64 #define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' ')) 65 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 /* 75 * readyL and readyR, these are bits, except R_EMPTY 76 */ 77 #define R_EMPTY 0 /* not loaded and not loading */ 78 #define R_LOADING 1 /* loading */ 79 #define R_DOUBLE 2 /* loading double */ 80 #define R_LOADED 4 /* loaded */ 81 #define R_INITIAL 8 /* loaded initial */ 82 83 #define HULL 0 84 #define RIGGING 1 85 86 #define W_CAPTAIN 1 87 #define W_CAPTURED 2 88 #define W_CLASS 3 89 #define W_CREW 4 90 #define W_DBP 5 91 #define W_DRIFT 6 92 #define W_EXPLODE 7 93 #define W_FILE 8 94 #define W_FOUL 9 95 #define W_GUNL 10 96 #define W_GUNR 11 97 #define W_HULL 12 98 #define W_MOVE 13 99 #define W_OBP 14 100 #define W_PCREW 15 101 #define W_UNFOUL 16 102 #define W_POINTS 17 103 #define W_QUAL 18 104 #define W_UNGRAP 19 105 #define W_RIGG 20 106 #define W_COL 21 107 #define W_DIR 22 108 #define W_ROW 23 109 #define W_SIGNAL 24 110 #define W_SINK 25 111 #define W_STRUCK 26 112 #define W_TA 27 113 #define W_ALIVE 28 114 #define W_TURN 29 115 #define W_WIND 30 116 #define W_FS 31 117 #define W_GRAP 32 118 #define W_RIG1 33 119 #define W_RIG2 34 120 #define W_RIG3 35 121 #define W_RIG4 36 122 #define W_BEGIN 37 123 #define W_END 38 124 #define W_DDEAD 39 125 126 #define NLOG 10 127 struct logs { 128 char l_name[20]; 129 int l_uid; 130 int l_shipnum; 131 int l_gamenum; 132 int l_netpoints; 133 }; 134 135 struct BP { 136 short turnsent; 137 struct ship *toship; 138 short mensent; 139 }; 140 141 struct snag { 142 short sn_count; 143 short sn_turn; 144 }; 145 146 #define NSCENE nscene 147 #define NSHIP 10 148 #define NBP 3 149 150 #define NNATION 8 151 #define N_A 0 152 #define N_B 1 153 #define N_S 2 154 #define N_F 3 155 #define N_J 4 156 #define N_D 5 157 #define N_K 6 158 #define N_O 7 159 160 struct File { 161 int index; 162 char captain[20]; /* 0 */ 163 short points; /* 20 */ 164 char loadL; /* 22 */ 165 char loadR; /* 24 */ 166 char readyL; /* 26 */ 167 char readyR; /* 28 */ 168 struct BP OBP[NBP]; /* 30 */ 169 struct BP DBP[NBP]; /* 48 */ 170 char struck; /* 66 */ 171 struct ship *captured; /* 68 */ 172 short pcrew; /* 70 */ 173 char movebuf[10]; /* 72 */ 174 char drift; /* 82 */ 175 short nfoul; 176 short ngrap; 177 struct snag foul[NSHIP]; /* 84 */ 178 struct snag grap[NSHIP]; /* 124 */ 179 char RH; /* 224 */ 180 char RG; /* 226 */ 181 char RR; /* 228 */ 182 char FS; /* 230 */ 183 char explode; /* 232 */ 184 char sink; /* 234 */ 185 char dir; 186 short col; 187 short row; 188 char loadwith; 189 char stern; 190 }; 191 192 struct ship { 193 char *shipname; /* 0 */ 194 struct shipspecs *specs; /* 2 */ 195 char nationality; /* 4 */ 196 short shiprow; /* 6 */ 197 short shipcol; /* 8 */ 198 char shipdir; /* 10 */ 199 struct File *file; /* 12 */ 200 }; 201 202 struct scenario { 203 char winddir; /* 0 */ 204 char windspeed; /* 2 */ 205 char windchange; /* 4 */ 206 char vessels; /* 12 */ 207 char *name; /* 14 */ 208 struct ship ship[NSHIP]; /* 16 */ 209 }; 210 struct scenario scene[]; 211 int nscene; 212 213 struct shipspecs { 214 char bs; 215 char fs; 216 char ta; 217 short guns; 218 char class; 219 char hull; 220 char qual; 221 char crew1; 222 char crew2; 223 char crew3; 224 char gunL; 225 char gunR; 226 char carL; 227 char carR; 228 char rig1; 229 char rig2; 230 char rig3; 231 char rig4; 232 short pts; 233 }; 234 struct shipspecs specs[]; 235 236 struct scenario *cc; /* the current scenario */ 237 struct ship *ls; /* &cc->ship[cc->vessels] */ 238 239 #define SHIP(s) (&cc->ship[s]) 240 #define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++) 241 242 struct windeffects { 243 char A, B, C, D; 244 }; 245 struct windeffects WET[7][6]; 246 247 struct Tables { 248 char H, G, C, R; 249 }; 250 struct Tables RigTable[11][6]; 251 struct Tables HullTable[11][6]; 252 253 char AMMO[9][4]; 254 char HDT[9][10]; 255 char HDTrake[9][10]; 256 char QUAL[9][5]; 257 char MT[9][3]; 258 259 char *countryname[]; 260 char *classname[]; 261 char *directionname[]; 262 char *qualname[]; 263 char loadname[]; 264 265 char rangeofshot[]; 266 267 char dr[], dc[]; 268 269 int winddir; 270 int windspeed; 271 int turn; 272 int game; 273 int alive; 274 int people; 275 char hasdriver; 276 277 char *info(); 278 char *quality(); 279 double arctan(); 280 char *saywhat(); 281 struct ship *closestenemy(); 282 283 char *calloc(); 284 char *rindex(); 285 char *strcpy(); 286 char *strcat(); 287 char *strncpy(); 288 char *getenv(); 289 char *gets(); 290