Home | History | Annotate | Line # | Download | only in mille
mille.h revision 1.11
      1 /*	$NetBSD: mille.h,v 1.11 1999/09/30 18:01:32 jsm Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)mille.h	8.1 (Berkeley) 5/31/93
     36  */
     37 
     38 # include	<sys/types.h>
     39 # include	<sys/uio.h>
     40 # include	<sys/stat.h>
     41 # include	<ctype.h>
     42 # include	<err.h>
     43 # include	<errno.h>
     44 # include	<curses.h>
     45 # include	<fcntl.h>
     46 # include	<stdlib.h>
     47 # include	<string.h>
     48 # include	<termios.h>
     49 # include	<unistd.h>
     50 
     51 /*
     52  * @(#)mille.h	1.1 (Berkeley) 4/1/82
     53  */
     54 
     55 /*
     56  * Miscellaneous constants
     57  */
     58 
     59 # define	unsgn		unsigned
     60 # define	CARD		short
     61 
     62 # define	HAND_SZ		7	/* number of cards in a hand	*/
     63 # define	DECK_SZ		101	/* number of cards in decks	*/
     64 # define	NUM_SAFE	4	/* number of saftey cards	*/
     65 # define	NUM_MILES	5	/* number of milestones types	*/
     66 # define	NUM_CARDS	20	/* number of types of cards	*/
     67 # define	BOARD_Y		17	/* size of board screen		*/
     68 # define	BOARD_X		40
     69 # define	MILES_Y		7	/* size of mileage screen	*/
     70 # define	MILES_X		80
     71 # define	SCORE_Y		17	/* size of score screen		*/
     72 # define	SCORE_X		40
     73 # define	MOVE_Y		10	/* Where to print move prompt	*/
     74 # define	MOVE_X		20
     75 # define	ERR_Y		15	/* Where to print errors	*/
     76 # define	ERR_X		5
     77 # define	EXT_Y		4	/* Where to put Extension	*/
     78 # define	EXT_X		9
     79 
     80 # define	PLAYER		0
     81 # define	COMP		1
     82 
     83 # define	W_SMALL		0	/* Small (initial) window	*/
     84 # define	W_FULL		1	/* Full (final) window		*/
     85 
     86 /*
     87  * Move types
     88  */
     89 
     90 # define	M_DISCARD	0
     91 # define	M_DRAW		1
     92 # define	M_PLAY		2
     93 # define	M_ORDER		3
     94 
     95 /*
     96  * Scores
     97  */
     98 
     99 # define	SC_SAFETY	100
    100 # define	SC_ALL_SAFE	300
    101 # define	SC_COUP		300
    102 # define	SC_TRIP		400
    103 # define	SC_SAFE		300
    104 # define	SC_DELAY	300
    105 # define	SC_EXTENSION	200
    106 # define	SC_SHUT_OUT	500
    107 
    108 /*
    109  * safety descriptions
    110  */
    111 
    112 # undef		S_UNKNOWN
    113 # undef		S_IN_HAND
    114 # undef		S_PLAYED
    115 # undef		S_GAS_SAFE
    116 # undef		S_SPARE_SAFE
    117 # undef		S_DRIVE_SAFE
    118 # undef		S_RIGHT_WAY
    119 # undef		S_CONV
    120 # define	S_UNKNOWN	0	/* location of safety unknown	*/
    121 # define	S_IN_HAND	1	/* safety in player's hand	*/
    122 # define	S_PLAYED	2	/* safety has been played	*/
    123 # define	S_GAS_SAFE	0	/* Gas safety card index	*/
    124 # define	S_SPARE_SAFE	1	/* Tire safety card index	*/
    125 # define	S_DRIVE_SAFE	2	/* Driveing safety card index	*/
    126 # define	S_RIGHT_WAY	3	/* Right-of-Way card index	*/
    127 # define	S_CONV		15	/* conversion from C_ to S_	*/
    128 
    129 /*
    130  * card numbers
    131  */
    132 
    133 # define	C_INIT		-1
    134 # define	C_25		0
    135 # define	C_50		1
    136 # define	C_75		2
    137 # define	C_100		3
    138 # define	C_200		4
    139 # define	C_EMPTY		5
    140 # define	C_FLAT		6
    141 # define	C_CRASH		7
    142 # define	C_STOP		8
    143 # define	C_LIMIT		9
    144 # define	C_GAS		10
    145 # define	C_SPARE		11
    146 # define	C_REPAIRS	12
    147 # define	C_GO		13
    148 # define	C_END_LIMIT	14
    149 # define	C_GAS_SAFE	15
    150 # define	C_SPARE_SAFE	16
    151 # define	C_DRIVE_SAFE	17
    152 # define	C_RIGHT_WAY	18
    153 
    154 /*
    155  * prompt types
    156  */
    157 
    158 # define	MOVEPROMPT		0
    159 # define	REALLYPROMPT		1
    160 # define	ANOTHERHANDPROMPT	2
    161 # define	ANOTHERGAMEPROMPT	3
    162 # define	SAVEGAMEPROMPT		4
    163 # define	SAMEFILEPROMPT		5
    164 # define	FILEPROMPT		6
    165 # define	EXTENSIONPROMPT		7
    166 # define	OVERWRITEFILEPROMPT	8
    167 
    168 # ifdef	SYSV
    169 # define	srandom(x)	srand(x)
    170 # define	random()	rand()
    171 # endif	/* SYSV */
    172 
    173 typedef struct {
    174 	bool	coups[NUM_SAFE];
    175 	bool	can_go;
    176 	bool	new_battle;
    177 	bool	new_speed;
    178 	short	safety[NUM_SAFE];
    179 	short	sh_safety[NUM_SAFE];
    180 	short	nummiles[NUM_MILES];
    181 	short	sh_nummiles[NUM_MILES];
    182 	CARD	hand[HAND_SZ];
    183 	CARD	sh_hand[HAND_SZ];
    184 	CARD	battle;
    185 	CARD	sh_battle;
    186 	CARD	speed;
    187 	CARD	sh_speed;
    188 	int	mileage;
    189 	int	sh_mileage;
    190 	int	hand_tot;
    191 	int	sh_hand_tot;
    192 	int	safescore;
    193 	int	sh_safescore;
    194 	int	coupscore;
    195 	int	total;
    196 	int	sh_total;
    197 	int	games;
    198 	int	sh_games;
    199 	int	was_finished;
    200 } PLAY;
    201 
    202 /*
    203  * macros
    204  */
    205 
    206 # define	other(x)	(1 - x)
    207 # define	nextplay()	(Play = other(Play))
    208 # define	nextwin(x)	(1 - x)
    209 # define	opposite(x)	(Opposite[x])
    210 # define	is_safety(x)	(x >= C_GAS_SAFE)
    211 
    212 /*
    213  * externals
    214  */
    215 
    216 extern bool	Debug, Finished, Next, On_exit, Order, Saved;
    217 
    218 extern char	Initstr[];
    219 extern const char	*C_fmt, *const *C_name, *Fromfile;
    220 
    221 extern int	Card_no, End, Handstart, Movetype, Numgos,
    222 		Numneed[], Numseen[NUM_CARDS], Play, Window;
    223 extern const int	Numcards[], Value[];
    224 
    225 extern CARD	Deck[DECK_SZ], Discard, Sh_discard, *Topcard;
    226 extern const CARD	Opposite[NUM_CARDS];
    227 
    228 extern FILE	*outf;
    229 
    230 extern PLAY	Player[2];
    231 
    232 extern WINDOW	*Board, *Miles, *Score;
    233 
    234 /*
    235  * functions
    236  */
    237 
    238 void	account __P((CARD));
    239 void	calcmove __P((void));
    240 int	canplay __P((const PLAY *, const PLAY *, CARD));
    241 int	check_ext __P((bool));
    242 void	check_go __P((void));
    243 void	check_more __P((void));
    244 void	die __P((int)) __attribute__((__noreturn__));
    245 void	domove __P((void));
    246 bool	error __P((const char *, ...));
    247 void	extrapolate __P((PLAY *));
    248 void	finalscore __P((PLAY *));
    249 CARD	getcard __P((void));
    250 void	getmove __P((void));
    251 int	getyn __P((int));
    252 int	haspicked __P((const PLAY *));
    253 void	init __P((void));
    254 int	is_repair __P((CARD));
    255 int	main __P((int, char **));
    256 void	newboard __P((void));
    257 void	newscore __P((void));
    258 int	onecard __P((const PLAY *));
    259 int	playcard __P((PLAY *));
    260 void	prboard __P((void));
    261 void	prompt __P((int));
    262 void	prscore __P((bool));
    263 int	readch __P((void));
    264 bool	rest_f __P((const char *));
    265 int	roll __P((int, int));
    266 void	rub __P((int));
    267 int	safety __P((CARD));
    268 bool	save __P((void));
    269 void	show_card __P((int, int, CARD, CARD *));
    270 void	show_score __P((int, int, int, int *));
    271 void	shuffle __P((void));
    272 void	sort __P((CARD *));
    273 void	undoex __P((int));
    274 bool	varpush __P((int, ssize_t __P((int, const struct iovec *, int))));
    275