]>
cvs.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;
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
);
86 void InitFundingLevel(void)
88 firePercent
= 1.0; /* 1.0 */
90 policePercent
= 1.0; /* 1.0 */
92 roadPercent
= 1.0; /* 1.0 */
107 DoBudgetFromMenu(void)
114 DoBudgetNow(int fromMenu
)
119 QUAD fireInt
, policeInt
, roadInt
;
121 fireInt
= (int)(((float)FireFund
) * firePercent
);
122 policeInt
= (int)(((float)PoliceFund
) * policePercent
);
123 roadInt
= (int)(((float)RoadFund
) * roadPercent
);
125 total
= fireInt
+ policeInt
+ roadInt
;
127 yumDuckets
= TaxFund
+ TotalFunds
;
129 if (yumDuckets
> total
) {
131 policeValue
= policeInt
;
133 } else if (total
> 0) {
134 if (yumDuckets
> roadInt
) {
136 yumDuckets
-= roadInt
;
138 if (yumDuckets
> fireInt
) {
140 yumDuckets
-= fireInt
;
142 if (yumDuckets
> policeInt
) {
143 policeValue
= policeInt
;
144 yumDuckets
-= policeInt
;
146 policeValue
= yumDuckets
;
148 policePercent
= ((float)yumDuckets
) / ((float)PoliceFund
);
153 fireValue
= yumDuckets
;
157 firePercent
= ((float)yumDuckets
) / ((float)FireFund
);
162 roadValue
= yumDuckets
;
164 roadPercent
= ((float)yumDuckets
) / ((float)RoadFund
);
182 fireMaxValue
= FireFund
;
183 policeMaxValue
= PoliceFund
;
184 roadMaxValue
= RoadFund
;
189 if ((!autoBudget
) || fromMenu
) {
191 /* TODO: append the the current year to the budget string */
194 ShowBudgetWindowAndStartWaiting();
197 FireSpend
= fireValue
;
198 PoliceSpend
= policeValue
;
199 RoadSpend
= roadValue
;
201 total
= FireSpend
+ PoliceSpend
+ RoadSpend
;
202 moreDough
= (QUAD
)(TaxFund
- total
);
209 } else { /* autoBudget & !fromMenu */
210 if ((yumDuckets
) > total
) {
211 moreDough
= (QUAD
)(TaxFund
- total
);
213 FireSpend
= FireFund
;
214 PoliceSpend
= PoliceFund
;
215 RoadSpend
= RoadFund
;
220 autoBudget
= 0; /* XXX: force autobudget */
221 MustUpdateOptions
= 1;
231 drawBudgetWindow(void)
233 MustDrawBudgetWindow
= 1;
238 ReallyDrawBudgetWindow(void)
240 short cashFlow
, cashFlow2
;
241 char numStr
[256], dollarStr
[256], collectedStr
[256],
242 flowStr
[256], previousStr
[256], currentStr
[256];
244 cashFlow
= TaxFund
- fireValue
- policeValue
- roadValue
;
246 cashFlow2
= cashFlow
;
248 cashFlow
= -cashFlow
;
249 sprintf(numStr
, "%d", cashFlow
);
250 makeDollarDecimalStr(numStr
, dollarStr
);
251 sprintf(flowStr
, "-%s", dollarStr
);
253 sprintf(numStr
, "%d", cashFlow
);
254 makeDollarDecimalStr(numStr
, dollarStr
);
255 sprintf(flowStr
, "+%s", dollarStr
);
258 sprintf(numStr
, "%ld", TotalFunds
);
259 makeDollarDecimalStr(numStr
, previousStr
);
261 sprintf(numStr
, "%ld", cashFlow2
+ TotalFunds
);
262 makeDollarDecimalStr(numStr
, currentStr
);
264 sprintf(numStr
, "%ld", TaxFund
);
265 makeDollarDecimalStr(numStr
, collectedStr
);
267 SetBudget(flowStr
, previousStr
, currentStr
, collectedStr
, CityTax
);
272 drawCurrPercents(void)
274 MustDrawCurrPercents
= 1;
279 ReallyDrawCurrPercents(void)
282 char fireWant
[256], policeWant
[256], roadWant
[256];
283 char fireGot
[256], policeGot
[256], roadGot
[256];
285 sprintf(num
, "%ld", fireMaxValue
);
286 makeDollarDecimalStr(num
, fireWant
);
288 sprintf(num
, "%ld", policeMaxValue
);
289 makeDollarDecimalStr(num
, policeWant
);
291 sprintf(num
, "%ld", roadMaxValue
);
292 makeDollarDecimalStr(num
, roadWant
);
294 sprintf(num
, "%d", (int)(fireMaxValue
* firePercent
));
295 makeDollarDecimalStr(num
, fireGot
);
297 sprintf(num
, "%d", (int)(policeMaxValue
* policePercent
));
298 makeDollarDecimalStr(num
, policeGot
);
300 sprintf(num
, "%d", (int)(roadMaxValue
* roadPercent
));
301 makeDollarDecimalStr(num
, roadGot
);
303 SetBudgetValues(roadGot
, roadWant
,
304 policeGot
, policeWant
,
310 UpdateBudgetWindow(void)
312 if (MustDrawCurrPercents
) {
313 ReallyDrawCurrPercents();
314 MustDrawCurrPercents
= 0;
316 if (MustDrawBudgetWindow
) {
317 ReallyDrawBudgetWindow();
318 MustDrawBudgetWindow
= 0;
328 Eval("UIUpdateBudget");
333 ShowBudgetWindowAndStartWaiting(void)
335 Eval("UIShowBudgetAndWait");
342 SetBudget(char *flowStr
, char *previousStr
,
343 char *currentStr
, char *collectedStr
, short tax
)
347 sprintf(buf
, "UISetBudget {%s} {%s} {%s} {%s} {%d}",
348 flowStr
, previousStr
, currentStr
, collectedStr
, tax
);
354 SetBudgetValues(char *roadGot
, char *roadWant
,
355 char *policeGot
, char *policeWant
,
356 char *fireGot
, char *fireWant
)
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));