xref: /original-bsd/games/monop/morg.c (revision 42f60e33)
1 /*
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)morg.c	8.1 (Berkeley) 05/31/93";
10 #endif /* not lint */
11 
12 # include	"monop.ext"
13 
14 /*
15  *	These routines deal with mortgaging.
16  */
17 
18 static char	*names[MAX_PRP+2],
19 		*morg_coms[]	= {
20 			"quit",		/*  0 */
21 			"print",	/*  1 */
22 			"where",	/*  2 */
23 			"own holdings",	/*  3 */
24 			"holdings",	/*  4 */
25 			"mortgage",	/*  5 */
26 			"unmortgage",	/*  6 */
27 			"buy",		/*  7 */
28 			"sell",		/*  8 */
29 			"card",		/*  9 */
30 			"pay",		/* 10 */
31 			"trade",	/* 11 */
32 			"resign",	/* 12 */
33 			"save game",	/* 13 */
34 			"restore game",	/* 14 */
35 			0
36 		};
37 
38 static shrt	square[MAX_PRP+2];
39 
40 static int	num_good,got_houses;
41 
42 /*
43  *	This routine is the command level response the mortgage command.
44  * it gets the list of mortgageable property and asks which are to
45  * be mortgaged.
46  */
47 mortgage() {
48 
49 	reg int	prop;
50 
51 	for (;;) {
52 		if (set_mlist() == 0) {
53 			if (got_houses)
54 				printf("You can't mortgage property with houses on it.\n");
55 			else
56 				printf("You don't have any un-mortgaged property.\n");
57 			return;
58 		}
59 		if (num_good == 1) {
60 			printf("Your only mortageable property is %s\n",names[0]);
61 			if (getyn("Do you want to mortgage it? ") == 0)
62 				m(square[0]);
63 			return;
64 		}
65 		prop = getinp("Which property do you want to mortgage? ",names);
66 		if (prop == num_good)
67 			return;
68 		m(square[prop]);
69 		notify(cur_p);
70 	}
71 }
72 /*
73  *	This routine sets up the list of mortgageable property
74  */
75 set_mlist() {
76 
77 	reg OWN	*op;
78 
79 	num_good = 0;
80 	for (op = cur_p->own_list; op; op = op->next)
81 		if (!op->sqr->desc->morg)
82 			if (op->sqr->type == PRPTY && op->sqr->desc->houses)
83 				got_houses++;
84 			else {
85 				names[num_good] = op->sqr->name;
86 				square[num_good++] = sqnum(op->sqr);
87 			}
88 	names[num_good++] = "done";
89 	names[num_good--] = 0;
90 	return num_good;
91 }
92 /*
93  *	This routine actually mortgages the property.
94  */
95 m(prop)
96 reg int	prop; {
97 
98 	reg int	price;
99 
100 	price = board[prop].cost/2;
101 	board[prop].desc->morg = TRUE;
102 	printf("That got you $%d\n",price);
103 	cur_p->money += price;
104 }
105 /*
106  *	This routine is the command level repsponse to the unmortgage
107  * command.  It gets the list of mortgaged property and asks which are
108  * to be unmortgaged.
109  */
110 unmortgage() {
111 
112 	reg int	prop;
113 
114 	for (;;) {
115 		if (set_umlist() == 0) {
116 			printf("You don't have any mortgaged property.\n");
117 			return;
118 		}
119 		if (num_good == 1) {
120 			printf("Your only mortaged property is %s\n",names[0]);
121 			if (getyn("Do you want to unmortgage it? ") == 0)
122 				unm(square[0]);
123 			return;
124 		}
125 		prop = getinp("Which property do you want to unmortgage? ",names);
126 		if (prop == num_good)
127 			return;
128 		unm(square[prop]);
129 	}
130 }
131 /*
132  *	This routine sets up the list of mortgaged property
133  */
134 set_umlist() {
135 
136 	reg OWN	*op;
137 
138 	num_good = 0;
139 	for (op = cur_p->own_list; op; op = op->next)
140 		if (op->sqr->desc->morg) {
141 			names[num_good] = op->sqr->name;
142 			square[num_good++] = sqnum(op->sqr);
143 		}
144 	names[num_good++] = "done";
145 	names[num_good--] = 0;
146 	return num_good;
147 }
148 /*
149  *	This routine actually unmortgages the property
150  */
151 unm(prop)
152 reg int	prop; {
153 
154 	reg int	price;
155 
156 	price = board[prop].cost/2;
157 	board[prop].desc->morg = FALSE;
158 	price += price/10;
159 	printf("That cost you $%d\n",price);
160 	cur_p->money -= price;
161 	set_umlist();
162 }
163 /*
164  *	This routine forces the indebted player to fix his
165  * financial woes.
166  */
167 force_morg() {
168 
169 	told_em = fixing = TRUE;
170 	while (cur_p->money <= 0)
171 		fix_ex(getinp("How are you going to fix it up? ",morg_coms));
172 	fixing = FALSE;
173 }
174 /*
175  *	This routine is a special execute for the force_morg routine
176  */
177 fix_ex(com_num)
178 reg int	com_num; {
179 
180 	told_em = FALSE;
181 	(*func[com_num])();
182 	notify();
183 }
184