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[] = "@(#)prop.c 8.1 (Berkeley) 5/31/93";
36: #else
37: __RCSID("$NetBSD: prop.c,v 1.9 2004/01/27 20:30:30 jsm Exp $");
38: #endif
39: #endif
40:
41: #include <stdlib.h>
42: #include "monop.ext"
43:
44: static int value(SQUARE *);
45:
46:
47:
48:
49:
50: void
51: buy(player, sqrp)
52: int player;
53: SQUARE *sqrp;
54: {
55: trading = FALSE;
56: sqrp->owner = player;
57: add_list(player, &(play[player].own_list), cur_p->loc);
58: }
59:
60:
61:
62:
63: void
64: add_list(plr, head, op_sqr)
65: int plr;
66: OWN **head;
67: int op_sqr;
68: {
69: int val;
70: OWN *tp, *last_tp;
71: OWN *op;
72:
73: op = (OWN *)calloc(1, sizeof (OWN));
74: if (op == NULL)
75: errx(1, "out of memory");
76: op->sqr = &board[op_sqr];
77: val = value(op->sqr);
78: last_tp = NULL;
79: for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
80: if (val == value(tp->sqr)) {
81: free(op);
82: return;
83: }
84: else
85: last_tp = tp;
86: op->next = tp;
87: if (last_tp != NULL)
88: last_tp->next = op;
89: else
90: *head = op;
91: if (!trading)
92: set_ownlist(plr);
93: }
94:
95:
96:
97:
98: void
99: del_list(plr, head, op_sqr)
100: int plr;
101: OWN **head;
102: short op_sqr;
103: {
104: OWN *op, *last_op;
105:
106: switch (board[op_sqr].type) {
107: case PRPTY:
108: board[op_sqr].desc->mon_desc->num_own--;
109: break;
110: case RR:
111: play[plr].num_rr--;
112: break;
113: case UTIL:
114: play[plr].num_util--;
115: break;
116: }
117: last_op = NULL;
118: for (op = *head; op; op = op->next)
119: if (op->sqr == &board[op_sqr])
120: break;
121: else
122: last_op = op;
123: if (last_op == NULL)
124: *head = op->next;
125: else {
126: last_op->next = op->next;
127: free(op);
128: }
129: }
130:
131:
132:
133:
134:
135: static int
136: value(sqp)
137: SQUARE *sqp;
138: {
139: int sqr;
140:
141: sqr = sqnum(sqp);
142: switch (sqp->type) {
143: case SAFE:
144: return 0;
145: default:
146: return 1;
147: case UTIL:
148: if (sqr == 12)
149: return 2;
150: else
151: return 3;
152: case RR:
153: return 4 + sqr/10;
154: case PRPTY:
155: return 8 + (sqp->desc) - prop;
156: }
157: }
158:
159:
160:
161:
162:
163: void
164: bid()
165: {
166: static bool in[MAX_PL];
167: int i, num_in, cur_max;
168: char buf[80];
169: int cur_bid;
170:
171: printf("\nSo it goes up for auction. Type your bid after your name\n");
172: for (i = 0; i < num_play; i++)
173: in[i] = TRUE;
174: i = -1;
175: cur_max = 0;
176: num_in = num_play;
177: while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
178: i = (i + 1) % num_play;
179: if (in[i]) {
180: do {
181: (void)sprintf(buf, "%s: ", name_list[i]);
182: cur_bid = get_int(buf);
183: if (cur_bid == 0) {
184: in[i] = FALSE;
185: if (--num_in == 0)
186: break;
187: }
188: else if (cur_bid <= cur_max) {
189: printf("You must bid higher than %d "
190: "to stay in\n", cur_max);
191: printf("(bid of 0 drops you out)\n");
192: }
193: } while (cur_bid != 0 && cur_bid <= cur_max);
194: cur_max = (cur_bid ? cur_bid : cur_max);
195: }
196: }
197: if (cur_max != 0) {
198: while (!in[i])
199: i = (i + 1) % num_play;
200: printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
201: buy(i, &board[cur_p->loc]);
202: play[i].money -= cur_max;
203: }
204: else
205: printf("Nobody seems to want it, so we'll leave it for "
206: "later\n");
207: }
208:
209:
210:
211:
212:
213: int
214: prop_worth(plp)
215: PLAY *plp;
216: {
217: OWN *op;
218: int worth;
219:
220: worth = 0;
221: for (op = plp->own_list; op; op = op->next) {
222: if (op->sqr->type == PRPTY && op->sqr->desc->monop)
223: worth += op->sqr->desc->mon_desc->h_cost * 50 *
224: op->sqr->desc->houses;
225: worth += op->sqr->cost;
226: }
227: return worth;
228: }