Home | History | Annotate | Line # | Download | only in monop
morg.c revision 1.1
      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[] = "@(#)morg.c	5.3 (Berkeley) 6/1/90";
     36 #endif /* not lint */
     37 
     38 # include	"monop.ext"
     39 
     40 /*
     41  *	These routines deal with mortgaging.
     42  */
     43 
     44 static char	*names[MAX_PRP+2],
     45 		*morg_coms[]	= {
     46 			"quit",		/*  0 */
     47 			"print",	/*  1 */
     48 			"where",	/*  2 */
     49 			"own holdings",	/*  3 */
     50 			"holdings",	/*  4 */
     51 			"shell",	/*  5 */
     52 			"mortgage",	/*  6 */
     53 			"unmortgage",	/*  7 */
     54 			"buy",		/*  8 */
     55 			"sell",		/*  9 */
     56 			"card",		/* 10 */
     57 			"pay",		/* 11 */
     58 			"trade",	/* 12 */
     59 			"resign",	/* 13 */
     60 			"save game",	/* 14 */
     61 			"restore game",	/* 15 */
     62 			0
     63 		};
     64 
     65 static shrt	square[MAX_PRP+2];
     66 
     67 static int	num_good,got_houses;
     68 
     69 /*
     70  *	This routine is the command level response the mortgage command.
     71  * it gets the list of mortgageable property and asks which are to
     72  * be mortgaged.
     73  */
     74 mortgage() {
     75 
     76 	reg int	prop;
     77 
     78 	for (;;) {
     79 		if (set_mlist() == 0) {
     80 			if (got_houses)
     81 				printf("You can't mortgage property with houses on it.\n");
     82 			else
     83 				printf("You don't have any un-mortgaged property.\n");
     84 			return;
     85 		}
     86 		if (num_good == 1) {
     87 			printf("Your only mortageable property is %s\n",names[0]);
     88 			if (getyn("Do you want to mortgage it? ") == 0)
     89 				m(square[0]);
     90 			return;
     91 		}
     92 		prop = getinp("Which property do you want to mortgage? ",names);
     93 		if (prop == num_good)
     94 			return;
     95 		m(square[prop]);
     96 		notify(cur_p);
     97 	}
     98 }
     99 /*
    100  *	This routine sets up the list of mortgageable property
    101  */
    102 set_mlist() {
    103 
    104 	reg OWN	*op;
    105 
    106 	num_good = 0;
    107 	for (op = cur_p->own_list; op; op = op->next)
    108 		if (!op->sqr->desc->morg)
    109 			if (op->sqr->type == PRPTY && op->sqr->desc->houses)
    110 				got_houses++;
    111 			else {
    112 				names[num_good] = op->sqr->name;
    113 				square[num_good++] = sqnum(op->sqr);
    114 			}
    115 	names[num_good++] = "done";
    116 	names[num_good--] = 0;
    117 	return num_good;
    118 }
    119 /*
    120  *	This routine actually mortgages the property.
    121  */
    122 m(prop)
    123 reg int	prop; {
    124 
    125 	reg int	price;
    126 
    127 	price = board[prop].cost/2;
    128 	board[prop].desc->morg = TRUE;
    129 	printf("That got you $%d\n",price);
    130 	cur_p->money += price;
    131 }
    132 /*
    133  *	This routine is the command level repsponse to the unmortgage
    134  * command.  It gets the list of mortgaged property and asks which are
    135  * to be unmortgaged.
    136  */
    137 unmortgage() {
    138 
    139 	reg int	prop;
    140 
    141 	for (;;) {
    142 		if (set_umlist() == 0) {
    143 			printf("You don't have any mortgaged property.\n");
    144 			return;
    145 		}
    146 		if (num_good == 1) {
    147 			printf("Your only mortaged property is %s\n",names[0]);
    148 			if (getyn("Do you want to unmortgage it? ") == 0)
    149 				unm(square[0]);
    150 			return;
    151 		}
    152 		prop = getinp("Which property do you want to unmortgage? ",names);
    153 		if (prop == num_good)
    154 			return;
    155 		unm(square[prop]);
    156 	}
    157 }
    158 /*
    159  *	This routine sets up the list of mortgaged property
    160  */
    161 set_umlist() {
    162 
    163 	reg OWN	*op;
    164 
    165 	num_good = 0;
    166 	for (op = cur_p->own_list; op; op = op->next)
    167 		if (op->sqr->desc->morg) {
    168 			names[num_good] = op->sqr->name;
    169 			square[num_good++] = sqnum(op->sqr);
    170 		}
    171 	names[num_good++] = "done";
    172 	names[num_good--] = 0;
    173 	return num_good;
    174 }
    175 /*
    176  *	This routine actually unmortgages the property
    177  */
    178 unm(prop)
    179 reg int	prop; {
    180 
    181 	reg int	price;
    182 
    183 	price = board[prop].cost/2;
    184 	board[prop].desc->morg = FALSE;
    185 	price += price/10;
    186 	printf("That cost you $%d\n",price);
    187 	cur_p->money -= price;
    188 	set_umlist();
    189 }
    190 /*
    191  *	This routine forces the indebted player to fix his
    192  * financial woes.
    193  */
    194 force_morg() {
    195 
    196 	told_em = fixing = TRUE;
    197 	while (cur_p->money <= 0)
    198 		fix_ex(getinp("How are you going to fix it up? ",morg_coms));
    199 	fixing = FALSE;
    200 }
    201 /*
    202  *	This routine is a special execute for the force_morg routine
    203  */
    204 fix_ex(com_num)
    205 reg int	com_num; {
    206 
    207 	told_em = FALSE;
    208 	(*func[com_num])();
    209 	notify();
    210 }
    211