Home | History | Annotate | Line # | Download | only in monop
houses.c revision 1.1
      1  1.1  cgd /*
      2  1.1  cgd  * Copyright (c) 1980 Regents of the University of California.
      3  1.1  cgd  * All rights reserved.
      4  1.1  cgd  *
      5  1.1  cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1  cgd  * modification, are permitted provided that the following conditions
      7  1.1  cgd  * are met:
      8  1.1  cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1  cgd  *    must display the following acknowledgement:
     15  1.1  cgd  *	This product includes software developed by the University of
     16  1.1  cgd  *	California, Berkeley and its contributors.
     17  1.1  cgd  * 4. Neither the name of the University nor the names of its contributors
     18  1.1  cgd  *    may be used to endorse or promote products derived from this software
     19  1.1  cgd  *    without specific prior written permission.
     20  1.1  cgd  *
     21  1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  cgd  * SUCH DAMAGE.
     32  1.1  cgd  */
     33  1.1  cgd 
     34  1.1  cgd #ifndef lint
     35  1.1  cgd static char sccsid[] = "@(#)houses.c	5.5 (Berkeley) 6/1/90";
     36  1.1  cgd #endif /* not lint */
     37  1.1  cgd 
     38  1.1  cgd # include	"monop.ext"
     39  1.1  cgd 
     40  1.1  cgd static char	*names[N_MON+2],
     41  1.1  cgd 		cur_prop[80];
     42  1.1  cgd 
     43  1.1  cgd static MON	*monops[N_MON];
     44  1.1  cgd 
     45  1.1  cgd /*
     46  1.1  cgd  *	These routines deal with buying and selling houses
     47  1.1  cgd  */
     48  1.1  cgd buy_houses() {
     49  1.1  cgd 
     50  1.1  cgd 	reg int num_mon;
     51  1.1  cgd 	reg MON	*mp;
     52  1.1  cgd 	reg OWN	*op;
     53  1.1  cgd 	bool	good,got_morg;
     54  1.1  cgd 	int	i,p;
     55  1.1  cgd 
     56  1.1  cgd over:
     57  1.1  cgd 	num_mon = 0;
     58  1.1  cgd 	good = TRUE;
     59  1.1  cgd 	got_morg = FALSE;
     60  1.1  cgd 	for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
     61  1.1  cgd 		continue;
     62  1.1  cgd 	while (op)
     63  1.1  cgd 		if (op->sqr->desc->monop) {
     64  1.1  cgd 			mp = op->sqr->desc->mon_desc;
     65  1.1  cgd 			names[num_mon] = (monops[num_mon]=mp)->name;
     66  1.1  cgd 			num_mon++;
     67  1.1  cgd 			got_morg = good = FALSE;
     68  1.1  cgd 			for (i = 0; i < mp->num_in; i++) {
     69  1.1  cgd 				if (op->sqr->desc->morg)
     70  1.1  cgd 					got_morg++;
     71  1.1  cgd 				if (op->sqr->desc->houses != 5)
     72  1.1  cgd 					good++;
     73  1.1  cgd 				op = op->next;
     74  1.1  cgd 			}
     75  1.1  cgd 			if (!good || got_morg)
     76  1.1  cgd 				--num_mon;
     77  1.1  cgd 		}
     78  1.1  cgd 		else
     79  1.1  cgd 			op = op->next;
     80  1.1  cgd 	if (num_mon == 0) {
     81  1.1  cgd 		if (got_morg)
     82  1.1  cgd 			printf("You can't build on mortgaged monopolies.\n");
     83  1.1  cgd 		else if (!good)
     84  1.1  cgd 			printf("You can't build any more.\n");
     85  1.1  cgd 		else
     86  1.1  cgd 			printf("But you don't have any monopolies!!\n");
     87  1.1  cgd 		return;
     88  1.1  cgd 	}
     89  1.1  cgd 	if (num_mon == 1)
     90  1.1  cgd 		buy_h(monops[0]);
     91  1.1  cgd 	else {
     92  1.1  cgd 		names[num_mon++] = "done";
     93  1.1  cgd 		names[num_mon--] = 0;
     94  1.1  cgd 		if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
     95  1.1  cgd 			return;
     96  1.1  cgd 		buy_h(monops[p]);
     97  1.1  cgd 		goto over;
     98  1.1  cgd 	}
     99  1.1  cgd }
    100  1.1  cgd 
    101  1.1  cgd buy_h(mnp)
    102  1.1  cgd MON	*mnp; {
    103  1.1  cgd 
    104  1.1  cgd 	reg int	i;
    105  1.1  cgd 	reg MON	*mp;
    106  1.1  cgd 	reg int	price;
    107  1.1  cgd 	shrt	input[3],temp[3];
    108  1.1  cgd 	int	tot;
    109  1.1  cgd 	PROP	*pp;
    110  1.1  cgd 
    111  1.1  cgd 	mp = mnp;
    112  1.1  cgd 	price = mp->h_cost * 50;
    113  1.1  cgd blew_it:
    114  1.1  cgd 	list_cur(mp);
    115  1.1  cgd 	printf("Houses will cost $%d\n", price);
    116  1.1  cgd 	printf("How many houses do you wish to buy for\n");
    117  1.1  cgd 	for (i = 0; i < mp->num_in; i++) {
    118  1.1  cgd 		pp = mp->sq[i]->desc;
    119  1.1  cgd over:
    120  1.1  cgd 		if (pp->houses == 5) {
    121  1.1  cgd 			printf("%s (H):\n", mp->sq[i]->name);
    122  1.1  cgd 			input[i] = 0;
    123  1.1  cgd 			temp[i] = 5;
    124  1.1  cgd 			continue;
    125  1.1  cgd 		}
    126  1.1  cgd 		(void)sprintf(cur_prop, "%s (%d): ",
    127  1.1  cgd 			mp->sq[i]->name, pp->houses);
    128  1.1  cgd 		input[i] = get_int(cur_prop);
    129  1.1  cgd 		temp[i] = input[i] + pp->houses;
    130  1.1  cgd 		if (temp[i] > 5) {
    131  1.1  cgd 			printf("That's too many.  The most you can buy is %d\n",
    132  1.1  cgd 				5 - pp->houses);
    133  1.1  cgd 				goto over;
    134  1.1  cgd 			}
    135  1.1  cgd 	}
    136  1.1  cgd 	if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
    137  1.1  cgd 	    abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
    138  1.1  cgd err:		printf("That makes the spread too wide.  Try again\n");
    139  1.1  cgd 		goto blew_it;
    140  1.1  cgd 	}
    141  1.1  cgd 	else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
    142  1.1  cgd 		goto err;
    143  1.1  cgd 	for (tot = i = 0; i < mp->num_in; i++)
    144  1.1  cgd 		tot += input[i];
    145  1.1  cgd 	if (tot) {
    146  1.1  cgd 		printf("You asked for %d houses for $%d\n", tot, tot * price);
    147  1.1  cgd 		if (getyn("Is that ok? ", yn) == 0) {
    148  1.1  cgd 			cur_p->money -= tot * price;
    149  1.1  cgd 			for (tot = i = 0; i < mp->num_in; i++)
    150  1.1  cgd 				mp->sq[i]->desc->houses = temp[i];
    151  1.1  cgd 		}
    152  1.1  cgd 	}
    153  1.1  cgd }
    154  1.1  cgd 
    155  1.1  cgd /*
    156  1.1  cgd  *	This routine sells houses.
    157  1.1  cgd  */
    158  1.1  cgd sell_houses() {
    159  1.1  cgd 
    160  1.1  cgd 	reg int	num_mon;
    161  1.1  cgd 	reg MON	*mp;
    162  1.1  cgd 	reg OWN	*op;
    163  1.1  cgd 	bool	good;
    164  1.1  cgd 	int	p;
    165  1.1  cgd 
    166  1.1  cgd over:
    167  1.1  cgd 	num_mon = 0;
    168  1.1  cgd 	good = TRUE;
    169  1.1  cgd 	for (op = cur_p->own_list; op; op = op->next)
    170  1.1  cgd 		if (op->sqr->type == PRPTY && op->sqr->desc->monop) {
    171  1.1  cgd 			mp = op->sqr->desc->mon_desc;
    172  1.1  cgd 			names[num_mon] = (monops[num_mon]=mp)->name;
    173  1.1  cgd 			num_mon++;
    174  1.1  cgd 			good = 0;
    175  1.1  cgd 			do
    176  1.1  cgd 				if (!good && op->sqr->desc->houses != 0)
    177  1.1  cgd 					good++;
    178  1.1  cgd 			while (op->next && op->sqr->desc->mon_desc == mp
    179  1.1  cgd 			    && (op=op->next));
    180  1.1  cgd 			if (!good)
    181  1.1  cgd 				--num_mon;
    182  1.1  cgd 		}
    183  1.1  cgd 	if (num_mon == 0) {
    184  1.1  cgd 		printf("You don't have any houses to sell!!\n");
    185  1.1  cgd 		return;
    186  1.1  cgd 	}
    187  1.1  cgd 	if (num_mon == 1)
    188  1.1  cgd 		sell_h(monops[0]);
    189  1.1  cgd 	else {
    190  1.1  cgd 		names[num_mon++] = "done";
    191  1.1  cgd 		names[num_mon--] = 0;
    192  1.1  cgd 		if ((p=getinp("Which property do you wish to sell houses from? ", names)) == num_mon)
    193  1.1  cgd 			return;
    194  1.1  cgd 		sell_h(monops[p]);
    195  1.1  cgd 		notify();
    196  1.1  cgd 		goto over;
    197  1.1  cgd 	}
    198  1.1  cgd }
    199  1.1  cgd 
    200  1.1  cgd sell_h(mnp)
    201  1.1  cgd MON	*mnp; {
    202  1.1  cgd 
    203  1.1  cgd 	reg int	i;
    204  1.1  cgd 	reg MON	*mp;
    205  1.1  cgd 	reg int	price;
    206  1.1  cgd 	shrt	input[3],temp[3];
    207  1.1  cgd 	int	tot;
    208  1.1  cgd 	PROP	*pp;
    209  1.1  cgd 
    210  1.1  cgd 	mp = mnp;
    211  1.1  cgd 	price = mp->h_cost * 25;
    212  1.1  cgd blew_it:
    213  1.1  cgd 	printf("Houses will get you $%d apiece\n", price);
    214  1.1  cgd 	list_cur(mp);
    215  1.1  cgd 	printf("How many houses do you wish to sell from\n");
    216  1.1  cgd 	for (i = 0; i < mp->num_in; i++) {
    217  1.1  cgd 		pp = mp->sq[i]->desc;
    218  1.1  cgd over:
    219  1.1  cgd 		if (pp->houses == 0) {
    220  1.1  cgd 			printf("%s (0):\n", mp->sq[i]->name);
    221  1.1  cgd 			input[i] = temp[i] = 0;
    222  1.1  cgd 			continue;
    223  1.1  cgd 		}
    224  1.1  cgd 		if (pp->houses < 5)
    225  1.1  cgd 			(void)sprintf(cur_prop,"%s (%d): ",
    226  1.1  cgd 				mp->sq[i]->name,pp->houses);
    227  1.1  cgd 		else
    228  1.1  cgd 			(void)sprintf(cur_prop,"%s (H): ",mp->sq[i]->name);
    229  1.1  cgd 		input[i] = get_int(cur_prop);
    230  1.1  cgd 		temp[i] = pp->houses - input[i];
    231  1.1  cgd 		if (temp[i] < 0) {
    232  1.1  cgd 			printf("That's too many.  The most you can sell is %d\n", pp->houses);
    233  1.1  cgd 				goto over;
    234  1.1  cgd 			}
    235  1.1  cgd 	}
    236  1.1  cgd 	if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
    237  1.1  cgd 	    abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
    238  1.1  cgd err:		printf("That makes the spread too wide.  Try again\n");
    239  1.1  cgd 		goto blew_it;
    240  1.1  cgd 	}
    241  1.1  cgd 	else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
    242  1.1  cgd 		goto err;
    243  1.1  cgd 	for (tot = i = 0; i < mp->num_in; i++)
    244  1.1  cgd 		tot += input[i];
    245  1.1  cgd 	if (tot) {
    246  1.1  cgd 		printf("You asked to sell %d houses for $%d\n",tot,tot * price);
    247  1.1  cgd 		if (getyn("Is that ok? ", yn) == 0) {
    248  1.1  cgd 			cur_p->money += tot * price;
    249  1.1  cgd 			for (tot = i = 0; i < mp->num_in; i++)
    250  1.1  cgd 				mp->sq[i]->desc->houses = temp[i];
    251  1.1  cgd 		}
    252  1.1  cgd 	}
    253  1.1  cgd }
    254  1.1  cgd 
    255  1.1  cgd list_cur(mp)
    256  1.1  cgd reg MON	*mp; {
    257  1.1  cgd 
    258  1.1  cgd 	reg int		i;
    259  1.1  cgd 	reg SQUARE	*sqp;
    260  1.1  cgd 
    261  1.1  cgd 	for (i = 0; i < mp->num_in; i++) {
    262  1.1  cgd 		sqp = mp->sq[i];
    263  1.1  cgd 		if (sqp->desc->houses == 5)
    264  1.1  cgd 			printf("%s (H) ", sqp->name);
    265  1.1  cgd 		else
    266  1.1  cgd 			printf("%s (%d) ", sqp->name, sqp->desc->houses);
    267  1.1  cgd 	}
    268  1.1  cgd 	putchar('\n');
    269  1.1  cgd }
    270