1 /* 2 * Copyright (c) 1987 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)prop.c 5.4 (Berkeley) 01/02/88"; 15 #endif /* not lint */ 16 17 # include "monop.ext" 18 19 extern char *calloc(); 20 21 /* 22 * This routine deals with buying property, setting all the 23 * appropriate flags. 24 */ 25 buy(player, sqrp) 26 reg int player; 27 reg SQUARE *sqrp; { 28 29 trading = FALSE; 30 sqrp->owner = player; 31 add_list(player, &(play[player].own_list), cur_p->loc); 32 } 33 /* 34 * This routine adds an item to the list. 35 */ 36 add_list(plr, head, op_sqr) 37 int plr; 38 OWN **head; 39 int op_sqr; { 40 41 reg int val; 42 reg OWN *tp, *last_tp; 43 MON *mp; 44 OWN *op; 45 46 op = (OWN *)calloc(1, sizeof (OWN)); 47 op->sqr = &board[op_sqr]; 48 val = value(op->sqr); 49 last_tp = NULL; 50 for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next) 51 if (val == value(tp->sqr)) { 52 cfree(op); 53 return; 54 } 55 else 56 last_tp = tp; 57 op->next = tp; 58 if (last_tp != NULL) 59 last_tp->next = op; 60 else 61 *head = op; 62 if (!trading) 63 set_ownlist(plr); 64 } 65 /* 66 * This routine deletes property from the list. 67 */ 68 del_list(plr, head, op_sqr) 69 int plr; 70 OWN **head; 71 shrt op_sqr; { 72 73 reg int i; 74 reg OWN *op, *last_op; 75 76 switch (board[op_sqr].type) { 77 case PRPTY: 78 board[op_sqr].desc->mon_desc->num_own--; 79 break; 80 case RR: 81 play[plr].num_rr--; 82 break; 83 case UTIL: 84 play[plr].num_util--; 85 break; 86 } 87 last_op = NULL; 88 for (op = *head; op; op = op->next) 89 if (op->sqr == &board[op_sqr]) 90 break; 91 else 92 last_op = op; 93 if (last_op == NULL) 94 *head = op->next; 95 else { 96 last_op->next = op->next; 97 cfree(op); 98 } 99 } 100 /* 101 * This routine calculates the value for sorting of the 102 * given square. 103 */ 104 value(sqp) 105 reg SQUARE *sqp; { 106 107 reg int sqr; 108 109 sqr = sqnum(sqp); 110 switch (sqp->type) { 111 case SAFE: 112 return 0; 113 default: /* Specials, etc */ 114 return 1; 115 case UTIL: 116 if (sqr == 12) 117 return 2; 118 else 119 return 3; 120 case RR: 121 return 4 + sqr/10; 122 case PRPTY: 123 return 8 + (sqp->desc) - prop; 124 } 125 } 126 /* 127 * This routine accepts bids for the current peice 128 * of property. 129 */ 130 bid() { 131 132 static bool in[MAX_PL]; 133 reg int i, num_in, cur_max; 134 char buf[80]; 135 int cur_bid; 136 137 printf("\nSo it goes up for auction. Type your bid after your name\n"); 138 for (i = 0; i < num_play; i++) 139 in[i] = TRUE; 140 i = -1; 141 cur_max = 0; 142 num_in = num_play; 143 while (num_in > 1 || (cur_max == 0 && num_in > 0)) { 144 i = ++i % num_play; 145 if (in[i]) { 146 do { 147 (void)sprintf(buf, "%s: ", name_list[i]); 148 cur_bid = get_int(buf); 149 if (cur_bid == 0) { 150 in[i] = FALSE; 151 if (--num_in == 0) 152 break; 153 } 154 else if (cur_bid <= cur_max) { 155 printf("You must bid higher than %d to stay in\n", cur_max); 156 printf("(bid of 0 drops you out)\n"); 157 } 158 } while (cur_bid != 0 && cur_bid <= cur_max); 159 cur_max = (cur_bid ? cur_bid : cur_max); 160 } 161 } 162 if (cur_max != 0) { 163 while (!in[i]) 164 i = ++i % num_play; 165 printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max); 166 buy(i, &board[cur_p->loc]); 167 play[i].money -= cur_max; 168 } 169 else 170 printf("Nobody seems to want it, so we'll leave it for later\n"); 171 } 172 /* 173 * This routine calculates the value of the property 174 * of given player. 175 */ 176 prop_worth(plp) 177 reg PLAY *plp; { 178 179 reg OWN *op; 180 reg int worth; 181 182 worth = 0; 183 for (op = plp->own_list; op; op = op->next) { 184 if (op->sqr->type == PRPTY && op->sqr->desc->monop) 185 worth += op->sqr->desc->mon_desc->h_cost * 50 * 186 op->sqr->desc->houses; 187 worth += op->sqr->cost; 188 } 189 return worth; 190 } 191