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