]>
cvs.zerfleddert.de Git - micropolis/blob - src/sim/s_scan.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
69 short NewMapFlags
[NMAPS
];
70 short CCx
, CCy
, CCx2
, CCy2
;
71 short PolMaxX
, PolMaxY
;
72 short CrimeMaxX
, CrimeMaxY
;
76 /* comefrom: Simulate SpecialInit */
77 FireAnalysis(void) /* Make firerate map from firestation map */
84 for (x
= 0; x
< SmX
; x
++)
85 for (y
= 0; y
< SmY
; y
++)
86 FireRate
[x
][y
] = FireStMap
[x
][y
];
88 NewMapFlags
[DYMAP
] = NewMapFlags
[FIMAP
] = 1;
92 /* comefrom: Simulate SpecialInit */
93 PopDenScan(void) /* sets: PopDensity, , , ComRate */
95 QUAD Xtot
, Ytot
, Ztot
;
96 register short x
, y
, z
;
102 for (x
= 0; x
< WORLD_X
; x
++)
103 for (y
= 0; y
< WORLD_Y
; y
++) {
112 tem
[x
>>1][y
>>1] = z
;
118 DoSmooth(); /* T1 -> T2 */
119 DoSmooth2(); /* T2 -> T1 */
120 DoSmooth(); /* T1 -> T2 */
122 for (x
= 0; x
< HWLDX
; x
++)
123 for (y
= 0; y
< HWLDY
; y
++)
124 PopDensity
[x
][y
] = tem2
[x
][y
] <<1;
126 DistIntMarket(); /* set ComRate w/ (/ComMap) */
128 if (Ztot
) { /* Find Center of Mass for City */
132 CCx
= HWLDX
; /* if pop=0 center of Map is CC */
137 NewMapFlags
[DYMAP
] = NewMapFlags
[PDMAP
] = NewMapFlags
[RGMAP
] = 1;
141 /* comefrom: PopDenScan */
147 pop
= DoFreePop(Ch9
);
155 pop
= (CZPop(Ch9
) <<3);
158 if (Ch9
< PORTBASE
) {
159 pop
= (IZPop(Ch9
) <<3);
166 /* comefrom: Simulate SpecialInit */
167 PTLScan(void) /* Does pollution, terrain, land value */
170 register int x
, y
, z
, dis
;
171 int Plevel
, LVflag
, loc
, zx
, zy
, Mx
, My
, pnum
, LVnum
, pmax
;
173 for (x
= 0; x
< QWX
; x
++)
174 for (y
= 0; y
< QWY
; y
++)
178 for (x
= 0; x
< HWLDX
; x
++)
179 for (y
= 0; y
< HWLDY
; y
++) {
184 for (Mx
= zx
; Mx
<= zx
+ 1; Mx
++)
185 for (My
= zy
; My
<= zy
+ 1; My
++) {
186 if (loc
= (Map
[Mx
][My
] & LOMASK
)) {
188 Qtem
[x
>>1][y
>>1] += 15; /* inc terrainMem */
191 Plevel
+= GetPValue(loc
);
203 if (LVflag
) { /* LandValue Equation */
204 dis
= 34 - GetDisCC(x
, y
);
206 dis
+= (TerrainMem
[x
>>1][y
>>1] );
207 dis
-= (PollutionMem
[x
][y
]);
208 if (CrimeMem
[x
][y
] > 190) dis
-= 20;
209 if (dis
> 250) dis
= 250;
210 if (dis
< 1) dis
= 1;
211 LandValueMem
[x
][y
] = dis
;
215 LandValueMem
[x
][y
] = 0;
219 LVAverage
= LVtot
/ LVnum
;
228 for (x
= 0; x
< HWLDX
; x
++) {
229 for (y
= 0; y
< HWLDY
; y
++) {
231 PollutionMem
[x
][y
] = z
;
232 if (z
) { /* get pollute average */
235 /* find max pol for monster */
237 ((z
== pmax
) && (!(Rand16() & 3)))) {
246 PolluteAverage
= ptot
/ pnum
;
252 NewMapFlags
[DYMAP
] = NewMapFlags
[PLMAP
] = NewMapFlags
[LVMAP
] = 1;
256 /* comefrom: PTLScan */
259 if (loc
< POWERBASE
) {
260 if (loc
>= HTRFBASE
) return (/* 25 */ 75); /* heavy traf */
261 if (loc
>= LTRFBASE
) return (/* 10 */ 50); /* light traf */
262 if (loc
< ROADBASE
) {
263 if (loc
> FIREBASE
) return (/* 60 */ 90);
264 /* XXX: Why negative pollution from radiation? */
265 if (loc
>= RADTILE
) return (/* -40 */ 255); /* radioactivity */
269 if (loc
<= LASTIND
) return (0);
270 if (loc
< PORTBASE
) return (50); /* Ind */
271 if (loc
<= LASTPOWERPLANT
) return (/* 60 */ 100); /* prt, aprt, cpp */
276 /* comefrom: PTLScan DistIntMarket */
277 GetDisCC(int x
, int y
)
299 /* comefrom: Simulate SpecialInit */
304 register short x
, y
, z
;
313 for (x
= 0; x
< HWLDX
; x
++)
314 for (y
= 0; y
< HWLDY
; y
++) {
315 if (z
= LandValueMem
[x
][y
]) {
318 z
+= PopDensity
[x
][y
];
319 if (z
> 300) z
= 300;
320 z
-= PoliceMap
[x
>>2][y
>>2];
321 if (z
> 250) z
= 250;
326 ((z
== cmax
) && (!(Rand16() & 3)))) {
336 CrimeAverage
= totz
/ numz
;
339 for (x
= 0; x
< SmX
; x
++)
340 for (y
= 0; y
< SmY
; y
++)
341 PoliceMapEffect
[x
][y
] = PoliceMap
[x
][y
];
342 NewMapFlags
[DYMAP
] = NewMapFlags
[CRMAP
] = NewMapFlags
[POMAP
] = 1;
346 /* comefrom: PTLScan */
350 register int x
, y
= 0, z
= 0, dir
= 1;
352 for (x
= 0; x
< QWX
; x
++) {
353 for (; y
!= QWY
&& y
!= -1; y
+= dir
) {
354 z
+= Qtem
[(x
== 0) ? x
: (x
- 1)][y
] +
355 Qtem
[(x
== (QWX
- 1)) ? x
: (x
+ 1)][y
] +
356 Qtem
[x
][(y
== 0) ? (0) : (y
- 1)] +
357 Qtem
[x
][(y
== (QWY
- 1)) ? y
: (y
+ 1)] +
359 TerrainMem
[x
][y
] = (unsigned char)(((unsigned)z
) >>3);
366 register short x
,y
,z
;
368 for (x
= 0; x
< QWX
; x
++)
369 for (y
= 0; y
< QWY
; y
++) {
371 if (x
> 0) z
+= Qtem
[x
- 1][y
];
372 if (x
< (QWX
- 1)) z
+= Qtem
[x
+ 1][y
];
373 if (y
> 0) z
+= Qtem
[x
][y
- 1];
374 if (y
< (QWY
- 1)) z
+= Qtem
[x
][y
+ 1];
375 TerrainMem
[x
][y
] = (unsigned char)((z
>>2) + Qtem
[x
][y
]) >>1;
380 /* comefrom: PopDenScan */
381 DoSmooth (void) /* smooths data in tem[x][y] into tem2[x][y] */
384 register int x
, y
= 0, z
= 0, dir
= 1;
386 for (x
= 0; x
< HWLDX
; x
++) {
387 for (; y
!= HWLDY
&& y
!= -1; y
+= dir
) {
389 z += tem[(x == 0) ? x : (x - 1)][y] +
390 tem[(x == (HWLDX - 1)) ? x : (x + 1)][y] +
391 tem[x][(y == 0) ? (0) : (y - 1)] +
392 tem[x][(y == (HWLDY - 1)) ? y : (y + 1)] +
394 tem2[x][y] = (unsigned char)(((unsigned int)z) >>2);
397 z
+= tem
[(x
== 0) ? x
: (x
- 1)][y
] +
398 tem
[(x
== (HWLDX
- 1)) ? x
: (x
+ 1)][y
] +
399 tem
[x
][(y
== 0) ? (0) : (y
- 1)] +
400 tem
[x
][(y
== (HWLDY
- 1)) ? y
: (y
+ 1)] +
402 tem2
[x
][y
] = (unsigned char)(((unsigned int)z
) >>2);
409 register short x
,y
,z
;
411 for (x
= 0; x
< HWLDX
; x
++) {
412 for (y
= 0; y
< HWLDY
; y
++) {
414 if (x
> 0) z
+= tem
[x
- 1][y
];
415 if (x
< (HWLDX
- 1)) z
+= tem
[x
+ 1][y
];
416 if (y
> 0) z
+= tem
[x
][y
- 1];
417 if (y
< (HWLDY
- 1)) z
+= tem
[x
][y
+ 1];
418 z
= (z
+ tem
[x
][y
]) >>2;
419 if (z
> 255) z
= 255;
420 tem2
[x
][y
] = (unsigned char)z
;
427 /* comefrom: PopDenScan */
428 DoSmooth2 (void) /* smooths data in tem2[x][y] into tem[x][y] */
431 register int x
, y
= 0, z
= 0, dir
= 1;
433 for (x
= 0; x
< HWLDX
; x
++) {
434 for (; y
!= HWLDY
&& y
!= -1; y
+= dir
) {
436 z += tem2[(x == 0) ? x : (x - 1)][y] +
437 tem2[(x == (HWLDX - 1)) ? x : (x + 1)][y] +
438 tem2[x][(y == 0) ? (0) : (y - 1)] +
439 tem2[x][(y == (HWLDY - 1)) ? y : (y + 1)] +
441 tem[x][y] = (unsigned char)(z >>2);
444 z
+= tem2
[(x
== 0) ? x
: (x
- 1)][y
] +
445 tem2
[(x
== (HWLDX
- 1)) ? x
: (x
+ 1)][y
] +
446 tem2
[x
][(y
== 0) ? (0) : (y
- 1)] +
447 tem2
[x
][(y
== (HWLDY
- 1)) ? y
: (y
+ 1)] +
449 tem
[x
][y
] = (unsigned char)(((unsigned char)z
) >>2);
456 register short x
,y
,z
;
458 for (x
= 0; x
< HWLDX
; x
++) {
459 for (y
= 0; y
< HWLDY
; y
++) {
461 if (x
> 0) z
+= tem2
[x
- 1][y
];
462 if (x
< (HWLDX
- 1)) z
+= tem2
[x
+ 1][y
];
463 if (y
> 0) z
+= tem2
[x
][y
- 1];
464 if (y
< (HWLDY
- 1)) z
+= tem2
[x
][y
+ 1];
465 z
= (z
+ tem2
[x
][y
]) >>2;
466 if (z
> 255) z
= 255;
467 tem
[x
][y
] = (unsigned char)z
;
474 /* comefrom: PopDenScan */
477 register short x
, y
, z
;
480 for (x
= 0; x
< HWLDX
; x
++)
481 for (y
= 0; y
< HWLDY
; y
++)
486 /* comefrom: FireAnalysis */
489 register short x
, y
, edge
;
491 for (x
= 0; x
< SmX
; x
++)
492 for (y
= 0; y
< SmY
; y
++) {
494 if (x
) edge
+= FireStMap
[x
- 1][y
];
495 if (x
< (SmX
- 1)) edge
+= FireStMap
[x
+ 1][y
];
496 if (y
) edge
+= FireStMap
[x
][y
- 1];
497 if (y
< (SmY
- 1)) edge
+= FireStMap
[x
][y
+ 1];
498 edge
= (edge
>>2) + FireStMap
[x
][y
];
499 STem
[x
][y
] = edge
>>1;
501 for (x
= 0; x
< SmX
; x
++)
502 for (y
= 0; y
< SmY
; y
++)
503 FireStMap
[x
][y
] = STem
[x
][y
];
507 /* comefrom: CrimeScan */
512 for (x
= 0; x
< SmX
; x
++)
513 for (y
= 0; y
< SmY
; y
++) {
515 if (x
) edge
+= PoliceMap
[x
- 1][y
];
516 if (x
< (SmX
- 1)) edge
+= PoliceMap
[x
+ 1][y
];
517 if (y
) edge
+= PoliceMap
[x
][y
- 1];
518 if (y
< (SmY
- 1)) edge
+= PoliceMap
[x
][y
+ 1];
519 edge
= (edge
>>2) + PoliceMap
[x
][y
];
520 STem
[x
][y
] = edge
>>1;
522 for (x
= 0; x
< SmX
; x
++)
523 for (y
= 0; y
< SmY
; y
++)
524 PoliceMap
[x
][y
] = STem
[x
][y
];
528 /* comefrom: PopDenScan */
531 register short x
, y
, z
;
533 for (x
= 0; x
< SmX
; x
++)
534 for (y
= 0; y
< SmY
; y
++) {
535 z
= GetDisCC(x
<<2,y
<<2);