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