Merge from vendor branch TNFTP:
[dragonfly.git] / games / sail / externs.h
CommitLineData
984263bc
MD
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
4be74d36 34 * $DragonFly: src/games/sail/externs.h,v 1.4 2006/09/03 17:33:13 pavalos Exp $
984263bc
MD
35 */
36
4be74d36
PA
37#include <stdarg.h>
38#include <stdbool.h>
39#include <string.h>
984263bc
MD
40#include <stdio.h>
41#include <signal.h>
42#include <ctype.h>
43#include <setjmp.h>
44#include <stdlib.h>
4be74d36 45#include <unistd.h>
984263bc
MD
46#include "machdep.h"
47
48 /* program mode */
4be74d36
PA
49extern int mode;
50extern jmp_buf restart;
984263bc
MD
51#define MODE_PLAYER 1
52#define MODE_DRIVER 2
53#define MODE_LOGGER 3
54
55 /* command line flags */
4be74d36
PA
56extern char debug; /* -D */
57extern char randomize; /* -x, give first available ship */
58extern char longfmt; /* -l, print score in long format */
59extern char nobells; /* -b, don't ring bell before Signal */
984263bc
MD
60
61 /* other initial modes */
4be74d36 62extern char issetuid; /* running setuid */
984263bc
MD
63
64#define die() (random() % 6 + 1)
65#define sqr(a) ((a) * (a))
66#define abs(a) ((a) > 0 ? (a) : -(a))
67#define min(a,b) ((a) < (b) ? (a) : (b))
68
69#define grappled(a) ((a)->file->ngrap)
70#define fouled(a) ((a)->file->nfoul)
71#define snagged(a) (grappled(a) + fouled(a))
72
73#define grappled2(a, b) ((a)->file->grap[(b)->file->index].sn_count)
74#define fouled2(a, b) ((a)->file->foul[(b)->file->index].sn_count)
75#define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
76
77#define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
78#define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
79#define Xsnagged2(a, b) (Xgrappled2(a, b) + Xfouled2(a, b))
80
81#define cleangrapple(a, b, c) Cleansnag(a, b, c, 1)
82#define cleanfoul(a, b, c) Cleansnag(a, b, c, 2)
83#define cleansnag(a, b, c) Cleansnag(a, b, c, 3)
84
85#define sterncolour(sp) ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
86#define sternrow(sp) ((sp)->file->row + dr[(sp)->file->dir])
87#define sterncol(sp) ((sp)->file->col + dc[(sp)->file->dir])
88
89#define capship(sp) ((sp)->file->captured?(sp)->file->captured:(sp))
90
91#define readyname(r) ((r) & R_LOADING ? '*' : ((r) & R_INITIAL ? '!' : ' '))
92
93/* loadL and loadR, should match loadname[] */
94#define L_EMPTY 0 /* should be 0, don't change */
95#define L_GRAPE 1
96#define L_CHAIN 2
97#define L_ROUND 3
98#define L_DOUBLE 4
99#define L_EXPLODE 5
100
101/*
102 * readyL and readyR, these are bits, except R_EMPTY
103 */
104#define R_EMPTY 0 /* not loaded and not loading */
105#define R_LOADING 1 /* loading */
106#define R_DOUBLE 2 /* loading double */
107#define R_LOADED 4 /* loaded */
108#define R_INITIAL 8 /* loaded initial */
109
110#define HULL 0
111#define RIGGING 1
112
113#define W_CAPTAIN 1
114#define W_CAPTURED 2
115#define W_CLASS 3
116#define W_CREW 4
117#define W_DBP 5
118#define W_DRIFT 6
119#define W_EXPLODE 7
120#define W_FILE 8
121#define W_FOUL 9
122#define W_GUNL 10
123#define W_GUNR 11
124#define W_HULL 12
125#define W_MOVE 13
126#define W_OBP 14
127#define W_PCREW 15
128#define W_UNFOUL 16
129#define W_POINTS 17
130#define W_QUAL 18
131#define W_UNGRAP 19
132#define W_RIGG 20
133#define W_COL 21
134#define W_DIR 22
135#define W_ROW 23
136#define W_SIGNAL 24
137#define W_SINK 25
138#define W_STRUCK 26
139#define W_TA 27
140#define W_ALIVE 28
141#define W_TURN 29
142#define W_WIND 30
143#define W_FS 31
144#define W_GRAP 32
145#define W_RIG1 33
146#define W_RIG2 34
147#define W_RIG3 35
148#define W_RIG4 36
149#define W_BEGIN 37
150#define W_END 38
151#define W_DDEAD 39
152
153#define NLOG 10
154struct logs {
155 char l_name[20];
156 int l_uid;
157 int l_shipnum;
158 int l_gamenum;
159 int l_netpoints;
160};
161
162struct BP {
163 short turnsent;
164 struct ship *toship;
165 short mensent;
166};
167
168struct snag {
169 short sn_count;
170 short sn_turn;
171};
172
173#define NSCENE nscene
174#define NSHIP 10
175#define NBP 3
176
177#define NNATION 8
178#define N_A 0
179#define N_B 1
180#define N_S 2
181#define N_F 3
182#define N_J 4
183#define N_D 5
184#define N_K 6
185#define N_O 7
186
187struct File {
188 int index;
189 char captain[20]; /* 0 */
190 short points; /* 20 */
4be74d36
PA
191 unsigned char loadL; /* 22 */
192 unsigned char loadR; /* 24 */
984263bc
MD
193 char readyL; /* 26 */
194 char readyR; /* 28 */
195 struct BP OBP[NBP]; /* 30 */
196 struct BP DBP[NBP]; /* 48 */
197 char struck; /* 66 */
198 struct ship *captured; /* 68 */
199 short pcrew; /* 70 */
200 char movebuf[60]; /* 72 */
201 char drift; /* 132 */
202 short nfoul;
203 short ngrap;
204 struct snag foul[NSHIP]; /* 134 */
205 struct snag grap[NSHIP]; /* 144 */
206 char RH; /* 274 */
207 char RG; /* 276 */
208 char RR; /* 278 */
209 char FS; /* 280 */
210 char explode; /* 282 */
211 char sink; /* 284 */
4be74d36 212 unsigned char dir;
984263bc
MD
213 short col;
214 short row;
215 char loadwith;
216 char stern;
217};
218
219struct ship {
4be74d36 220 const char *shipname; /* 0 */
984263bc 221 struct shipspecs *specs; /* 2 */
4be74d36 222 unsigned char nationality; /* 4 */
984263bc
MD
223 short shiprow; /* 6 */
224 short shipcol; /* 8 */
225 char shipdir; /* 10 */
226 struct File *file; /* 12 */
227};
228
229struct scenario {
230 char winddir; /* 0 */
231 char windspeed; /* 2 */
232 char windchange; /* 4 */
4be74d36
PA
233 unsigned char vessels; /* 12 */
234 const char *name; /* 14 */
984263bc
MD
235 struct ship ship[NSHIP]; /* 16 */
236};
237extern struct scenario scene[];
4be74d36 238extern int nscene;
984263bc
MD
239
240struct shipspecs {
241 char bs;
242 char fs;
243 char ta;
244 short guns;
4be74d36 245 unsigned char class;
984263bc 246 char hull;
4be74d36 247 unsigned char qual;
984263bc
MD
248 char crew1;
249 char crew2;
250 char crew3;
251 char gunL;
252 char gunR;
253 char carL;
254 char carR;
255 char rig1;
256 char rig2;
257 char rig3;
258 char rig4;
259 short pts;
260};
261extern struct shipspecs specs[];
262
4be74d36
PA
263extern struct scenario *cc; /* the current scenario */
264extern struct ship *ls; /* &cc->ship[cc->vessels] */
984263bc
MD
265
266#define SHIP(s) (&cc->ship[s])
267#define foreachship(sp) for ((sp) = cc->ship; (sp) < ls; (sp)++)
268
269struct windeffects {
270 char A, B, C, D;
271};
4be74d36 272extern struct windeffects WET[7][6];
984263bc
MD
273
274struct Tables {
275 char H, G, C, R;
276};
4be74d36
PA
277extern struct Tables RigTable[11][6];
278extern struct Tables HullTable[11][6];
279
280extern char AMMO[9][4];
281extern char HDT[9][10];
282extern char HDTrake[9][10];
283extern char QUAL[9][5];
284extern char MT[9][3];
285
286extern const char *countryname[];
287extern const char *classname[];
288extern const char *directionname[];
289extern const char *qualname[];
984263bc
MD
290extern char loadname[];
291
292extern char rangeofshot[];
293
294extern char dr[], dc[];
295
4be74d36
PA
296extern int winddir;
297extern int windspeed;
298extern int turn;
299extern int game;
300extern int alive;
301extern int people;
302extern char hasdriver;
303
304/* assorted.c */
305void table(int, int, int, struct ship *, struct ship *, int);
306void Cleansnag(struct ship *, struct ship *, char, char);
307
308/* dr_1.c */
309void unfoul(void);
310void boardcomp(void);
311void resolve(void);
312void compcombat(void);
313int next(void);
314
315/* dr_2.c */
316void thinkofgrapples(void);
317void checkup(void);
318void prizecheck(void);
319void closeon(struct ship *, struct ship *, char *, int, int, int);
320
321/* dr_3.c */
322void moveall(void);
323void sendbp(struct ship *, struct ship *, int, char);
324int toughmelee(struct ship *, struct ship *, int, int);
325void reload(void);
326void checksails(void);
327
328/* dr_4.c */
329void ungrap(struct ship *, struct ship *);
330void grap(struct ship *, struct ship *);
331
332/* dr_5.c */
333void subtract(struct ship *, int, int [3], struct ship *, int);
334int mensent(struct ship *, struct ship *, int [3], struct ship **, int *, char);
335
336/* dr_main.c */
337int dr_main(void);
338
339/* game.c */
340int maxturns(struct ship *, char *);
341int maxmove(struct ship *, int, int);
342
343/* lo_main.c */
344int lo_main(void);
345
346/* misc.c */
347int range(struct ship *, struct ship *);
348struct ship *closestenemy(struct ship *, char, char);
349char gunsbear(struct ship *, struct ship *);
350int portside(struct ship *, struct ship *, int);
351char colours(struct ship *);
352void write_log(struct ship *);
353
354/* parties.c */
355bool meleeing(struct ship *, struct ship *);
356bool boarding(struct ship *, char);
357void unboard(struct ship *, struct ship *, char);
358
359/* pl_1.c */
360void leave(int);
361void choke(void);
362void child(void);
363
364/* pl_2.c */
365void play(void);
366
367/* pl_3.c */
368void acceptcombat(void);
369void grapungrap(void);
370void unfoulplayer(void);
371
372/* pl_4.c */
373void changesail(void);
374void acceptsignal(void);
375void lookout(void);
376const char *saywhat(struct ship *, char);
377void eyeball(struct ship *);
378
379/* pl_5.c */
380void acceptmove(void);
381void acceptboard(void);
382
383/* pl_6.c */
384void repair(void);
385void loadplayer(void);
386
387/* pl_7.c */
388void initscreen(void);
389void cleanupscreen(void);
390void newturn(void);
391void Signal(const char *, struct ship *, ...);
392int sgetch(const char *, struct ship *, char);
393void sgetstr(const char *, char *, int);
394void draw_screen(void);
395void draw_view(void);
396void draw_turn(void);
397void draw_stat(void);
398void draw_slot(void);
399void draw_board(void);
400void centerview(void);
401void upview(void);
402void downview(void);
403void leftview(void);
404void rightview(void);
405
406/* pl_main.c */
407int pl_main(void);
408
409/* sync.c */
410void fmtship(char *, size_t, const char *, struct ship *);
411void makesignal(struct ship *, const char *, struct ship *, ...);
412bool sync_exists(int);
413int sync_open(void);
414void sync_close(char);
415void Write(int, struct ship *, char, int, int, int, int);
416int Sync(void);