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