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