]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - mille/mille.h
Add use of `const' where appropriate to the games.
[bsdgames-darwin.git] / mille / mille.h
1 /* $NetBSD: mille.h,v 1.10 1999/09/08 21:17:50 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 # define S_UNKNOWN 0 /* location of safety unknown */
113 # define S_IN_HAND 1 /* safety in player's hand */
114 # define S_PLAYED 2 /* safety has been played */
115 # define S_GAS_SAFE 0 /* Gas safety card index */
116 # define S_SPARE_SAFE 1 /* Tire safety card index */
117 # define S_DRIVE_SAFE 2 /* Driveing safety card index */
118 # define S_RIGHT_WAY 3 /* Right-of-Way card index */
119 # define S_CONV 15 /* conversion from C_ to S_ */
120
121 /*
122 * card numbers
123 */
124
125 # define C_INIT -1
126 # define C_25 0
127 # define C_50 1
128 # define C_75 2
129 # define C_100 3
130 # define C_200 4
131 # define C_EMPTY 5
132 # define C_FLAT 6
133 # define C_CRASH 7
134 # define C_STOP 8
135 # define C_LIMIT 9
136 # define C_GAS 10
137 # define C_SPARE 11
138 # define C_REPAIRS 12
139 # define C_GO 13
140 # define C_END_LIMIT 14
141 # define C_GAS_SAFE 15
142 # define C_SPARE_SAFE 16
143 # define C_DRIVE_SAFE 17
144 # define C_RIGHT_WAY 18
145
146 /*
147 * prompt types
148 */
149
150 # define MOVEPROMPT 0
151 # define REALLYPROMPT 1
152 # define ANOTHERHANDPROMPT 2
153 # define ANOTHERGAMEPROMPT 3
154 # define SAVEGAMEPROMPT 4
155 # define SAMEFILEPROMPT 5
156 # define FILEPROMPT 6
157 # define EXTENSIONPROMPT 7
158 # define OVERWRITEFILEPROMPT 8
159
160 # ifdef SYSV
161 # define srandom(x) srand(x)
162 # define random() rand()
163 # endif /* SYSV */
164
165 typedef struct {
166 bool coups[NUM_SAFE];
167 bool can_go;
168 bool new_battle;
169 bool new_speed;
170 short safety[NUM_SAFE];
171 short sh_safety[NUM_SAFE];
172 short nummiles[NUM_MILES];
173 short sh_nummiles[NUM_MILES];
174 CARD hand[HAND_SZ];
175 CARD sh_hand[HAND_SZ];
176 CARD battle;
177 CARD sh_battle;
178 CARD speed;
179 CARD sh_speed;
180 int mileage;
181 int sh_mileage;
182 int hand_tot;
183 int sh_hand_tot;
184 int safescore;
185 int sh_safescore;
186 int coupscore;
187 int total;
188 int sh_total;
189 int games;
190 int sh_games;
191 int was_finished;
192 } PLAY;
193
194 /*
195 * macros
196 */
197
198 # define other(x) (1 - x)
199 # define nextplay() (Play = other(Play))
200 # define nextwin(x) (1 - x)
201 # define opposite(x) (Opposite[x])
202 # define issafety(x) (x >= C_GAS_SAFE)
203
204 /*
205 * externals
206 */
207
208 extern bool Debug, Finished, Next, On_exit, Order, Saved;
209
210 extern char Initstr[];
211 extern const char *C_fmt, *const *C_name, *Fromfile;
212
213 extern int Card_no, End, Handstart, Movetype, Numgos,
214 Numneed[], Numseen[NUM_CARDS], Play, Window;
215 extern const int Numcards[], Value[];
216
217 extern CARD Deck[DECK_SZ], Discard, Sh_discard, *Topcard;
218 extern const CARD Opposite[NUM_CARDS];
219
220 extern FILE *outf;
221
222 extern PLAY Player[2];
223
224 extern WINDOW *Board, *Miles, *Score;
225
226 /*
227 * functions
228 */
229
230 void account __P((CARD));
231 void calcmove __P((void));
232 int canplay __P((const PLAY *, const PLAY *, CARD));
233 int check_ext __P((bool));
234 void check_go __P((void));
235 void check_more __P((void));
236 void die __P((int)) __attribute__((__noreturn__));
237 void domove __P((void));
238 bool error __P((const char *, ...));
239 void extrapolate __P((PLAY *));
240 void finalscore __P((PLAY *));
241 CARD getcard __P((void));
242 void getmove __P((void));
243 int getyn __P((int));
244 int haspicked __P((const PLAY *));
245 void init __P((void));
246 int isrepair __P((CARD));
247 int main __P((int, char **));
248 void newboard __P((void));
249 void newscore __P((void));
250 int onecard __P((const PLAY *));
251 int playcard __P((PLAY *));
252 void prboard __P((void));
253 void prompt __P((int));
254 void prscore __P((bool));
255 int readch __P((void));
256 bool rest_f __P((const char *));
257 int roll __P((int, int));
258 void rub __P((int));
259 int safety __P((CARD));
260 bool save __P((void));
261 void show_card __P((int, int, CARD, CARD *));
262 void show_score __P((int, int, int, int *));
263 void shuffle __P((void));
264 void sort __P((CARD *));
265 void undoex __P((int));
266 bool varpush __P((int, ssize_t __P((int, const struct iovec *, int))));