]>
git.zerfleddert.de Git - micropolis/blob - src/sim/g_map.c
5a65e00cf5db5ea554e0037bb9a3b62b7657c775
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 #define VAL_VERYHIGH 4
71 #define VAL_VERYPLUS 6
73 #define VAL_VERYMINUS 8
76 -1, COLOR_LIGHTGRAY
, COLOR_YELLOW
, COLOR_ORANGE
, COLOR_RED
,
77 COLOR_DARKGREEN
, COLOR_LIGHTGREEN
, COLOR_ORANGE
, COLOR_YELLOW
80 short valGrayMap
[] = {
81 -1, 31, 127, 191, 255,
86 void (*mapProcs
[NMAPS
])();
88 void drawPopDensity(SimView
*view
);
89 void drawRateOfGrowth(SimView
*view
);
90 void drawTrafMap(SimView
*view
);
91 void drawPolMap(SimView
*view
);
92 void drawCrimeMap(SimView
*view
);
93 void drawLandMap(SimView
*view
);
94 void drawFireRadius(SimView
*view
);
95 void drawPoliceRadius(SimView
*view
);
96 void ditherMap(SimView
*view
);
97 void drawRect(SimView
*view
, int pixel
, int solid
,
98 int x
, int y
, int w
, int h
);
99 void maybeDrawRect(SimView
*view
, int val
,
100 int x
, int y
, int w
, int h
);
105 if (x
< 50) return(VAL_NONE
);
106 if (x
< 100) return(VAL_LOW
);
107 if (x
< 150) return(VAL_MEDIUM
);
108 if (x
< 200) return(VAL_HIGH
);
109 return(VAL_VERYHIGH
);
114 drawPopDensity(SimView
*view
)
119 for (x
= 0; x
< HWLDX
; x
++) {
120 for (y
= 0; y
< HWLDY
; y
++) {
121 maybeDrawRect(view
, GetCI(PopDensity
[x
][y
]),
129 drawRateOfGrowth(SimView
*view
)
134 for (x
= 0; x
< SmX
; x
++) {
135 for (y
= 0; y
< SmY
; y
++) {
136 short val
, z
= RateOGMem
[x
][y
];
138 if (z
> 100) val
= VAL_VERYPLUS
;
140 if (z
> 20) val
= VAL_PLUS
;
142 if (z
< -100) val
= VAL_VERYMINUS
;
144 if (z
< -20) val
= VAL_MINUS
;
149 maybeDrawRect(view
, val
,
150 x
* 24, y
* 24, 24, 24);
157 drawTrafMap(SimView
*view
)
162 drawLilTransMap(view
);
164 for (x
= 0; x
< HWLDX
; x
++) {
165 for (y
= 0; y
< HWLDY
; y
++) {
166 maybeDrawRect(view
, GetCI(TrfDensity
[x
][y
]),
174 drawPolMap(SimView
*view
)
180 for (x
= 0; x
< HWLDX
; x
++) {
181 for (y
= 0; y
< HWLDY
; y
++) {
182 maybeDrawRect(view
, GetCI(10 + PollutionMem
[x
][y
]),
190 drawCrimeMap(SimView
*view
)
196 for (x
= 0; x
< HWLDX
; x
++) {
197 for (y
= 0; y
< HWLDY
; y
++) {
198 maybeDrawRect(view
, GetCI(CrimeMem
[x
][y
]),
206 drawLandMap(SimView
*view
)
212 for (x
= 0; x
< HWLDX
; x
++) {
213 for (y
= 0; y
< HWLDY
; y
++) {
214 maybeDrawRect(view
, GetCI(LandValueMem
[x
][y
]),
222 drawFireRadius(SimView
*view
)
227 for (x
= 0; x
< SmX
; x
++) {
228 for (y
= 0; y
< SmY
; y
++) {
229 maybeDrawRect(view
, GetCI(FireRate
[x
][y
]),
230 x
* 24, y
* 24, 24, 24);
237 drawPoliceRadius(SimView
*view
)
242 for (x
= 0; x
< SmX
; x
++) {
243 for (y
= 0; y
< SmY
; y
++) {
244 maybeDrawRect(view
, GetCI(PoliceMapEffect
[x
][y
]),
245 x
* 24, y
* 24, 24, 24);
254 mapProcs
[ALMAP
] = drawAll
;
255 mapProcs
[REMAP
] = drawRes
;
256 mapProcs
[COMAP
] = drawCom
;
257 mapProcs
[INMAP
] = drawInd
;
258 mapProcs
[PRMAP
] = drawPower
;
259 mapProcs
[RDMAP
] = drawLilTransMap
;
260 mapProcs
[PDMAP
] = drawPopDensity
;
261 mapProcs
[RGMAP
] = drawRateOfGrowth
;
262 mapProcs
[TDMAP
] = drawTrafMap
;
263 mapProcs
[PLMAP
] = drawPolMap
;
264 mapProcs
[CRMAP
] = drawCrimeMap
;
265 mapProcs
[LVMAP
] = drawLandMap
;
266 mapProcs
[FIMAP
] = drawFireRadius
;
267 mapProcs
[POMAP
] = drawPoliceRadius
;
268 mapProcs
[DYMAP
] = drawDynamic
;
273 MemDrawMap(SimView
*view
)
275 (*mapProcs
[view
->map_state
])(view
);
276 if (!view
->x
->color
) {
278 XSetForeground(view
->x
->dpy
, view
->x
->gc
, view
->pixels
[COLOR_BLACK
]);
279 XSetBackground(view
->x
->dpy
, view
->x
->gc
, view
->pixels
[COLOR_WHITE
]);
280 XPutImage(view
->x
->dpy
, view
->pixmap
, view
->x
->gc
, view
->image
,
281 0, 0, 0, 0, view
->m_width
, view
->m_height
);
287 ditherMap(SimView
*view
)
289 int i
, x
, y
, width
, height
;
290 int err
, pixel1
, pixel8
;
291 int line_bytes1
= view
->line_bytes
;
292 int line_bytes8
= view
->line_bytes8
;
293 unsigned char *image1
= view
->data
;
294 unsigned char *image8
= view
->data8
;
297 width
= view
->m_width
; height
= view
->m_height
;
299 errors
= (int *)malloc(sizeof(int) * (width
));
301 for (i
= 0; i
< width
; i
++)
302 errors
[i
] = (Rand16() & 15) - 7;
304 err
= (Rand16() & 15) - 7;
306 for (y
= 0; y
< height
; y
+= 2) {
307 unsigned char *i1
= image1
;
308 unsigned char *i8
= image8
;
310 image1
+= line_bytes1
;
311 image8
+= line_bytes8
;
313 for (x
= 0; x
< width
; x
+= 8) {
315 for (i
= 0; i
< 8; i
++) {
317 pixel8
= *(i8
++) + err
+ errors
[x
+ i
];
324 errors
[x
+ i
] = err
/2;
330 i1
= image1
+ (width
/ 8) - 1;
331 i8
= image8
+ width
- 1;
333 image1
+= line_bytes1
;
334 image8
+= line_bytes8
;
336 for (x
= width
- 8; x
>= 0; x
-= 8) {
338 for (i
= 7; i
>= 0; i
--) {
340 pixel8
= *(i8
--) + err
+ errors
[x
+ i
];
347 errors
[x
+ i
] = err
/2;
359 maybeDrawRect(SimView
*view
, int val
,
360 int x
, int y
, int w
, int h
)
362 if (val
== VAL_NONE
) return;
364 if (view
->x
->color
) {
365 drawRect(view
, view
->pixels
[valMap
[val
]], 0, x
, y
, w
, h
);
367 drawRect(view
, valGrayMap
[val
], 1, x
, y
, w
, h
);
373 drawRect(SimView
*view
, int pixel
, int solid
,
374 int x
, int y
, int w
, int h
)
376 int W
= view
->m_width
, H
= view
->m_height
;
379 if ((w
+= x
) < 0) w
= 0;
388 if ((h
+= y
) < 0) h
= 0;
398 int i
, j
, stipple
= (x
^ y
) & 1;
400 unsigned char *data
=
401 view
->x
->color
? view
->data
: view
->data8
;
404 /* In the case of black and white, we use an 8 bit buffer and dither it. */
406 view
->x
->color
? view
->pixel_bytes
: 1;
408 view
->x
->color
? view
->line_bytes
: view
->line_bytes8
;
411 unsigned char *image
=
412 &(data
[(line
* y
) + (x
* pixelBytes
)]);
415 switch (pixelBytes
) {
419 unsigned char *data
=
421 unsigned char *image
=
422 &data
[(line
* y
) + (x
* pixelBytes
)];
424 for (i
= h
; i
> 0; i
--) {
425 for (j
= w
; j
> 0; j
--) {
426 if (solid
|| stipple
++ & 1)
439 unsigned short *data
=
440 (unsigned short *)view
->data
;
441 unsigned short *image
;
442 line
>>= 1; /* Convert from byte offset to short offset */
444 &data
[(line
* y
) + x
];
446 for (i
= h
; i
> 0; i
--) {
447 for (j
= w
; j
> 0; j
--) {
448 if (solid
|| stipple
++ & 1) {
449 if (view
->x
->x_big_endian
) {
450 *image
= ((pixel
& 0xff) << 8) | ((pixel
& 0xff00) >> 8);
468 unsigned char *data
=
469 (unsigned char *)view
->data
;
470 unsigned char *image
;
472 &data
[(line
* y
) + x
* pixelBytes
];
474 for (i
= h
; i
> 0; i
--) {
475 for (j
= w
; j
> 0; j
--) {
476 if (view
->x
->x_big_endian
) {
477 if (pixelBytes
== 4) {
480 if (solid
|| stipple
++ & 1) {
481 *(image
++) = (pixel
>> 16) & 0xff;
482 *(image
++) = (pixel
>> 8) & 0xff;
483 *(image
++) = (pixel
>> 0) & 0xff;
488 if (solid
|| stipple
++ & 1) {
489 *(image
++) = (pixel
>> 0) & 0xff;
490 *(image
++) = (pixel
>> 8) & 0xff;
491 *(image
++) = (pixel
>> 16) & 0xff;
495 if (pixelBytes
== 4) {
503 image
+= line
- w
* pixelBytes
;
509 assert(0); /* Undefined depth */