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