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