Home | History | Annotate | Line # | Download | only in monop
prop.c revision 1.2
      1 /*
      2  * Copyright (c) 1980 Regents of the University of California.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #ifndef lint
     35 /*static char sccsid[] = "from: @(#)prop.c	5.6 (Berkeley) 6/1/90";*/
     36 static char rcsid[] = "$Id: prop.c,v 1.2 1993/08/01 18:53:33 mycroft Exp $";
     37 #endif /* not lint */
     38 
     39 # include	"monop.ext"
     40 
     41 extern char *calloc();
     42 
     43 /*
     44  *	This routine deals with buying property, setting all the
     45  * appropriate flags.
     46  */
     47 buy(player, sqrp)
     48 reg int		player;
     49 reg SQUARE	*sqrp; {
     50 
     51 	trading = FALSE;
     52 	sqrp->owner = player;
     53 	add_list(player, &(play[player].own_list), cur_p->loc);
     54 }
     55 /*
     56  *	This routine adds an item to the list.
     57  */
     58 add_list(plr, head, op_sqr)
     59 int	plr;
     60 OWN	**head;
     61 int	op_sqr; {
     62 
     63 	reg int	val;
     64 	reg OWN	*tp, *last_tp;
     65 	MON	*mp;
     66 	OWN	*op;
     67 
     68 	op = (OWN *)calloc(1, sizeof (OWN));
     69 	op->sqr = &board[op_sqr];
     70 	val = value(op->sqr);
     71 	last_tp = NULL;
     72 	for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
     73 		if (val == value(tp->sqr)) {
     74 			cfree(op);
     75 			return;
     76 		}
     77 		else
     78 			last_tp = tp;
     79 	op->next = tp;
     80 	if (last_tp != NULL)
     81 		last_tp->next = op;
     82 	else
     83 		*head = op;
     84 	if (!trading)
     85 		set_ownlist(plr);
     86 }
     87 /*
     88  *	This routine deletes property from the list.
     89  */
     90 del_list(plr, head, op_sqr)
     91 int	plr;
     92 OWN	**head;
     93 shrt	op_sqr; {
     94 
     95 	reg int	i;
     96 	reg OWN	*op, *last_op;
     97 
     98 	switch (board[op_sqr].type) {
     99 	  case PRPTY:
    100 		board[op_sqr].desc->mon_desc->num_own--;
    101 		break;
    102 	  case RR:
    103 		play[plr].num_rr--;
    104 		break;
    105 	  case UTIL:
    106 		play[plr].num_util--;
    107 		break;
    108 	}
    109 	last_op = NULL;
    110 	for (op = *head; op; op = op->next)
    111 		if (op->sqr == &board[op_sqr])
    112 			break;
    113 		else
    114 			last_op = op;
    115 	if (last_op == NULL)
    116 		*head = op->next;
    117 	else {
    118 		last_op->next = op->next;
    119 		cfree(op);
    120 	}
    121 }
    122 /*
    123  *	This routine calculates the value for sorting of the
    124  * given square.
    125  */
    126 value(sqp)
    127 reg SQUARE	*sqp; {
    128 
    129 	reg int	sqr;
    130 
    131 	sqr = sqnum(sqp);
    132 	switch (sqp->type) {
    133 	  case SAFE:
    134 		return 0;
    135 	  default:		/* Specials, etc */
    136 		return 1;
    137 	  case UTIL:
    138 		if (sqr == 12)
    139 			return 2;
    140 		else
    141 			return 3;
    142 	  case RR:
    143 		return 4 + sqr/10;
    144 	  case PRPTY:
    145 		return 8 + (sqp->desc) - prop;
    146 	}
    147 }
    148 /*
    149  *	This routine accepts bids for the current peice
    150  * of property.
    151  */
    152 bid() {
    153 
    154 	static bool	in[MAX_PL];
    155 	reg int		i, num_in, cur_max;
    156 	char		buf[80];
    157 	int		cur_bid;
    158 
    159 	printf("\nSo it goes up for auction.  Type your bid after your name\n");
    160 	for (i = 0; i < num_play; i++)
    161 		in[i] = TRUE;
    162 	i = -1;
    163 	cur_max = 0;
    164 	num_in = num_play;
    165 	while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
    166 		i = ++i % num_play;
    167 		if (in[i]) {
    168 			do {
    169 				(void)sprintf(buf, "%s: ", name_list[i]);
    170 				cur_bid = get_int(buf);
    171 				if (cur_bid == 0) {
    172 					in[i] = FALSE;
    173 					if (--num_in == 0)
    174 						break;
    175 				}
    176 				else if (cur_bid <= cur_max) {
    177 					printf("You must bid higher than %d to stay in\n", cur_max);
    178 					printf("(bid of 0 drops you out)\n");
    179 				}
    180 			} while (cur_bid != 0 && cur_bid <= cur_max);
    181 			cur_max = (cur_bid ? cur_bid : cur_max);
    182 		}
    183 	}
    184 	if (cur_max != 0) {
    185 		while (!in[i])
    186 			i = ++i % num_play;
    187 		printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
    188 		buy(i, &board[cur_p->loc]);
    189 		play[i].money -= cur_max;
    190 	}
    191 	else
    192 		printf("Nobody seems to want it, so we'll leave it for later\n");
    193 }
    194 /*
    195  *	This routine calculates the value of the property
    196  * of given player.
    197  */
    198 prop_worth(plp)
    199 reg PLAY	*plp; {
    200 
    201 	reg OWN	*op;
    202 	reg int	worth;
    203 
    204 	worth = 0;
    205 	for (op = plp->own_list; op; op = op->next) {
    206 		if (op->sqr->type == PRPTY && op->sqr->desc->monop)
    207 			worth += op->sqr->desc->mon_desc->h_cost * 50 *
    208 			    op->sqr->desc->houses;
    209 		worth += op->sqr->cost;
    210 	}
    211 	return worth;
    212 }
    213