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