1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32: #include <sys/cdefs.h>
33: #ifndef lint
34: #if 0
35: static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93";
36: #else
37: __RCSID("$NetBSD: misc.c,v 1.13 2004/11/05 21:30:32 dsl Exp $");
38: #endif
39: #endif
40:
41: #include "monop.ext"
42: #include <ctype.h>
43: #include <signal.h>
44:
45:
46:
47:
48:
49: int
50: getyn(prompt)
51: const char *prompt;
52: {
53: int com;
54:
55: for (;;)
56: if ((com=getinp(prompt, yncoms)) < 2)
57: return com;
58: else
59: (*func[com-2])();
60: }
61:
62:
63:
64:
65: void
66: notify()
67: {
68: if (cur_p->money < 0)
69: printf("That leaves you $%d in debt\n", -cur_p->money);
70: else if (cur_p->money == 0)
71: printf("that leaves you broke\n");
72: else if (fixing && !told_em && cur_p->money > 0) {
73: printf("-- You are now Solvent ---\n");
74: told_em = TRUE;
75: }
76: }
77:
78:
79:
80:
81: void
82: next_play()
83: {
84: player = (player + 1) % num_play;
85: cur_p = &play[player];
86: num_doub = 0;
87: }
88:
89:
90:
91:
92:
93: int
94: get_int(prompt)
95: const char *prompt;
96: {
97: int num;
98: char *sp;
99: int c;
100: char buf[257];
101:
102: for (;;) {
103: inter:
104: printf(prompt);
105: num = 0;
106: for (sp = buf; (c=getchar()) != '\n'; *sp++ = c)
107: if (c == -1)
108: goto inter;
109: *sp = c;
110: if (sp == buf)
111: continue;
112: for (sp = buf; isspace((unsigned char)*sp); sp++)
113: continue;
114: for (; isdigit((unsigned char)*sp); sp++)
115: num = num * 10 + *sp - '0';
116: if (*sp == '\n')
117: return num;
118: else
119: printf("I can't understand that\n");
120: }
121: }
122:
123:
124:
125:
126: void
127: set_ownlist(pl)
128: int pl;
129: {
130: int num;
131: MON *orig;
132: OWN *op;
133: OWN *orig_op;
134:
135: op = play[pl].own_list;
136: #ifdef DEBUG
137: printf("op [%d] = play[pl [%d] ].own_list;\n", op, pl);
138: #endif
139: while (op) {
140: #ifdef DEBUG
141: printf("op->sqr->type = %d\n", op->sqr->type);
142: #endif
143: switch (op->sqr->type) {
144: case UTIL:
145: #ifdef DEBUG
146: printf(" case UTIL:\n");
147: #endif
148: for (num = 0; op && op->sqr->type == UTIL;
149: op = op->next)
150: num++;
151: play[pl].num_util = num;
152: #ifdef DEBUG
153: printf("play[pl].num_util = num [%d];\n", num);
154: #endif
155: break;
156: case RR:
157: #ifdef DEBUG
158: printf(" case RR:\n");
159: #endif
160: for (num = 0; op && op->sqr->type == RR;
161: op = op->next) {
162: #ifdef DEBUG
163: printf("iter: %d\n", num);
164: printf("op = %d, op->sqr = %d, "
165: "op->sqr->type = %d\n", op, op->sqr,
166: op->sqr->type);
167: #endif
168: num++;
169: }
170: play[pl].num_rr = num;
171: #ifdef DEBUG
172: printf("play[pl].num_rr = num [%d];\n", num);
173: #endif
174: break;
175: case PRPTY:
176: #ifdef DEBUG
177: printf(" case PRPTY:\n");
178: #endif
179: orig = op->sqr->desc->mon_desc;
180: orig_op = op;
181: num = 0;
182: while (op && op->sqr->desc->mon_desc == orig) {
183: #ifdef DEBUG
184: printf("iter: %d\n", num);
185: #endif
186: num++;
187: #ifdef DEBUG
188: printf("op = op->next ");
189: #endif
190: op = op->next;
191: #ifdef DEBUG
192: printf("[%d];\n", op);
193: #endif
194: }
195: #ifdef DEBUG
196: printf("num = %d\n");
197: #endif
198: if (orig == 0) {
199: printf("panic: bad monopoly descriptor: "
200: "orig = %p\n", orig);
201: printf("player # %d\n", pl+1);
202: printhold(pl);
203: printf("orig_op = %p\n", orig_op);
204: printf("orig_op->sqr->type = %d (PRPTY)\n",
205: op->sqr->type);
206: printf("orig_op->next = %p\n", op->next);
207: printf("orig_op->sqr->desc = %p\n",
208: op->sqr->desc);
209: printf("op = %p\n", op);
210: printf("op->sqr->type = %d (PRPTY)\n",
211: op->sqr->type);
212: printf("op->next = %p\n", op->next);
213: printf("op->sqr->desc = %p\n", op->sqr->desc);
214: printf("num = %d\n", num);
215: }
216: #ifdef DEBUG
217: printf("orig->num_in = %d\n", orig->num_in);
218: #endif
219: if (num == orig->num_in)
220: is_monop(orig, pl);
221: else
222: is_not_monop(orig);
223: break;
224: }
225: }
226: }
227:
228:
229:
230:
231: void
232: is_monop(mp, pl)
233: MON *mp;
234: int pl;
235: {
236: int i;
237:
238: mp->owner = pl;
239: mp->num_own = mp->num_in;
240: for (i = 0; i < mp->num_in; i++)
241: mp->sq[i]->desc->monop = TRUE;
242: mp->name = mp->mon_n;
243: }
244:
245:
246:
247:
248: void
249: is_not_monop(mp)
250: MON *mp;
251: {
252: int i;
253:
254: mp->owner = -1;
255: for (i = 0; i < mp->num_in; i++)
256: mp->sq[i]->desc->monop = FALSE;
257: mp->name = mp->not_m;
258: }
259:
260:
261:
262:
263: void
264: list()
265: {
266: printhold(player);
267: }
268:
269:
270:
271:
272: void
273: list_all()
274: {
275: int pl;
276:
277: while ((pl = getinp("Whose holdings do you want to see? ", name_list))
278: < num_play)
279: printhold(pl);
280: }
281:
282:
283:
284:
285: void
286: quit()
287: {
288: putchar('\n');
289: if (getyn("Do you all really want to quit? ") == 0)
290: exit(0);
291: }