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