]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - mille/init.c
Fix uses of namespaces reserved by ISO C or POSIX.1.
[bsdgames-darwin.git] / mille / init.c
1 /* $NetBSD: init.c,v 1.8 1999/09/30 18:01:32 jsm 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: init.c,v 1.8 1999/09/30 18:01:32 jsm Exp $");
42 #endif
43 #endif /* not lint */
44
45 # include "mille.h"
46
47 /*
48 * @(#)init.c 1.1 (Berkeley) 4/1/82
49 */
50
51 void
52 init()
53 {
54 PLAY *pp;
55 int i, j;
56 CARD card;
57
58 memset(Numseen, 0, sizeof Numseen);
59 Numgos = 0;
60
61 for (i = 0; i < 2; i++) {
62 pp = &Player[i];
63 pp->hand[0] = C_INIT;
64 for (j = 0; j < NUM_SAFE; j++) {
65 pp->safety[j] = S_UNKNOWN;
66 pp->coups[j] = FALSE;
67 }
68 for (j = 1; j < HAND_SZ; j++) {
69 pp->hand[j] = *--Topcard;
70 if (i == COMP) {
71 account(card = *Topcard);
72 if (is_safety(card))
73 pp->safety[card - S_CONV] = S_IN_HAND;
74 }
75 }
76 pp->mileage = 0;
77 pp->hand_tot = 0;
78 pp->safescore = 0;
79 pp->coupscore = 0;
80 pp->can_go = FALSE;
81 pp->speed = C_INIT;
82 pp->battle = C_INIT;
83 pp->new_speed = FALSE;
84 pp->new_battle = FALSE;
85 for (j = 0; j < NUM_MILES; j++)
86 pp->nummiles[j] = 0;
87 }
88 if (Order)
89 sort(Player[PLAYER].hand);
90 Discard = C_INIT;
91 Finished = FALSE;
92 End = 700;
93 }
94
95 void
96 shuffle()
97 {
98 int i, r;
99 CARD temp;
100
101 for (i = 0; i < DECK_SZ; i++) {
102 r = roll(1, DECK_SZ) - 1;
103 if (r < 0 || r > DECK_SZ - 1) {
104 warnx("shuffle: card no. error: %d", r);
105 die(1);
106 }
107 temp = Deck[r];
108 Deck[r] = Deck[i];
109 Deck[i] = temp;
110 }
111 Topcard = &Deck[DECK_SZ];
112 }
113
114 void
115 newboard()
116 {
117 int i;
118 PLAY *pp;
119 static int first = TRUE;
120
121 if (first) {
122 werase(Board);
123 werase(Score);
124 mvaddstr(5, 0, "--HAND--");
125 mvaddch(6, 0, 'P');
126 mvaddch(7, 0, '1');
127 mvaddch(8, 0, '2');
128 mvaddch(9, 0, '3');
129 mvaddch(10, 0, '4');
130 mvaddch(11, 0, '5');
131 mvaddch(12, 0, '6');
132 mvaddstr(13, 0, "--BATTLE--");
133 mvaddstr(15, 0, "--SPEED--");
134 mvaddstr(5, 20, "--DECK--");
135 mvaddstr(7, 20, "--DISCARD--");
136 mvaddstr(13, 20, "--BATTLE--");
137 mvaddstr(15, 20, "--SPEED--");
138 mvwaddstr(Miles, 0, 0, "--MILEAGE--");
139 mvwaddstr(Miles, 0, 41, "--MILEAGE--");
140 Sh_discard = -1;
141 for (pp = Player; pp <= &Player[COMP]; pp++) {
142 for (i = 0; i < HAND_SZ; i++)
143 pp->sh_hand[i] = -1;
144 pp->sh_battle = -1;
145 pp->sh_speed = -1;
146 pp->sh_mileage = -1;
147 }
148 first = FALSE;
149 }
150 else {
151 for (i = 0; i < 5; i++) {
152 move(i, 0);
153 clrtoeol();
154 }
155 wmove(Miles, 1, 0);
156 wclrtobot(Miles);
157 wmove(Board, MOVE_Y + 1, MOVE_X);
158 wclrtoeol(Board);
159 wmove(Board, MOVE_Y + 2, MOVE_X);
160 wclrtoeol(Board);
161 }
162 Sh_discard = -1;
163 for (pp = Player; pp <= &Player[COMP]; pp++) {
164 for (i = 0; i < NUM_SAFE; i++)
165 pp->sh_safety[i] = FALSE;
166 for (i = 0; i < NUM_MILES; i++)
167 pp->sh_nummiles[i] = 0;
168 pp->sh_safescore = -1;
169 }
170 newscore();
171 }
172
173 void
174 newscore()
175 {
176 int i, new;
177 PLAY *pp;
178 static int was_full = -1;
179 static int last_win = -1;
180
181 if (was_full < 0)
182 was_full = (Window != W_FULL);
183 stdscr = Score;
184 move(0, 22);
185 new = FALSE;
186 if (inch() != 'Y') {
187 erase();
188 mvaddstr(0, 22, "You Comp Value");
189 mvaddstr(1, 2, "Milestones Played");
190 mvaddstr(2, 8, "Each Safety");
191 mvaddstr(3, 5, "All 4 Safeties");
192 mvaddstr(4, 3, "Each Coup Fourre");
193 mvaddstr(2, 37, "100");
194 mvaddstr(3, 37, "300");
195 mvaddstr(4, 37, "300");
196 new = TRUE;
197 }
198 else if ((Window == W_FULL || Finished) ^ was_full) {
199 move(5, 1);
200 clrtobot();
201 new = TRUE;
202 }
203 else if (Window != last_win)
204 new = TRUE;
205 if (new) {
206 for (i = 0; i < SCORE_Y; i++)
207 mvaddch(i, 0, '|');
208 move(SCORE_Y - 1, 1);
209 for (i = 0; i < SCORE_X; i++)
210 addch('_');
211 for (pp = Player; pp <= &Player[COMP]; pp++) {
212 pp->sh_hand_tot = -1;
213 pp->sh_total = -1;
214 pp->sh_games = -1;
215 pp->sh_safescore = -1;
216 }
217 }
218 Player[PLAYER].was_finished = !Finished;
219 Player[COMP].was_finished = !Finished;
220 if (Window == W_FULL || Finished) {
221 if (!was_full || new) {
222 mvaddstr(5, 5, "Trip Completed");
223 mvaddstr(6, 10, "Safe Trip");
224 mvaddstr(7, 5, "Delayed Action");
225 mvaddstr(8, 10, "Extension");
226 mvaddstr(9, 11, "Shut-Out");
227 mvaddstr(10, 21, "---- ---- -----");
228 mvaddstr(11, 9, "Hand Total");
229 mvaddstr(12, 20, "----- -----");
230 mvaddstr(13, 6, "Overall Total");
231 mvaddstr(14, 15, "Games");
232 mvaddstr(5, 37, "400");
233 mvaddstr(6, 37, "300");
234 mvaddstr(7, 37, "300");
235 mvaddstr(8, 37, "200");
236 mvaddstr(9, 37, "500");
237 }
238 }
239 else
240 if (was_full || new) {
241 mvaddstr(5, 21, "---- ---- -----");
242 mvaddstr(6, 9, "Hand Total");
243 mvaddstr(7, 20, "----- -----");
244 mvaddstr(8, 6, "Overall Total");
245 mvaddstr(9, 15, "Games");
246 mvaddstr(11, 2, "p: pick");
247 mvaddstr(12, 2, "u: use #");
248 mvaddstr(13, 2, "d: discard #");
249 mvaddstr(14, 2, "w: toggle window");
250 mvaddstr(11, 21, "q: quit");
251 if (!Order)
252 mvaddstr(12, 21, "o: order hand");
253 else
254 mvaddstr(12, 21, "o: stop ordering");
255 mvaddstr(13, 21, "s: save");
256 mvaddstr(14, 21, "r: reprint");
257 }
258 stdscr = Board;
259 was_full = (Window == W_FULL || Finished);
260 last_win = Window;
261 }