133202Sbostic /*
2*60815Sbostic * Copyright (c) 1980, 1993
3*60815Sbostic * The Regents of the University of California. All rights reserved.
433202Sbostic *
542583Sbostic * %sccs.include.redist.c%
633202Sbostic */
733202Sbostic
832479Sbostic #ifndef lint
9*60815Sbostic static char sccsid[] = "@(#)prop.c 8.1 (Berkeley) 05/31/93";
1033202Sbostic #endif /* not lint */
1132479Sbostic
1232479Sbostic # include "monop.ext"
1332479Sbostic
1433216Sbostic extern char *calloc();
1533216Sbostic
1632479Sbostic /*
1732479Sbostic * This routine deals with buying property, setting all the
1832479Sbostic * appropriate flags.
1932479Sbostic */
buy(player,sqrp)2032479Sbostic buy(player, sqrp)
2132479Sbostic reg int player;
2232479Sbostic reg SQUARE *sqrp; {
2332479Sbostic
2432479Sbostic trading = FALSE;
2532479Sbostic sqrp->owner = player;
2632479Sbostic add_list(player, &(play[player].own_list), cur_p->loc);
2732479Sbostic }
2832479Sbostic /*
2932479Sbostic * This routine adds an item to the list.
3032479Sbostic */
add_list(plr,head,op_sqr)3132479Sbostic add_list(plr, head, op_sqr)
3232479Sbostic int plr;
3332479Sbostic OWN **head;
3432479Sbostic int op_sqr; {
3532479Sbostic
3632479Sbostic reg int val;
3732479Sbostic reg OWN *tp, *last_tp;
3832479Sbostic MON *mp;
3932479Sbostic OWN *op;
4032479Sbostic
4133216Sbostic op = (OWN *)calloc(1, sizeof (OWN));
4232479Sbostic op->sqr = &board[op_sqr];
4332479Sbostic val = value(op->sqr);
4432479Sbostic last_tp = NULL;
4532479Sbostic for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
4632479Sbostic if (val == value(tp->sqr)) {
4732479Sbostic cfree(op);
4832479Sbostic return;
4932479Sbostic }
5032479Sbostic else
5132479Sbostic last_tp = tp;
5232479Sbostic op->next = tp;
5332479Sbostic if (last_tp != NULL)
5432479Sbostic last_tp->next = op;
5532479Sbostic else
5632479Sbostic *head = op;
5732479Sbostic if (!trading)
5832479Sbostic set_ownlist(plr);
5932479Sbostic }
6032479Sbostic /*
6132479Sbostic * This routine deletes property from the list.
6232479Sbostic */
del_list(plr,head,op_sqr)6332479Sbostic del_list(plr, head, op_sqr)
6432479Sbostic int plr;
6532479Sbostic OWN **head;
6632479Sbostic shrt op_sqr; {
6732479Sbostic
6832479Sbostic reg int i;
6932479Sbostic reg OWN *op, *last_op;
7032479Sbostic
7132479Sbostic switch (board[op_sqr].type) {
7232479Sbostic case PRPTY:
7332479Sbostic board[op_sqr].desc->mon_desc->num_own--;
7432479Sbostic break;
7532479Sbostic case RR:
7632479Sbostic play[plr].num_rr--;
7732479Sbostic break;
7832479Sbostic case UTIL:
7932479Sbostic play[plr].num_util--;
8032479Sbostic break;
8132479Sbostic }
8232479Sbostic last_op = NULL;
8332479Sbostic for (op = *head; op; op = op->next)
8432479Sbostic if (op->sqr == &board[op_sqr])
8532479Sbostic break;
8632479Sbostic else
8732479Sbostic last_op = op;
8832479Sbostic if (last_op == NULL)
8932479Sbostic *head = op->next;
9032479Sbostic else {
9132479Sbostic last_op->next = op->next;
9232479Sbostic cfree(op);
9332479Sbostic }
9432479Sbostic }
9532479Sbostic /*
9632479Sbostic * This routine calculates the value for sorting of the
9732479Sbostic * given square.
9832479Sbostic */
value(sqp)9932479Sbostic value(sqp)
10032479Sbostic reg SQUARE *sqp; {
10132479Sbostic
10232479Sbostic reg int sqr;
10332479Sbostic
10432479Sbostic sqr = sqnum(sqp);
10532479Sbostic switch (sqp->type) {
10632479Sbostic case SAFE:
10732479Sbostic return 0;
10833216Sbostic default: /* Specials, etc */
10932479Sbostic return 1;
11032479Sbostic case UTIL:
11132479Sbostic if (sqr == 12)
11232479Sbostic return 2;
11332479Sbostic else
11432479Sbostic return 3;
11532479Sbostic case RR:
11632479Sbostic return 4 + sqr/10;
11732479Sbostic case PRPTY:
11833216Sbostic return 8 + (sqp->desc) - prop;
11932479Sbostic }
12032479Sbostic }
12132479Sbostic /*
12232479Sbostic * This routine accepts bids for the current peice
12332479Sbostic * of property.
12432479Sbostic */
bid()12532479Sbostic bid() {
12632479Sbostic
12732479Sbostic static bool in[MAX_PL];
12832479Sbostic reg int i, num_in, cur_max;
12932479Sbostic char buf[80];
13032479Sbostic int cur_bid;
13132479Sbostic
13232479Sbostic printf("\nSo it goes up for auction. Type your bid after your name\n");
13332479Sbostic for (i = 0; i < num_play; i++)
13432479Sbostic in[i] = TRUE;
13532479Sbostic i = -1;
13632479Sbostic cur_max = 0;
13732479Sbostic num_in = num_play;
13832479Sbostic while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
13932479Sbostic i = ++i % num_play;
14032479Sbostic if (in[i]) {
14132479Sbostic do {
14232480Sbostic (void)sprintf(buf, "%s: ", name_list[i]);
14332479Sbostic cur_bid = get_int(buf);
14432479Sbostic if (cur_bid == 0) {
14532479Sbostic in[i] = FALSE;
14632479Sbostic if (--num_in == 0)
14732479Sbostic break;
14832479Sbostic }
14932479Sbostic else if (cur_bid <= cur_max) {
15032479Sbostic printf("You must bid higher than %d to stay in\n", cur_max);
15132479Sbostic printf("(bid of 0 drops you out)\n");
15232479Sbostic }
15332479Sbostic } while (cur_bid != 0 && cur_bid <= cur_max);
15432479Sbostic cur_max = (cur_bid ? cur_bid : cur_max);
15532479Sbostic }
15632479Sbostic }
15732479Sbostic if (cur_max != 0) {
15832479Sbostic while (!in[i])
15932479Sbostic i = ++i % num_play;
16032479Sbostic printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
16132479Sbostic buy(i, &board[cur_p->loc]);
16232479Sbostic play[i].money -= cur_max;
16332479Sbostic }
16432479Sbostic else
16532479Sbostic printf("Nobody seems to want it, so we'll leave it for later\n");
16632479Sbostic }
16732479Sbostic /*
16832479Sbostic * This routine calculates the value of the property
16932479Sbostic * of given player.
17032479Sbostic */
prop_worth(plp)17132479Sbostic prop_worth(plp)
17232479Sbostic reg PLAY *plp; {
17332479Sbostic
17432479Sbostic reg OWN *op;
17532479Sbostic reg int worth;
17632479Sbostic
17732479Sbostic worth = 0;
17832479Sbostic for (op = plp->own_list; op; op = op->next) {
17932479Sbostic if (op->sqr->type == PRPTY && op->sqr->desc->monop)
18032479Sbostic worth += op->sqr->desc->mon_desc->h_cost * 50 *
18132479Sbostic op->sqr->desc->houses;
18232479Sbostic worth += op->sqr->cost;
18332479Sbostic }
18432479Sbostic return worth;
18532479Sbostic }
186