1 /* $NetBSD: misc.c,v 1.23 2012/06/19 05:35:32 dholland Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: misc.c,v 1.23 2012/06/19 05:35:32 dholland Exp $");
48 static void is_monop(MON
*, int);
51 * This routine executes a truncated set of commands until a
52 * "yes or "no" answer is gotten.
55 getyn(const char *prompt
)
60 if ((com
=getinp(prompt
, yncoms
)) < 2)
67 * This routine tells the player if he's out of money.
73 printf("That leaves you $%d in debt\n", -cur_p
->money
);
74 else if (cur_p
->money
== 0)
75 printf("that leaves you broke\n");
76 else if (fixing
&& !told_em
&& cur_p
->money
> 0) {
77 printf("-- You are now Solvent ---\n");
83 * This routine switches to the next player
88 player
= (player
+ 1) % num_play
;
89 cur_p
= &play
[player
];
94 * This routine gets an integer from the keyboard after the
98 get_int(const char *prompt
)
105 printf("%s", prompt
);
106 fgets(buf
, sizeof(buf
), stdin
);
107 /* if stdin is closed we cant really play anymore */
110 sp
= strchr(buf
, '\n');
114 num
= strtol(buf
, &sp
, 10);
115 if (errno
|| strlen(sp
) > 0 || num
< 0 || num
>= INT_MAX
) {
116 printf("I can't understand that\n");
124 * This routine sets the monopoly flag from the list given.
129 int num
; /* general counter */
130 MON
*orig
; /* remember starting monop ptr */
131 OWN
*op
; /* current owned prop */
132 OWN
*orig_op
; /* original prop before loop */
134 op
= play
[pl
].own_list
;
136 printf("op [%p] = play[pl [%d] ].own_list;\n", op
, pl
);
140 printf("op->sqr->type = %d\n", op
->sqr
->type
);
142 switch (op
->sqr
->type
) {
145 printf(" case UTIL:\n");
147 for (num
= 0; op
&& op
->sqr
->type
== UTIL
;
150 play
[pl
].num_util
= num
;
152 printf("play[pl].num_util = num [%d];\n", num
);
157 printf(" case RR:\n");
159 for (num
= 0; op
&& op
->sqr
->type
== RR
;
162 printf("iter: %d\n", num
);
163 printf("op = %p, op->sqr = %p, "
164 "op->sqr->type = %d\n", op
, op
->sqr
,
169 play
[pl
].num_rr
= num
;
171 printf("play[pl].num_rr = num [%d];\n", num
);
176 printf(" case PRPTY:\n");
178 orig
= op
->sqr
->desc
->mon_desc
;
181 while (op
&& op
->sqr
->desc
->mon_desc
== orig
) {
183 printf("iter: %d\n", num
);
187 printf("op = op->next ");
191 printf("[%p];\n", op
);
195 printf("num = %d\n", num
);
198 printf("panic: bad monopoly descriptor: "
199 "orig = %p\n", orig
);
200 printf("player # %d\n", pl
+1);
202 printf("orig_op = %p\n", orig_op
);
204 printf("orig_op->sqr->type = %d (PRPTY)\n",
206 printf("orig_op->next = %p\n",
208 printf("orig_op->sqr->desc = %p\n",
211 printf("op = %p\n", op
);
213 printf("op->sqr->type = %d (PRPTY)\n",
215 printf("op->next = %p\n", op
->next
);
216 printf("op->sqr->desc = %p\n",
219 printf("num = %d\n", num
);
223 printf("orig->num_in = %d\n", orig
->num_in
);
225 if (num
== orig
->num_in
)
235 * This routine sets things up as if it is a new monopoly
238 is_monop(MON
*mp
, int pl
)
243 mp
->num_own
= mp
->num_in
;
244 for (i
= 0; i
< mp
->num_in
; i
++)
245 mp
->sq
[i
]->desc
->monop
= TRUE
;
246 mp
->name
= mp
->mon_n
;
250 * This routine sets things up as if it is no longer a monopoly
253 is_not_monop(MON
*mp
)
258 for (i
= 0; i
< mp
->num_in
; i
++)
259 mp
->sq
[i
]->desc
->monop
= FALSE
;
260 mp
->name
= mp
->not_m
;
264 * This routine gives a list of the current player's routine
273 * This routine gives a list of a given players holdings
280 while ((pl
= getinp("Whose holdings do you want to see? ", name_list
))
286 * This routine gives the players a chance before it exits.
293 /* We dont even have a chance to input y/n if stdin is closed */
297 if (getyn("Do you all really want to quit? ") == 0)