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