xref: /csrg-svn/games/mille/init.c (revision 60812)
130201Sbostic /*
2*60812Sbostic  * Copyright (c) 1982, 1993
3*60812Sbostic  *	The Regents of the University of California.  All rights reserved.
433172Sbostic  *
542578Sbostic  * %sccs.include.redist.c%
630201Sbostic  */
730201Sbostic 
830201Sbostic #ifndef lint
9*60812Sbostic static char sccsid[] = "@(#)init.c	8.1 (Berkeley) 05/31/93";
1033172Sbostic #endif /* not lint */
1130201Sbostic 
1230201Sbostic # include	"mille.h"
1330201Sbostic 
1430201Sbostic /*
1530201Sbostic  * @(#)init.c	1.1 (Berkeley) 4/1/82
1630201Sbostic  */
1730201Sbostic 
init()1830201Sbostic init() {
1930201Sbostic 
2030201Sbostic 	reg PLAY	*pp;
2130201Sbostic 	reg int		i, j;
2230201Sbostic 	reg CARD	card;
2330201Sbostic 
2430201Sbostic 	bzero(Numseen, sizeof Numseen);
2530201Sbostic 	Numgos = 0;
2630201Sbostic 
2730201Sbostic 	for (i = 0; i < 2; i++) {
2830201Sbostic 		pp = &Player[i];
2930201Sbostic 		pp->hand[0] = C_INIT;
3030201Sbostic 		for (j = 0; j < NUM_SAFE; j++) {
3130201Sbostic 			pp->safety[j] = S_UNKNOWN;
3230201Sbostic 			pp->coups[j] = FALSE;
3330201Sbostic 		}
3430201Sbostic 		for (j = 1; j < HAND_SZ; j++) {
3530201Sbostic 			pp->hand[j] = *--Topcard;
3630201Sbostic 			if (i == COMP) {
3730201Sbostic 				account(card = *Topcard);
3830201Sbostic 				if (issafety(card))
3930201Sbostic 					pp->safety[card - S_CONV] = S_IN_HAND;
4030201Sbostic 			}
4130201Sbostic 		}
4230201Sbostic 		pp->mileage = 0;
4330201Sbostic 		pp->hand_tot = 0;
4430201Sbostic 		pp->safescore = 0;
4530201Sbostic 		pp->coupscore = 0;
4630201Sbostic 		pp->can_go = FALSE;
4730201Sbostic 		pp->speed = C_INIT;
4830201Sbostic 		pp->battle = C_INIT;
4930201Sbostic 		pp->new_speed = FALSE;
5030201Sbostic 		pp->new_battle = FALSE;
5130201Sbostic 		for (j = 0; j < NUM_MILES; j++)
5230201Sbostic 			pp->nummiles[j] = 0;
5330201Sbostic 	}
5430201Sbostic 	if (Order)
5530201Sbostic 		sort(Player[PLAYER].hand);
5630201Sbostic 	Discard = C_INIT;
5730201Sbostic 	Finished = FALSE;
5830201Sbostic 	End = 700;
5930201Sbostic }
6030201Sbostic 
shuffle()6130201Sbostic shuffle() {
6230201Sbostic 
6330201Sbostic 	reg int		i, r;
6430201Sbostic 	reg CARD	temp;
6530201Sbostic 
6630201Sbostic 	for (i = 0; i < DECK_SZ; i++) {
6730201Sbostic 		r = roll(1, DECK_SZ) - 1;
6830201Sbostic 		if (r < 0 || r > DECK_SZ - 1) {
6930201Sbostic 			fprintf(stderr, "shuffle: card no. error: %d\n", r);
7052873Storek 			die(1);
7130201Sbostic 		}
7230201Sbostic 		temp = Deck[r];
7330201Sbostic 		Deck[r] = Deck[i];
7430201Sbostic 		Deck[i] = temp;
7530201Sbostic 	}
7630201Sbostic 	Topcard = &Deck[DECK_SZ];
7730201Sbostic }
7830201Sbostic 
newboard()7930201Sbostic newboard() {
8030201Sbostic 
8130201Sbostic 	register int	i;
8230201Sbostic 	register PLAY	*pp;
8330201Sbostic 	static int	first = TRUE;
8430201Sbostic 
8530201Sbostic 	if (first) {
8630201Sbostic 		werase(Board);
8730201Sbostic 		werase(Score);
8830201Sbostic 		mvaddstr(5, 0, "--HAND--");
8930201Sbostic 		mvaddch(6, 0, 'P');
9030201Sbostic 		mvaddch(7, 0, '1');
9130201Sbostic 		mvaddch(8, 0, '2');
9230201Sbostic 		mvaddch(9, 0, '3');
9330201Sbostic 		mvaddch(10, 0, '4');
9430201Sbostic 		mvaddch(11, 0, '5');
9530201Sbostic 		mvaddch(12, 0, '6');
9630201Sbostic 		mvaddstr(13, 0, "--BATTLE--");
9730201Sbostic 		mvaddstr(15, 0, "--SPEED--");
9830201Sbostic 		mvaddstr(5, 20, "--DECK--");
9930201Sbostic 		mvaddstr(7, 20, "--DISCARD--");
10030201Sbostic 		mvaddstr(13, 20, "--BATTLE--");
10130201Sbostic 		mvaddstr(15, 20, "--SPEED--");
10230201Sbostic 		mvwaddstr(Miles, 0, 0, "--MILEAGE--");
10330201Sbostic 		mvwaddstr(Miles, 0, 41, "--MILEAGE--");
10430201Sbostic 		Sh_discard = -1;
10530201Sbostic 		for (pp = Player; pp <= &Player[COMP]; pp++) {
10630201Sbostic 			for (i = 0; i < HAND_SZ; i++)
10730201Sbostic 				pp->sh_hand[i] = -1;
10830201Sbostic 			pp->sh_battle = -1;
10930201Sbostic 			pp->sh_speed = -1;
11030201Sbostic 			pp->sh_mileage = -1;
11130201Sbostic 		}
11230201Sbostic 		first = FALSE;
11330201Sbostic 	}
11430201Sbostic 	else {
11530201Sbostic 		for (i = 0; i < 5; i++) {
11630201Sbostic 			move(i, 0);
11730201Sbostic 			clrtoeol();
11830201Sbostic 		}
11930201Sbostic 		wmove(Miles, 1, 0);
12030201Sbostic 		wclrtobot(Miles);
12130201Sbostic 		wmove(Board, MOVE_Y + 1, MOVE_X);
12230201Sbostic 		wclrtoeol(Board);
12330201Sbostic 		wmove(Board, MOVE_Y + 2, MOVE_X);
12430201Sbostic 		wclrtoeol(Board);
12530201Sbostic 	}
12630201Sbostic 	Sh_discard = -1;
12730201Sbostic 	for (pp = Player; pp <= &Player[COMP]; pp++) {
12830201Sbostic 		for (i = 0; i < NUM_SAFE; i++)
12930201Sbostic 			pp->sh_safety[i] = FALSE;
13030201Sbostic 		for (i = 0; i < NUM_MILES; i++)
13130201Sbostic 			pp->sh_nummiles[i] = 0;
13230201Sbostic 		pp->sh_safescore = -1;
13330201Sbostic 	}
13430201Sbostic 	newscore();
13530201Sbostic }
13630201Sbostic 
newscore()13730201Sbostic newscore() {
13830201Sbostic 
13930201Sbostic 	reg int		i, new;
14030201Sbostic 	register PLAY	*pp;
14130201Sbostic 	static int	was_full = -1;
14230201Sbostic 	static int	last_win = -1;
14330201Sbostic 
14430201Sbostic 	if (was_full < 0)
14530201Sbostic 		was_full = (Window != W_FULL);
14630201Sbostic 	stdscr = Score;
14730201Sbostic 	move(0, 22);
14830201Sbostic 	new = FALSE;
14930201Sbostic 	if (inch() != 'Y') {
15030201Sbostic 		erase();
15130201Sbostic 		mvaddstr(0, 22,  "You   Comp   Value");
15230201Sbostic 		mvaddstr(1, 2, "Milestones Played");
15330201Sbostic 		mvaddstr(2, 8, "Each Safety");
15430201Sbostic 		mvaddstr(3, 5, "All 4 Safeties");
15530201Sbostic 		mvaddstr(4, 3, "Each Coup Fourre");
15630201Sbostic 		mvaddstr(2, 37, "100");
15730201Sbostic 		mvaddstr(3, 37, "300");
15830201Sbostic 		mvaddstr(4, 37, "300");
15930201Sbostic 		new = TRUE;
16030201Sbostic 	}
16152873Storek 	else if ((Window == W_FULL || Finished) ^ was_full) {
16230201Sbostic 		move(5, 1);
16330201Sbostic 		clrtobot();
16430201Sbostic 		new = TRUE;
16530201Sbostic 	}
16630201Sbostic 	else if (Window != last_win)
16730201Sbostic 		new = TRUE;
16830201Sbostic 	if (new) {
16930201Sbostic 		for (i = 0; i < SCORE_Y; i++)
17030201Sbostic 			mvaddch(i, 0, '|');
17130201Sbostic 		move(SCORE_Y - 1, 1);
17256724Selan 		for (i = 0; i < SCORE_X; i++)
17356724Selan 			addch('_');
17430201Sbostic 		for (pp = Player; pp <= &Player[COMP]; pp++) {
17530201Sbostic 			pp->sh_hand_tot = -1;
17630201Sbostic 			pp->sh_total = -1;
17730201Sbostic 			pp->sh_games = -1;
17830201Sbostic 			pp->sh_safescore = -1;
17930201Sbostic 		}
18030201Sbostic 	}
18130201Sbostic 	Player[PLAYER].was_finished = !Finished;
18230201Sbostic 	Player[COMP].was_finished = !Finished;
18330201Sbostic 	if (Window == W_FULL || Finished) {
18430201Sbostic 		if (!was_full || new) {
18530201Sbostic 			mvaddstr(5, 5, "Trip Completed");
18630201Sbostic 			mvaddstr(6, 10, "Safe Trip");
18730201Sbostic 			mvaddstr(7, 5, "Delayed Action");
18830201Sbostic 			mvaddstr(8, 10, "Extension");
18930201Sbostic 			mvaddstr(9, 11, "Shut-Out");
19030201Sbostic 			mvaddstr(10, 21, "----   ----   -----");
19130201Sbostic 			mvaddstr(11, 9, "Hand Total");
19230201Sbostic 			mvaddstr(12, 20, "-----  -----");
19330201Sbostic 			mvaddstr(13, 6, "Overall Total");
19430201Sbostic 			mvaddstr(14, 15, "Games");
19530201Sbostic 			mvaddstr(5, 37, "400");
19630201Sbostic 			mvaddstr(6, 37, "300");
19730201Sbostic 			mvaddstr(7, 37, "300");
19830201Sbostic 			mvaddstr(8, 37, "200");
19930201Sbostic 			mvaddstr(9, 37, "500");
20030201Sbostic 		}
20130201Sbostic 	}
20230201Sbostic 	else
20330201Sbostic 		if (was_full || new) {
20430201Sbostic 			mvaddstr(5, 21, "----   ----   -----");
20530201Sbostic 			mvaddstr(6, 9, "Hand Total");
20630201Sbostic 			mvaddstr(7, 20, "-----  -----");
20730201Sbostic 			mvaddstr(8, 6, "Overall Total");
20830201Sbostic 			mvaddstr(9, 15, "Games");
20930201Sbostic 			mvaddstr(11, 2, "p: pick");
21030201Sbostic 			mvaddstr(12, 2, "u: use #");
21130201Sbostic 			mvaddstr(13, 2, "d: discard #");
21230201Sbostic 			mvaddstr(14, 2, "w: toggle window");
21330201Sbostic 			mvaddstr(11, 21, "q: quit");
21430201Sbostic 			if (!Order)
21530201Sbostic 				mvaddstr(12, 21, "o: order hand");
21630201Sbostic 			else
21730201Sbostic 				mvaddstr(12, 21, "o: stop ordering");
21830201Sbostic 			mvaddstr(13, 21, "s: save");
21930201Sbostic 			mvaddstr(14, 21, "r: reprint");
22030201Sbostic 		}
22130201Sbostic 	stdscr = Board;
22230201Sbostic 	was_full = (Window == W_FULL || Finished);
22330201Sbostic 	last_win = Window;
22430201Sbostic }
225