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