xref: /openbsd/games/sail/extern.h (revision 39ac0be5)
1 /*	$OpenBSD: extern.h,v 1.12 2015/12/31 16:44:22 mestre 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 <sys/types.h>
36 
37 #include <setjmp.h>
38 
39 #ifndef __GNUC__
40 #define __attribute__(x)
41 #endif
42 
43 	/* program mode */
44 extern int mode;
45 extern jmp_buf restart;
46 #define MODE_PLAYER	1
47 #define MODE_DRIVER	2
48 #define MODE_LOGGER	3
49 
50 	/* command line flags */
51 extern char debug;			/* -D */
52 extern char randomize;			/* -x, give first available ship */
53 extern char longfmt;			/* -l, print score in long format */
54 extern char nobells;			/* -b, don't ring bell before Signal */
55 
56 	/* other initial modes */
57 extern gid_t gid;
58 extern gid_t egid;
59 
60 #define die()		(arc4random_uniform(6) + 1)
61 #define sqr(a)		((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 	uid_t 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 	unsigned char loadL;		/* 22 */
187 	unsigned char loadR;		/* 24 */
188 	unsigned char readyL;		/* 26 */
189 	unsigned 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[10];		/* 72 */
196 	char drift;			/* 82 */
197 	short nfoul;
198 	short ngrap;
199 	struct snag foul[NSHIP];	/* 84 */
200 	struct snag grap[NSHIP];	/* 124 */
201 	char RH;			/* 224 */
202 	char RG;			/* 226 */
203 	char RR;			/* 228 */
204 	char FS;			/* 230 */
205 	char explode;			/* 232 */
206 	char sink;			/* 234 */
207 	unsigned char dir;
208 	short col;
209 	short row;
210 	char loadwith;
211 	char stern;
212 };
213 
214 struct ship {
215 	const char *shipname;		/* 0 */
216 	struct shipspecs *specs;	/* 2 */
217 	unsigned 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 	unsigned char vessels;		/* 12 */
229 	const char *name;		/* 14 */
230 	struct ship ship[NSHIP];	/* 16 */
231 };
232 extern struct scenario scene[];
233 extern int nscene;
234 
235 struct shipspecs {
236 	char bs;
237 	char fs;
238 	char ta;
239 	short guns;
240 	unsigned char class;
241 	char hull;
242 	unsigned char qual;
243 	char crew1;
244 	char crew2;
245 	char crew3;
246 	char gunL;
247 	char gunR;
248 	char carL;
249 	char carR;
250 	int rig1;
251 	int rig2;
252 	int rig3;
253 	int rig4;
254 	short pts;
255 };
256 extern struct shipspecs specs[];
257 
258 extern struct scenario *cc;		/* the current scenario */
259 extern 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 extern const struct windeffects WET[7][6];
268 
269 struct Tables {
270 	char H, G, C, R;
271 };
272 extern const struct Tables RigTable[11][6];
273 extern const struct Tables HullTable[11][6];
274 
275 extern const char AMMO[9][4];
276 extern const char HDT[9][10];
277 extern const char HDTrake[9][10];
278 extern const char QUAL[9][5];
279 extern const char MT[9][3];
280 
281 extern const char *const countryname[];
282 extern const char *const classname[];
283 extern const char *const directionname[];
284 extern const char *const qualname[];
285 extern const char loadname[];
286 
287 extern const char rangeofshot[];
288 
289 extern const char dr[], dc[];
290 
291 extern int winddir;
292 extern int windspeed;
293 extern int turn;
294 extern int game;
295 extern int alive;
296 extern int people;
297 extern char hasdriver;
298 
299 /* assorted.c */
300 void table(int, int, int, struct ship *, struct ship *, int);
301 void Cleansnag(struct ship *, struct ship *, int, int);
302 
303 /* dr_1.c */
304 void unfoul(void);
305 void boardcomp(void);
306 int fightitout(struct ship *, struct ship *, int);
307 void resolve(void);
308 void compcombat(void);
309 int next(void);
310 
311 /* dr_2.c */
312 void thinkofgrapples(void);
313 void checkup(void);
314 void prizecheck(void);
315 int str_end(const char *);
316 void closeon(struct ship *, struct ship *, char[], size_t, int, int, int);
317 int score(char[], size_t, struct ship *, struct ship *, int);
318 void move_ship(const char *, struct ship *, unsigned char *, short *, short *, char *);
319 void try(char[], size_t, char [], size_t, int, int, int, int, int, struct ship *,
320     struct ship *, int *, int);
321 void rmend(char *);
322 
323 /* dr_3.c */
324 void moveall(void);
325 int stillmoving(int);
326 int is_isolated(struct ship *);
327 int push(struct ship *, struct ship *);
328 void step(int, struct ship *, char *);
329 void sendbp(struct ship *, struct ship *, int, int);
330 int is_toughmelee(struct ship *, struct ship *, int, int);
331 void reload(void);
332 void checksails(void);
333 
334 /* dr_4.c */
335 void ungrap(struct ship *, struct ship *);
336 void grap(struct ship *, struct ship *);
337 
338 /* dr_5.c */
339 void subtract(struct ship *, int, int [3], struct ship *, int);
340 int mensent(struct ship *, struct ship *, int[3], struct ship **, int *, int);
341 
342 /* dr_main.c */
343 int dr_main(void);
344 
345 /* game.c */
346 int maxturns(struct ship *, char *);
347 int maxmove(struct ship *, int, int);
348 
349 /* lo_main.c */
350 int lo_main(void);
351 
352 /* misc.c */
353 int range(struct ship *, struct ship *);
354 struct ship *closestenemy(struct ship *, int, int);
355 int angle(int, int);
356 int gunsbear(struct ship *, struct ship *);
357 int portside(struct ship *, struct ship *, int);
358 int colours(struct ship *);
359 void logger(struct ship *);
360 
361 /* parties.c */
362 int meleeing(struct ship *, struct ship *);
363 int boarding(struct ship *, int);
364 void unboard(struct ship *, struct ship *, int);
365 
366 /* pl_1.c */
367 void child(int);
368 __dead void choke(int);
369 __dead void leave(int);
370 
371 /* pl_2.c */
372 __dead void play(void);
373 
374 /* pl_3.c */
375 void acceptcombat(void);
376 void grapungrap(void);
377 void unfoulplayer(void);
378 
379 /* pl_4.c */
380 void changesail(void);
381 void acceptsignal(void);
382 void lookout(void);
383 const char *saywhat(struct ship *, int);
384 void eyeball(struct ship *);
385 
386 /* pl_5.c */
387 void acceptmove(void);
388 void acceptboard(void);
389 void parties(int[3], struct ship *, int, int);
390 
391 /* pl_6.c */
392 void repair(void);
393 int turned(void);
394 void loadplayer(void);
395 
396 /* pl_7.c */
397 void initscreen(void);
398 void cleanupscreen(void);
399 void newturn(int);
400 void Signal(char *, struct ship *, ...)
401 	 __attribute__((__format__(__printf__,1,3)));
402 void Msg(char *, ...)
403 	 __attribute__((__format__(__printf__,1,2)));
404 void Scroll(void);
405 void prompt(const char *, struct ship *);
406 void endprompt(int);
407 int sgetch(const char *, struct ship *, int);
408 void sgetstr(const char *, char *, int);
409 void draw_screen(void);
410 void draw_view(void);
411 void draw_turn(void);
412 void draw_stat(void);
413 void draw_slot(void);
414 void draw_board(void);
415 void centerview(void);
416 void upview(void);
417 void downview(void);
418 void leftview(void);
419 void rightview(void);
420 void adjustview(void);
421 
422 /* pl_main.c */
423 __dead void pl_main(void);
424 void initialize(void);
425 
426 /* sync.c */
427 void fmtship(char *, size_t, const char *, struct ship *);
428 void makesignal(struct ship *, const char *, struct ship *, ...)
429 	 __attribute__((__format__(__printf__,2,4)));
430 void makemsg(struct ship *, const char *, ...)
431 	 __attribute__((__format__(__printf__,2,3)));
432 int sync_exists(int);
433 int sync_open(void);
434 void sync_close(int);
435 void Write(int, struct ship *, long, long, long, long);
436 void Writestr(int, struct ship *, const char *);
437 int Sync(void);
438 int sync_update(int, struct ship *, const char *, long, long, long, long);
439