]>
git.zerfleddert.de Git - micropolis/blob - src/sim/w_budget.c
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.
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.
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/>.
21 * ADDITIONAL TERMS per GNU GPL Section 7
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.
29 * Any propagation or conveyance of this program must include this
30 * copyright notice and these terms.
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.
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.
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
65 float roadPercent
= 0.0;
66 float policePercent
= 0.0;
67 float firePercent
= 0.0;
74 int MustDrawCurrPercents
= 0;
75 int MustDrawBudgetWindow
= 0;
76 int SetBudget(char *flowStr
, char *previousStr
,
77 char *currentStr
, char *collectedStr
, short tax
);
80 void InitFundingLevel(void)
82 firePercent
= 1.0; /* 1.0 */
84 policePercent
= 1.0; /* 1.0 */
86 roadPercent
= 1.0; /* 1.0 */
105 DoBudgetNow(int fromMenu
)
110 QUAD fireInt
, policeInt
, roadInt
;
112 fireInt
= (int)(((float)FireFund
) * firePercent
);
113 policeInt
= (int)(((float)PoliceFund
) * policePercent
);
114 roadInt
= (int)(((float)RoadFund
) * roadPercent
);
116 total
= fireInt
+ policeInt
+ roadInt
;
118 yumDuckets
= TaxFund
+ TotalFunds
;
120 if (yumDuckets
> total
) {
122 policeValue
= policeInt
;
124 } else if (total
> 0) {
125 if (yumDuckets
> roadInt
) {
127 yumDuckets
-= roadInt
;
129 if (yumDuckets
> fireInt
) {
131 yumDuckets
-= fireInt
;
133 if (yumDuckets
> policeInt
) {
134 policeValue
= policeInt
;
135 yumDuckets
-= policeInt
;
137 policeValue
= yumDuckets
;
139 policePercent
= ((float)yumDuckets
) / ((float)PoliceFund
);
144 fireValue
= yumDuckets
;
148 firePercent
= ((float)yumDuckets
) / ((float)FireFund
);
153 roadValue
= yumDuckets
;
155 roadPercent
= ((float)yumDuckets
) / ((float)RoadFund
);
173 fireMaxValue
= FireFund
;
174 policeMaxValue
= PoliceFund
;
175 roadMaxValue
= RoadFund
;
180 if ((!autoBudget
) || fromMenu
) {
182 /* TODO: append the the current year to the budget string */
185 ShowBudgetWindowAndStartWaiting();
188 FireSpend
= fireValue
;
189 PoliceSpend
= policeValue
;
190 RoadSpend
= roadValue
;
192 total
= FireSpend
+ PoliceSpend
+ RoadSpend
;
193 moreDough
= (QUAD
)(TaxFund
- total
);
200 } else { /* autoBudget & !fromMenu */
201 if ((yumDuckets
) > total
) {
202 moreDough
= (QUAD
)(TaxFund
- total
);
204 FireSpend
= FireFund
;
205 PoliceSpend
= PoliceFund
;
206 RoadSpend
= RoadFund
;
211 autoBudget
= 0; /* XXX: force autobudget */
212 MustUpdateOptions
= 1;
221 drawBudgetWindow(void)
223 MustDrawBudgetWindow
= 1;
227 ReallyDrawBudgetWindow(void)
229 short cashFlow
, cashFlow2
;
230 char numStr
[256], dollarStr
[256], collectedStr
[256],
231 flowStr
[256], previousStr
[256], currentStr
[256];
233 cashFlow
= TaxFund
- fireValue
- policeValue
- roadValue
;
235 cashFlow2
= cashFlow
;
237 cashFlow
= -cashFlow
;
238 sprintf(numStr
, "%d", cashFlow
);
239 makeDollarDecimalStr(numStr
, dollarStr
);
240 sprintf(flowStr
, "-%s", dollarStr
);
242 sprintf(numStr
, "%d", cashFlow
);
243 makeDollarDecimalStr(numStr
, dollarStr
);
244 sprintf(flowStr
, "+%s", dollarStr
);
247 sprintf(numStr
, "%d", TotalFunds
);
248 makeDollarDecimalStr(numStr
, previousStr
);
250 sprintf(numStr
, "%d", cashFlow2
+ TotalFunds
);
251 makeDollarDecimalStr(numStr
, currentStr
);
253 sprintf(numStr
, "%d", TaxFund
);
254 makeDollarDecimalStr(numStr
, collectedStr
);
256 SetBudget(flowStr
, previousStr
, currentStr
, collectedStr
, CityTax
);
260 drawCurrPercents(void)
262 MustDrawCurrPercents
= 1;
266 ReallyDrawCurrPercents(void)
269 char fireWant
[256], policeWant
[256], roadWant
[256];
270 char fireGot
[256], policeGot
[256], roadGot
[256];
272 sprintf(num
, "%d", fireMaxValue
);
273 makeDollarDecimalStr(num
, fireWant
);
275 sprintf(num
, "%d", policeMaxValue
);
276 makeDollarDecimalStr(num
, policeWant
);
278 sprintf(num
, "%d", roadMaxValue
);
279 makeDollarDecimalStr(num
, roadWant
);
281 sprintf(num
, "%d", (int)(fireMaxValue
* firePercent
));
282 makeDollarDecimalStr(num
, fireGot
);
284 sprintf(num
, "%d", (int)(policeMaxValue
* policePercent
));
285 makeDollarDecimalStr(num
, policeGot
);
287 sprintf(num
, "%d", (int)(roadMaxValue
* roadPercent
));
288 makeDollarDecimalStr(num
, roadGot
);
290 SetBudgetValues(roadGot
, roadWant
,
291 policeGot
, policeWant
,
298 if (MustDrawCurrPercents
) {
299 ReallyDrawCurrPercents();
300 MustDrawCurrPercents
= 0;
302 if (MustDrawBudgetWindow
) {
303 ReallyDrawBudgetWindow();
304 MustDrawBudgetWindow
= 0;
313 Eval("UIUpdateBudget");
317 ShowBudgetWindowAndStartWaiting()
319 Eval("UIShowBudgetAndWait");
325 SetBudget(char *flowStr
, char *previousStr
,
326 char *currentStr
, char *collectedStr
, short tax
)
330 sprintf(buf
, "UISetBudget {%s} {%s} {%s} {%s} {%d}",
331 flowStr
, previousStr
, currentStr
, collectedStr
, tax
);
336 SetBudgetValues(char *roadGot
, char *roadWant
,
337 char *policeGot
, char *policeWant
,
338 char *fireGot
, char *fireWant
)
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));