Initial import from FreeBSD RELENG_4:
[dragonfly.git] / games / mille / mille.h
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  */
37
38 # include       <sys/types.h>
39 # include       <sys/uio.h>
40 # include       <ctype.h>
41 # include       <curses.h>
42 # include       <string.h>
43 # include       <stdlib.h>
44 # include       <unistd.h>
45
46 /*
47  * @(#)mille.h  1.1 (Berkeley) 4/1/82
48  */
49
50 /*
51  * Miscellaneous constants
52  */
53
54 # define        unsgn           unsigned
55 # define        CARD            short
56
57 # define        HAND_SZ         7       /* number of cards in a hand    */
58 # define        DECK_SZ         101     /* number of cards in decks     */
59 # define        NUM_SAFE        4       /* number of saftey cards       */
60 # define        NUM_MILES       5       /* number of milestones types   */
61 # define        NUM_CARDS       20      /* number of types of cards     */
62 # define        BOARD_Y         17      /* size of board screen         */
63 # define        BOARD_X         40
64 # define        MILES_Y         7       /* size of mileage screen       */
65 # define        MILES_X         80
66 # define        SCORE_Y         17      /* size of score screen         */
67 # define        SCORE_X         40
68 # define        MOVE_Y          10      /* Where to print move prompt   */
69 # define        MOVE_X          20
70 # define        ERR_Y           15      /* Where to print errors        */
71 # define        ERR_X           5
72 # define        EXT_Y           4       /* Where to put Extension       */
73 # define        EXT_X           9
74
75 # define        PLAYER          0
76 # define        COMP            1
77
78 # define        W_SMALL         0       /* Small (initial) window       */
79 # define        W_FULL          1       /* Full (final) window          */
80
81 /*
82  * Move types
83  */
84
85 # define        M_DISCARD       0
86 # define        M_DRAW          1
87 # define        M_PLAY          2
88 # define        M_ORDER         3
89
90 /*
91  * Scores
92  */
93
94 # define        SC_SAFETY       100
95 # define        SC_ALL_SAFE     300
96 # define        SC_COUP         300
97 # define        SC_TRIP         400
98 # define        SC_SAFE         300
99 # define        SC_DELAY        300
100 # define        SC_EXTENSION    200
101 # define        SC_SHUT_OUT     500
102
103 /*
104  * safety descriptions
105  */
106
107 # define        S_UNKNOWN       0       /* location of safety unknown   */
108 # define        S_IN_HAND       1       /* safety in player's hand      */
109 # define        S_PLAYED        2       /* safety has been played       */
110 # define        S_GAS_SAFE      0       /* Gas safety card index        */
111 # define        S_SPARE_SAFE    1       /* Tire safety card index       */
112 # define        S_DRIVE_SAFE    2       /* Driveing safety card index   */
113 # define        S_RIGHT_WAY     3       /* Right-of-Way card index      */
114 # define        S_CONV          15      /* conversion from C_ to S_     */
115
116 /*
117  * card numbers
118  */
119
120 # define        C_INIT          -1
121 # define        C_25            0
122 # define        C_50            1
123 # define        C_75            2
124 # define        C_100           3
125 # define        C_200           4
126 # define        C_EMPTY         5
127 # define        C_FLAT          6
128 # define        C_CRASH         7
129 # define        C_STOP          8
130 # define        C_LIMIT         9
131 # define        C_GAS           10
132 # define        C_SPARE         11
133 # define        C_REPAIRS       12
134 # define        C_GO            13
135 # define        C_END_LIMIT     14
136 # define        C_GAS_SAFE      15
137 # define        C_SPARE_SAFE    16
138 # define        C_DRIVE_SAFE    17
139 # define        C_RIGHT_WAY     18
140
141 /*
142  * prompt types
143  */
144
145 # define        MOVEPROMPT              0
146 # define        REALLYPROMPT            1
147 # define        ANOTHERHANDPROMPT       2
148 # define        ANOTHERGAMEPROMPT       3
149 # define        SAVEGAMEPROMPT          4
150 # define        SAMEFILEPROMPT          5
151 # define        FILEPROMPT              6
152 # define        EXTENSIONPROMPT         7
153 # define        OVERWRITEFILEPROMPT     8
154
155 # ifdef SYSV
156 # define        srandom(x)      srand(x)
157 # define        random()        rand()
158 # endif
159
160 # if defined(SYSV) || defined(__FreeBSD__)
161 # ifndef        attron
162 #       define  erasechar()     _tty.c_cc[VERASE]
163 #       define  killchar()      _tty.c_cc[VKILL]
164 # endif
165 # else
166 # ifndef        erasechar
167 #       define  erasechar()     _tty.sg_erase
168 #       define  killchar()      _tty.sg_kill
169 # endif
170 # endif SYSV
171
172 typedef struct {
173         bool    coups[NUM_SAFE];
174         bool    can_go;
175         bool    new_battle;
176         bool    new_speed;
177         short   safety[NUM_SAFE];
178         short   sh_safety[NUM_SAFE];
179         short   nummiles[NUM_MILES];
180         short   sh_nummiles[NUM_MILES];
181         CARD    hand[HAND_SZ];
182         CARD    sh_hand[HAND_SZ];
183         CARD    battle;
184         CARD    sh_battle;
185         CARD    speed;
186         CARD    sh_speed;
187         int     mileage;
188         int     sh_mileage;
189         int     hand_tot;
190         int     sh_hand_tot;
191         int     safescore;
192         int     sh_safescore;
193         int     coupscore;
194         int     total;
195         int     sh_total;
196         int     games;
197         int     sh_games;
198         int     was_finished;
199 } PLAY;
200
201 /*
202  * macros
203  */
204
205 # define        other(x)        (1 - x)
206 # define        nextplay()      (Play = other(Play))
207 # define        nextwin(x)      (1 - x)
208 # define        opposite(x)     (Opposite[x])
209 # define        issafety(x)     (x >= C_GAS_SAFE)
210
211 /*
212  * externals
213  */
214
215 extern bool     Debug, Finished, Next, On_exit, Order, Saved;
216
217 extern char     *C_fmt, **C_name, *Fromfile, Initstr[];
218
219 extern int      Card_no, End, Handstart, Movetype, Numcards[], Numgos,
220                 Numneed[], Numseen[NUM_CARDS], Play, Value[], Window;
221
222 extern CARD     Deck[DECK_SZ], Discard, Opposite[NUM_CARDS], Sh_discard,
223                 *Topcard;
224
225 extern FILE     *outf;
226
227 extern PLAY     Player[2];
228
229 extern WINDOW   *Board, *Miles, *Score;
230
231 /*
232  * functions
233  */
234
235 void    account __P((CARD));
236 void    calcmove __P((void));
237 bool    canplay __P((PLAY *, PLAY *, CARD));
238 bool    check_ext __P((bool));
239 void    check_more __P((void));
240 void    die __P((int));
241 void    domove __P((void));
242 bool    error __P((char *, ...));
243 #ifdef EXTRAP
244 void    extrapolate __P((PLAY *));
245 #endif
246 void    finalscore __P((PLAY *));
247 CARD    getcard __P((void));
248 bool    getyn __P((int));
249 void    init __P((void));
250 int     isrepair __P((CARD));
251 void    newboard __P((void));
252 void    newscore __P((void));
253 bool    onecard __P((PLAY *));
254 void    prboard __P((void));
255 void    prompt __P((int));
256 void    prscore __P((bool));
257 char    readch __P((void));
258 bool    rest_f __P((char *));
259 int     roll __P((int, int));
260 void    rub __P((int));
261 CARD    safety __P((CARD));
262 bool    save __P((void));
263 void    shuffle __P((void));
264 void    sort __P((CARD *));
265 void    varpush __P((int, int (*)()));
266 #ifdef EXTRAP
267 void    undoex __P((void));
268 #endif