Add copyright
[unix-history] / usr / src / games / sail / extern.h
CommitLineData
261fa12c 1/*
b5f0675e
EW
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.
261fa12c 5 */
b5f0675e
EW
6
7/*
8 * @(#)extern.h 2.7 85/04/23
9 */
10
261fa12c
CL
11#include <stdio.h>
12#include <signal.h>
13#include <ctype.h>
ba28d9ed 14#include <setjmp.h>
261fa12c
CL
15#include "machdep.h"
16
ba28d9ed
EW
17 /* program mode */
18int mode;
19jmp_buf restart;
20#define MODE_PLAYER 1
21#define MODE_DRIVER 2
22#define MODE_LOGGER 3
23
24 /* command line flags */
25char debug; /* -D */
33873692
EW
26char randomize; /* -x, give first available ship */
27char longfmt; /* -l, print score in long format */
28char nobells; /* -b, don't ring bell before Signal */
ba28d9ed
EW
29
30 /* other initial modes */
31char issetuid; /* running setuid */
32
b3a57661
EW
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
6ca45914
EW
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)
b3a57661 53
2a43399b 54#define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
b3a57661
EW
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
261fa12c 69
b3a57661
EW
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
6ca45914 94#define W_MOVE 13
b3a57661
EW
95#define W_OBP 14
96#define W_PCREW 15
6ca45914 97#define W_UNFOUL 16
b3a57661
EW
98#define W_POINTS 17
99#define W_QUAL 18
6ca45914 100#define W_UNGRAP 19
b3a57661 101#define W_RIGG 20
6ca45914
EW
102#define W_COL 21
103#define W_DIR 22
104#define W_ROW 23
b3a57661
EW
105#define W_SIGNAL 24
106#define W_SINK 25
107#define W_STRUCK 26
108#define W_TA 27
6c17b19a 109#define W_ALIVE 28
b3a57661
EW
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
6c17b19a
EW
118#define W_BEGIN 37
119#define W_END 38
8606f36c 120#define W_DDEAD 39
261fa12c 121
8606f36c 122#define NLOG 10
261fa12c 123struct logs {
b3a57661
EW
124 char l_name[20];
125 int l_uid;
126 int l_shipnum;
127 int l_gamenum;
128 int l_netpoints;
261fa12c
CL
129};
130
2016bd8e 131struct BP {
1eda8103 132 short turnsent;
b3a57661 133 struct ship *toship;
1eda8103 134 short mensent;
261fa12c
CL
135};
136
2016bd8e 137struct snag {
6ca45914
EW
138 short sn_count;
139 short sn_turn;
261fa12c
CL
140};
141
d95a9c3b 142#define NSCENE nscene
b3a57661
EW
143#define NSHIP 10
144#define NBP 3
145
d95a9c3b 146#define NNATION 8
b3a57661
EW
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
d95a9c3b
EW
152#define N_D 5
153#define N_K 6
154#define N_O 7
261fa12c 155
2016bd8e 156struct File {
6ca45914 157 int index;
b3a57661 158 char captain[20]; /* 0 */
1eda8103
EW
159 short points; /* 20 */
160 char loadL; /* 22 */
161 char loadR; /* 24 */
162 char readyL; /* 26 */
163 char readyR; /* 28 */
b3a57661
EW
164 struct BP OBP[NBP]; /* 30 */
165 struct BP DBP[NBP]; /* 48 */
1eda8103 166 char struck; /* 66 */
b3a57661 167 struct ship *captured; /* 68 */
1eda8103 168 short pcrew; /* 70 */
6ca45914 169 char movebuf[10]; /* 72 */
1eda8103 170 char drift; /* 82 */
6ca45914
EW
171 short nfoul;
172 short ngrap;
173 struct snag foul[NSHIP]; /* 84 */
174 struct snag grap[NSHIP]; /* 124 */
1eda8103
EW
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;
261fa12c
CL
186};
187
b3a57661
EW
188struct ship {
189 char *shipname; /* 0 */
190 struct shipspecs *specs; /* 2 */
1eda8103
EW
191 char nationality; /* 4 */
192 short shiprow; /* 6 */
193 short shipcol; /* 8 */
194 char shipdir; /* 10 */
b3a57661
EW
195 struct File *file; /* 12 */
196};
261fa12c
CL
197
198struct scenario {
1eda8103
EW
199 char winddir; /* 0 */
200 char windspeed; /* 2 */
201 char windchange; /* 4 */
1eda8103 202 char vessels; /* 12 */
b3a57661
EW
203 char *name; /* 14 */
204 struct ship ship[NSHIP]; /* 16 */
261fa12c 205};
d95a9c3b
EW
206struct scenario scene[];
207int nscene;
261fa12c
CL
208
209struct shipspecs {
1eda8103
EW
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;
261fa12c 229};
2016bd8e 230struct shipspecs specs[];
261fa12c 231
b3a57661
EW
232struct scenario *cc; /* the current scenario */
233struct 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
2016bd8e 238struct windeffects {
1eda8103 239 char A, B, C, D;
2016bd8e
EW
240};
241struct windeffects WET[7][6];
242
243struct Tables {
1eda8103 244 char H, G, C, R;
2016bd8e
EW
245};
246struct Tables RigTable[11][6];
247struct Tables HullTable[11][6];
261fa12c 248
1eda8103
EW
249char AMMO[9][4];
250char HDT[9][10];
251char HDTrake[9][10];
252char QUAL[9][5];
253char MT[9][3];
261fa12c 254
b3a57661
EW
255char *countryname[];
256char *classname[];
257char *directionname[];
258char *qualname[];
259char loadname[];
260
1eda8103 261char rangeofshot[];
b3a57661
EW
262
263char dr[], dc[];
264
6c17b19a
EW
265int winddir;
266int windspeed;
267int turn;
b3a57661 268int game;
6c17b19a
EW
269int alive;
270int people;
8606f36c 271char hasdriver;
261fa12c 272
261fa12c 273char *info();
261fa12c 274char *quality();
261fa12c 275double arctan();
b3a57661
EW
276char *saywhat();
277struct ship *closestenemy();
278
279char *calloc();
ba28d9ed 280char *rindex();
b3a57661
EW
281char *strcpy();
282char *strcat();
283char *strncpy();
284char *getenv();
285char *gets();