1 /* $NetBSD: misc.c,v 1.20 2008/02/24 03:52:09 christos 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.20 2008/02/24 03:52:09 christos 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.
61 if ((com
=getinp(prompt
, yncoms
)) < 2)
68 * This routine tells the player if he's out of money.
74 printf("That leaves you $%d in debt\n", -cur_p
->money
);
75 else if (cur_p
->money
== 0)
76 printf("that leaves you broke\n");
77 else if (fixing
&& !told_em
&& cur_p
->money
> 0) {
78 printf("-- You are now Solvent ---\n");
84 * This routine switches to the next player
89 player
= (player
+ 1) % num_play
;
90 cur_p
= &play
[player
];
95 * This routine gets an integer from the keyboard after the
107 printf("%s", prompt
);
108 fgets(buf
, sizeof(buf
), stdin
);
111 sp
= strchr(buf
, '\n');
115 num
= strtol(buf
, &sp
, 10);
116 if (errno
|| strlen(sp
) > 0 || num
< 0 || num
>= INT_MAX
) {
117 printf("I can't understand that\n");
125 * This routine sets the monopoly flag from the list given.
131 int num
; /* general counter */
132 MON
*orig
; /* remember starting monop ptr */
133 OWN
*op
; /* current owned prop */
134 OWN
*orig_op
; /* original prop before loop */
136 op
= play
[pl
].own_list
;
138 printf("op [%p] = play[pl [%d] ].own_list;\n", op
, pl
);
142 printf("op->sqr->type = %d\n", op
->sqr
->type
);
144 switch (op
->sqr
->type
) {
147 printf(" case UTIL:\n");
149 for (num
= 0; op
&& op
->sqr
->type
== UTIL
;
152 play
[pl
].num_util
= num
;
154 printf("play[pl].num_util = num [%d];\n", num
);
159 printf(" case RR:\n");
161 for (num
= 0; op
&& op
->sqr
->type
== RR
;
164 printf("iter: %d\n", num
);
165 printf("op = %p, op->sqr = %p, "
166 "op->sqr->type = %d\n", op
, op
->sqr
,
171 play
[pl
].num_rr
= num
;
173 printf("play[pl].num_rr = num [%d];\n", num
);
178 printf(" case PRPTY:\n");
180 orig
= op
->sqr
->desc
->mon_desc
;
183 while (op
&& op
->sqr
->desc
->mon_desc
== orig
) {
185 printf("iter: %d\n", num
);
189 printf("op = op->next ");
193 printf("[%p];\n", op
);
197 printf("num = %d\n", num
);
200 printf("panic: bad monopoly descriptor: "
201 "orig = %p\n", orig
);
202 printf("player # %d\n", pl
+1);
204 printf("orig_op = %p\n", orig_op
);
206 printf("orig_op->sqr->type = %d (PRPTY)\n",
208 printf("orig_op->next = %p\n",
210 printf("orig_op->sqr->desc = %p\n",
213 printf("op = %p\n", op
);
215 printf("op->sqr->type = %d (PRPTY)\n",
217 printf("op->next = %p\n", op
->next
);
218 printf("op->sqr->desc = %p\n",
221 printf("num = %d\n", num
);
225 printf("orig->num_in = %d\n", orig
->num_in
);
227 if (num
== orig
->num_in
)
237 * This routine sets things up as if it is a new monopoly
247 mp
->num_own
= mp
->num_in
;
248 for (i
= 0; i
< mp
->num_in
; i
++)
249 mp
->sq
[i
]->desc
->monop
= TRUE
;
250 mp
->name
= mp
->mon_n
;
254 * This routine sets things up as if it is no longer a monopoly
263 for (i
= 0; i
< mp
->num_in
; i
++)
264 mp
->sq
[i
]->desc
->monop
= FALSE
;
265 mp
->name
= mp
->not_m
;
269 * This routine gives a list of the current player's routine
278 * This routine gives a list of a given players holdings
285 while ((pl
= getinp("Whose holdings do you want to see? ", name_list
))
291 * This routine gives the players a chance before it exits.
297 if (getyn("Do you all really want to quit? ") == 0)