mille.h revision 1.14 1 1.14 dholland /* $NetBSD: mille.h,v 1.14 2009/05/25 23:17:31 dholland 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.1 cgd # include <sys/types.h>
35 1.7 lukem # include <sys/uio.h>
36 1.7 lukem # include <sys/stat.h>
37 1.1 cgd # include <ctype.h>
38 1.7 lukem # include <err.h>
39 1.7 lukem # include <errno.h>
40 1.1 cgd # include <curses.h>
41 1.7 lukem # include <fcntl.h>
42 1.7 lukem # include <stdlib.h>
43 1.7 lukem # include <string.h>
44 1.3 mycroft # include <termios.h>
45 1.7 lukem # 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.1 cgd # define unsgn unsigned
56 1.1 cgd # define CARD short
57 1.1 cgd
58 1.1 cgd # define HAND_SZ 7 /* number of cards in a hand */
59 1.1 cgd # define DECK_SZ 101 /* number of cards in decks */
60 1.1 cgd # define NUM_SAFE 4 /* number of saftey cards */
61 1.1 cgd # define NUM_MILES 5 /* number of milestones types */
62 1.1 cgd # define NUM_CARDS 20 /* number of types of cards */
63 1.1 cgd # define BOARD_Y 17 /* size of board screen */
64 1.1 cgd # define BOARD_X 40
65 1.1 cgd # define MILES_Y 7 /* size of mileage screen */
66 1.1 cgd # define MILES_X 80
67 1.1 cgd # define SCORE_Y 17 /* size of score screen */
68 1.1 cgd # define SCORE_X 40
69 1.1 cgd # define MOVE_Y 10 /* Where to print move prompt */
70 1.1 cgd # define MOVE_X 20
71 1.1 cgd # define ERR_Y 15 /* Where to print errors */
72 1.1 cgd # define ERR_X 5
73 1.1 cgd # define EXT_Y 4 /* Where to put Extension */
74 1.1 cgd # define EXT_X 9
75 1.1 cgd
76 1.1 cgd # define PLAYER 0
77 1.1 cgd # define COMP 1
78 1.1 cgd
79 1.1 cgd # define W_SMALL 0 /* Small (initial) window */
80 1.1 cgd # define W_FULL 1 /* Full (final) window */
81 1.1 cgd
82 1.1 cgd /*
83 1.1 cgd * Move types
84 1.1 cgd */
85 1.1 cgd
86 1.1 cgd # define M_DISCARD 0
87 1.1 cgd # define M_DRAW 1
88 1.1 cgd # define M_PLAY 2
89 1.1 cgd # define M_ORDER 3
90 1.1 cgd
91 1.1 cgd /*
92 1.1 cgd * Scores
93 1.1 cgd */
94 1.1 cgd
95 1.1 cgd # define SC_SAFETY 100
96 1.1 cgd # define SC_ALL_SAFE 300
97 1.1 cgd # define SC_COUP 300
98 1.1 cgd # define SC_TRIP 400
99 1.1 cgd # define SC_SAFE 300
100 1.1 cgd # define SC_DELAY 300
101 1.1 cgd # define SC_EXTENSION 200
102 1.1 cgd # define SC_SHUT_OUT 500
103 1.1 cgd
104 1.1 cgd /*
105 1.1 cgd * safety descriptions
106 1.1 cgd */
107 1.1 cgd
108 1.11 jsm # undef S_UNKNOWN
109 1.11 jsm # undef S_IN_HAND
110 1.11 jsm # undef S_PLAYED
111 1.11 jsm # undef S_GAS_SAFE
112 1.11 jsm # undef S_SPARE_SAFE
113 1.11 jsm # undef S_DRIVE_SAFE
114 1.11 jsm # undef S_RIGHT_WAY
115 1.11 jsm # undef S_CONV
116 1.1 cgd # define S_UNKNOWN 0 /* location of safety unknown */
117 1.1 cgd # define S_IN_HAND 1 /* safety in player's hand */
118 1.1 cgd # define S_PLAYED 2 /* safety has been played */
119 1.1 cgd # define S_GAS_SAFE 0 /* Gas safety card index */
120 1.1 cgd # define S_SPARE_SAFE 1 /* Tire safety card index */
121 1.1 cgd # define S_DRIVE_SAFE 2 /* Driveing safety card index */
122 1.1 cgd # define S_RIGHT_WAY 3 /* Right-of-Way card index */
123 1.1 cgd # define S_CONV 15 /* conversion from C_ to S_ */
124 1.1 cgd
125 1.1 cgd /*
126 1.1 cgd * card numbers
127 1.1 cgd */
128 1.1 cgd
129 1.1 cgd # define C_INIT -1
130 1.1 cgd # define C_25 0
131 1.1 cgd # define C_50 1
132 1.1 cgd # define C_75 2
133 1.1 cgd # define C_100 3
134 1.1 cgd # define C_200 4
135 1.1 cgd # define C_EMPTY 5
136 1.1 cgd # define C_FLAT 6
137 1.1 cgd # define C_CRASH 7
138 1.1 cgd # define C_STOP 8
139 1.1 cgd # define C_LIMIT 9
140 1.1 cgd # define C_GAS 10
141 1.1 cgd # define C_SPARE 11
142 1.1 cgd # define C_REPAIRS 12
143 1.1 cgd # define C_GO 13
144 1.1 cgd # define C_END_LIMIT 14
145 1.1 cgd # define C_GAS_SAFE 15
146 1.1 cgd # define C_SPARE_SAFE 16
147 1.1 cgd # define C_DRIVE_SAFE 17
148 1.1 cgd # define C_RIGHT_WAY 18
149 1.1 cgd
150 1.1 cgd /*
151 1.1 cgd * prompt types
152 1.1 cgd */
153 1.1 cgd
154 1.1 cgd # define MOVEPROMPT 0
155 1.1 cgd # define REALLYPROMPT 1
156 1.1 cgd # define ANOTHERHANDPROMPT 2
157 1.1 cgd # define ANOTHERGAMEPROMPT 3
158 1.1 cgd # define SAVEGAMEPROMPT 4
159 1.1 cgd # define SAMEFILEPROMPT 5
160 1.1 cgd # define FILEPROMPT 6
161 1.1 cgd # define EXTENSIONPROMPT 7
162 1.1 cgd # define OVERWRITEFILEPROMPT 8
163 1.1 cgd
164 1.1 cgd # ifdef SYSV
165 1.1 cgd # define srandom(x) srand(x)
166 1.1 cgd # define random() rand()
167 1.6 jtc # endif /* SYSV */
168 1.1 cgd
169 1.1 cgd typedef struct {
170 1.1 cgd bool coups[NUM_SAFE];
171 1.1 cgd bool can_go;
172 1.1 cgd bool new_battle;
173 1.1 cgd bool new_speed;
174 1.1 cgd short safety[NUM_SAFE];
175 1.1 cgd short sh_safety[NUM_SAFE];
176 1.1 cgd short nummiles[NUM_MILES];
177 1.1 cgd short sh_nummiles[NUM_MILES];
178 1.1 cgd CARD hand[HAND_SZ];
179 1.1 cgd CARD sh_hand[HAND_SZ];
180 1.1 cgd CARD battle;
181 1.1 cgd CARD sh_battle;
182 1.1 cgd CARD speed;
183 1.1 cgd CARD sh_speed;
184 1.1 cgd int mileage;
185 1.1 cgd int sh_mileage;
186 1.1 cgd int hand_tot;
187 1.1 cgd int sh_hand_tot;
188 1.1 cgd int safescore;
189 1.1 cgd int sh_safescore;
190 1.1 cgd int coupscore;
191 1.1 cgd int total;
192 1.1 cgd int sh_total;
193 1.1 cgd int games;
194 1.1 cgd int sh_games;
195 1.1 cgd int was_finished;
196 1.1 cgd } PLAY;
197 1.1 cgd
198 1.1 cgd /*
199 1.1 cgd * macros
200 1.1 cgd */
201 1.1 cgd
202 1.1 cgd # define other(x) (1 - x)
203 1.1 cgd # define nextplay() (Play = other(Play))
204 1.1 cgd # define nextwin(x) (1 - x)
205 1.1 cgd # define opposite(x) (Opposite[x])
206 1.11 jsm # define is_safety(x) (x >= C_GAS_SAFE)
207 1.1 cgd
208 1.1 cgd /*
209 1.1 cgd * externals
210 1.1 cgd */
211 1.1 cgd
212 1.1 cgd extern bool Debug, Finished, Next, On_exit, Order, Saved;
213 1.1 cgd
214 1.14 dholland #define INITSTR_SIZE 100
215 1.14 dholland extern char Initstr[INITSTR_SIZE];
216 1.10 jsm extern const char *C_fmt, *const *C_name, *Fromfile;
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_go(void);
240 1.13 jsm void check_more(void);
241 1.13 jsm void die(int) __attribute__((__noreturn__));
242 1.13 jsm void domove(void);
243 1.13 jsm bool error(const char *, ...);
244 1.13 jsm void extrapolate(PLAY *);
245 1.13 jsm void finalscore(PLAY *);
246 1.13 jsm CARD getcard(void);
247 1.13 jsm void getmove(void);
248 1.13 jsm int getyn(int);
249 1.13 jsm int haspicked(const PLAY *);
250 1.13 jsm void init(void);
251 1.13 jsm int is_repair(CARD);
252 1.13 jsm int main(int, char **);
253 1.13 jsm void newboard(void);
254 1.13 jsm void newscore(void);
255 1.13 jsm int onecard(const PLAY *);
256 1.13 jsm int playcard(PLAY *);
257 1.13 jsm void prboard(void);
258 1.13 jsm void prompt(int);
259 1.13 jsm void prscore(bool);
260 1.13 jsm int readch(void);
261 1.13 jsm bool rest_f(const char *);
262 1.13 jsm int roll(int, int);
263 1.13 jsm void rub(int);
264 1.13 jsm int safety(CARD);
265 1.13 jsm bool save(void);
266 1.13 jsm void show_card(int, int, CARD, CARD *);
267 1.13 jsm void show_score(int, int, int, int *);
268 1.13 jsm void shuffle(void);
269 1.13 jsm void sort(CARD *);
270 1.13 jsm void undoex(int);
271 1.13 jsm bool varpush(int, ssize_t (int, const struct iovec *, int));
272