xref: /original-bsd/games/monop/prop.c (revision 7a8f01dc)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)prop.c	5.6 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 # include	"monop.ext"
13 
14 extern char *calloc();
15 
16 /*
17  *	This routine deals with buying property, setting all the
18  * appropriate flags.
19  */
20 buy(player, sqrp)
21 reg int		player;
22 reg SQUARE	*sqrp; {
23 
24 	trading = FALSE;
25 	sqrp->owner = player;
26 	add_list(player, &(play[player].own_list), cur_p->loc);
27 }
28 /*
29  *	This routine adds an item to the list.
30  */
31 add_list(plr, head, op_sqr)
32 int	plr;
33 OWN	**head;
34 int	op_sqr; {
35 
36 	reg int	val;
37 	reg OWN	*tp, *last_tp;
38 	MON	*mp;
39 	OWN	*op;
40 
41 	op = (OWN *)calloc(1, sizeof (OWN));
42 	op->sqr = &board[op_sqr];
43 	val = value(op->sqr);
44 	last_tp = NULL;
45 	for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
46 		if (val == value(tp->sqr)) {
47 			cfree(op);
48 			return;
49 		}
50 		else
51 			last_tp = tp;
52 	op->next = tp;
53 	if (last_tp != NULL)
54 		last_tp->next = op;
55 	else
56 		*head = op;
57 	if (!trading)
58 		set_ownlist(plr);
59 }
60 /*
61  *	This routine deletes property from the list.
62  */
63 del_list(plr, head, op_sqr)
64 int	plr;
65 OWN	**head;
66 shrt	op_sqr; {
67 
68 	reg int	i;
69 	reg OWN	*op, *last_op;
70 
71 	switch (board[op_sqr].type) {
72 	  case PRPTY:
73 		board[op_sqr].desc->mon_desc->num_own--;
74 		break;
75 	  case RR:
76 		play[plr].num_rr--;
77 		break;
78 	  case UTIL:
79 		play[plr].num_util--;
80 		break;
81 	}
82 	last_op = NULL;
83 	for (op = *head; op; op = op->next)
84 		if (op->sqr == &board[op_sqr])
85 			break;
86 		else
87 			last_op = op;
88 	if (last_op == NULL)
89 		*head = op->next;
90 	else {
91 		last_op->next = op->next;
92 		cfree(op);
93 	}
94 }
95 /*
96  *	This routine calculates the value for sorting of the
97  * given square.
98  */
99 value(sqp)
100 reg SQUARE	*sqp; {
101 
102 	reg int	sqr;
103 
104 	sqr = sqnum(sqp);
105 	switch (sqp->type) {
106 	  case SAFE:
107 		return 0;
108 	  default:		/* Specials, etc */
109 		return 1;
110 	  case UTIL:
111 		if (sqr == 12)
112 			return 2;
113 		else
114 			return 3;
115 	  case RR:
116 		return 4 + sqr/10;
117 	  case PRPTY:
118 		return 8 + (sqp->desc) - prop;
119 	}
120 }
121 /*
122  *	This routine accepts bids for the current peice
123  * of property.
124  */
125 bid() {
126 
127 	static bool	in[MAX_PL];
128 	reg int		i, num_in, cur_max;
129 	char		buf[80];
130 	int		cur_bid;
131 
132 	printf("\nSo it goes up for auction.  Type your bid after your name\n");
133 	for (i = 0; i < num_play; i++)
134 		in[i] = TRUE;
135 	i = -1;
136 	cur_max = 0;
137 	num_in = num_play;
138 	while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
139 		i = ++i % num_play;
140 		if (in[i]) {
141 			do {
142 				(void)sprintf(buf, "%s: ", name_list[i]);
143 				cur_bid = get_int(buf);
144 				if (cur_bid == 0) {
145 					in[i] = FALSE;
146 					if (--num_in == 0)
147 						break;
148 				}
149 				else if (cur_bid <= cur_max) {
150 					printf("You must bid higher than %d to stay in\n", cur_max);
151 					printf("(bid of 0 drops you out)\n");
152 				}
153 			} while (cur_bid != 0 && cur_bid <= cur_max);
154 			cur_max = (cur_bid ? cur_bid : cur_max);
155 		}
156 	}
157 	if (cur_max != 0) {
158 		while (!in[i])
159 			i = ++i % num_play;
160 		printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
161 		buy(i, &board[cur_p->loc]);
162 		play[i].money -= cur_max;
163 	}
164 	else
165 		printf("Nobody seems to want it, so we'll leave it for later\n");
166 }
167 /*
168  *	This routine calculates the value of the property
169  * of given player.
170  */
171 prop_worth(plp)
172 reg PLAY	*plp; {
173 
174 	reg OWN	*op;
175 	reg int	worth;
176 
177 	worth = 0;
178 	for (op = plp->own_list; op; op = op->next) {
179 		if (op->sqr->type == PRPTY && op->sqr->desc->monop)
180 			worth += op->sqr->desc->mon_desc->h_cost * 50 *
181 			    op->sqr->desc->houses;
182 		worth += op->sqr->cost;
183 	}
184 	return worth;
185 }
186