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