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