1 /*
2 * Copyright (c) 1982, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 05/31/93";
10 #endif /* not lint */
11
12 # include "mille.h"
13
14 /*
15 * @(#)init.c 1.1 (Berkeley) 4/1/82
16 */
17
init()18 init() {
19
20 reg PLAY *pp;
21 reg int i, j;
22 reg CARD card;
23
24 bzero(Numseen, sizeof Numseen);
25 Numgos = 0;
26
27 for (i = 0; i < 2; i++) {
28 pp = &Player[i];
29 pp->hand[0] = C_INIT;
30 for (j = 0; j < NUM_SAFE; j++) {
31 pp->safety[j] = S_UNKNOWN;
32 pp->coups[j] = FALSE;
33 }
34 for (j = 1; j < HAND_SZ; j++) {
35 pp->hand[j] = *--Topcard;
36 if (i == COMP) {
37 account(card = *Topcard);
38 if (issafety(card))
39 pp->safety[card - S_CONV] = S_IN_HAND;
40 }
41 }
42 pp->mileage = 0;
43 pp->hand_tot = 0;
44 pp->safescore = 0;
45 pp->coupscore = 0;
46 pp->can_go = FALSE;
47 pp->speed = C_INIT;
48 pp->battle = C_INIT;
49 pp->new_speed = FALSE;
50 pp->new_battle = FALSE;
51 for (j = 0; j < NUM_MILES; j++)
52 pp->nummiles[j] = 0;
53 }
54 if (Order)
55 sort(Player[PLAYER].hand);
56 Discard = C_INIT;
57 Finished = FALSE;
58 End = 700;
59 }
60
shuffle()61 shuffle() {
62
63 reg int i, r;
64 reg CARD temp;
65
66 for (i = 0; i < DECK_SZ; i++) {
67 r = roll(1, DECK_SZ) - 1;
68 if (r < 0 || r > DECK_SZ - 1) {
69 fprintf(stderr, "shuffle: card no. error: %d\n", r);
70 die(1);
71 }
72 temp = Deck[r];
73 Deck[r] = Deck[i];
74 Deck[i] = temp;
75 }
76 Topcard = &Deck[DECK_SZ];
77 }
78
newboard()79 newboard() {
80
81 register int i;
82 register PLAY *pp;
83 static int first = TRUE;
84
85 if (first) {
86 werase(Board);
87 werase(Score);
88 mvaddstr(5, 0, "--HAND--");
89 mvaddch(6, 0, 'P');
90 mvaddch(7, 0, '1');
91 mvaddch(8, 0, '2');
92 mvaddch(9, 0, '3');
93 mvaddch(10, 0, '4');
94 mvaddch(11, 0, '5');
95 mvaddch(12, 0, '6');
96 mvaddstr(13, 0, "--BATTLE--");
97 mvaddstr(15, 0, "--SPEED--");
98 mvaddstr(5, 20, "--DECK--");
99 mvaddstr(7, 20, "--DISCARD--");
100 mvaddstr(13, 20, "--BATTLE--");
101 mvaddstr(15, 20, "--SPEED--");
102 mvwaddstr(Miles, 0, 0, "--MILEAGE--");
103 mvwaddstr(Miles, 0, 41, "--MILEAGE--");
104 Sh_discard = -1;
105 for (pp = Player; pp <= &Player[COMP]; pp++) {
106 for (i = 0; i < HAND_SZ; i++)
107 pp->sh_hand[i] = -1;
108 pp->sh_battle = -1;
109 pp->sh_speed = -1;
110 pp->sh_mileage = -1;
111 }
112 first = FALSE;
113 }
114 else {
115 for (i = 0; i < 5; i++) {
116 move(i, 0);
117 clrtoeol();
118 }
119 wmove(Miles, 1, 0);
120 wclrtobot(Miles);
121 wmove(Board, MOVE_Y + 1, MOVE_X);
122 wclrtoeol(Board);
123 wmove(Board, MOVE_Y + 2, MOVE_X);
124 wclrtoeol(Board);
125 }
126 Sh_discard = -1;
127 for (pp = Player; pp <= &Player[COMP]; pp++) {
128 for (i = 0; i < NUM_SAFE; i++)
129 pp->sh_safety[i] = FALSE;
130 for (i = 0; i < NUM_MILES; i++)
131 pp->sh_nummiles[i] = 0;
132 pp->sh_safescore = -1;
133 }
134 newscore();
135 }
136
newscore()137 newscore() {
138
139 reg int i, new;
140 register PLAY *pp;
141 static int was_full = -1;
142 static int last_win = -1;
143
144 if (was_full < 0)
145 was_full = (Window != W_FULL);
146 stdscr = Score;
147 move(0, 22);
148 new = FALSE;
149 if (inch() != 'Y') {
150 erase();
151 mvaddstr(0, 22, "You Comp Value");
152 mvaddstr(1, 2, "Milestones Played");
153 mvaddstr(2, 8, "Each Safety");
154 mvaddstr(3, 5, "All 4 Safeties");
155 mvaddstr(4, 3, "Each Coup Fourre");
156 mvaddstr(2, 37, "100");
157 mvaddstr(3, 37, "300");
158 mvaddstr(4, 37, "300");
159 new = TRUE;
160 }
161 else if ((Window == W_FULL || Finished) ^ was_full) {
162 move(5, 1);
163 clrtobot();
164 new = TRUE;
165 }
166 else if (Window != last_win)
167 new = TRUE;
168 if (new) {
169 for (i = 0; i < SCORE_Y; i++)
170 mvaddch(i, 0, '|');
171 move(SCORE_Y - 1, 1);
172 for (i = 0; i < SCORE_X; i++)
173 addch('_');
174 for (pp = Player; pp <= &Player[COMP]; pp++) {
175 pp->sh_hand_tot = -1;
176 pp->sh_total = -1;
177 pp->sh_games = -1;
178 pp->sh_safescore = -1;
179 }
180 }
181 Player[PLAYER].was_finished = !Finished;
182 Player[COMP].was_finished = !Finished;
183 if (Window == W_FULL || Finished) {
184 if (!was_full || new) {
185 mvaddstr(5, 5, "Trip Completed");
186 mvaddstr(6, 10, "Safe Trip");
187 mvaddstr(7, 5, "Delayed Action");
188 mvaddstr(8, 10, "Extension");
189 mvaddstr(9, 11, "Shut-Out");
190 mvaddstr(10, 21, "---- ---- -----");
191 mvaddstr(11, 9, "Hand Total");
192 mvaddstr(12, 20, "----- -----");
193 mvaddstr(13, 6, "Overall Total");
194 mvaddstr(14, 15, "Games");
195 mvaddstr(5, 37, "400");
196 mvaddstr(6, 37, "300");
197 mvaddstr(7, 37, "300");
198 mvaddstr(8, 37, "200");
199 mvaddstr(9, 37, "500");
200 }
201 }
202 else
203 if (was_full || new) {
204 mvaddstr(5, 21, "---- ---- -----");
205 mvaddstr(6, 9, "Hand Total");
206 mvaddstr(7, 20, "----- -----");
207 mvaddstr(8, 6, "Overall Total");
208 mvaddstr(9, 15, "Games");
209 mvaddstr(11, 2, "p: pick");
210 mvaddstr(12, 2, "u: use #");
211 mvaddstr(13, 2, "d: discard #");
212 mvaddstr(14, 2, "w: toggle window");
213 mvaddstr(11, 21, "q: quit");
214 if (!Order)
215 mvaddstr(12, 21, "o: order hand");
216 else
217 mvaddstr(12, 21, "o: stop ordering");
218 mvaddstr(13, 21, "s: save");
219 mvaddstr(14, 21, "r: reprint");
220 }
221 stdscr = Board;
222 was_full = (Window == W_FULL || Finished);
223 last_win = Window;
224 }
225