xref: /original-bsd/games/monop/morg.c (revision 22c2ba50)
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 are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)morg.c	5.2 (Berkeley) 06/18/88";
20 #endif /* not lint */
21 
22 # include	"monop.ext"
23 
24 /*
25  *	These routines deal with mortgaging.
26  */
27 
28 static char	*names[MAX_PRP+2],
29 		*morg_coms[]	= {
30 			"quit",		/*  0 */
31 			"print",	/*  1 */
32 			"where",	/*  2 */
33 			"own holdings",	/*  3 */
34 			"holdings",	/*  4 */
35 			"shell",	/*  5 */
36 			"mortgage",	/*  6 */
37 			"unmortgage",	/*  7 */
38 			"buy",		/*  8 */
39 			"sell",		/*  9 */
40 			"card",		/* 10 */
41 			"pay",		/* 11 */
42 			"trade",	/* 12 */
43 			"resign",	/* 13 */
44 			"save game",	/* 14 */
45 			"restore game",	/* 15 */
46 			0
47 		};
48 
49 static shrt	square[MAX_PRP+2];
50 
51 static int	num_good,got_houses;
52 
53 /*
54  *	This routine is the command level response the mortgage command.
55  * it gets the list of mortgageable property and asks which are to
56  * be mortgaged.
57  */
58 mortgage() {
59 
60 	reg int	prop;
61 
62 	for (;;) {
63 		if (set_mlist() == 0) {
64 			if (got_houses)
65 				printf("You can't mortgage property with houses on it.\n");
66 			else
67 				printf("You don't have any un-mortgaged property.\n");
68 			return;
69 		}
70 		if (num_good == 1) {
71 			printf("Your only mortageable property is %s\n",names[0]);
72 			if (getyn("Do you want to mortgage it? ") == 0)
73 				m(square[0]);
74 			return;
75 		}
76 		prop = getinp("Which property do you want to mortgage? ",names);
77 		if (prop == num_good)
78 			return;
79 		m(square[prop]);
80 		notify(cur_p);
81 	}
82 }
83 /*
84  *	This routine sets up the list of mortgageable property
85  */
86 set_mlist() {
87 
88 	reg OWN	*op;
89 
90 	num_good = 0;
91 	for (op = cur_p->own_list; op; op = op->next)
92 		if (!op->sqr->desc->morg)
93 			if (op->sqr->type == PRPTY && op->sqr->desc->houses)
94 				got_houses++;
95 			else {
96 				names[num_good] = op->sqr->name;
97 				square[num_good++] = sqnum(op->sqr);
98 			}
99 	names[num_good++] = "done";
100 	names[num_good--] = 0;
101 	return num_good;
102 }
103 /*
104  *	This routine actually mortgages the property.
105  */
106 m(prop)
107 reg int	prop; {
108 
109 	reg int	price;
110 
111 	price = board[prop].cost/2;
112 	board[prop].desc->morg = TRUE;
113 	printf("That got you $%d\n",price);
114 	cur_p->money += price;
115 }
116 /*
117  *	This routine is the command level repsponse to the unmortgage
118  * command.  It gets the list of mortgaged property and asks which are
119  * to be unmortgaged.
120  */
121 unmortgage() {
122 
123 	reg int	prop;
124 
125 	for (;;) {
126 		if (set_umlist() == 0) {
127 			printf("You don't have any mortgaged property.\n");
128 			return;
129 		}
130 		if (num_good == 1) {
131 			printf("Your only mortaged property is %s\n",names[0]);
132 			if (getyn("Do you want to unmortgage it? ") == 0)
133 				unm(square[0]);
134 			return;
135 		}
136 		prop = getinp("Which property do you want to unmortgage? ",names);
137 		if (prop == num_good)
138 			return;
139 		unm(square[prop]);
140 	}
141 }
142 /*
143  *	This routine sets up the list of mortgaged property
144  */
145 set_umlist() {
146 
147 	reg OWN	*op;
148 
149 	num_good = 0;
150 	for (op = cur_p->own_list; op; op = op->next)
151 		if (op->sqr->desc->morg) {
152 			names[num_good] = op->sqr->name;
153 			square[num_good++] = sqnum(op->sqr);
154 		}
155 	names[num_good++] = "done";
156 	names[num_good--] = 0;
157 	return num_good;
158 }
159 /*
160  *	This routine actually unmortgages the property
161  */
162 unm(prop)
163 reg int	prop; {
164 
165 	reg int	price;
166 
167 	price = board[prop].cost/2;
168 	board[prop].desc->morg = FALSE;
169 	price += price/10;
170 	printf("That cost you $%d\n",price);
171 	cur_p->money -= price;
172 	set_umlist();
173 }
174 /*
175  *	This routine forces the indebted player to fix his
176  * financial woes.
177  */
178 force_morg() {
179 
180 	told_em = fixing = TRUE;
181 	while (cur_p->money <= 0)
182 		fix_ex(getinp("How are you going to fix it up? ",morg_coms));
183 	fixing = FALSE;
184 }
185 /*
186  *	This routine is a special execute for the force_morg routine
187  */
188 fix_ex(com_num)
189 reg int	com_num; {
190 
191 	told_em = FALSE;
192 	(*func[com_num])();
193 	notify();
194 }
195