print.c revision 1.4 1 /* $NetBSD: print.c,v 1.4 1997/10/12 17:45:22 christos Exp $ */
2
3 /*
4 * Copyright (c) 1980, 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 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: print.c,v 1.4 1997/10/12 17:45:22 christos Exp $");
42 #endif
43 #endif /* not lint */
44
45 # include "monop.ext"
46
47 static char *header = "Name Own Price Mg # Rent";
48
49 static void printmorg __P((SQUARE *));
50
51 /*
52 * This routine prints out the current board
53 */
54 void
55 printboard()
56 {
57
58 int i;
59
60 printf("%s\t%s\n", header, header);
61 for (i = 0; i < N_SQRS/2; i++) {
62 printsq(i, FALSE);
63 putchar('\t');
64 printsq(i+N_SQRS/2, TRUE);
65 }
66 }
67 /*
68 * This routine lists where each player is.
69 */
70 void
71 where()
72 {
73
74 int i;
75
76 printf("%s Player\n", header);
77 for (i = 0; i < num_play; i++) {
78 printsq(play[i].loc, FALSE);
79 printf(" %s (%d)", play[i].name, i+1);
80 if (cur_p == &play[i])
81 printf(" *");
82 putchar('\n');
83 }
84 }
85 /*
86 * This routine prints out an individual square
87 */
88 void
89 printsq(sqn, eoln)
90 int sqn;
91 bool eoln;
92 {
93
94 int rnt;
95 PROP *pp;
96 SQUARE *sqp;
97
98 sqp = &board[sqn];
99 printf("%-10.10s", sqp->name);
100 switch (sqp->type) {
101 case SAFE:
102 case CC:
103 case CHANCE:
104 case INC_TAX:
105 case GOTO_J:
106 case LUX_TAX:
107 case IN_JAIL:
108 if (!eoln)
109 printf(" ");
110 break;
111 case PRPTY:
112 pp = sqp->desc;
113 if (sqp->owner < 0) {
114 printf(" - %-8.8s %3d", pp->mon_desc->name, sqp->cost);
115 if (!eoln)
116 printf(" ");
117 break;
118 }
119 printf(" %d %-8.8s %3d", sqp->owner+1, pp->mon_desc->name,
120 sqp->cost);
121 printmorg(sqp);
122 if (pp->monop) {
123 if (pp->houses < 5)
124 if (pp->houses > 0)
125 printf("%d %4d", pp->houses,
126 pp->rent[pp->houses]);
127 else
128 printf("0 %4d", pp->rent[0] * 2);
129 else
130 printf("H %4d", pp->rent[5]);
131 }
132 else
133 printf(" %4d", pp->rent[0]);
134 break;
135 case UTIL:
136 if (sqp->owner < 0) {
137 printf(" - 150");
138 if (!eoln)
139 printf(" ");
140 break;
141 }
142 printf(" %d 150", sqp->owner+1);
143 printmorg(sqp);
144 printf("%d", play[sqp->owner].num_util);
145 if (!eoln)
146 printf(" ");
147 break;
148 case RR:
149 if (sqp->owner < 0) {
150 printf(" - Railroad 200");
151 if (!eoln)
152 printf(" ");
153 break;
154 }
155 printf(" %d Railroad 200", sqp->owner+1);
156 printmorg(sqp);
157 rnt = 25;
158 rnt <<= play[sqp->owner].num_rr - 1;
159 printf("%d %4d", play[sqp->owner].num_rr, 25 << (play[sqp->owner].num_rr - 1));
160 break;
161 }
162 if (eoln)
163 putchar('\n');
164 }
165 /*
166 * This routine prints out the mortgage flag.
167 */
168 static void
169 printmorg(sqp)
170 SQUARE *sqp;
171 {
172
173 if (sqp->desc->morg)
174 printf(" * ");
175 else
176 printf(" ");
177 }
178 /*
179 * This routine lists the holdings of the player given
180 */
181 void
182 printhold(pl)
183 int pl;
184 {
185
186 OWN *op;
187 PLAY *pp;
188
189 pp = &play[pl];
190 printf("%s's (%d) holdings (Total worth: $%d):\n", name_list[pl], pl+1,
191 pp->money + prop_worth(pp));
192 printf("\t$%d", pp->money);
193 if (pp->num_gojf) {
194 printf(", %d get-out-of-jail-free card", pp->num_gojf);
195 if (pp->num_gojf > 1)
196 putchar('s');
197 }
198 putchar('\n');
199 if (pp->own_list) {
200 printf("\t%s\n", header);
201 for (op = pp->own_list; op; op = op->next) {
202 putchar('\t');
203 printsq(sqnum(op->sqr), TRUE);
204 }
205 }
206 }
207