]> cvs.zerfleddert.de Git - micropolis/blob - src/sim/w_budget.c
Import Micropolis from http://www.donhopkins.com/home/micropolis/
[micropolis] / src / sim / w_budget.c
1 /* w_budget.c
2 *
3 * Micropolis, Unix Version. This game was released for the Unix platform
4 * in or about 1990 and has been modified for inclusion in the One Laptop
5 * Per Child program. Copyright (C) 1989 - 2007 Electronic Arts Inc. If
6 * you need assistance with this program, you may contact:
7 * http://wiki.laptop.org/go/Micropolis or email micropolis@laptop.org.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program. If
19 * not, see <http://www.gnu.org/licenses/>.
20 *
21 * ADDITIONAL TERMS per GNU GPL Section 7
22 *
23 * No trademark or publicity rights are granted. This license does NOT
24 * give you any right, title or interest in the trademark SimCity or any
25 * other Electronic Arts trademark. You may not distribute any
26 * modification of this program using the trademark SimCity or claim any
27 * affliation or association with Electronic Arts Inc. or its employees.
28 *
29 * Any propagation or conveyance of this program must include this
30 * copyright notice and these terms.
31 *
32 * If you convey this program (or any modifications of it) and assume
33 * contractual liability for the program to recipients of it, you agree
34 * to indemnify Electronic Arts for any liability that those contractual
35 * assumptions impose on Electronic Arts.
36 *
37 * You may not misrepresent the origins of this program; modified
38 * versions of the program must be marked as such and not identified as
39 * the original program.
40 *
41 * This disclaimer supplements the one included in the General Public
42 * License. TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, THIS
43 * PROGRAM IS PROVIDED TO YOU "AS IS," WITH ALL FAULTS, WITHOUT WARRANTY
44 * OF ANY KIND, AND YOUR USE IS AT YOUR SOLE RISK. THE ENTIRE RISK OF
45 * SATISFACTORY QUALITY AND PERFORMANCE RESIDES WITH YOU. ELECTRONIC ARTS
46 * DISCLAIMS ANY AND ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES,
47 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY,
48 * FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT OF THIRD PARTY
49 * RIGHTS, AND WARRANTIES (IF ANY) ARISING FROM A COURSE OF DEALING,
50 * USAGE, OR TRADE PRACTICE. ELECTRONIC ARTS DOES NOT WARRANT AGAINST
51 * INTERFERENCE WITH YOUR ENJOYMENT OF THE PROGRAM; THAT THE PROGRAM WILL
52 * MEET YOUR REQUIREMENTS; THAT OPERATION OF THE PROGRAM WILL BE
53 * UNINTERRUPTED OR ERROR-FREE, OR THAT THE PROGRAM WILL BE COMPATIBLE
54 * WITH THIRD PARTY SOFTWARE OR THAT ANY ERRORS IN THE PROGRAM WILL BE
55 * CORRECTED. NO ORAL OR WRITTEN ADVICE PROVIDED BY ELECTRONIC ARTS OR
56 * ANY AUTHORIZED REPRESENTATIVE SHALL CREATE A WARRANTY. SOME
57 * JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF OR LIMITATIONS ON IMPLIED
58 * WARRANTIES OR THE LIMITATIONS ON THE APPLICABLE STATUTORY RIGHTS OF A
59 * CONSUMER, SO SOME OR ALL OF THE ABOVE EXCLUSIONS AND LIMITATIONS MAY
60 * NOT APPLY TO YOU.
61 */
62 #include "sim.h"
63
64
65 float roadPercent = 0.0;
66 float policePercent = 0.0;
67 float firePercent = 0.0;
68 QUAD roadValue;
69 QUAD policeValue;
70 QUAD fireValue;
71 QUAD roadMaxValue;
72 QUAD policeMaxValue;
73 QUAD fireMaxValue;
74 int MustDrawCurrPercents = 0;
75 int MustDrawBudgetWindow = 0;
76 int SetBudget(char *flowStr, char *previousStr,
77 char *currentStr, char *collectedStr, short tax);
78
79
80 void InitFundingLevel(void)
81 {
82 firePercent = 1.0; /* 1.0 */
83 fireValue = 0;
84 policePercent = 1.0; /* 1.0 */
85 policeValue = 0;
86 roadPercent = 1.0; /* 1.0 */
87 roadValue = 0;
88 drawBudgetWindow();
89 drawCurrPercents();
90 }
91
92
93 DoBudget()
94 {
95 DoBudgetNow(0);
96 }
97
98
99 DoBudgetFromMenu()
100 {
101 DoBudgetNow(1);
102 }
103
104
105 DoBudgetNow(int fromMenu)
106 {
107 QUAD yumDuckets;
108 QUAD total;
109 QUAD moreDough;
110 QUAD fireInt, policeInt, roadInt;
111
112 fireInt = (int)(((float)FireFund) * firePercent);
113 policeInt = (int)(((float)PoliceFund) * policePercent);
114 roadInt = (int)(((float)RoadFund) * roadPercent);
115
116 total = fireInt + policeInt + roadInt;
117
118 yumDuckets = TaxFund + TotalFunds;
119
120 if (yumDuckets > total) {
121 fireValue = fireInt;
122 policeValue = policeInt;
123 roadValue = roadInt;
124 } else if (total > 0) {
125 if (yumDuckets > roadInt) {
126 roadValue = roadInt;
127 yumDuckets -= roadInt;
128
129 if (yumDuckets > fireInt) {
130 fireValue = fireInt;
131 yumDuckets -= fireInt;
132
133 if (yumDuckets > policeInt) {
134 policeValue = policeInt;
135 yumDuckets -= policeInt;
136 } else {
137 policeValue = yumDuckets;
138 if (yumDuckets > 0)
139 policePercent = ((float)yumDuckets) / ((float)PoliceFund);
140 else
141 policePercent = 0.0;
142 }
143 } else {
144 fireValue = yumDuckets;
145 policeValue = 0;
146 policePercent = 0.0;
147 if (yumDuckets > 0)
148 firePercent = ((float)yumDuckets) / ((float)FireFund);
149 else
150 firePercent = 0.0;
151 }
152 } else {
153 roadValue = yumDuckets;
154 if (yumDuckets > 0)
155 roadPercent = ((float)yumDuckets) / ((float)RoadFund);
156 else
157 roadPercent = 0.0;
158
159 fireValue = 0;
160 policeValue = 0;
161 firePercent = 0.0;
162 policePercent = 0.0;
163 }
164 } else {
165 fireValue = 0;
166 policeValue = 0;
167 roadValue = 0;
168 firePercent = 1.0;
169 policePercent = 1.0;
170 roadPercent = 1.0;
171 }
172
173 fireMaxValue = FireFund;
174 policeMaxValue = PoliceFund;
175 roadMaxValue = RoadFund;
176
177 drawCurrPercents();
178
179 noMoney:
180 if ((!autoBudget) || fromMenu) {
181 if (!autoBudget) {
182 /* TODO: append the the current year to the budget string */
183 }
184
185 ShowBudgetWindowAndStartWaiting();
186
187 if (!fromMenu) {
188 FireSpend = fireValue;
189 PoliceSpend = policeValue;
190 RoadSpend = roadValue;
191
192 total = FireSpend + PoliceSpend + RoadSpend;
193 moreDough = (QUAD)(TaxFund - total);
194 Spend(-moreDough);
195 }
196 drawBudgetWindow();
197 drawCurrPercents();
198 DoUpdateHeads();
199
200 } else { /* autoBudget & !fromMenu */
201 if ((yumDuckets) > total) {
202 moreDough = (QUAD)(TaxFund - total);
203 Spend(-moreDough);
204 FireSpend = FireFund;
205 PoliceSpend = PoliceFund;
206 RoadSpend = RoadFund;
207 drawBudgetWindow();
208 drawCurrPercents();
209 DoUpdateHeads();
210 } else {
211 autoBudget = 0; /* XXX: force autobudget */
212 MustUpdateOptions = 1;
213 ClearMes();
214 SendMes(29);
215 goto noMoney;
216 }
217 }
218 }
219
220
221 drawBudgetWindow(void)
222 {
223 MustDrawBudgetWindow = 1;
224 }
225
226
227 ReallyDrawBudgetWindow(void)
228 {
229 short cashFlow, cashFlow2;
230 char numStr[256], dollarStr[256], collectedStr[256],
231 flowStr[256], previousStr[256], currentStr[256];
232
233 cashFlow = TaxFund - fireValue - policeValue - roadValue;
234
235 cashFlow2 = cashFlow;
236 if (cashFlow < 0) {
237 cashFlow = -cashFlow;
238 sprintf(numStr, "%d", cashFlow);
239 makeDollarDecimalStr(numStr, dollarStr);
240 sprintf(flowStr, "-%s", dollarStr);
241 } else {
242 sprintf(numStr, "%d", cashFlow);
243 makeDollarDecimalStr(numStr, dollarStr);
244 sprintf(flowStr, "+%s", dollarStr);
245 }
246
247 sprintf(numStr, "%d", TotalFunds);
248 makeDollarDecimalStr(numStr, previousStr);
249
250 sprintf(numStr, "%d", cashFlow2 + TotalFunds);
251 makeDollarDecimalStr(numStr, currentStr);
252
253 sprintf(numStr, "%d", TaxFund);
254 makeDollarDecimalStr(numStr, collectedStr);
255
256 SetBudget(flowStr, previousStr, currentStr, collectedStr, CityTax);
257 }
258
259
260 drawCurrPercents(void)
261 {
262 MustDrawCurrPercents = 1;
263 }
264
265
266 ReallyDrawCurrPercents(void)
267 {
268 char num[256];
269 char fireWant[256], policeWant[256], roadWant[256];
270 char fireGot[256], policeGot[256], roadGot[256];
271
272 sprintf(num, "%d", fireMaxValue);
273 makeDollarDecimalStr(num, fireWant);
274
275 sprintf(num, "%d", policeMaxValue);
276 makeDollarDecimalStr(num, policeWant);
277
278 sprintf(num, "%d", roadMaxValue);
279 makeDollarDecimalStr(num, roadWant);
280
281 sprintf(num, "%d", (int)(fireMaxValue * firePercent));
282 makeDollarDecimalStr(num, fireGot);
283
284 sprintf(num, "%d", (int)(policeMaxValue * policePercent));
285 makeDollarDecimalStr(num, policeGot);
286
287 sprintf(num, "%d", (int)(roadMaxValue * roadPercent));
288 makeDollarDecimalStr(num, roadGot);
289
290 SetBudgetValues(roadGot, roadWant,
291 policeGot, policeWant,
292 fireGot, fireWant);
293 }
294
295
296 UpdateBudgetWindow()
297 {
298 if (MustDrawCurrPercents) {
299 ReallyDrawCurrPercents();
300 MustDrawCurrPercents = 0;
301 }
302 if (MustDrawBudgetWindow) {
303 ReallyDrawBudgetWindow();
304 MustDrawBudgetWindow = 0;
305 }
306 }
307
308
309 UpdateBudget()
310 {
311 drawCurrPercents();
312 drawBudgetWindow();
313 Eval("UIUpdateBudget");
314 }
315
316
317 ShowBudgetWindowAndStartWaiting()
318 {
319 Eval("UIShowBudgetAndWait");
320
321 Pause();
322 }
323
324
325 SetBudget(char *flowStr, char *previousStr,
326 char *currentStr, char *collectedStr, short tax)
327 {
328 char buf[256];
329
330 sprintf(buf, "UISetBudget {%s} {%s} {%s} {%s} {%d}",
331 flowStr, previousStr, currentStr, collectedStr, tax);
332 Eval(buf);
333 }
334
335
336 SetBudgetValues(char *roadGot, char *roadWant,
337 char *policeGot, char *policeWant,
338 char *fireGot, char *fireWant)
339 {
340 char buf[256];
341
342 sprintf(buf, "UISetBudgetValues {%s} {%s} %d {%s} {%s} %d {%s} {%s} %d",
343 roadGot, roadWant, (int)(roadPercent * 100),
344 policeGot, policeWant, (int)(policePercent * 100),
345 fireGot, fireWant, (int)(firePercent * 100));
346 Eval(buf);
347 }
348
349
Impressum, Datenschutz