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