Home | History | Annotate | Line # | Download | only in mille
print.c revision 1.17
      1  1.17  christos /*	$NetBSD: print.c,v 1.17 2011/08/16 11:14:04 christos Exp $	*/
      2   1.4       cgd 
      3   1.1       cgd /*
      4   1.3       jtc  * Copyright (c) 1982, 1993
      5   1.3       jtc  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15  1.11       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1       cgd  *    may be used to endorse or promote products derived from this software
     17   1.1       cgd  *    without specific prior written permission.
     18   1.1       cgd  *
     19   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1       cgd  * SUCH DAMAGE.
     30   1.1       cgd  */
     31   1.1       cgd 
     32   1.6     lukem #include <sys/cdefs.h>
     33   1.1       cgd #ifndef lint
     34   1.4       cgd #if 0
     35   1.4       cgd static char sccsid[] = "@(#)print.c	8.1 (Berkeley) 5/31/93";
     36   1.4       cgd #else
     37  1.17  christos __RCSID("$NetBSD: print.c,v 1.17 2011/08/16 11:14:04 christos Exp $");
     38   1.4       cgd #endif
     39   1.1       cgd #endif /* not lint */
     40   1.1       cgd 
     41  1.14  dholland #include "mille.h"
     42   1.1       cgd 
     43   1.1       cgd /*
     44   1.1       cgd  * @(#)print.c	1.1 (Berkeley) 4/1/82
     45   1.1       cgd  */
     46   1.1       cgd 
     47  1.14  dholland #define COMP_STRT	20
     48  1.14  dholland #define CARD_STRT	2
     49   1.1       cgd 
     50  1.15  dholland static void show_card(int, int, CARD, CARD *);
     51  1.15  dholland static void show_score(int, int, int, int *);
     52  1.15  dholland 
     53   1.6     lukem void
     54  1.13  dholland prboard(void)
     55   1.6     lukem {
     56   1.6     lukem 	PLAY	*pp;
     57   1.6     lukem 	int	i, j, k, temp;
     58   1.1       cgd 
     59   1.1       cgd 	for (k = 0; k < 2; k++) {
     60   1.1       cgd 		pp = &Player[k];
     61   1.1       cgd 		temp = k * COMP_STRT + CARD_STRT;
     62   1.1       cgd 		for (i = 0; i < NUM_SAFE; i++)
     63   1.1       cgd 			if (pp->safety[i] == S_PLAYED && !pp->sh_safety[i]) {
     64   1.1       cgd 				mvaddstr(i, temp, C_name[i + S_CONV]);
     65   1.1       cgd 				if (pp->coups[i])
     66   1.1       cgd 					mvaddch(i, temp - CARD_STRT, '*');
     67   1.1       cgd 				pp->sh_safety[i] = TRUE;
     68   1.1       cgd 			}
     69   1.1       cgd 		show_card(14, temp, pp->battle, &pp->sh_battle);
     70   1.1       cgd 		show_card(16, temp, pp->speed, &pp->sh_speed);
     71   1.1       cgd 		for (i = C_25; i <= C_200; i++) {
     72   1.7       jsm 			const char	*name;
     73   1.6     lukem 			int	end;
     74   1.1       cgd 
     75   1.1       cgd 			if (pp->nummiles[i] == pp->sh_nummiles[i])
     76   1.1       cgd 				continue;
     77   1.1       cgd 
     78   1.1       cgd 			name = C_name[i];
     79   1.1       cgd 			temp = k * 40;
     80   1.1       cgd 			end = pp->nummiles[i];
     81   1.1       cgd 			for (j = pp->sh_nummiles[i]; j < end; j++)
     82   1.1       cgd 				mvwaddstr(Miles, i + 1, (j << 2) + temp, name);
     83   1.1       cgd 			pp->sh_nummiles[i] = end;
     84   1.1       cgd 		}
     85   1.1       cgd 	}
     86   1.1       cgd 	prscore(TRUE);
     87   1.1       cgd 	temp = CARD_STRT;
     88   1.1       cgd 	pp = &Player[PLAYER];
     89   1.1       cgd 	for (i = 0; i < HAND_SZ; i++)
     90   1.1       cgd 		show_card(i + 6, temp, pp->hand[i], &pp->sh_hand[i]);
     91  1.10   thorpej 	mvprintw(6, COMP_STRT + CARD_STRT, "%2ld", (long)(Topcard - Deck));
     92   1.1       cgd 	show_card(8, COMP_STRT + CARD_STRT, Discard, &Sh_discard);
     93   1.1       cgd 	if (End == 1000) {
     94   1.1       cgd 		move(EXT_Y, EXT_X);
     95   1.1       cgd 		standout();
     96   1.1       cgd 		addstr("Extension");
     97   1.1       cgd 		standend();
     98   1.1       cgd 	}
     99   1.1       cgd 	wrefresh(Board);
    100   1.1       cgd 	wrefresh(Miles);
    101   1.1       cgd 	wrefresh(Score);
    102   1.1       cgd }
    103   1.1       cgd 
    104   1.1       cgd /*
    105   1.1       cgd  * show_card:
    106   1.1       cgd  *	Show the given card if it is different from the last one shown
    107   1.1       cgd  */
    108  1.15  dholland static void
    109  1.13  dholland show_card(int y, int x, CARD c, CARD *lc)
    110   1.1       cgd {
    111   1.1       cgd 	if (c == *lc)
    112   1.1       cgd 		return;
    113   1.1       cgd 
    114   1.1       cgd 	mvprintw(y, x, C_fmt, C_name[c]);
    115   1.1       cgd 	*lc = c;
    116   1.1       cgd }
    117   1.1       cgd 
    118  1.17  christos #define	Score_fmt "%4d"
    119   1.1       cgd 
    120   1.6     lukem void
    121  1.16     joerg prscore(bool for_real)
    122   1.5       jtc {
    123   1.6     lukem 	PLAY	*pp;
    124   1.6     lukem 	int	x;
    125   1.1       cgd 
    126   1.1       cgd 	stdscr = Score;
    127   1.1       cgd 	for (pp = Player; pp < &Player[2]; pp++) {
    128   1.1       cgd 		x = (pp - Player) * 6 + 21;
    129   1.1       cgd 		show_score(1, x, pp->mileage, &pp->sh_mileage);
    130   1.1       cgd 		if (pp->safescore != pp->sh_safescore) {
    131   1.1       cgd 			mvprintw(2, x, Score_fmt, pp->safescore);
    132   1.1       cgd 			if (pp->safescore == 400)
    133   1.1       cgd 				mvaddstr(3, x + 1, "300");
    134   1.1       cgd 			else
    135   1.1       cgd 				mvaddstr(3, x + 1, "  0");
    136   1.1       cgd 			mvprintw(4, x, Score_fmt, pp->coupscore);
    137   1.1       cgd 			pp->sh_safescore = pp->safescore;
    138   1.1       cgd 		}
    139   1.1       cgd 		if (Window == W_FULL || Finished) {
    140   1.1       cgd #ifdef EXTRAP
    141   1.1       cgd 			if (for_real)
    142   1.1       cgd 				finalscore(pp);
    143   1.1       cgd 			else
    144   1.1       cgd 				extrapolate(pp);
    145   1.1       cgd #else
    146   1.1       cgd 			finalscore(pp);
    147   1.1       cgd #endif
    148   1.1       cgd 			show_score(11, x, pp->hand_tot, &pp->sh_hand_tot);
    149   1.1       cgd 			show_score(13, x, pp->total, &pp->sh_total);
    150   1.1       cgd 			show_score(14, x, pp->games, &pp->sh_games);
    151   1.1       cgd 		}
    152   1.1       cgd 		else {
    153   1.1       cgd 			show_score(6, x, pp->hand_tot, &pp->sh_hand_tot);
    154   1.1       cgd 			show_score(8, x, pp->total, &pp->sh_total);
    155   1.1       cgd 			show_score(9, x, pp->games, &pp->sh_games);
    156   1.1       cgd 		}
    157   1.1       cgd 	}
    158   1.1       cgd 	stdscr = Board;
    159   1.1       cgd }
    160   1.1       cgd 
    161   1.1       cgd /*
    162   1.1       cgd  * show_score:
    163   1.1       cgd  *	Show a score value if it is different from the last time we
    164   1.1       cgd  *	showed it.
    165   1.1       cgd  */
    166  1.15  dholland static void
    167  1.13  dholland show_score(int y, int x, int s, int *ls)
    168   1.1       cgd {
    169   1.1       cgd 	if (s == *ls)
    170   1.1       cgd 		return;
    171   1.1       cgd 
    172   1.1       cgd 	mvprintw(y, x, Score_fmt, s);
    173   1.1       cgd 	*ls = s;
    174   1.1       cgd }
    175