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