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