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