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