mille.h revision 1.12
1/* $NetBSD: mille.h,v 1.12 2003/08/07 09:37:25 agc 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. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * @(#)mille.h 8.1 (Berkeley) 5/31/93 32 */ 33 34# include <sys/types.h> 35# include <sys/uio.h> 36# include <sys/stat.h> 37# include <ctype.h> 38# include <err.h> 39# include <errno.h> 40# include <curses.h> 41# include <fcntl.h> 42# include <stdlib.h> 43# include <string.h> 44# include <termios.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# undef S_UNKNOWN 109# undef S_IN_HAND 110# undef S_PLAYED 111# undef S_GAS_SAFE 112# undef S_SPARE_SAFE 113# undef S_DRIVE_SAFE 114# undef S_RIGHT_WAY 115# undef S_CONV 116# define S_UNKNOWN 0 /* location of safety unknown */ 117# define S_IN_HAND 1 /* safety in player's hand */ 118# define S_PLAYED 2 /* safety has been played */ 119# define S_GAS_SAFE 0 /* Gas safety card index */ 120# define S_SPARE_SAFE 1 /* Tire safety card index */ 121# define S_DRIVE_SAFE 2 /* Driveing safety card index */ 122# define S_RIGHT_WAY 3 /* Right-of-Way card index */ 123# define S_CONV 15 /* conversion from C_ to S_ */ 124 125/* 126 * card numbers 127 */ 128 129# define C_INIT -1 130# define C_25 0 131# define C_50 1 132# define C_75 2 133# define C_100 3 134# define C_200 4 135# define C_EMPTY 5 136# define C_FLAT 6 137# define C_CRASH 7 138# define C_STOP 8 139# define C_LIMIT 9 140# define C_GAS 10 141# define C_SPARE 11 142# define C_REPAIRS 12 143# define C_GO 13 144# define C_END_LIMIT 14 145# define C_GAS_SAFE 15 146# define C_SPARE_SAFE 16 147# define C_DRIVE_SAFE 17 148# define C_RIGHT_WAY 18 149 150/* 151 * prompt types 152 */ 153 154# define MOVEPROMPT 0 155# define REALLYPROMPT 1 156# define ANOTHERHANDPROMPT 2 157# define ANOTHERGAMEPROMPT 3 158# define SAVEGAMEPROMPT 4 159# define SAMEFILEPROMPT 5 160# define FILEPROMPT 6 161# define EXTENSIONPROMPT 7 162# define OVERWRITEFILEPROMPT 8 163 164# ifdef SYSV 165# define srandom(x) srand(x) 166# define random() rand() 167# endif /* SYSV */ 168 169typedef struct { 170 bool coups[NUM_SAFE]; 171 bool can_go; 172 bool new_battle; 173 bool new_speed; 174 short safety[NUM_SAFE]; 175 short sh_safety[NUM_SAFE]; 176 short nummiles[NUM_MILES]; 177 short sh_nummiles[NUM_MILES]; 178 CARD hand[HAND_SZ]; 179 CARD sh_hand[HAND_SZ]; 180 CARD battle; 181 CARD sh_battle; 182 CARD speed; 183 CARD sh_speed; 184 int mileage; 185 int sh_mileage; 186 int hand_tot; 187 int sh_hand_tot; 188 int safescore; 189 int sh_safescore; 190 int coupscore; 191 int total; 192 int sh_total; 193 int games; 194 int sh_games; 195 int was_finished; 196} PLAY; 197 198/* 199 * macros 200 */ 201 202# define other(x) (1 - x) 203# define nextplay() (Play = other(Play)) 204# define nextwin(x) (1 - x) 205# define opposite(x) (Opposite[x]) 206# define is_safety(x) (x >= C_GAS_SAFE) 207 208/* 209 * externals 210 */ 211 212extern bool Debug, Finished, Next, On_exit, Order, Saved; 213 214extern char Initstr[]; 215extern const char *C_fmt, *const *C_name, *Fromfile; 216 217extern int Card_no, End, Handstart, Movetype, Numgos, 218 Numneed[], Numseen[NUM_CARDS], Play, Window; 219extern const int Numcards[], Value[]; 220 221extern CARD Deck[DECK_SZ], Discard, Sh_discard, *Topcard; 222extern const CARD Opposite[NUM_CARDS]; 223 224extern FILE *outf; 225 226extern PLAY Player[2]; 227 228extern WINDOW *Board, *Miles, *Score; 229 230/* 231 * functions 232 */ 233 234void account __P((CARD)); 235void calcmove __P((void)); 236int canplay __P((const PLAY *, const PLAY *, CARD)); 237int check_ext __P((bool)); 238void check_go __P((void)); 239void check_more __P((void)); 240void die __P((int)) __attribute__((__noreturn__)); 241void domove __P((void)); 242bool error __P((const char *, ...)); 243void extrapolate __P((PLAY *)); 244void finalscore __P((PLAY *)); 245CARD getcard __P((void)); 246void getmove __P((void)); 247int getyn __P((int)); 248int haspicked __P((const PLAY *)); 249void init __P((void)); 250int is_repair __P((CARD)); 251int main __P((int, char **)); 252void newboard __P((void)); 253void newscore __P((void)); 254int onecard __P((const PLAY *)); 255int playcard __P((PLAY *)); 256void prboard __P((void)); 257void prompt __P((int)); 258void prscore __P((bool)); 259int readch __P((void)); 260bool rest_f __P((const char *)); 261int roll __P((int, int)); 262void rub __P((int)); 263int safety __P((CARD)); 264bool save __P((void)); 265void show_card __P((int, int, CARD, CARD *)); 266void show_score __P((int, int, int, int *)); 267void shuffle __P((void)); 268void sort __P((CARD *)); 269void undoex __P((int)); 270bool varpush __P((int, ssize_t __P((int, const struct iovec *, int)))); 271