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