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