xref: /dragonfly/games/monop/print.c (revision 11c3b524)
1 /*	$NetBSD: print.c,v 1.13 2012/06/19 05:35:32 dholland 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. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)print.c	8.1 (Berkeley) 5/31/93
32  */
33 
34 #include "monop.h"
35 
36 static const char *header = "Name      Own      Price Mg # Rent";
37 
38 static void printmorg(const SQUARE *);
39 
40 /*
41  *	This routine prints out the current board
42  */
43 void
printboard(void)44 printboard(void)
45 {
46 	int i;
47 
48 	printf("%s\t%s\n", header, header);
49 	for (i = 0; i < N_SQRS/2; i++) {
50 		printsq(i, FALSE);
51 		putchar('\t');
52 		printsq(i+N_SQRS/2, TRUE);
53 	}
54 }
55 
56 /*
57  *	This routine lists where each player is.
58  */
59 void
where(void)60 where(void)
61 {
62 	int i;
63 
64 	printf("%s Player\n", header);
65 	for (i = 0; i < num_play; i++) {
66 		printsq(play[i].loc, FALSE);
67 		printf(" %s (%d)", play[i].name, i+1);
68 		if (cur_p == &play[i])
69 			printf(" *");
70 		putchar('\n');
71 	}
72 }
73 
74 /*
75  *	This routine prints out an individual square
76  */
77 void
printsq(int sqn,bool eoln)78 printsq(int sqn, bool eoln)
79 {
80 	int rnt;
81 	PROP *pp;
82 	SQUARE *sqp;
83 
84 	sqp = &board[sqn];
85 	printf("%-10.10s", sqp->name);
86 	switch (sqp->type) {
87 	  case SAFE:
88 	  case CC:
89 	  case CHANCE:
90 	  case INC_TAX:
91 	  case GOTO_J:
92 	  case LUX_TAX:
93 	  case IN_JAIL:
94 		if (!eoln)
95 			printf("                        ");
96 		break;
97 	  case PRPTY:
98 		pp = sqp->desc;
99 		if (sqp->owner < 0) {
100 			printf(" - %-8.8s %3d", pp->mon_desc->name, sqp->cost);
101 			if (!eoln)
102 				printf("         ");
103 			break;
104 		}
105 		printf(" %d %-8.8s %3d", sqp->owner+1, pp->mon_desc->name,
106 			sqp->cost);
107 		printmorg(sqp);
108 		if (pp->monop) {
109 			if (pp->houses < 5)
110 				if (pp->houses > 0)
111 					printf("%d %4d", pp->houses,
112 						pp->rent[pp->houses]);
113 				else
114 					printf("0 %4d", pp->rent[0] * 2);
115 			else
116 				printf("H %4d", pp->rent[5]);
117 		} else
118 			printf("  %4d", pp->rent[0]);
119 		break;
120 	  case UTIL:
121 		if (sqp->owner < 0) {
122 			printf(" -          150");
123 			if (!eoln)
124 				printf("         ");
125 			break;
126 		}
127 		printf(" %d          150", sqp->owner+1);
128 		printmorg(sqp);
129 		printf("%d", play[sqp->owner].num_util);
130 		if (!eoln)
131 			printf("    ");
132 		break;
133 	  case RR:
134 		if (sqp->owner < 0) {
135 			printf(" - Railroad 200");
136 			if (!eoln)
137 				printf("         ");
138 			break;
139 		}
140 		printf(" %d Railroad 200", sqp->owner+1);
141 		printmorg(sqp);
142 		rnt = 25;
143 		rnt <<= play[sqp->owner].num_rr - 1;
144 		printf("%d %4d", play[sqp->owner].num_rr,
145 		    25 << (play[sqp->owner].num_rr - 1));
146 		break;
147 	}
148 	if (eoln)
149 		putchar('\n');
150 }
151 
152 /*
153  *	This routine prints out the mortgage flag.
154  */
155 static void
printmorg(const SQUARE * sqp)156 printmorg(const SQUARE *sqp)
157 {
158 	if (sqp->desc->morg)
159 		printf(" * ");
160 	else
161 		printf("   ");
162 }
163 
164 /*
165  *	This routine lists the holdings of the player given
166  */
167 void
printhold(int pl)168 printhold(int pl)
169 {
170 	OWN *op;
171 	PLAY *pp;
172 
173 	pp = &play[pl];
174 	printf("%s's (%d) holdings (Total worth: $%d):\n", name_list[pl],
175 	    pl + 1, pp->money + prop_worth(pp));
176 	printf("\t$%d", pp->money);
177 	if (pp->num_gojf) {
178 		printf(", %d get-out-of-jail-free card", pp->num_gojf);
179 		if (pp->num_gojf > 1)
180 			putchar('s');
181 	}
182 	putchar('\n');
183 	if (pp->own_list) {
184 		printf("\t%s\n", header);
185 		for (op = pp->own_list; op; op = op->next) {
186 			putchar('\t');
187 			printsq(sqnum(op->sqr), TRUE);
188 		}
189 	}
190 }
191