]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/prop.c
src/games/quiz from Lite
[bsdgames-darwin.git] / monop / prop.c
1 /* $NetBSD: prop.c,v 1.3 1995/03/23 08:35:06 cgd 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)prop.c 8.1 (Berkeley) 5/31/93";
39 #else
40 static char rcsid[] = "$NetBSD: prop.c,v 1.3 1995/03/23 08:35:06 cgd Exp $";
41 #endif
42 #endif /* not lint */
43
44 # include "monop.ext"
45
46 extern char *calloc();
47
48 /*
49 * This routine deals with buying property, setting all the
50 * appropriate flags.
51 */
52 buy(player, sqrp)
53 reg int player;
54 reg SQUARE *sqrp; {
55
56 trading = FALSE;
57 sqrp->owner = player;
58 add_list(player, &(play[player].own_list), cur_p->loc);
59 }
60 /*
61 * This routine adds an item to the list.
62 */
63 add_list(plr, head, op_sqr)
64 int plr;
65 OWN **head;
66 int op_sqr; {
67
68 reg int val;
69 reg OWN *tp, *last_tp;
70 MON *mp;
71 OWN *op;
72
73 op = (OWN *)calloc(1, sizeof (OWN));
74 op->sqr = &board[op_sqr];
75 val = value(op->sqr);
76 last_tp = NULL;
77 for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
78 if (val == value(tp->sqr)) {
79 cfree(op);
80 return;
81 }
82 else
83 last_tp = tp;
84 op->next = tp;
85 if (last_tp != NULL)
86 last_tp->next = op;
87 else
88 *head = op;
89 if (!trading)
90 set_ownlist(plr);
91 }
92 /*
93 * This routine deletes property from the list.
94 */
95 del_list(plr, head, op_sqr)
96 int plr;
97 OWN **head;
98 shrt op_sqr; {
99
100 reg int i;
101 reg OWN *op, *last_op;
102
103 switch (board[op_sqr].type) {
104 case PRPTY:
105 board[op_sqr].desc->mon_desc->num_own--;
106 break;
107 case RR:
108 play[plr].num_rr--;
109 break;
110 case UTIL:
111 play[plr].num_util--;
112 break;
113 }
114 last_op = NULL;
115 for (op = *head; op; op = op->next)
116 if (op->sqr == &board[op_sqr])
117 break;
118 else
119 last_op = op;
120 if (last_op == NULL)
121 *head = op->next;
122 else {
123 last_op->next = op->next;
124 cfree(op);
125 }
126 }
127 /*
128 * This routine calculates the value for sorting of the
129 * given square.
130 */
131 value(sqp)
132 reg SQUARE *sqp; {
133
134 reg int sqr;
135
136 sqr = sqnum(sqp);
137 switch (sqp->type) {
138 case SAFE:
139 return 0;
140 default: /* Specials, etc */
141 return 1;
142 case UTIL:
143 if (sqr == 12)
144 return 2;
145 else
146 return 3;
147 case RR:
148 return 4 + sqr/10;
149 case PRPTY:
150 return 8 + (sqp->desc) - prop;
151 }
152 }
153 /*
154 * This routine accepts bids for the current peice
155 * of property.
156 */
157 bid() {
158
159 static bool in[MAX_PL];
160 reg int i, num_in, cur_max;
161 char buf[80];
162 int cur_bid;
163
164 printf("\nSo it goes up for auction. Type your bid after your name\n");
165 for (i = 0; i < num_play; i++)
166 in[i] = TRUE;
167 i = -1;
168 cur_max = 0;
169 num_in = num_play;
170 while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
171 i = ++i % num_play;
172 if (in[i]) {
173 do {
174 (void)sprintf(buf, "%s: ", name_list[i]);
175 cur_bid = get_int(buf);
176 if (cur_bid == 0) {
177 in[i] = FALSE;
178 if (--num_in == 0)
179 break;
180 }
181 else if (cur_bid <= cur_max) {
182 printf("You must bid higher than %d to stay in\n", cur_max);
183 printf("(bid of 0 drops you out)\n");
184 }
185 } while (cur_bid != 0 && cur_bid <= cur_max);
186 cur_max = (cur_bid ? cur_bid : cur_max);
187 }
188 }
189 if (cur_max != 0) {
190 while (!in[i])
191 i = ++i % num_play;
192 printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
193 buy(i, &board[cur_p->loc]);
194 play[i].money -= cur_max;
195 }
196 else
197 printf("Nobody seems to want it, so we'll leave it for later\n");
198 }
199 /*
200 * This routine calculates the value of the property
201 * of given player.
202 */
203 prop_worth(plp)
204 reg PLAY *plp; {
205
206 reg OWN *op;
207 reg int worth;
208
209 worth = 0;
210 for (op = plp->own_list; op; op = op->next) {
211 if (op->sqr->type == PRPTY && op->sqr->desc->monop)
212 worth += op->sqr->desc->mon_desc->h_cost * 50 *
213 op->sqr->desc->houses;
214 worth += op->sqr->cost;
215 }
216 return worth;
217 }