xref: /netbsd-src/games/monop/morg.c (revision c34afa686bf074a6dcc7f17157faae72111dde9a)
1*c34afa68Sdholland /*	$NetBSD: morg.c,v 1.19 2012/06/19 05:35:32 dholland Exp $	*/
242fb1b9dScgd 
361f28255Scgd /*
442fb1b9dScgd  * Copyright (c) 1980, 1993
542fb1b9dScgd  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * Redistribution and use in source and binary forms, with or without
861f28255Scgd  * modification, are permitted provided that the following conditions
961f28255Scgd  * are met:
1061f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1261f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1461f28255Scgd  *    documentation and/or other materials provided with the distribution.
15e5aeb4eaSagc  * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd  *    may be used to endorse or promote products derived from this software
1761f28255Scgd  *    without specific prior written permission.
1861f28255Scgd  *
1961f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd  * SUCH DAMAGE.
3061f28255Scgd  */
3161f28255Scgd 
32b118ad22Schristos #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
3442fb1b9dScgd #if 0
3542fb1b9dScgd static char sccsid[] = "@(#)morg.c	8.1 (Berkeley) 5/31/93";
3642fb1b9dScgd #else
37*c34afa68Sdholland __RCSID("$NetBSD: morg.c,v 1.19 2012/06/19 05:35:32 dholland Exp $");
3842fb1b9dScgd #endif
3961f28255Scgd #endif /* not lint */
4061f28255Scgd 
41b51259daSdholland #include "monop.h"
4261f28255Scgd 
4361f28255Scgd /*
4461f28255Scgd  *	These routines deal with mortgaging.
4561f28255Scgd  */
4661f28255Scgd 
47092d3130Sjsm static const char	*names[MAX_PRP+2],
48092d3130Sjsm 		*const morg_coms[]	= {
4961f28255Scgd 			"quit",		/*  0 */
5061f28255Scgd 			"print",	/*  1 */
5161f28255Scgd 			"where",	/*  2 */
5261f28255Scgd 			"own holdings",	/*  3 */
5361f28255Scgd 			"holdings",	/*  4 */
547bc024bdSmycroft 			"mortgage",	/*  5 */
557bc024bdSmycroft 			"unmortgage",	/*  6 */
567bc024bdSmycroft 			"buy",		/*  7 */
577bc024bdSmycroft 			"sell",		/*  8 */
587bc024bdSmycroft 			"card",		/*  9 */
597bc024bdSmycroft 			"pay",		/* 10 */
607bc024bdSmycroft 			"trade",	/* 11 */
617bc024bdSmycroft 			"resign",	/* 12 */
627bc024bdSmycroft 			"save game",	/* 13 */
637bc024bdSmycroft 			"restore game",	/* 14 */
6461f28255Scgd 			0
6561f28255Scgd 		};
6661f28255Scgd 
67b118ad22Schristos static short	square[MAX_PRP+2];
6861f28255Scgd 
6961f28255Scgd static int	num_good, got_houses;
7061f28255Scgd 
71b118ad22Schristos 
72cb5fd834Sjsm static int set_mlist(void);
73cb5fd834Sjsm static void m(int);
74cb5fd834Sjsm static int set_umlist(void);
75cb5fd834Sjsm static void unm(int);
76b118ad22Schristos 
7761f28255Scgd /*
7861f28255Scgd  *	This routine is the command level response the mortgage command.
7961f28255Scgd  * it gets the list of mortgageable property and asks which are to
8061f28255Scgd  * be mortgaged.
8161f28255Scgd  */
82b118ad22Schristos void
mortgage(void)83*c34afa68Sdholland mortgage(void)
84b118ad22Schristos {
854e5cdff5Sdholland 	int propnum;
8661f28255Scgd 
8761f28255Scgd 	for (;;) {
8861f28255Scgd 		if (set_mlist() == 0) {
8961f28255Scgd 			if (got_houses)
90e42b2048Ssimonb 				printf("You can't mortgage property with "
91e42b2048Ssimonb 				    "houses on it.\n");
9261f28255Scgd 			else
93e42b2048Ssimonb 				printf("You don't have any un-mortgaged "
94e42b2048Ssimonb 				    "property.\n");
9561f28255Scgd 			return;
9661f28255Scgd 		}
9761f28255Scgd 		if (num_good == 1) {
98c303095dSdholland 			printf("Your only mortgageable property is %s\n",
99e42b2048Ssimonb 			    names[0]);
10061f28255Scgd 			if (getyn("Do you want to mortgage it? ") == 0)
10161f28255Scgd 				m(square[0]);
10261f28255Scgd 			return;
10361f28255Scgd 		}
1044e5cdff5Sdholland 		propnum = getinp("Which property do you want to mortgage? ",
1054e5cdff5Sdholland 				names);
1064e5cdff5Sdholland 		if (propnum == num_good)
10761f28255Scgd 			return;
1084e5cdff5Sdholland 		m(square[propnum]);
109b118ad22Schristos 		notify();
11061f28255Scgd 	}
11161f28255Scgd }
112e42b2048Ssimonb 
11361f28255Scgd /*
11461f28255Scgd  *	This routine sets up the list of mortgageable property
11561f28255Scgd  */
116b118ad22Schristos static int
set_mlist(void)117*c34afa68Sdholland set_mlist(void)
118b118ad22Schristos {
119b118ad22Schristos 	OWN *op;
12061f28255Scgd 
12161f28255Scgd 	num_good = 0;
12261f28255Scgd 	for (op = cur_p->own_list; op; op = op->next)
12304afeca6Sveego 		if (!op->sqr->desc->morg) {
12461f28255Scgd 			if (op->sqr->type == PRPTY && op->sqr->desc->houses)
12561f28255Scgd 				got_houses++;
12661f28255Scgd 			else {
12761f28255Scgd 				names[num_good] = op->sqr->name;
12861f28255Scgd 				square[num_good++] = sqnum(op->sqr);
12961f28255Scgd 			}
13004afeca6Sveego 		}
13161f28255Scgd 	names[num_good++] = "done";
13261f28255Scgd 	names[num_good--] = 0;
13361f28255Scgd 	return num_good;
13461f28255Scgd }
135e42b2048Ssimonb 
13661f28255Scgd /*
13761f28255Scgd  *	This routine actually mortgages the property.
13861f28255Scgd  */
139b118ad22Schristos static void
m(int propnum)140*c34afa68Sdholland m(int propnum)
141b118ad22Schristos {
142b118ad22Schristos 	int price;
14361f28255Scgd 
144df819b08Sdholland 	price = board[propnum].cost/2;
145df819b08Sdholland 	board[propnum].desc->morg = TRUE;
14661f28255Scgd 	printf("That got you $%d\n",price);
14761f28255Scgd 	cur_p->money += price;
14861f28255Scgd }
149e42b2048Ssimonb 
15061f28255Scgd /*
15161f28255Scgd  *	This routine is the command level repsponse to the unmortgage
15261f28255Scgd  * command.  It gets the list of mortgaged property and asks which are
15361f28255Scgd  * to be unmortgaged.
15461f28255Scgd  */
155b118ad22Schristos void
unmortgage(void)156*c34afa68Sdholland unmortgage(void)
157b118ad22Schristos {
158df819b08Sdholland 	int propnum;
15961f28255Scgd 
16061f28255Scgd 	for (;;) {
16161f28255Scgd 		if (set_umlist() == 0) {
16261f28255Scgd 			printf("You don't have any mortgaged property.\n");
16361f28255Scgd 			return;
16461f28255Scgd 		}
16561f28255Scgd 		if (num_good == 1) {
166c303095dSdholland 			printf("Your only mortgaged property is %s\n",
167c303095dSdholland 			    names[0]);
16861f28255Scgd 			if (getyn("Do you want to unmortgage it? ") == 0)
16961f28255Scgd 				unm(square[0]);
17061f28255Scgd 			return;
17161f28255Scgd 		}
172df819b08Sdholland 		propnum = getinp("Which property do you want to unmortgage? ",
173e42b2048Ssimonb 		    names);
174df819b08Sdholland 		if (propnum == num_good)
17561f28255Scgd 			return;
176df819b08Sdholland 		unm(square[propnum]);
17761f28255Scgd 	}
17861f28255Scgd }
179e42b2048Ssimonb 
18061f28255Scgd /*
18161f28255Scgd  *	This routine sets up the list of mortgaged property
18261f28255Scgd  */
183b118ad22Schristos static int
set_umlist(void)184*c34afa68Sdholland set_umlist(void)
185b118ad22Schristos {
186b118ad22Schristos 	OWN *op;
18761f28255Scgd 
18861f28255Scgd 	num_good = 0;
18961f28255Scgd 	for (op = cur_p->own_list; op; op = op->next)
19061f28255Scgd 		if (op->sqr->desc->morg) {
19161f28255Scgd 			names[num_good] = op->sqr->name;
19261f28255Scgd 			square[num_good++] = sqnum(op->sqr);
19361f28255Scgd 		}
19461f28255Scgd 	names[num_good++] = "done";
19561f28255Scgd 	names[num_good--] = 0;
19661f28255Scgd 	return num_good;
19761f28255Scgd }
198e42b2048Ssimonb 
19961f28255Scgd /*
20061f28255Scgd  *	This routine actually unmortgages the property
20161f28255Scgd  */
202b118ad22Schristos static void
unm(int propnum)2035ec0096cSdholland unm(int propnum)
204b118ad22Schristos {
205b118ad22Schristos 	int price;
20661f28255Scgd 
207df819b08Sdholland 	price = board[propnum].cost/2;
208df819b08Sdholland 	board[propnum].desc->morg = FALSE;
20961f28255Scgd 	price += price/10;
21061f28255Scgd 	printf("That cost you $%d\n",price);
21161f28255Scgd 	cur_p->money -= price;
2125ec0096cSdholland 	(void)set_umlist();
21361f28255Scgd }
214e42b2048Ssimonb 
21561f28255Scgd /*
21661f28255Scgd  *	This routine forces the indebted player to fix his
2177913f644Sdholland  * financial woes.  It is fine to have $0 but not to be in debt.
21861f28255Scgd  */
219b118ad22Schristos void
force_morg(void)2205ec0096cSdholland force_morg(void)
221b118ad22Schristos {
22261f28255Scgd 	told_em = fixing = TRUE;
2237913f644Sdholland 	while (cur_p->money < 0) {
22461f28255Scgd 		told_em = FALSE;
2257913f644Sdholland 		(*func[(getinp("How are you going to fix it up? ", morg_coms))])();
22661f28255Scgd 		notify();
22761f28255Scgd 	}
2287913f644Sdholland 	fixing = FALSE;
2297913f644Sdholland }
230