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