extern.h revision 1.30 1 /* $NetBSD: extern.h,v 1.30 2009/03/14 19:35:13 dholland Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)externs.h 8.1 (Berkeley) 5/31/93
32 */
33
34 #include <sys/types.h>
35
36 #include "machdep.h"
37
38 /* program mode */
39 extern int mode;
40 #define MODE_PLAYER 1
41 #define MODE_DRIVER 2
42 #define MODE_LOGGER 3
43
44 /* command line flags */
45 extern int randomize; /* -x, give first available ship */
46 extern int longfmt; /* -l, print score in long format */
47 extern int nobells; /* -b, don't ring bell before Signal */
48
49 /* other initial modes */
50 extern gid_t gid;
51 extern gid_t egid;
52
53 #define dieroll() ((random()) % 6 + 1)
54 #define sqr(a) ((a) * (a))
55 #define min(a,b) ((a) < (b) ? (a) : (b))
56
57 #define grappled(a) ((a)->file->ngrap)
58 #define fouled(a) ((a)->file->nfoul)
59 #define snagged(a) (grappled(a) + fouled(a))
60
61 #define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count)
62 #define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count)
63 #define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
64
65 #define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 \
66 ? grappled2(a, b) : 0)
67 #define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 \
68 ? fouled2(a, b) : 0)
69 #define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b))
70
71 #define cleangrapple(a, b, c) Cleansnag(a, b, c, 1)
72 #define cleanfoul(a, b, c) Cleansnag(a, b, c, 2)
73 #define cleansnag(a, b, c) Cleansnag(a, b, c, 3)
74
75 #define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured ? 10 : 0))
76 #define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir])
77 #define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir])
78
79 #define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp))
80
81 #define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
82
83 /* loadL and loadR, should match loadname[] */
84 #define L_EMPTY 0 /* should be 0, don't change */
85 #define L_GRAPE 1
86 #define L_CHAIN 2
87 #define L_ROUND 3
88 #define L_DOUBLE 4
89 #define L_EXPLODE 5
90
91 /*
92 * readyL and readyR, these are bits, except R_EMPTY
93 */
94 #define R_EMPTY 0 /* not loaded and not loading */
95 #define R_LOADING 1 /* loading */
96 #define R_DOUBLE 2 /* loading double */
97 #define R_LOADED 4 /* loaded */
98 #define R_INITIAL 8 /* loaded initial */
99
100 #define HULL 0
101 #define RIGGING 1
102
103 #define W_CAPTAIN 1
104 #define W_CAPTURED 2
105 #define W_CLASS 3
106 #define W_CREW 4
107 #define W_DBP 5
108 #define W_DRIFT 6
109 #define W_EXPLODE 7
110 #define W_FILE 8
111 #define W_FOUL 9
112 #define W_GUNL 10
113 #define W_GUNR 11
114 #define W_HULL 12
115 #define W_MOVE 13
116 #define W_OBP 14
117 #define W_PCREW 15
118 #define W_UNFOUL 16
119 #define W_POINTS 17
120 #define W_QUAL 18
121 #define W_UNGRAP 19
122 #define W_RIGG 20
123 #define W_COL 21
124 #define W_DIR 22
125 #define W_ROW 23
126 #define W_SIGNAL 24
127 #define W_SINK 25
128 #define W_STRUCK 26
129 #define W_TA 27
130 #define W_ALIVE 28
131 #define W_TURN 29
132 #define W_WIND 30
133 #define W_FS 31
134 #define W_GRAP 32
135 #define W_RIG1 33
136 #define W_RIG2 34
137 #define W_RIG3 35
138 #define W_RIG4 36
139 #define W_BEGIN 37
140 #define W_END 38
141 #define W_DDEAD 39
142
143 #define NLOG 10
144 struct logs {
145 char l_name[20];
146 int l_uid;
147 int l_shipnum;
148 int l_gamenum;
149 int l_netpoints;
150 };
151
152 struct BP {
153 struct ship *toship;
154 short turnsent;
155 short mensent;
156 };
157
158 struct snag {
159 short sn_count;
160 short sn_turn;
161 };
162
163 #define NSCENE nscene
164 #define NSHIP 10
165 #define NBP 3
166
167 #define NNATION 8
168 #define N_A 0
169 #define N_B 1
170 #define N_S 2
171 #define N_F 3
172 #define N_J 4
173 #define N_D 5
174 #define N_K 6
175 #define N_O 7
176
177 struct File {
178 int index;
179 char captain[20]; /* 0 */
180 short points; /* 20 */
181 unsigned char loadL; /* 22 */
182 unsigned char loadR; /* 24 */
183 unsigned char readyL; /* 26 */
184 unsigned char readyR; /* 28 */
185 struct BP OBP[NBP]; /* 30 */
186 struct BP DBP[NBP]; /* 48 */
187 char struck; /* 66 */
188 struct ship *captured; /* 68 */
189 short pcrew; /* 70 */
190 char movebuf[10]; /* 72 */
191 char drift; /* 82 */
192 short nfoul;
193 short ngrap;
194 struct snag foul[NSHIP]; /* 84 */
195 struct snag grap[NSHIP]; /* 124 */
196 char RH; /* 224 */
197 char RG; /* 226 */
198 char RR; /* 228 */
199 char FS; /* 230 */
200 char explode; /* 232 */
201 char sink; /* 234 */
202 unsigned char dir;
203 short col;
204 short row;
205 char loadwith;
206 char stern;
207 };
208
209 struct ship {
210 const char *shipname; /* 0 */
211 struct shipspecs *specs; /* 2 */
212 unsigned char nationality; /* 4 */
213 short shiprow; /* 6 */
214 short shipcol; /* 8 */
215 char shipdir; /* 10 */
216 struct File *file; /* 12 */
217 };
218
219 struct scenario {
220 char winddir; /* 0 */
221 char windspeed; /* 2 */
222 char windchange; /* 4 */
223 unsigned char vessels; /* 12 */
224 const char *name; /* 14 */
225 struct ship ship[NSHIP]; /* 16 */
226 };
227 extern struct scenario scene[];
228 extern int nscene;
229
230 struct shipspecs {
231 char bs;
232 char fs;
233 char ta;
234 short guns;
235 unsigned char class;
236 char hull;
237 unsigned char qual;
238 char crew1;
239 char crew2;
240 char crew3;
241 char gunL;
242 char gunR;
243 char carL;
244 char carR;
245 int rig1;
246 int rig2;
247 int rig3;
248 int rig4;
249 short pts;
250 };
251 extern struct shipspecs specs[];
252
253 extern struct scenario *cc; /* the current scenario */
254 extern struct ship *ls; /* &cc->ship[cc->vessels] */
255
256 #define SHIP(s) (&cc->ship[s])
257 #define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++)
258
259 struct windeffects {
260 char A, B, C, D;
261 };
262 extern const struct windeffects WET[7][6];
263
264 struct Tables {
265 char H, G, C, R;
266 };
267 extern const struct Tables RigTable[11][6];
268 extern const struct Tables HullTable[11][6];
269
270 extern const char AMMO[9][4];
271 extern const char HDT[9][10];
272 extern const char HDTrake[9][10];
273 extern const char QUAL[9][5];
274 extern const char MT[9][3];
275
276 extern const char *const countryname[];
277 extern const char *const classname[];
278 extern const char *const directionname[];
279 extern const char *const qualname[];
280 extern const char loadname[];
281
282 extern const char rangeofshot[];
283
284 extern const char dr[], dc[];
285
286 extern int winddir;
287 extern int windspeed;
288 extern int turn;
289 extern int game;
290 extern int alive;
291 extern int people;
292 extern int hasdriver;
293
294 /* assorted.c */
295 void table(struct ship *, struct ship *, int, int, int, int);
296 void Cleansnag(struct ship *, struct ship *, int, int);
297
298 /* dr_1.c */
299 void unfoul(void);
300 void boardcomp(void);
301 void resolve(void);
302 void compcombat(void);
303 int next(void);
304
305 /* dr_2.c */
306 void thinkofgrapples(void);
307 void checkup(void);
308 void prizecheck(void);
309 void closeon(struct ship *, struct ship *, char *, size_t, int, int, int);
310
311 /* dr_3.c */
312 void moveall(void);
313 void sendbp(struct ship *, struct ship *, int, int);
314 int is_toughmelee(struct ship *, struct ship *, int, int);
315 void reload(void);
316 void checksails(void);
317
318 /* dr_4.c */
319 void ungrap(struct ship *, struct ship *);
320 void grap(struct ship *, struct ship *);
321
322 /* dr_5.c */
323 void subtract(struct ship *, struct ship *, int, int [3], int);
324 int mensent(struct ship *, struct ship *, int[3], struct ship **, int *, int);
325
326 /* dr_main.c */
327 int dr_main(void);
328
329 /* game.c */
330 int maxturns(struct ship *, char *);
331 int maxmove(struct ship *, int, int);
332
333 /* lo_main.c */
334 int lo_main(void);
335
336 /* misc.c */
337 int range(struct ship *, struct ship *);
338 struct ship *closestenemy(struct ship *, int, int);
339 int gunsbear(struct ship *, struct ship *);
340 int portside(struct ship *, struct ship *, int);
341 int colours(struct ship *);
342 void logger(struct ship *);
343
344 /* parties.c */
345 int meleeing(struct ship *, struct ship *);
346 int boarding(struct ship *, int);
347 void unboard(struct ship *, struct ship *, int);
348
349 /* pl_1.c */
350 void leave(int) __attribute__((__noreturn__));
351 void choke(int) __attribute__((__noreturn__));
352 void child(int);
353
354 /* pl_2.c */
355 void play(void) __attribute__((__noreturn__));
356
357 /* pl_3.c */
358 void acceptcombat(void);
359 void grapungrap(void);
360 void unfoulplayer(void);
361
362 /* pl_4.c */
363 void changesail(void);
364 void acceptsignal(void);
365 void lookout(void);
366 const char *saywhat(struct ship *, int);
367 void eyeball(struct ship *);
368
369 /* pl_5.c */
370 void acceptmove(void);
371 void acceptboard(void);
372
373 /* pl_6.c */
374 void repair(void);
375 void loadplayer(void);
376
377 /* pl_7.c */
378 void initscreen(void);
379 void cleanupscreen(void);
380 void newturn(int);
381 void Signal(const char *, struct ship *, ...)
382 __attribute__((__format__(__printf__,1,3)));
383 void Msg(const char *, ...)
384 __attribute__((__format__(__printf__,1,2)));
385 void prompt(const char *, struct ship *);
386 int sgetch(const char *, struct ship *, int);
387 void sgetstr(const char *, char *, int);
388 void draw_screen(void);
389 void draw_view(void);
390 void draw_turn(void);
391 void draw_stat(void);
392 void draw_slot(void);
393 void draw_board(void);
394 void centerview(void);
395 void upview(void);
396 void downview(void);
397 void leftview(void);
398 void rightview(void);
399
400 /* pl_main.c */
401 int pl_main(void);
402
403 /* sync.c */
404 void fmtship(char *, size_t, const char *, struct ship *);
405 void makesignal(struct ship *, const char *, struct ship *, ...)
406 __attribute__((__format__(__printf__,2,4)));
407 void makemsg(struct ship *, const char *, ...)
408 __attribute__((__format__(__printf__,2,3)));
409 int sync_exists(int);
410 int sync_open(void);
411 void sync_close(int);
412 void Write(int, struct ship *, long, long, long, long);
413 void Writestr(int, struct ship *, const char *);
414 int Sync(void);
415