1: # include "monop.ext"
2:
3: static char *names[N_MON+2],
4: cur_prop[80];
5:
6: static MON *monops[N_MON];
7:
8: /*
9: * These routines deal with buying and selling houses
10: */
11: buy_houses() {
12:
13: reg int num_mon;
14: reg MON *mp;
15: reg OWN *op;
16: bool good,got_morg;
17: int i,p;
18:
19: over:
20: num_mon = 0;
21: good = TRUE;
22: got_morg = FALSE;
23: for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
24: continue;
25: while (op)
26: if (op->sqr->desc->monop) {
27: mp = op->sqr->desc->mon_desc;
28: names[num_mon] = (monops[num_mon]=mp)->name;
29: num_mon++;
30: got_morg = good = FALSE;
31: for (i = 0; i < mp->num_in; i++) {
32: if (op->sqr->desc->morg)
33: got_morg++;
34: if (op->sqr->desc->houses != 5)
35: good++;
36: op = op->next;
37: }
38: if (!good || got_morg)
39: --num_mon;
40: }
41: else
42: op = op->next;
43: if (num_mon == 0) {
44: if (got_morg)
45: printf("You can't build on mortgaged monopolies.\n");
46: else if (!good)
47: printf("You can't build any more.\n");
48: else
49: printf("But you don't have any monopolies!!\n");
50: return;
51: }
52: if (num_mon == 1)
53: buy_h(monops[0]);
54: else {
55: names[num_mon++] = "done";
56: names[num_mon--] = 0;
57: if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
58: return;
59: buy_h(monops[p]);
60: goto over;
61: }
62: }
63:
64: buy_h(mnp)
65: MON *mnp; {
66:
67: reg int i;
68: reg MON *mp;
69: reg int price;
70: shrt input[3],temp[3];
71: int tot;
72: PROP *pp;
73:
74: mp = mnp;
75: price = mp->h_cost * 50;
76: blew_it:
77: list_cur(mp);
78: printf("Houses will cost $%d\n", price);
79: printf("How many houses do you wish to buy for\n");
80: for (i = 0; i < mp->num_in; i++) {
81: pp = mp->sq[i]->desc;
82: over:
83: if (pp->houses == 5) {
84: printf("%s (H):\n", mp->sq[i]->name);
85: input[i] = 0;
86: temp[i] = 5;
87: continue;
88: }
89: sprintf(cur_prop, "%s (%d): ", mp->sq[i]->name, pp->houses);
90: input[i] = get_int(cur_prop);
91: temp[i] = input[i] + pp->houses;
92: if (temp[i] > 5) {
93: printf("That's too many. The most you can buy is %d\n",
94: 5 - pp->houses);
95: goto over;
96: }
97: }
98: if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
99: abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
100: err: printf("That makes the spread too wide. Try again\n");
101: goto blew_it;
102: }
103: else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
104: goto err;
105: for (tot = i = 0; i < mp->num_in; i++)
106: tot += input[i];
107: if (tot) {
108: printf("You asked for %d houses for $%d\n", tot, tot * price);
109: if (getyn("Is that ok? ", yn) == 0) {
110: cur_p->money -= tot * price;
111: for (tot = i = 0; i < mp->num_in; i++)
112: mp->sq[i]->desc->houses = temp[i];
113: }
114: }
115: }
116:
117: /*
118: * This routine sells houses.
119: */
120: sell_houses() {
121:
122: reg int num_mon;
123: reg MON *mp;
124: reg OWN *op;
125: bool good;
126: int p;
127:
128: over:
129: num_mon = 0;
130: good = TRUE;
131: for (op = cur_p->own_list; op; op = op->next)
132: if (op->sqr->type == PRPTY && op->sqr->desc->monop) {
133: mp = op->sqr->desc->mon_desc;
134: names[num_mon] = (monops[num_mon]=mp)->name;
135: num_mon++;
136: good = 0;
137: do
138: if (!good && op->sqr->desc->houses != 0)
139: good++;
140: while (op->next && op->sqr->desc->mon_desc == mp
141: && (op=op->next));
142: if (!good)
143: --num_mon;
144: }
145: if (num_mon == 0) {
146: printf("You don't have any houses to sell!!\n");
147: return;
148: }
149: if (num_mon == 1)
150: sell_h(monops[0]);
151: else {
152: names[num_mon++] = "done";
153: names[num_mon--] = 0;
154: if ((p=getinp("Which property do you wish to sell houses from? ", names)) == num_mon)
155: return;
156: sell_h(monops[p]);
157: notify();
158: goto over;
159: }
160: }
161:
162: sell_h(mnp)
163: MON *mnp; {
164:
165: reg int i;
166: reg MON *mp;
167: reg int price;
168: shrt input[3],temp[3];
169: int tot;
170: PROP *pp;
171:
172: mp = mnp;
173: price = mp->h_cost * 25;
174: blew_it:
175: printf("Houses will get you $%d apiece\n", price);
176: list_cur(mp);
177: printf("How many houses do you wish to sell from\n");
178: for (i = 0; i < mp->num_in; i++) {
179: pp = mp->sq[i]->desc;
180: over:
181: if (pp->houses == 0) {
182: printf("%s (0):\n", mp->sq[i]->name);
183: input[i] = temp[i] = 0;
184: continue;
185: }
186: if (pp->houses < 5)
187: sprintf(cur_prop,"%s (%d): ",mp->sq[i]->name,pp->houses);
188: else
189: sprintf(cur_prop,"%s (H): ",mp->sq[i]->name,pp->houses);
190: input[i] = get_int(cur_prop);
191: temp[i] = pp->houses - input[i];
192: if (temp[i] < 0) {
193: printf("That's too many. The most you can sell is %d\n", pp->houses);
194: goto over;
195: }
196: }
197: if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
198: abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
199: err: printf("That makes the spread too wide. Try again\n");
200: goto blew_it;
201: }
202: else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
203: goto err;
204: for (tot = i = 0; i < mp->num_in; i++)
205: tot += input[i];
206: if (tot) {
207: printf("You asked to sell %d houses for $%d\n",tot,tot * price);
208: if (getyn("Is that ok? ", yn) == 0) {
209: cur_p->money += tot * price;
210: for (tot = i = 0; i < mp->num_in; i++)
211: mp->sq[i]->desc->houses = temp[i];
212: }
213: }
214: }
215:
216: list_cur(mp)
217: reg MON *mp; {
218:
219: reg int i;
220: reg SQUARE *sqp;
221:
222: for (i = 0; i < mp->num_in; i++) {
223: sqp = mp->sq[i];
224: if (sqp->desc->houses == 5)
225: printf("%s (H) ", sqp->name);
226: else
227: printf("%s (%d) ", sqp->name, sqp->desc->houses);
228: }
229: putchar('\n');
230: }
Defined functions
buy_h
defined in line
64; used 2 times
Defined variables
names
defined in line
3; used 8 times