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