]>
git.zerfleddert.de Git - micropolis/blob - src/sim/g_map.c
87c7e273b1c508c041e40b11de5ed4422e98d282
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 int (*mapProcs
[NMAPS
])();
88 int drawAll(SimView
*view
);
89 int drawRes(SimView
*view
);
90 int drawCom(SimView
*view
);
91 int drawInd(SimView
*view
);
92 int drawPower(SimView
*view
);
93 int drawLilTransMap(SimView
*view
);
94 int drawPopDensity(SimView
*view
);
95 int drawRateOfGrowth(SimView
*view
);
96 int drawTrafMap(SimView
*view
);
97 int drawPolMap(SimView
*view
);
98 int drawCrimeMap(SimView
*view
);
99 int drawLandMap(SimView
*view
);
100 int drawFireRadius(SimView
*view
);
101 int drawPoliceRadius(SimView
*view
);
102 int drawDynamic(SimView
*view
);
107 if (x
< 50) return(VAL_NONE
);
108 if (x
< 100) return(VAL_LOW
);
109 if (x
< 150) return(VAL_MEDIUM
);
110 if (x
< 200) return(VAL_HIGH
);
111 return(VAL_VERYHIGH
);
115 drawPopDensity(SimView
*view
)
120 for (x
= 0; x
< HWLDX
; x
++) {
121 for (y
= 0; y
< HWLDY
; y
++) {
122 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);
156 drawTrafMap(SimView
*view
)
161 drawLilTransMap(view
);
163 for (x
= 0; x
< HWLDX
; x
++) {
164 for (y
= 0; y
< HWLDY
; y
++) {
165 maybeDrawRect(view
, GetCI(TrfDensity
[x
][y
]),
172 drawPolMap(SimView
*view
)
178 for (x
= 0; x
< HWLDX
; x
++) {
179 for (y
= 0; y
< HWLDY
; y
++) {
180 maybeDrawRect(view
, GetCI(10 + PollutionMem
[x
][y
]),
187 drawCrimeMap(SimView
*view
)
193 for (x
= 0; x
< HWLDX
; x
++) {
194 for (y
= 0; y
< HWLDY
; y
++) {
195 maybeDrawRect(view
, GetCI(CrimeMem
[x
][y
]),
202 drawLandMap(SimView
*view
)
208 for (x
= 0; x
< HWLDX
; x
++) {
209 for (y
= 0; y
< HWLDY
; y
++) {
210 maybeDrawRect(view
, GetCI(LandValueMem
[x
][y
]),
217 drawFireRadius(SimView
*view
)
222 for (x
= 0; x
< SmY
; x
++) {
223 for (y
= 0; y
< SmY
; y
++) {
224 maybeDrawRect(view
, GetCI(FireRate
[x
][y
]),
225 x
* 24, y
* 24, 24, 24);
231 drawPoliceRadius(SimView
*view
)
236 for (x
= 0; x
< SmX
; x
++) {
237 for (y
= 0; y
< SmY
; y
++) {
238 maybeDrawRect(view
, GetCI(PoliceMapEffect
[x
][y
]),
239 x
* 24, y
* 24, 24, 24);
247 mapProcs
[ALMAP
] = drawAll
;
248 mapProcs
[REMAP
] = drawRes
;
249 mapProcs
[COMAP
] = drawCom
;
250 mapProcs
[INMAP
] = drawInd
;
251 mapProcs
[PRMAP
] = drawPower
;
252 mapProcs
[RDMAP
] = drawLilTransMap
;
253 mapProcs
[PDMAP
] = drawPopDensity
;
254 mapProcs
[RGMAP
] = drawRateOfGrowth
;
255 mapProcs
[TDMAP
] = drawTrafMap
;
256 mapProcs
[PLMAP
] = drawPolMap
;
257 mapProcs
[CRMAP
] = drawCrimeMap
;
258 mapProcs
[LVMAP
] = drawLandMap
;
259 mapProcs
[FIMAP
] = drawFireRadius
;
260 mapProcs
[POMAP
] = drawPoliceRadius
;
261 mapProcs
[DYMAP
] = drawDynamic
;
265 MemDrawMap(SimView
*view
)
267 (*mapProcs
[view
->map_state
])(view
);
268 if (!view
->x
->color
) {
270 XSetForeground(view
->x
->dpy
, view
->x
->gc
, view
->pixels
[COLOR_BLACK
]);
271 XSetBackground(view
->x
->dpy
, view
->x
->gc
, view
->pixels
[COLOR_WHITE
]);
272 XPutImage(view
->x
->dpy
, view
->pixmap
, view
->x
->gc
, view
->image
,
273 0, 0, 0, 0, view
->m_width
, view
->m_height
);
278 ditherMap(SimView
*view
)
280 int i
, x
, y
, width
, height
;
281 int err
, pixel1
, pixel8
;
282 int line_bytes1
= view
->line_bytes
;
283 int line_bytes8
= view
->line_bytes8
;
284 unsigned char *image1
= view
->data
;
285 unsigned char *image8
= view
->data8
;
288 width
= view
->m_width
; height
= view
->m_height
;
290 errors
= (int *)malloc(sizeof(int) * (width
));
292 for (i
= 0; i
< width
; i
++)
293 errors
[i
] = (Rand16() & 15) - 7;
295 err
= (Rand16() & 15) - 7;
297 for (y
= 0; y
< height
; y
+= 2) {
298 unsigned char *i1
= image1
;
299 unsigned char *i8
= image8
;
301 image1
+= line_bytes1
;
302 image8
+= line_bytes8
;
304 for (x
= 0; x
< width
; x
+= 8) {
306 for (i
= 0; i
< 8; i
++) {
308 pixel8
= *(i8
++) + err
+ errors
[x
+ i
];
315 errors
[x
+ i
] = err
/2;
321 i1
= image1
+ (width
/ 8) - 1;
322 i8
= image8
+ width
- 1;
324 image1
+= line_bytes1
;
325 image8
+= line_bytes8
;
327 for (x
= width
- 8; x
>= 0; x
-= 8) {
329 for (i
= 7; i
>= 0; i
--) {
331 pixel8
= *(i8
--) + err
+ errors
[x
+ i
];
338 errors
[x
+ i
] = err
/2;
349 maybeDrawRect(SimView
*view
, int val
,
350 int x
, int y
, int w
, int h
)
352 if (val
== VAL_NONE
) return;
354 if (view
->x
->color
) {
355 drawRect(view
, view
->pixels
[valMap
[val
]], 0, x
, y
, w
, h
);
357 drawRect(view
, valGrayMap
[val
], 1, x
, y
, w
, h
);
362 drawRect(SimView
*view
, int pixel
, int solid
,
363 int x
, int y
, int w
, int h
)
365 int W
= view
->m_width
, H
= view
->m_height
;
368 if ((w
+= x
) < 0) w
= 0;
377 if ((h
+= y
) < 0) h
= 0;
387 int i
, j
, stipple
= (x
^ y
) & 1;
388 unsigned char *data
=
389 view
->x
->color
? view
->data
: view
->data8
;
391 /* In the case of black and white, we use an 8 bit buffer and dither it. */
393 view
->x
->color
? view
->pixel_bytes
: 1;
395 view
->x
->color
? view
->line_bytes
: view
->line_bytes8
;
397 unsigned char *image
=
398 &(data
[(line
* y
) + (x
* pixelBytes
)]);
400 switch (pixelBytes
) {
404 unsigned char *data
=
406 unsigned char *image
=
407 &data
[(line
* y
) + (x
* pixelBytes
)];
410 for (i
= h
; i
> 0; i
--) {
411 for (j
= w
; j
> 0; j
--) {
418 for (i
= h
; i
> 0; i
--) {
419 for (j
= w
; j
> 0; j
--) {
434 unsigned short *data
=
435 (unsigned short *)view
->data
;
436 unsigned short *image
;
437 line
>>= 1; /* Convert from byte offset to short offset */
439 &data
[(line
* y
) + x
];
442 for (i
= h
; i
> 0; i
--) {
443 for (j
= w
; j
> 0; j
--) {
450 for (i
= h
; i
> 0; i
--) {
451 for (j
= w
; j
> 0; j
--) {
467 unsigned char *data
=
468 (unsigned char *)view
->data
;
469 unsigned char *image
;
471 &data
[(line
* y
) + x
* pixelBytes
];
474 for (i
= h
; i
> 0; i
--) {
475 for (j
= w
; j
> 0; j
--) {
476 *(image
++) = (pixel
>> 0) & 0xff;
477 *(image
++) = (pixel
>> 8) & 0xff;
478 *(image
++) = (pixel
>> 16) & 0xff;
479 if (pixelBytes
== 4) {
483 image
+= line
- w
* pixelBytes
;
486 for (i
= h
; i
> 0; i
--) {
487 for (j
= w
; j
> 0; j
--) {
489 *(image
++) = (pixel
>> 0) & 0xff;
490 *(image
++) = (pixel
>> 8) & 0xff;
491 *(image
++) = (pixel
>> 16) & 0xff;
495 if (pixelBytes
== 4) {
502 image
+= line
- w
* pixelBytes
;
509 assert(0); /* Undefined depth */