BSD 4_3_Net_2 release
[unix-history] / usr / src / games / sail / externs.h
CommitLineData
261fa12c 1/*
1e008c14 2 * Copyright (c) 1983 Regents of the University of California.
c0ca48ec 3 * All rights reserved.
1e008c14 4 *
af359dea
C
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
c0ca48ec 20 *
af359dea
C
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
c0ca48ec 32 *
1c15e888 33 * @(#)externs.h 5.4 (Berkeley) 6/1/90
b5f0675e
EW
34 */
35
261fa12c
CL
36#include <stdio.h>
37#include <signal.h>
38#include <ctype.h>
ba28d9ed 39#include <setjmp.h>
261fa12c
CL
40#include "machdep.h"
41
ba28d9ed
EW
42 /* program mode */
43int mode;
44jmp_buf restart;
45#define MODE_PLAYER 1
46#define MODE_DRIVER 2
47#define MODE_LOGGER 3
48
49 /* command line flags */
50char debug; /* -D */
33873692
EW
51char randomize; /* -x, give first available ship */
52char longfmt; /* -l, print score in long format */
53char nobells; /* -b, don't ring bell before Signal */
ba28d9ed
EW
54
55 /* other initial modes */
56char issetuid; /* running setuid */
57
b3a57661
EW
58#define die() ((rand() >> 3) % 6 + 1)
59#define sqr(a) ((a) * (a))
60#define abs(a) ((a) > 0 ? (a) : -(a))
61#define min(a,b) ((a) < (b) ? (a) : (b))
62
6ca45914
EW
63#define grappled(a) ((a)->file->ngrap)
64#define fouled(a) ((a)->file->nfoul)
65#define snagged(a) (grappled(a) + fouled(a))
66
67#define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count)
68#define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count)
69#define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
70
71#define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
72#define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
73#define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b))
74
75#define cleangrapple(a, b, c) Cleansnag(a, b, c, 1)
76#define cleanfoul(a, b, c) Cleansnag(a, b, c, 2)
77#define cleansnag(a, b, c) Cleansnag(a, b, c, 3)
b3a57661 78
2a43399b 79#define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
b3a57661
EW
80#define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir])
81#define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir])
82
83#define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp))
84
85#define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
86
87/* loadL and loadR, should match loadname[] */
88#define L_EMPTY 0 /* should be 0, don't change */
89#define L_GRAPE 1
90#define L_CHAIN 2
91#define L_ROUND 3
92#define L_DOUBLE 4
93#define L_EXPLODE 5
261fa12c 94
b3a57661
EW
95/*
96 * readyL and readyR, these are bits, except R_EMPTY
97 */
98#define R_EMPTY 0 /* not loaded and not loading */
99#define R_LOADING 1 /* loading */
100#define R_DOUBLE 2 /* loading double */
101#define R_LOADED 4 /* loaded */
102#define R_INITIAL 8 /* loaded initial */
103
104#define HULL 0
105#define RIGGING 1
106
107#define W_CAPTAIN 1
108#define W_CAPTURED 2
109#define W_CLASS 3
110#define W_CREW 4
111#define W_DBP 5
112#define W_DRIFT 6
113#define W_EXPLODE 7
114#define W_FILE 8
115#define W_FOUL 9
116#define W_GUNL 10
117#define W_GUNR 11
118#define W_HULL 12
6ca45914 119#define W_MOVE 13
b3a57661
EW
120#define W_OBP 14
121#define W_PCREW 15
6ca45914 122#define W_UNFOUL 16
b3a57661
EW
123#define W_POINTS 17
124#define W_QUAL 18
6ca45914 125#define W_UNGRAP 19
b3a57661 126#define W_RIGG 20
6ca45914
EW
127#define W_COL 21
128#define W_DIR 22
129#define W_ROW 23
b3a57661
EW
130#define W_SIGNAL 24
131#define W_SINK 25
132#define W_STRUCK 26
133#define W_TA 27
6c17b19a 134#define W_ALIVE 28
b3a57661
EW
135#define W_TURN 29
136#define W_WIND 30
137#define W_FS 31
138#define W_GRAP 32
139#define W_RIG1 33
140#define W_RIG2 34
141#define W_RIG3 35
142#define W_RIG4 36
6c17b19a
EW
143#define W_BEGIN 37
144#define W_END 38
8606f36c 145#define W_DDEAD 39
261fa12c 146
8606f36c 147#define NLOG 10
261fa12c 148struct logs {
b3a57661
EW
149 char l_name[20];
150 int l_uid;
151 int l_shipnum;
152 int l_gamenum;
153 int l_netpoints;
261fa12c
CL
154};
155
2016bd8e 156struct BP {
1eda8103 157 short turnsent;
b3a57661 158 struct ship *toship;
1eda8103 159 short mensent;
261fa12c
CL
160};
161
2016bd8e 162struct snag {
6ca45914
EW
163 short sn_count;
164 short sn_turn;
261fa12c
CL
165};
166
d95a9c3b 167#define NSCENE nscene
b3a57661
EW
168#define NSHIP 10
169#define NBP 3
170
d95a9c3b 171#define NNATION 8
b3a57661
EW
172#define N_A 0
173#define N_B 1
174#define N_S 2
175#define N_F 3
176#define N_J 4
d95a9c3b
EW
177#define N_D 5
178#define N_K 6
179#define N_O 7
261fa12c 180
2016bd8e 181struct File {
6ca45914 182 int index;
b3a57661 183 char captain[20]; /* 0 */
1eda8103
EW
184 short points; /* 20 */
185 char loadL; /* 22 */
186 char loadR; /* 24 */
187 char readyL; /* 26 */
188 char readyR; /* 28 */
b3a57661
EW
189 struct BP OBP[NBP]; /* 30 */
190 struct BP DBP[NBP]; /* 48 */
1eda8103 191 char struck; /* 66 */
b3a57661 192 struct ship *captured; /* 68 */
1eda8103 193 short pcrew; /* 70 */
6ca45914 194 char movebuf[10]; /* 72 */
1eda8103 195 char drift; /* 82 */
6ca45914
EW
196 short nfoul;
197 short ngrap;
198 struct snag foul[NSHIP]; /* 84 */
199 struct snag grap[NSHIP]; /* 124 */
1eda8103
EW
200 char RH; /* 224 */
201 char RG; /* 226 */
202 char RR; /* 228 */
203 char FS; /* 230 */
204 char explode; /* 232 */
205 char sink; /* 234 */
206 char dir;
207 short col;
208 short row;
209 char loadwith;
210 char stern;
261fa12c
CL
211};
212
b3a57661
EW
213struct ship {
214 char *shipname; /* 0 */
215 struct shipspecs *specs; /* 2 */
1eda8103
EW
216 char nationality; /* 4 */
217 short shiprow; /* 6 */
218 short shipcol; /* 8 */
219 char shipdir; /* 10 */
b3a57661
EW
220 struct File *file; /* 12 */
221};
261fa12c
CL
222
223struct scenario {
1eda8103
EW
224 char winddir; /* 0 */
225 char windspeed; /* 2 */
226 char windchange; /* 4 */
1eda8103 227 char vessels; /* 12 */
b3a57661
EW
228 char *name; /* 14 */
229 struct ship ship[NSHIP]; /* 16 */
261fa12c 230};
d95a9c3b
EW
231struct scenario scene[];
232int nscene;
261fa12c
CL
233
234struct shipspecs {
1eda8103
EW
235 char bs;
236 char fs;
237 char ta;
238 short guns;
239 char class;
240 char hull;
241 char qual;
242 char crew1;
243 char crew2;
244 char crew3;
245 char gunL;
246 char gunR;
247 char carL;
248 char carR;
249 char rig1;
250 char rig2;
251 char rig3;
252 char rig4;
253 short pts;
261fa12c 254};
2016bd8e 255struct shipspecs specs[];
261fa12c 256
b3a57661
EW
257struct scenario *cc; /* the current scenario */
258struct ship *ls; /* &cc->ship[cc->vessels] */
259
260#define SHIP(s) (&cc->ship[s])
261#define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++)
262
2016bd8e 263struct windeffects {
1eda8103 264 char A, B, C, D;
2016bd8e
EW
265};
266struct windeffects WET[7][6];
267
268struct Tables {
1eda8103 269 char H, G, C, R;
2016bd8e
EW
270};
271struct Tables RigTable[11][6];
272struct Tables HullTable[11][6];
261fa12c 273
1eda8103
EW
274char AMMO[9][4];
275char HDT[9][10];
276char HDTrake[9][10];
277char QUAL[9][5];
278char MT[9][3];
261fa12c 279
b3a57661
EW
280char *countryname[];
281char *classname[];
282char *directionname[];
283char *qualname[];
284char loadname[];
285
1eda8103 286char rangeofshot[];
b3a57661
EW
287
288char dr[], dc[];
289
6c17b19a
EW
290int winddir;
291int windspeed;
292int turn;
b3a57661 293int game;
6c17b19a
EW
294int alive;
295int people;
8606f36c 296char hasdriver;
261fa12c 297
261fa12c 298char *info();
261fa12c 299char *quality();
261fa12c 300double arctan();
b3a57661
EW
301char *saywhat();
302struct ship *closestenemy();
303
304char *calloc();
ba28d9ed 305char *rindex();
b3a57661
EW
306char *strcpy();
307char *strcat();
308char *strncpy();
309char *getenv();
310char *gets();