133202Sbostic /* 2*34788Sbostic * Copyright (c) 1980 Regents of the University of California. 333202Sbostic * All rights reserved. 433202Sbostic * 533202Sbostic * Redistribution and use in source and binary forms are permitted 6*34788Sbostic * provided that the above copyright notice and this paragraph are 7*34788Sbostic * duplicated in all such forms and that any documentation, 8*34788Sbostic * advertising materials, and other materials related to such 9*34788Sbostic * distribution and use acknowledge that the software was developed 10*34788Sbostic * by the University of California, Berkeley. The name of the 11*34788Sbostic * University may not be used to endorse or promote products derived 12*34788Sbostic * from this software without specific prior written permission. 13*34788Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34788Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34788Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1633202Sbostic */ 1733202Sbostic 1832479Sbostic #ifndef lint 19*34788Sbostic static char sccsid[] = "@(#)prop.c 5.5 (Berkeley) 06/18/88"; 2033202Sbostic #endif /* not lint */ 2132479Sbostic 2232479Sbostic # include "monop.ext" 2332479Sbostic 2433216Sbostic extern char *calloc(); 2533216Sbostic 2632479Sbostic /* 2732479Sbostic * This routine deals with buying property, setting all the 2832479Sbostic * appropriate flags. 2932479Sbostic */ 3032479Sbostic buy(player, sqrp) 3132479Sbostic reg int player; 3232479Sbostic reg SQUARE *sqrp; { 3332479Sbostic 3432479Sbostic trading = FALSE; 3532479Sbostic sqrp->owner = player; 3632479Sbostic add_list(player, &(play[player].own_list), cur_p->loc); 3732479Sbostic } 3832479Sbostic /* 3932479Sbostic * This routine adds an item to the list. 4032479Sbostic */ 4132479Sbostic add_list(plr, head, op_sqr) 4232479Sbostic int plr; 4332479Sbostic OWN **head; 4432479Sbostic int op_sqr; { 4532479Sbostic 4632479Sbostic reg int val; 4732479Sbostic reg OWN *tp, *last_tp; 4832479Sbostic MON *mp; 4932479Sbostic OWN *op; 5032479Sbostic 5133216Sbostic op = (OWN *)calloc(1, sizeof (OWN)); 5232479Sbostic op->sqr = &board[op_sqr]; 5332479Sbostic val = value(op->sqr); 5432479Sbostic last_tp = NULL; 5532479Sbostic for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next) 5632479Sbostic if (val == value(tp->sqr)) { 5732479Sbostic cfree(op); 5832479Sbostic return; 5932479Sbostic } 6032479Sbostic else 6132479Sbostic last_tp = tp; 6232479Sbostic op->next = tp; 6332479Sbostic if (last_tp != NULL) 6432479Sbostic last_tp->next = op; 6532479Sbostic else 6632479Sbostic *head = op; 6732479Sbostic if (!trading) 6832479Sbostic set_ownlist(plr); 6932479Sbostic } 7032479Sbostic /* 7132479Sbostic * This routine deletes property from the list. 7232479Sbostic */ 7332479Sbostic del_list(plr, head, op_sqr) 7432479Sbostic int plr; 7532479Sbostic OWN **head; 7632479Sbostic shrt op_sqr; { 7732479Sbostic 7832479Sbostic reg int i; 7932479Sbostic reg OWN *op, *last_op; 8032479Sbostic 8132479Sbostic switch (board[op_sqr].type) { 8232479Sbostic case PRPTY: 8332479Sbostic board[op_sqr].desc->mon_desc->num_own--; 8432479Sbostic break; 8532479Sbostic case RR: 8632479Sbostic play[plr].num_rr--; 8732479Sbostic break; 8832479Sbostic case UTIL: 8932479Sbostic play[plr].num_util--; 9032479Sbostic break; 9132479Sbostic } 9232479Sbostic last_op = NULL; 9332479Sbostic for (op = *head; op; op = op->next) 9432479Sbostic if (op->sqr == &board[op_sqr]) 9532479Sbostic break; 9632479Sbostic else 9732479Sbostic last_op = op; 9832479Sbostic if (last_op == NULL) 9932479Sbostic *head = op->next; 10032479Sbostic else { 10132479Sbostic last_op->next = op->next; 10232479Sbostic cfree(op); 10332479Sbostic } 10432479Sbostic } 10532479Sbostic /* 10632479Sbostic * This routine calculates the value for sorting of the 10732479Sbostic * given square. 10832479Sbostic */ 10932479Sbostic value(sqp) 11032479Sbostic reg SQUARE *sqp; { 11132479Sbostic 11232479Sbostic reg int sqr; 11332479Sbostic 11432479Sbostic sqr = sqnum(sqp); 11532479Sbostic switch (sqp->type) { 11632479Sbostic case SAFE: 11732479Sbostic return 0; 11833216Sbostic default: /* Specials, etc */ 11932479Sbostic return 1; 12032479Sbostic case UTIL: 12132479Sbostic if (sqr == 12) 12232479Sbostic return 2; 12332479Sbostic else 12432479Sbostic return 3; 12532479Sbostic case RR: 12632479Sbostic return 4 + sqr/10; 12732479Sbostic case PRPTY: 12833216Sbostic return 8 + (sqp->desc) - prop; 12932479Sbostic } 13032479Sbostic } 13132479Sbostic /* 13232479Sbostic * This routine accepts bids for the current peice 13332479Sbostic * of property. 13432479Sbostic */ 13532479Sbostic bid() { 13632479Sbostic 13732479Sbostic static bool in[MAX_PL]; 13832479Sbostic reg int i, num_in, cur_max; 13932479Sbostic char buf[80]; 14032479Sbostic int cur_bid; 14132479Sbostic 14232479Sbostic printf("\nSo it goes up for auction. Type your bid after your name\n"); 14332479Sbostic for (i = 0; i < num_play; i++) 14432479Sbostic in[i] = TRUE; 14532479Sbostic i = -1; 14632479Sbostic cur_max = 0; 14732479Sbostic num_in = num_play; 14832479Sbostic while (num_in > 1 || (cur_max == 0 && num_in > 0)) { 14932479Sbostic i = ++i % num_play; 15032479Sbostic if (in[i]) { 15132479Sbostic do { 15232480Sbostic (void)sprintf(buf, "%s: ", name_list[i]); 15332479Sbostic cur_bid = get_int(buf); 15432479Sbostic if (cur_bid == 0) { 15532479Sbostic in[i] = FALSE; 15632479Sbostic if (--num_in == 0) 15732479Sbostic break; 15832479Sbostic } 15932479Sbostic else if (cur_bid <= cur_max) { 16032479Sbostic printf("You must bid higher than %d to stay in\n", cur_max); 16132479Sbostic printf("(bid of 0 drops you out)\n"); 16232479Sbostic } 16332479Sbostic } while (cur_bid != 0 && cur_bid <= cur_max); 16432479Sbostic cur_max = (cur_bid ? cur_bid : cur_max); 16532479Sbostic } 16632479Sbostic } 16732479Sbostic if (cur_max != 0) { 16832479Sbostic while (!in[i]) 16932479Sbostic i = ++i % num_play; 17032479Sbostic printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max); 17132479Sbostic buy(i, &board[cur_p->loc]); 17232479Sbostic play[i].money -= cur_max; 17332479Sbostic } 17432479Sbostic else 17532479Sbostic printf("Nobody seems to want it, so we'll leave it for later\n"); 17632479Sbostic } 17732479Sbostic /* 17832479Sbostic * This routine calculates the value of the property 17932479Sbostic * of given player. 18032479Sbostic */ 18132479Sbostic prop_worth(plp) 18232479Sbostic reg PLAY *plp; { 18332479Sbostic 18432479Sbostic reg OWN *op; 18532479Sbostic reg int worth; 18632479Sbostic 18732479Sbostic worth = 0; 18832479Sbostic for (op = plp->own_list; op; op = op->next) { 18932479Sbostic if (op->sqr->type == PRPTY && op->sqr->desc->monop) 19032479Sbostic worth += op->sqr->desc->mon_desc->h_cost * 50 * 19132479Sbostic op->sqr->desc->houses; 19232479Sbostic worth += op->sqr->cost; 19332479Sbostic } 19432479Sbostic return worth; 19532479Sbostic } 196