|
|
1.1 root 1: /* s_eval.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 [email protected].
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: /* City Evaluation */
66:
67:
68: short EvalValid;
69: short CityYes, CityNo;
70: short ProblemTable[PROBNUM];
71: short ProblemTaken[PROBNUM];
72: short ProblemVotes[PROBNUM]; /* these are the votes for each */
73: short ProblemOrder[4]; /* sorted index to above */
74: QUAD CityPop, deltaCityPop;
75: QUAD CityAssValue;
76: short CityClass; /* 0..5 */
77: short CityScore, deltaCityScore, AverageCityScore;
78: short TrafficAverage;
79:
80:
81: /* comefrom: SpecialInit Simulate */
82: CityEvaluation(void)
83: {
84: EvalValid = 0;
85: if (TotalPop) {
86: GetAssValue();
87: DoPopNum();
88: DoProblems();
89: GetScore();
90: DoVotes();
91: ChangeEval();
92: } else {
93: EvalInit();
94: ChangeEval();
95: }
96: EvalValid = 1;
97: }
98:
99:
100: /* comefrom: CityEvaluation SetCommonInits */
101: EvalInit(void)
102: {
103: register short x, z;
104:
105: z = 0;
106: CityYes = z;
107: CityNo = z;
108: CityPop = z;
109: deltaCityPop = z;
110: CityAssValue = z;
111: CityClass = z;
112: CityScore = 500;
113: deltaCityScore = z;
114: EvalValid = 1;
115: for (x = 0; x < PROBNUM; x++)
116: ProblemVotes[x] = z;
117: for (x = 0; x < 4; x++)
118: ProblemOrder[x] = z;
119: }
120:
121:
122: /* comefrom: CityEvaluation */
123: GetAssValue(void)
124: {
125: QUAD z;
126:
127: z = RoadTotal * 5;
128: z += RailTotal * 10;
129: z += PolicePop * 1000;
130: z += FireStPop * 1000;
131: z += HospPop * 400;
132: z += StadiumPop * 3000;
133: z += PortPop * 5000;
134: z += APortPop * 10000;
135: z += CoalPop * 3000;
136: z += NuclearPop * 6000;
137: CityAssValue = z * 1000;
138: }
139:
140:
141: /* comefrom: CityEvaluation */
142: DoPopNum(void)
143: {
144: QUAD OldCityPop;
145:
146: OldCityPop = CityPop;
147: CityPop = ((ResPop) + (ComPop * 8L) + (IndPop *8L)) * 20L;
148: if (OldCityPop == -1) {
149: OldCityPop = CityPop;
150: }
151: deltaCityPop = CityPop - OldCityPop;
152:
153: CityClass = 0; /* village */
154: if (CityPop > 2000) CityClass++; /* town */
155: if (CityPop > 10000) CityClass++; /* city */
156: if (CityPop > 50000) CityClass++; /* capital */
157: if (CityPop > 100000) CityClass++; /* metropolis */
158: if (CityPop > 500000) CityClass++; /* megalopolis */
159: }
160:
161:
162: /* comefrom: CityEvaluation */
163: DoProblems(void)
164: {
165: register short x, z;
166: short ThisProb, Max;
167:
168: for (z = 0; z < PROBNUM; z++)
169: ProblemTable[z] = 0;
170: ProblemTable[0] = CrimeAverage; /* Crime */
171: ProblemTable[1] = PolluteAverage; /* Pollution */
172: ProblemTable[2] = LVAverage * .7; /* Housing */
173: ProblemTable[3] = CityTax * 10; /* Taxes */
174: ProblemTable[4] = AverageTrf(); /* Traffic */
175: ProblemTable[5] = GetUnemployment(); /* Unemployment */
176: ProblemTable[6] = GetFire(); /* Fire */
177: VoteProblems();
178: for (z = 0; z < PROBNUM; z++)
179: ProblemTaken[z] = 0;
180: for (z = 0; z < 4; z++) {
181: Max = 0;
182: for (x = 0; x < 7; x++) {
183: if ((ProblemVotes[x] > Max) && (!ProblemTaken[x])) {
184: ThisProb = x;
185: Max = ProblemVotes[x];
186: }
187: }
188: if (Max) {
189: ProblemTaken[ThisProb] = 1;
190: ProblemOrder[z] = ThisProb;
191: }
192: else {
193: ProblemOrder[z] = 7;
194: ProblemTable[7] = 0;
195: }
196: }
197: }
198:
199:
200: /* comefrom: DoProblems */
201: VoteProblems(void)
202: {
203: register x, z, count;
204:
205: for (z = 0; z < PROBNUM; z++)
206: ProblemVotes[z] = 0;
207:
208: x = 0;
209: z = 0;
210: count = 0;
211: while ((z < 100) && (count < 600)) {
212: if (Rand(300) < ProblemTable[x]) {
213: ProblemVotes[x]++;
214: z++;
215: }
216: x++;
217: if (x > PROBNUM) x = 0;
218: count++;
219: }
220: }
221:
222:
223: /* comefrom: DoProblems */
224: AverageTrf(void)
225: {
226: QUAD TrfTotal;
227: register short x, y, count;
228:
229: TrfTotal = 0;
230: count = 1;
231: for (x=0; x < HWLDX; x++)
232: for (y=0; y < HWLDY; y++)
233: if (LandValueMem[x][y]) {
234: TrfTotal += TrfDensity[x][y];
235: count++;
236: }
237:
238: TrafficAverage = (TrfTotal / count) * 2.4;
239: return(TrafficAverage);
240: }
241:
242:
243: /* comefrom: DoProblems */
244: GetUnemployment(void)
245: {
246: float r;
247: short b;
248:
249: b = (ComPop + IndPop) << 3;
250: if (b)
251: r = ((float)ResPop) / b;
252: else
253: return(0);
254:
255: b = (r - 1) * 255;
256: if (b > 255)
257: b = 255;
258: return (b);
259: }
260:
261:
262: /* comefrom: DoProblems GetScore */
263: GetFire(void)
264: {
265: short z;
266:
267: z = FirePop * 5;
268: if (z > 255)
269: return(255);
270: else
271: return(z);
272: }
273:
274:
275: /* comefrom: CityEvaluation */
276: GetScore(void)
277: {
278: register x, z;
279: short OldCityScore;
280: float SM, TM;
281:
282: OldCityScore = CityScore;
283: x = 0;
284: for (z = 0; z < 7; z++)
285: x += ProblemTable[z]; /* add 7 probs */
286:
287: x = x / 3; /* 7 + 2 average */
288: if (x > 256) x = 256;
289:
290: z = (256 - x) * 4;
291: if (z > 1000) z = 1000;
292: if (z < 0 ) z = 0;
293:
294: if (ResCap) z = z * .85;
295: if (ComCap) z = z * .85;
296: if (IndCap) z = z * .85;
297: if (RoadEffect < 32) z = z - (32 - RoadEffect);
298: if (PoliceEffect < 1000) z = z * (.9 + (PoliceEffect / 10000.1));
299: if (FireEffect < 1000) z = z * (.9 + (FireEffect / 10000.1));
300: if (RValve < -1000) z = z * .85;
301: if (CValve < -1000) z = z * .85;
302: if (IValve < -1000) z = z * .85;
303:
304: SM = 1.0;
305: if ((CityPop == 0) || (deltaCityPop == 0))
306: SM = 1.0;
307: else if (deltaCityPop == CityPop)
308: SM = 1.0;
309: else if (deltaCityPop > 0)
310: SM = ((float)deltaCityPop/CityPop) + 1.0;
311: else if (deltaCityPop < 0)
312: SM = .95 + ((float) deltaCityPop/(CityPop - deltaCityPop));
313: z = z * SM;
314: z = z - GetFire(); /* dec score for fires */
315: z = z - (CityTax);
316:
317: TM = unPwrdZCnt + PwrdZCnt; /* dec score for unpowered zones */
318: if (TM) SM = PwrdZCnt / TM;
319: else SM = 1.0;
320: z = z * SM;
321:
322: if (z > 1000) z = 1000;
323: if (z < 0 ) z = 0;
324:
325: CityScore = (CityScore + z) / 2;
326:
327: deltaCityScore = CityScore - OldCityScore;
328: }
329:
330:
331: /* comefrom: CityEvaluation */
332: DoVotes(void)
333: {
334: register z;
335:
336: CityYes = 0;
337: CityNo = 0;
338: for (z = 0; z < 100; z++) {
339: if (Rand(1000) < CityScore)
340: CityYes++;
341: else
342: CityNo++;
343: }
344: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.