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