1 /* $OpenBSD: prop.c,v 1.6 2003/06/03 03:01:40 millert Exp $ */ 2 /* $NetBSD: prop.c,v 1.3 1995/03/23 08:35:06 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1980, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #ifndef lint 34 #if 0 35 static char sccsid[] = "@(#)prop.c 8.1 (Berkeley) 5/31/93"; 36 #else 37 static const char rcsid[] = "$OpenBSD: prop.c,v 1.6 2003/06/03 03:01:40 millert Exp $"; 38 #endif 39 #endif /* not lint */ 40 41 #include <err.h> 42 #include "monop.ext" 43 44 static int value(SQUARE *); 45 46 /* 47 * This routine deals with buying property, setting all the 48 * appropriate flags. 49 */ 50 void 51 buy(plr, sqrp) 52 int plr; 53 SQUARE *sqrp; 54 { 55 trading = FALSE; 56 sqrp->owner = plr; 57 add_list(plr, &(play[plr].own_list), cur_p->loc); 58 } 59 /* 60 * This routine adds an item to the list. 61 */ 62 void 63 add_list(plr, head, op_sqr) 64 int plr; 65 OWN **head; 66 int op_sqr; 67 { 68 int val; 69 OWN *tp, *last_tp; 70 OWN *op; 71 72 if ((op = (OWN *)calloc(1, sizeof (OWN))) == NULL) 73 err(1, NULL); 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 void 96 del_list(plr, head, op_sqr) 97 int plr; 98 OWN **head; 99 shrt op_sqr; 100 { 101 OWN *op, *last_op; 102 103 switch (board[(int)op_sqr].type) { 104 case PRPTY: 105 board[(int)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[(int)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 static int 132 value(sqp) 133 SQUARE *sqp; 134 { 135 int sqr; 136 137 sqr = sqnum(sqp); 138 switch (sqp->type) { 139 case SAFE: 140 return 0; 141 default: /* Specials, etc */ 142 return 1; 143 case UTIL: 144 if (sqr == 12) 145 return 2; 146 else 147 return 3; 148 case RR: 149 return 4 + sqr/10; 150 case PRPTY: 151 return 8 + (sqp->desc) - prop; 152 } 153 } 154 /* 155 * This routine accepts bids for the current piece of property. 156 */ 157 void 158 bid() 159 { 160 static bool in[MAX_PL]; 161 int i, num_in, cur_max; 162 char buf[257]; 163 int cur_bid; 164 165 printf("\nSo it goes up for auction. Type your bid after your name\n"); 166 for (i = 0; i < num_play; i++) 167 in[i] = TRUE; 168 i = -1; 169 cur_max = 0; 170 num_in = num_play; 171 while (num_in > 1 || (cur_max == 0 && num_in > 0)) { 172 i = (i + 1) % num_play; 173 if (in[i]) { 174 do { 175 (void)snprintf(buf, sizeof(buf), "%s: ", name_list[i]); 176 cur_bid = get_int(buf); 177 if (cur_bid == 0) { 178 in[i] = FALSE; 179 if (--num_in == 0) 180 break; 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 } else if (cur_bid > play[i].money) { 185 printf("You can't bid more than your cash ($%d)\n", 186 play[i].money); 187 cur_bid = -1; 188 } 189 } while (cur_bid != 0 && cur_bid <= cur_max); 190 cur_max = (cur_bid ? cur_bid : cur_max); 191 } 192 } 193 if (cur_max != 0) { 194 while (!in[i]) 195 i = (i + 1) % num_play; 196 printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max); 197 buy(i, &board[(int)cur_p->loc]); 198 play[i].money -= cur_max; 199 } 200 else 201 printf("Nobody seems to want it, so we'll leave it for later\n"); 202 } 203 /* 204 * This routine calculates the value of the property 205 * of given player. 206 */ 207 int 208 prop_worth(plp) 209 PLAY *plp; 210 { 211 OWN *op; 212 int worth; 213 214 worth = 0; 215 for (op = plp->own_list; op; op = op->next) { 216 if (op->sqr->type == PRPTY && op->sqr->desc->monop) 217 worth += op->sqr->desc->mon_desc->h_cost * 50 * 218 op->sqr->desc->houses; 219 worth += op->sqr->cost; 220 } 221 return worth; 222 } 223