]>
git.zerfleddert.de Git - micropolis/blob - src/sim/g_smmaps.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
70 unsigned short tile; \
72 unsigned char *imageBase; \
73 unsigned char *image; \
76 int lineBytes = view->line_bytes8; \
77 int pixelBytes = view->pixel_bytes; \
79 imageBase = view->x->color ? view->data : view->data8; \
80 for (col = 0; col < WORLD_X; col++) { \
81 image = imageBase + (3 * pixelBytes * col); \
82 for (row = 0; row < WORLD_Y; row++) { \
83 tile = *(mp++) & LOMASK; \
84 if (tile >= TILE_COUNT) tile -= TILE_COUNT;
87 #define LE_ROW1_8(n) \
94 #define LE_ROW1_16(n) \
95 memcpy((char *)image, ((char *)mem) + (n * 4 * 2), (3 * 2)); \
98 #define LE_ROW1_24(n) \
99 memcpy((char *)image, ((char *)mem) + (n * 4 * 3), (3 * 3)); \
102 #define LE_ROW1_32(n) \
103 memcpy((char *)image, ((char *)mem) + (n * 4 * 4), (3 * 4)); \
106 #define BE_ROW1_8(n) \
113 #define BE_ROW1_16(n) \
114 l = mem[n]; /* XXX: WRONG. handle depth */ \
120 #define BE_ROW1_24(n) \
121 l = mem[n]; /* XXX: WRONG. handle depth */ \
127 #define BE_ROW1_32(n) \
128 l = mem[n]; /* XXX: WRONG. handle depth */ \
134 #define LE_ROW3_8 LE_ROW1_8(0) LE_ROW1_8(1) LE_ROW1_8(2)
135 #define LE_ROW3_16 LE_ROW1_16(0) LE_ROW1_16(1) LE_ROW1_16(2)
136 #define LE_ROW3_24 LE_ROW1_24(0) LE_ROW1_24(1) LE_ROW1_24(2)
137 #define LE_ROW3_32 LE_ROW1_32(0) LE_ROW1_32(1) LE_ROW1_32(2)
139 #define BE_ROW3_8 BE_ROW1_8(0) BE_ROW1_8(1) BE_ROW1_8(2)
140 #define BE_ROW3_16 BE_ROW1_16(0) BE_ROW1_16(1) BE_ROW1_16(2)
141 #define BE_ROW3_24 BE_ROW1_24(0) BE_ROW1_24(1) BE_ROW1_24(2)
142 #define BE_ROW3_32 BE_ROW1_32(0) BE_ROW1_32(1) BE_ROW1_32(2)
144 #define ROW3_8 if (view->x->needs_swap) { BE_ROW3_8 } else { LE_ROW3_8 }
145 #define ROW3_16 LE_ROW3_16
146 #define ROW3_24 LE_ROW3_24
147 #define ROW3_32 LE_ROW3_32
150 switch (view->x->depth) { \
164 assert(0); /* Undefined depth */ \
169 mem = (unsigned QUAD *)&view->smalltiles[tile * 4 * 4 * pixelBytes]; \
175 void drawAll(SimView
*view
)
182 void drawRes(SimView
*view
)
191 void drawCom(SimView
*view
)
195 ((tile
>= 232) && (tile
< 423)))
201 void drawInd(SimView
*view
)
204 if (((tile
>= 240) && (tile
<= 611)) ||
205 ((tile
>= 693) && (tile
<= 851)) ||
206 ((tile
>= 860) && (tile
<= 883)) ||
213 void drawLilTransMap(SimView
*view
)
217 ((tile
>= 207) && tile
<= 220) ||
224 /* color pixel values */
225 #define UNPOWERED COLOR_LIGHTBLUE
226 #define POWERED COLOR_RED
227 #define CONDUCTIVE COLOR_LIGHTGRAY
230 void drawPower(SimView
*view
)
235 unsigned char *image
, *imageBase
;
238 int lineBytes
= view
->line_bytes8
;
239 int pixelBytes
= view
->pixel_bytes
;
242 int powered
, unpowered
, conductive
;
244 if (view
->x
->color
) {
245 powered
= view
->pixels
[POWERED
];
246 unpowered
= view
->pixels
[UNPOWERED
];
247 conductive
= view
->pixels
[CONDUCTIVE
];
255 imageBase
= view
->x
->color
? view
->data
: view
->data8
;
257 for (col
= 0; col
< WORLD_X
; col
++) {
258 image
= imageBase
+ (3 * pixelBytes
* col
);
259 for (row
= 0; row
< WORLD_Y
; row
++) {
262 if ((tile
& LOMASK
) >= TILE_COUNT
) tile
-= TILE_COUNT
;
264 if ((unsigned short)(tile
& LOMASK
) <= (unsigned short)63) {
267 } else if (tile
& ZONEBIT
) {
268 pix
= (tile
& PWRBIT
) ? powered
: unpowered
;
270 if (tile
& CONDBIT
) {
279 mem
= (unsigned QUAD
*)&view
->smalltiles
[tile
* 4 * 4 * pixelBytes
];
282 switch (view
->x
->depth
) {
286 image
[0] = image
[1] = image
[2] = pix
;
288 image
[0] = image
[1] = image
[2] = pix
;
290 image
[0] = image
[1] = image
[2] = pix
;
298 p
= (unsigned short *)image
;
299 if (view
->x
->x_big_endian
) {
300 p
[0] = p
[1] = p
[2] = ((pix
& 0xff) << 8) | ((pix
& 0xff00) >> 8);
302 p
[0] = p
[1] = p
[2] = pix
;
305 p
= (unsigned short *)image
;
306 if (view
->x
->x_big_endian
) {
307 p
[0] = p
[1] = p
[2] = ((pix
& 0xff) << 8) | ((pix
& 0xff00) >> 8);
309 p
[0] = p
[1] = p
[2] = pix
;
312 p
= (unsigned short *)image
;
313 if (view
->x
->x_big_endian
) {
314 p
[0] = p
[1] = p
[2] = ((pix
& 0xff) << 8) | ((pix
& 0xff00) >> 8);
316 p
[0] = p
[1] = p
[2] = pix
;
326 for (y
= 0; y
< 3; y
++) {
329 for (x
= 0; x
< 4; x
++) {
330 if (view
->x
->x_big_endian
) {
331 if (pixelBytes
== 4) {
334 *(img
++) = (pix
>> 16) & 0xff;
335 *(img
++) = (pix
>> 8) & 0xff;
336 *(img
++) = (pix
>> 0) & 0xff;
338 *(img
++) = (pix
>> 0) & 0xff;
339 *(img
++) = (pix
>> 8) & 0xff;
340 *(img
++) = (pix
>> 16) & 0xff;
341 if (pixelBytes
== 4) {
352 assert(0); /* Undefined depth */
362 int dynamicFilter(int col
, int row
)
369 if (((DynamicData
[0] > DynamicData
[1]) ||
370 (((x
= PopDensity
[c
][r
]) >= DynamicData
[0]) &&
371 (x
<= DynamicData
[1]))) &&
372 ((DynamicData
[2] > DynamicData
[3]) ||
373 (((x
= RateOGMem
[c
>>2][r
>>2]) >= ((2 * DynamicData
[2]) - 256)) &&
374 (x
<= ((2 * DynamicData
[3]) - 256)))) &&
375 ((DynamicData
[4] > DynamicData
[5]) ||
376 (((x
= TrfDensity
[c
][r
]) >= DynamicData
[4]) &&
377 (x
<= DynamicData
[5]))) &&
378 ((DynamicData
[6] > DynamicData
[7]) ||
379 (((x
= PollutionMem
[c
][r
]) >= DynamicData
[6]) &&
380 (x
<= DynamicData
[7]))) &&
381 ((DynamicData
[8] > DynamicData
[9]) ||
382 (((x
= CrimeMem
[c
][r
]) >= DynamicData
[8]) &&
383 (x
<= DynamicData
[9]))) &&
384 ((DynamicData
[10] > DynamicData
[11]) ||
385 (((x
= LandValueMem
[c
][r
]) >= DynamicData
[10]) &&
386 (x
<= DynamicData
[11]))) &&
387 ((DynamicData
[12] > DynamicData
[13]) ||
388 (((x
= PoliceMapEffect
[c
>>2][r
>>2]) >= DynamicData
[12]) &&
389 (x
<= DynamicData
[13]))) &&
390 ((DynamicData
[14] > DynamicData
[15]) ||
391 (((x
= FireRate
[c
>>2][r
>>2]) >= DynamicData
[14]) &&
392 (x
<= DynamicData
[15])))) {
400 void drawDynamic(SimView
*view
)
404 if (!dynamicFilter(col
, row
)) {