]>
Commit | Line | Data |
---|---|---|
6a5fa4e0 MG |
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; | |
6f214ac0 MG |
76 | |
77 | void SetBudget(char *flowStr, char *previousStr, | |
78 | char *currentStr, char *collectedStr, short tax); | |
79 | void SetBudgetValues(char *roadGot, char *roadWant, | |
80 | char *policeGot, char *policeWant, | |
81 | char *fireGot, char *fireWant); | |
82 | void ShowBudgetWindowAndStartWaiting(void); | |
83 | void DoBudgetNow(int fromMenu); | |
6a5fa4e0 MG |
84 | |
85 | ||
86 | void InitFundingLevel(void) | |
87 | { | |
88 | firePercent = 1.0; /* 1.0 */ | |
89 | fireValue = 0; | |
90 | policePercent = 1.0; /* 1.0 */ | |
91 | policeValue = 0; | |
92 | roadPercent = 1.0; /* 1.0 */ | |
93 | roadValue = 0; | |
94 | drawBudgetWindow(); | |
95 | drawCurrPercents(); | |
96 | } | |
97 | ||
98 | ||
6f214ac0 MG |
99 | void |
100 | DoBudget(void) | |
6a5fa4e0 MG |
101 | { |
102 | DoBudgetNow(0); | |
103 | } | |
104 | ||
105 | ||
6f214ac0 MG |
106 | void |
107 | DoBudgetFromMenu(void) | |
6a5fa4e0 MG |
108 | { |
109 | DoBudgetNow(1); | |
110 | } | |
111 | ||
112 | ||
6f214ac0 | 113 | void |
6a5fa4e0 MG |
114 | DoBudgetNow(int fromMenu) |
115 | { | |
116 | QUAD yumDuckets; | |
117 | QUAD total; | |
118 | QUAD moreDough; | |
119 | QUAD fireInt, policeInt, roadInt; | |
120 | ||
121 | fireInt = (int)(((float)FireFund) * firePercent); | |
122 | policeInt = (int)(((float)PoliceFund) * policePercent); | |
123 | roadInt = (int)(((float)RoadFund) * roadPercent); | |
124 | ||
125 | total = fireInt + policeInt + roadInt; | |
126 | ||
127 | yumDuckets = TaxFund + TotalFunds; | |
128 | ||
129 | if (yumDuckets > total) { | |
130 | fireValue = fireInt; | |
131 | policeValue = policeInt; | |
132 | roadValue = roadInt; | |
133 | } else if (total > 0) { | |
134 | if (yumDuckets > roadInt) { | |
135 | roadValue = roadInt; | |
136 | yumDuckets -= roadInt; | |
137 | ||
138 | if (yumDuckets > fireInt) { | |
139 | fireValue = fireInt; | |
140 | yumDuckets -= fireInt; | |
141 | ||
142 | if (yumDuckets > policeInt) { | |
143 | policeValue = policeInt; | |
144 | yumDuckets -= policeInt; | |
145 | } else { | |
146 | policeValue = yumDuckets; | |
147 | if (yumDuckets > 0) | |
148 | policePercent = ((float)yumDuckets) / ((float)PoliceFund); | |
149 | else | |
150 | policePercent = 0.0; | |
151 | } | |
152 | } else { | |
153 | fireValue = yumDuckets; | |
154 | policeValue = 0; | |
155 | policePercent = 0.0; | |
156 | if (yumDuckets > 0) | |
157 | firePercent = ((float)yumDuckets) / ((float)FireFund); | |
158 | else | |
159 | firePercent = 0.0; | |
160 | } | |
161 | } else { | |
162 | roadValue = yumDuckets; | |
163 | if (yumDuckets > 0) | |
164 | roadPercent = ((float)yumDuckets) / ((float)RoadFund); | |
165 | else | |
166 | roadPercent = 0.0; | |
167 | ||
168 | fireValue = 0; | |
169 | policeValue = 0; | |
170 | firePercent = 0.0; | |
171 | policePercent = 0.0; | |
172 | } | |
173 | } else { | |
174 | fireValue = 0; | |
175 | policeValue = 0; | |
176 | roadValue = 0; | |
177 | firePercent = 1.0; | |
178 | policePercent = 1.0; | |
179 | roadPercent = 1.0; | |
180 | } | |
181 | ||
182 | fireMaxValue = FireFund; | |
183 | policeMaxValue = PoliceFund; | |
184 | roadMaxValue = RoadFund; | |
185 | ||
186 | drawCurrPercents(); | |
187 | ||
188 | noMoney: | |
189 | if ((!autoBudget) || fromMenu) { | |
190 | if (!autoBudget) { | |
191 | /* TODO: append the the current year to the budget string */ | |
192 | } | |
193 | ||
194 | ShowBudgetWindowAndStartWaiting(); | |
195 | ||
196 | if (!fromMenu) { | |
197 | FireSpend = fireValue; | |
198 | PoliceSpend = policeValue; | |
199 | RoadSpend = roadValue; | |
200 | ||
201 | total = FireSpend + PoliceSpend + RoadSpend; | |
202 | moreDough = (QUAD)(TaxFund - total); | |
203 | Spend(-moreDough); | |
204 | } | |
205 | drawBudgetWindow(); | |
206 | drawCurrPercents(); | |
207 | DoUpdateHeads(); | |
208 | ||
209 | } else { /* autoBudget & !fromMenu */ | |
210 | if ((yumDuckets) > total) { | |
211 | moreDough = (QUAD)(TaxFund - total); | |
212 | Spend(-moreDough); | |
213 | FireSpend = FireFund; | |
214 | PoliceSpend = PoliceFund; | |
215 | RoadSpend = RoadFund; | |
216 | drawBudgetWindow(); | |
217 | drawCurrPercents(); | |
218 | DoUpdateHeads(); | |
219 | } else { | |
220 | autoBudget = 0; /* XXX: force autobudget */ | |
221 | MustUpdateOptions = 1; | |
222 | ClearMes(); | |
223 | SendMes(29); | |
224 | goto noMoney; | |
225 | } | |
226 | } | |
227 | } | |
228 | ||
229 | ||
6f214ac0 | 230 | void |
6a5fa4e0 MG |
231 | drawBudgetWindow(void) |
232 | { | |
233 | MustDrawBudgetWindow = 1; | |
234 | } | |
235 | ||
236 | ||
6f214ac0 | 237 | void |
6a5fa4e0 MG |
238 | ReallyDrawBudgetWindow(void) |
239 | { | |
240 | short cashFlow, cashFlow2; | |
241 | char numStr[256], dollarStr[256], collectedStr[256], | |
242 | flowStr[256], previousStr[256], currentStr[256]; | |
243 | ||
244 | cashFlow = TaxFund - fireValue - policeValue - roadValue; | |
245 | ||
246 | cashFlow2 = cashFlow; | |
247 | if (cashFlow < 0) { | |
248 | cashFlow = -cashFlow; | |
249 | sprintf(numStr, "%d", cashFlow); | |
250 | makeDollarDecimalStr(numStr, dollarStr); | |
251 | sprintf(flowStr, "-%s", dollarStr); | |
252 | } else { | |
253 | sprintf(numStr, "%d", cashFlow); | |
254 | makeDollarDecimalStr(numStr, dollarStr); | |
255 | sprintf(flowStr, "+%s", dollarStr); | |
256 | } | |
257 | ||
6f214ac0 | 258 | sprintf(numStr, "%ld", TotalFunds); |
6a5fa4e0 MG |
259 | makeDollarDecimalStr(numStr, previousStr); |
260 | ||
6f214ac0 | 261 | sprintf(numStr, "%ld", cashFlow2 + TotalFunds); |
6a5fa4e0 MG |
262 | makeDollarDecimalStr(numStr, currentStr); |
263 | ||
6f214ac0 | 264 | sprintf(numStr, "%ld", TaxFund); |
6a5fa4e0 MG |
265 | makeDollarDecimalStr(numStr, collectedStr); |
266 | ||
267 | SetBudget(flowStr, previousStr, currentStr, collectedStr, CityTax); | |
268 | } | |
269 | ||
270 | ||
6f214ac0 | 271 | void |
6a5fa4e0 MG |
272 | drawCurrPercents(void) |
273 | { | |
274 | MustDrawCurrPercents = 1; | |
275 | } | |
276 | ||
277 | ||
6f214ac0 | 278 | void |
6a5fa4e0 MG |
279 | ReallyDrawCurrPercents(void) |
280 | { | |
281 | char num[256]; | |
282 | char fireWant[256], policeWant[256], roadWant[256]; | |
283 | char fireGot[256], policeGot[256], roadGot[256]; | |
284 | ||
6f214ac0 | 285 | sprintf(num, "%ld", fireMaxValue); |
6a5fa4e0 MG |
286 | makeDollarDecimalStr(num, fireWant); |
287 | ||
6f214ac0 | 288 | sprintf(num, "%ld", policeMaxValue); |
6a5fa4e0 MG |
289 | makeDollarDecimalStr(num, policeWant); |
290 | ||
6f214ac0 | 291 | sprintf(num, "%ld", roadMaxValue); |
6a5fa4e0 MG |
292 | makeDollarDecimalStr(num, roadWant); |
293 | ||
294 | sprintf(num, "%d", (int)(fireMaxValue * firePercent)); | |
295 | makeDollarDecimalStr(num, fireGot); | |
296 | ||
297 | sprintf(num, "%d", (int)(policeMaxValue * policePercent)); | |
298 | makeDollarDecimalStr(num, policeGot); | |
299 | ||
300 | sprintf(num, "%d", (int)(roadMaxValue * roadPercent)); | |
301 | makeDollarDecimalStr(num, roadGot); | |
302 | ||
303 | SetBudgetValues(roadGot, roadWant, | |
304 | policeGot, policeWant, | |
305 | fireGot, fireWant); | |
306 | } | |
307 | ||
308 | ||
6f214ac0 MG |
309 | void |
310 | UpdateBudgetWindow(void) | |
6a5fa4e0 MG |
311 | { |
312 | if (MustDrawCurrPercents) { | |
313 | ReallyDrawCurrPercents(); | |
314 | MustDrawCurrPercents = 0; | |
315 | } | |
316 | if (MustDrawBudgetWindow) { | |
317 | ReallyDrawBudgetWindow(); | |
318 | MustDrawBudgetWindow = 0; | |
319 | } | |
320 | } | |
321 | ||
322 | ||
6f214ac0 MG |
323 | void |
324 | UpdateBudget(void) | |
6a5fa4e0 MG |
325 | { |
326 | drawCurrPercents(); | |
327 | drawBudgetWindow(); | |
328 | Eval("UIUpdateBudget"); | |
329 | } | |
330 | ||
331 | ||
6f214ac0 MG |
332 | void |
333 | ShowBudgetWindowAndStartWaiting(void) | |
6a5fa4e0 MG |
334 | { |
335 | Eval("UIShowBudgetAndWait"); | |
336 | ||
337 | Pause(); | |
338 | } | |
339 | ||
340 | ||
6f214ac0 | 341 | void |
6a5fa4e0 MG |
342 | SetBudget(char *flowStr, char *previousStr, |
343 | char *currentStr, char *collectedStr, short tax) | |
344 | { | |
345 | char buf[256]; | |
346 | ||
347 | sprintf(buf, "UISetBudget {%s} {%s} {%s} {%s} {%d}", | |
348 | flowStr, previousStr, currentStr, collectedStr, tax); | |
349 | Eval(buf); | |
350 | } | |
351 | ||
352 | ||
6f214ac0 | 353 | void |
6a5fa4e0 MG |
354 | SetBudgetValues(char *roadGot, char *roadWant, |
355 | char *policeGot, char *policeWant, | |
356 | char *fireGot, char *fireWant) | |
357 | { | |
358 | char buf[256]; | |
359 | ||
360 | sprintf(buf, "UISetBudgetValues {%s} {%s} %d {%s} {%s} %d {%s} {%s} %d", | |
361 | roadGot, roadWant, (int)(roadPercent * 100), | |
362 | policeGot, policeWant, (int)(policePercent * 100), | |
363 | fireGot, fireWant, (int)(firePercent * 100)); | |
364 | Eval(buf); | |
365 | } | |
366 | ||
367 |