1/*	$OpenBSD: mille.h,v 1.13 2016/01/08 18:05:58 mestre Exp $	*/
2/*	$NetBSD: mille.h,v 1.5 1995/03/24 05:01:51 cgd Exp $	*/
3
4/*
5 * Copyright (c) 1982, 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 *	@(#)mille.h	8.1 (Berkeley) 5/31/93
33 */
34
35#include <sys/uio.h>
36
37#include <curses.h>
38
39/*
40 * @(#)mille.h	1.1 (Berkeley) 4/1/82
41 */
42
43/*
44 * Miscellaneous constants
45 */
46
47#define	CARD		short
48
49#define	HAND_SZ		7	/* number of cards in a hand	*/
50#define	DECK_SZ		101	/* number of cards in decks	*/
51#define	NUM_SAFE	4	/* number of safety cards	*/
52#define	NUM_MILES	5	/* number of milestones types	*/
53#define	NUM_CARDS	20	/* number of types of cards	*/
54#define	BOARD_Y		17	/* size of board screen		*/
55#define	BOARD_X		40
56#define	MILES_Y		7	/* size of mileage screen	*/
57#define	MILES_X		80
58#define	SCORE_Y		17	/* size of score screen		*/
59#define	SCORE_X		40
60#define	MOVE_Y		10	/* Where to print move prompt	*/
61#define	MOVE_X		20
62#define	ERR_Y		15	/* Where to print errors	*/
63#define	ERR_X		5
64#define	EXT_Y		4	/* Where to put Extension	*/
65#define	EXT_X		9
66
67#define	PLAYER		0
68#define	COMP		1
69
70#define	W_SMALL		0	/* Small (initial) window	*/
71#define	W_FULL		1	/* Full (final) window		*/
72
73/*
74 * Move types
75 */
76
77#define	M_DISCARD	0
78#define	M_DRAW		1
79#define	M_PLAY		2
80#define	M_ORDER		3
81
82/*
83 * Scores
84 */
85
86#define	SC_SAFETY	100
87#define	SC_ALL_SAFE	300
88#define	SC_COUP		300
89#define	SC_TRIP		400
90#define	SC_SAFE		300
91#define	SC_DELAY	300
92#define	SC_EXTENSION	200
93#define	SC_SHUT_OUT	500
94
95/*
96 * safety descriptions
97 */
98
99#define	S_UNKNOWN	0	/* location of safety unknown	*/
100#define	S_IN_HAND	1	/* safety in player's hand	*/
101#define	S_PLAYED	2	/* safety has been played	*/
102#define	S_GAS_SAFE	0	/* Gas safety card index	*/
103#define	S_SPARE_SAFE	1	/* Tire safety card index	*/
104#define	S_DRIVE_SAFE	2	/* Driveing safety card index	*/
105#define	S_RIGHT_WAY	3	/* Right-of-Way card index	*/
106#define	S_CONV		15	/* conversion from C_ to S_	*/
107
108/*
109 * card numbers
110 */
111
112#define	C_INIT		-1
113#define	C_25		0
114#define	C_50		1
115#define	C_75		2
116#define	C_100		3
117#define	C_200		4
118#define	C_EMPTY		5
119#define	C_FLAT		6
120#define	C_CRASH		7
121#define	C_STOP		8
122#define	C_LIMIT		9
123#define	C_GAS		10
124#define	C_SPARE		11
125#define	C_REPAIRS	12
126#define	C_GO		13
127#define	C_END_LIMIT	14
128#define	C_GAS_SAFE	15
129#define	C_SPARE_SAFE	16
130#define	C_DRIVE_SAFE	17
131#define	C_RIGHT_WAY	18
132
133/*
134 * prompt types
135 */
136
137#define	MOVEPROMPT		0
138#define	REALLYPROMPT		1
139#define	ANOTHERHANDPROMPT	2
140#define	ANOTHERGAMEPROMPT	3
141#define	SAVEGAMEPROMPT		4
142#define	SAMEFILEPROMPT		5
143#define	FILEPROMPT		6
144#define	EXTENSIONPROMPT		7
145#define	OVERWRITEFILEPROMPT	8
146
147typedef struct {
148	bool	coups[NUM_SAFE];
149	bool	can_go;
150	bool	new_battle;
151	bool	new_speed;
152	short	safety[NUM_SAFE];
153	short	sh_safety[NUM_SAFE];
154	short	nummiles[NUM_MILES];
155	short	sh_nummiles[NUM_MILES];
156	CARD	hand[HAND_SZ];
157	CARD	sh_hand[HAND_SZ];
158	CARD	battle;
159	CARD	sh_battle;
160	CARD	speed;
161	CARD	sh_speed;
162	int	mileage;
163	int	sh_mileage;
164	int	hand_tot;
165	int	sh_hand_tot;
166	int	safescore;
167	int	sh_safescore;
168	int	coupscore;
169	int	total;
170	int	sh_total;
171	int	games;
172	int	sh_games;
173	int	was_finished;
174} PLAY;
175
176/*
177 * macros
178 */
179
180#undef 	CTRL
181#define	CTRL(c)		((c) & 0x1f)
182#define	other(x)	(1 - x)
183#define	nextplay()	(Play = other(Play))
184#define	nextwin(x)	(1 - x)
185#define	opposite(x)	(Opposite[x])
186#define	is_safety(x)	(x >= C_GAS_SAFE)
187
188/*
189 * externals
190 */
191
192extern bool	Debug, Finished, Next, On_exit, Order, Saved;
193
194extern char	Initstr[100], *C_fmt;
195extern const char	*const *C_name, *Fromfile;
196
197extern int	Card_no, End, Handstart, Movetype, Numgos,
198		Numneed[], Numseen[NUM_CARDS], Play, Window;
199extern const int	Numcards[], Value[];
200
201extern CARD	Deck[DECK_SZ], Discard, Sh_discard, *Topcard;
202extern const CARD	Opposite[NUM_CARDS];
203
204extern FILE	*outf;
205
206extern PLAY	Player[2];
207
208extern WINDOW	*Board, *Miles, *Score;
209
210/*
211 * functions
212 */
213
214void	account(CARD);
215void	calcmove(void);
216int	canplay(const PLAY *, const PLAY *, CARD);
217int	check_ext(bool);
218void	check_go(void);
219void	check_more(void);
220__dead void	die(int);
221void	domove(void);
222bool	error(char *, ...);
223void	finalscore(PLAY *);
224CARD	getcard(void);
225void	getmove(void);
226int	getyn(int);
227int	haspicked(const PLAY *);
228void	init(void);
229int	is_repair(CARD);
230void	newboard(void);
231void	newscore(void);
232int	onecard(const PLAY *);
233int	playcard(PLAY *);
234void	prboard(void);
235void	prompt(int);
236void	prscore(bool);
237int	readch(void);
238bool	rest_f(const char *);
239int	roll(int, int);
240void	rub(int);
241int	safety(CARD);
242bool	save(void);
243void	show_card(int, int, CARD, CARD *);
244void	show_score(int, int, int, int *);
245void	shuffle(void);
246void	sort(CARD *);
247bool	varpush(int, ssize_t(int, const struct iovec *, int));
248#ifdef EXTRAP
249void	extrapolate(PLAY *);
250void	undoex(void);
251#endif
252