xref: /csrg-svn/games/monop/prop.c (revision 33216)
133202Sbostic /*
233202Sbostic  * Copyright (c) 1987 Regents of the University of California.
333202Sbostic  * All rights reserved.
433202Sbostic  *
533202Sbostic  * Redistribution and use in source and binary forms are permitted
633202Sbostic  * provided that this notice is preserved and that due credit is given
733202Sbostic  * to the University of California at Berkeley. The name of the University
833202Sbostic  * may not be used to endorse or promote products derived from this
933202Sbostic  * software without specific prior written permission. This software
1033202Sbostic  * is provided ``as is'' without express or implied warranty.
1133202Sbostic  */
1233202Sbostic 
1332479Sbostic #ifndef lint
14*33216Sbostic static char sccsid[] = "@(#)prop.c	5.4 (Berkeley) 01/02/88";
1533202Sbostic #endif /* not lint */
1632479Sbostic 
1732479Sbostic # include	"monop.ext"
1832479Sbostic 
19*33216Sbostic extern char *calloc();
20*33216Sbostic 
2132479Sbostic /*
2232479Sbostic  *	This routine deals with buying property, setting all the
2332479Sbostic  * appropriate flags.
2432479Sbostic  */
2532479Sbostic buy(player, sqrp)
2632479Sbostic reg int		player;
2732479Sbostic reg SQUARE	*sqrp; {
2832479Sbostic 
2932479Sbostic 	trading = FALSE;
3032479Sbostic 	sqrp->owner = player;
3132479Sbostic 	add_list(player, &(play[player].own_list), cur_p->loc);
3232479Sbostic }
3332479Sbostic /*
3432479Sbostic  *	This routine adds an item to the list.
3532479Sbostic  */
3632479Sbostic add_list(plr, head, op_sqr)
3732479Sbostic int	plr;
3832479Sbostic OWN	**head;
3932479Sbostic int	op_sqr; {
4032479Sbostic 
4132479Sbostic 	reg int	val;
4232479Sbostic 	reg OWN	*tp, *last_tp;
4332479Sbostic 	MON	*mp;
4432479Sbostic 	OWN	*op;
4532479Sbostic 
46*33216Sbostic 	op = (OWN *)calloc(1, sizeof (OWN));
4732479Sbostic 	op->sqr = &board[op_sqr];
4832479Sbostic 	val = value(op->sqr);
4932479Sbostic 	last_tp = NULL;
5032479Sbostic 	for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
5132479Sbostic 		if (val == value(tp->sqr)) {
5232479Sbostic 			cfree(op);
5332479Sbostic 			return;
5432479Sbostic 		}
5532479Sbostic 		else
5632479Sbostic 			last_tp = tp;
5732479Sbostic 	op->next = tp;
5832479Sbostic 	if (last_tp != NULL)
5932479Sbostic 		last_tp->next = op;
6032479Sbostic 	else
6132479Sbostic 		*head = op;
6232479Sbostic 	if (!trading)
6332479Sbostic 		set_ownlist(plr);
6432479Sbostic }
6532479Sbostic /*
6632479Sbostic  *	This routine deletes property from the list.
6732479Sbostic  */
6832479Sbostic del_list(plr, head, op_sqr)
6932479Sbostic int	plr;
7032479Sbostic OWN	**head;
7132479Sbostic shrt	op_sqr; {
7232479Sbostic 
7332479Sbostic 	reg int	i;
7432479Sbostic 	reg OWN	*op, *last_op;
7532479Sbostic 
7632479Sbostic 	switch (board[op_sqr].type) {
7732479Sbostic 	  case PRPTY:
7832479Sbostic 		board[op_sqr].desc->mon_desc->num_own--;
7932479Sbostic 		break;
8032479Sbostic 	  case RR:
8132479Sbostic 		play[plr].num_rr--;
8232479Sbostic 		break;
8332479Sbostic 	  case UTIL:
8432479Sbostic 		play[plr].num_util--;
8532479Sbostic 		break;
8632479Sbostic 	}
8732479Sbostic 	last_op = NULL;
8832479Sbostic 	for (op = *head; op; op = op->next)
8932479Sbostic 		if (op->sqr == &board[op_sqr])
9032479Sbostic 			break;
9132479Sbostic 		else
9232479Sbostic 			last_op = op;
9332479Sbostic 	if (last_op == NULL)
9432479Sbostic 		*head = op->next;
9532479Sbostic 	else {
9632479Sbostic 		last_op->next = op->next;
9732479Sbostic 		cfree(op);
9832479Sbostic 	}
9932479Sbostic }
10032479Sbostic /*
10132479Sbostic  *	This routine calculates the value for sorting of the
10232479Sbostic  * given square.
10332479Sbostic  */
10432479Sbostic value(sqp)
10532479Sbostic reg SQUARE	*sqp; {
10632479Sbostic 
10732479Sbostic 	reg int	sqr;
10832479Sbostic 
10932479Sbostic 	sqr = sqnum(sqp);
11032479Sbostic 	switch (sqp->type) {
11132479Sbostic 	  case SAFE:
11232479Sbostic 		return 0;
113*33216Sbostic 	  default:		/* Specials, etc */
11432479Sbostic 		return 1;
11532479Sbostic 	  case UTIL:
11632479Sbostic 		if (sqr == 12)
11732479Sbostic 			return 2;
11832479Sbostic 		else
11932479Sbostic 			return 3;
12032479Sbostic 	  case RR:
12132479Sbostic 		return 4 + sqr/10;
12232479Sbostic 	  case PRPTY:
123*33216Sbostic 		return 8 + (sqp->desc) - prop;
12432479Sbostic 	}
12532479Sbostic }
12632479Sbostic /*
12732479Sbostic  *	This routine accepts bids for the current peice
12832479Sbostic  * of property.
12932479Sbostic  */
13032479Sbostic bid() {
13132479Sbostic 
13232479Sbostic 	static bool	in[MAX_PL];
13332479Sbostic 	reg int		i, num_in, cur_max;
13432479Sbostic 	char		buf[80];
13532479Sbostic 	int		cur_bid;
13632479Sbostic 
13732479Sbostic 	printf("\nSo it goes up for auction.  Type your bid after your name\n");
13832479Sbostic 	for (i = 0; i < num_play; i++)
13932479Sbostic 		in[i] = TRUE;
14032479Sbostic 	i = -1;
14132479Sbostic 	cur_max = 0;
14232479Sbostic 	num_in = num_play;
14332479Sbostic 	while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
14432479Sbostic 		i = ++i % num_play;
14532479Sbostic 		if (in[i]) {
14632479Sbostic 			do {
14732480Sbostic 				(void)sprintf(buf, "%s: ", name_list[i]);
14832479Sbostic 				cur_bid = get_int(buf);
14932479Sbostic 				if (cur_bid == 0) {
15032479Sbostic 					in[i] = FALSE;
15132479Sbostic 					if (--num_in == 0)
15232479Sbostic 						break;
15332479Sbostic 				}
15432479Sbostic 				else if (cur_bid <= cur_max) {
15532479Sbostic 					printf("You must bid higher than %d to stay in\n", cur_max);
15632479Sbostic 					printf("(bid of 0 drops you out)\n");
15732479Sbostic 				}
15832479Sbostic 			} while (cur_bid != 0 && cur_bid <= cur_max);
15932479Sbostic 			cur_max = (cur_bid ? cur_bid : cur_max);
16032479Sbostic 		}
16132479Sbostic 	}
16232479Sbostic 	if (cur_max != 0) {
16332479Sbostic 		while (!in[i])
16432479Sbostic 			i = ++i % num_play;
16532479Sbostic 		printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
16632479Sbostic 		buy(i, &board[cur_p->loc]);
16732479Sbostic 		play[i].money -= cur_max;
16832479Sbostic 	}
16932479Sbostic 	else
17032479Sbostic 		printf("Nobody seems to want it, so we'll leave it for later\n");
17132479Sbostic }
17232479Sbostic /*
17332479Sbostic  *	This routine calculates the value of the property
17432479Sbostic  * of given player.
17532479Sbostic  */
17632479Sbostic prop_worth(plp)
17732479Sbostic reg PLAY	*plp; {
17832479Sbostic 
17932479Sbostic 	reg OWN	*op;
18032479Sbostic 	reg int	worth;
18132479Sbostic 
18232479Sbostic 	worth = 0;
18332479Sbostic 	for (op = plp->own_list; op; op = op->next) {
18432479Sbostic 		if (op->sqr->type == PRPTY && op->sqr->desc->monop)
18532479Sbostic 			worth += op->sqr->desc->mon_desc->h_cost * 50 *
18632479Sbostic 			    op->sqr->desc->houses;
18732479Sbostic 		worth += op->sqr->cost;
18832479Sbostic 	}
18932479Sbostic 	return worth;
19032479Sbostic }
191