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