Home | History | Annotate | Line # | Download | only in monop
morg.c revision 1.8
      1 /*	$NetBSD: morg.c,v 1.8 1999/09/08 21:17:52 jsm Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1980, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 #ifndef lint
     38 #if 0
     39 static char sccsid[] = "@(#)morg.c	8.1 (Berkeley) 5/31/93";
     40 #else
     41 __RCSID("$NetBSD: morg.c,v 1.8 1999/09/08 21:17:52 jsm Exp $");
     42 #endif
     43 #endif /* not lint */
     44 
     45 #include "monop.ext"
     46 
     47 /*
     48  *	These routines deal with mortgaging.
     49  */
     50 
     51 static const char	*names[MAX_PRP+2],
     52 		*const morg_coms[]	= {
     53 			"quit",		/*  0 */
     54 			"print",	/*  1 */
     55 			"where",	/*  2 */
     56 			"own holdings",	/*  3 */
     57 			"holdings",	/*  4 */
     58 			"mortgage",	/*  5 */
     59 			"unmortgage",	/*  6 */
     60 			"buy",		/*  7 */
     61 			"sell",		/*  8 */
     62 			"card",		/*  9 */
     63 			"pay",		/* 10 */
     64 			"trade",	/* 11 */
     65 			"resign",	/* 12 */
     66 			"save game",	/* 13 */
     67 			"restore game",	/* 14 */
     68 			0
     69 		};
     70 
     71 static short	square[MAX_PRP+2];
     72 
     73 static int	num_good,got_houses;
     74 
     75 
     76 static int set_mlist __P((void));
     77 static void m __P((int));
     78 static int set_umlist __P((void));
     79 static void unm __P((int));
     80 static void fix_ex __P((int));
     81 
     82 /*
     83  *	This routine is the command level response the mortgage command.
     84  * it gets the list of mortgageable property and asks which are to
     85  * be mortgaged.
     86  */
     87 void
     88 mortgage()
     89 {
     90 	int prop;
     91 
     92 	for (;;) {
     93 		if (set_mlist() == 0) {
     94 			if (got_houses)
     95 				printf("You can't mortgage property with "
     96 				    "houses on it.\n");
     97 			else
     98 				printf("You don't have any un-mortgaged "
     99 				    "property.\n");
    100 			return;
    101 		}
    102 		if (num_good == 1) {
    103 			printf("Your only mortageable property is %s\n",
    104 			    names[0]);
    105 			if (getyn("Do you want to mortgage it? ") == 0)
    106 				m(square[0]);
    107 			return;
    108 		}
    109 		prop = getinp("Which property do you want to mortgage? ",names);
    110 		if (prop == num_good)
    111 			return;
    112 		m(square[prop]);
    113 		notify();
    114 	}
    115 }
    116 
    117 /*
    118  *	This routine sets up the list of mortgageable property
    119  */
    120 static int
    121 set_mlist()
    122 {
    123 	OWN *op;
    124 
    125 	num_good = 0;
    126 	for (op = cur_p->own_list; op; op = op->next)
    127 		if (!op->sqr->desc->morg) {
    128 			if (op->sqr->type == PRPTY && op->sqr->desc->houses)
    129 				got_houses++;
    130 			else {
    131 				names[num_good] = op->sqr->name;
    132 				square[num_good++] = sqnum(op->sqr);
    133 			}
    134 		}
    135 	names[num_good++] = "done";
    136 	names[num_good--] = 0;
    137 	return num_good;
    138 }
    139 
    140 /*
    141  *	This routine actually mortgages the property.
    142  */
    143 static void
    144 m(prop)
    145 	int prop;
    146 {
    147 	int price;
    148 
    149 	price = board[prop].cost/2;
    150 	board[prop].desc->morg = TRUE;
    151 	printf("That got you $%d\n",price);
    152 	cur_p->money += price;
    153 }
    154 
    155 /*
    156  *	This routine is the command level repsponse to the unmortgage
    157  * command.  It gets the list of mortgaged property and asks which are
    158  * to be unmortgaged.
    159  */
    160 void
    161 unmortgage()
    162 {
    163 	int prop;
    164 
    165 	for (;;) {
    166 		if (set_umlist() == 0) {
    167 			printf("You don't have any mortgaged property.\n");
    168 			return;
    169 		}
    170 		if (num_good == 1) {
    171 			printf("Your only mortaged property is %s\n",names[0]);
    172 			if (getyn("Do you want to unmortgage it? ") == 0)
    173 				unm(square[0]);
    174 			return;
    175 		}
    176 		prop = getinp("Which property do you want to unmortgage? ",
    177 		    names);
    178 		if (prop == num_good)
    179 			return;
    180 		unm(square[prop]);
    181 	}
    182 }
    183 
    184 /*
    185  *	This routine sets up the list of mortgaged property
    186  */
    187 static int
    188 set_umlist()
    189 {
    190 	OWN *op;
    191 
    192 	num_good = 0;
    193 	for (op = cur_p->own_list; op; op = op->next)
    194 		if (op->sqr->desc->morg) {
    195 			names[num_good] = op->sqr->name;
    196 			square[num_good++] = sqnum(op->sqr);
    197 		}
    198 	names[num_good++] = "done";
    199 	names[num_good--] = 0;
    200 	return num_good;
    201 }
    202 
    203 /*
    204  *	This routine actually unmortgages the property
    205  */
    206 static void
    207 unm(prop)
    208 	int prop;
    209 {
    210 	int price;
    211 
    212 	price = board[prop].cost/2;
    213 	board[prop].desc->morg = FALSE;
    214 	price += price/10;
    215 	printf("That cost you $%d\n",price);
    216 	cur_p->money -= price;
    217 	set_umlist();
    218 }
    219 
    220 /*
    221  *	This routine forces the indebted player to fix his
    222  * financial woes.
    223  */
    224 void
    225 force_morg()
    226 {
    227 	told_em = fixing = TRUE;
    228 	while (cur_p->money <= 0)
    229 		fix_ex(getinp("How are you going to fix it up? ",morg_coms));
    230 	fixing = FALSE;
    231 }
    232 
    233 /*
    234  *	This routine is a special execute for the force_morg routine
    235  */
    236 static void
    237 fix_ex(com_num)
    238 	int com_num;
    239 {
    240 	told_em = FALSE;
    241 	(*func[com_num])();
    242 	notify();
    243 }
    244