]> cvs.zerfleddert.de Git - micropolis/blame - src/sim/g_smmaps.c
Import Micropolis from http://www.donhopkins.com/home/micropolis/
[micropolis] / src / sim / g_smmaps.c
CommitLineData
6a5fa4e0
MG
1/* g_smmaps.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 micropolis@laptop.org.
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
65int DynamicData[32];
66
67
68#define DRAW_BEGIN \
69 int col, row; \
70 unsigned short tile; \
71 short *mp; \
72 unsigned char *imageBase; \
73 unsigned char *image; \
74 unsigned QUAD *mem; \
75 unsigned QUAD l; \
76 int lineBytes = view->line_bytes8; \
77 int pixelBytes = view->pixel_bytes; \
78 mp = &Map[0][0]; \
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;
85
86
87#if defined(MSDOS) || defined(OSF1) || defined(IS_INTEL)
88
89#define ROW1_8(n) \
90 l = mem[n]; \
91 image[0] = l; \
92 image[1] = l >>8; \
93 image[2] = l >>16; \
94 image += lineBytes;
95
96#define ROW1_16(n) \
97 memcpy((char *)image, ((char *)mem) + (n * 4 * 2), (3 * 2)); \
98 image += lineBytes;
99
100#define ROW1_24(n) \
101 memcpy((char *)image, ((char *)mem) + (n * 4 * 3), (3 * 3)); \
102 image += lineBytes;
103
104#define ROW1_32(n) \
105 memcpy((char *)image, ((char *)mem) + (n * 4 * 4), (3 * 4)); \
106 image += lineBytes;
107
108#else
109
110#define ROW1_8(n) \
111 l = mem[n]; \
112 image[0] = l >>24; \
113 image[1] = l >>16; \
114 image[2] = l >>8; \
115 image += lineBytes;
116
117#define ROW1_16(n) \
118 l = mem[n]; /* XXX: WRONG. handle depth */ \
119 image[0] = l >>24; \
120 image[1] = l >>16; \
121 image[2] = l >>8; \
122 image += lineBytes;
123
124#define ROW1_24(n) \
125 l = mem[n]; /* XXX: WRONG. handle depth */ \
126 image[0] = l >>24; \
127 image[1] = l >>16; \
128 image[2] = l >>8; \
129 image += lineBytes;
130
131#define ROW1_32(n) \
132 l = mem[n]; /* XXX: WRONG. handle depth */ \
133 image[0] = l >>24; \
134 image[1] = l >>16; \
135 image[2] = l >>8; \
136 image += lineBytes;
137
138#endif
139
140#define ROW3_8 ROW1_8(0) ROW1_8(1) ROW1_8(2)
141#define ROW3_16 ROW1_16(0) ROW1_16(1) ROW1_16(2)
142#define ROW3_24 ROW1_24(0) ROW1_24(1) ROW1_24(2)
143#define ROW3_32 ROW1_32(0) ROW1_32(1) ROW1_32(2)
144
145#define ROW3 \
146 switch (view->x->depth) { \
147 case 1: \
148 case 8: \
149 ROW3_8 \
150 break; \
151 case 15: \
152 case 16: \
153 ROW3_16 \
154 break; \
155 case 24: \
156 ROW3_24 \
157 break; \
158 case 32: \
159 ROW3_32 \
160 break; \
161 default: \
162 assert(0); /* Undefined depth */ \
163 break; \
164 }
165
166#define DRAW_END \
167 mem = (unsigned QUAD *)&view->smalltiles[tile * 4 * 4 * pixelBytes]; \
168 ROW3 \
169 } \
170 }
171
172
173void drawAll(SimView *view)
174{
175 DRAW_BEGIN
176 DRAW_END
177}
178
179
180void drawRes(SimView *view)
181{
182 DRAW_BEGIN
183 if (tile > 422)
184 tile = 0;
185 DRAW_END
186}
187
188
189void drawCom(SimView *view)
190{
191 DRAW_BEGIN
192 if ((tile > 609) ||
193 ((tile >= 232) && (tile < 423)))
194 tile = 0;
195 DRAW_END
196}
197
198
199void drawInd(SimView *view)
200{
201 DRAW_BEGIN
202 if (((tile >= 240) && (tile <= 611)) ||
203 ((tile >= 693) && (tile <= 851)) ||
204 ((tile >= 860) && (tile <= 883)) ||
205 (tile >= 932))
206 tile = 0;
207 DRAW_END
208}
209
210
211void drawLilTransMap(SimView *view)
212{
213 DRAW_BEGIN
214 if ((tile >= 240) ||
215 ((tile >= 207) && tile <= 220) ||
216 (tile == 223))
217 tile = 0;
218 DRAW_END
219}
220
221
222/* color pixel values */
223#define UNPOWERED COLOR_LIGHTBLUE
224#define POWERED COLOR_RED
225#define CONDUCTIVE COLOR_LIGHTGRAY
226
227
228void drawPower(SimView *view)
229{
230 short col, row;
231 unsigned short tile;
232 short *mp;
233 unsigned char *image, *imageBase;
234 unsigned QUAD *mem;
235 unsigned QUAD l;
236 int lineBytes = view->line_bytes8;
237 int pixelBytes = view->pixel_bytes;
238
239 int pix;
240 int powered, unpowered, conductive;
241
242 if (view->x->color) {
243 powered = view->pixels[POWERED];
244 unpowered = view->pixels[UNPOWERED];
245 conductive = view->pixels[CONDUCTIVE];
246 } else {
247 powered = 255;
248 unpowered = 0;
249 conductive = 127;
250 }
251
252 mp = &Map[0][0];
253 imageBase = view->x->color ? view->data : view->data8;
254
255 for (col = 0; col < WORLD_X; col++) {
256 image = imageBase + (3 * pixelBytes * col);
257 for (row = 0; row < WORLD_Y; row++) {
258 tile = *(mp++);
259
260 if ((tile & LOMASK) >= TILE_COUNT) tile -= TILE_COUNT;
261
262 if ((unsigned short)(tile & LOMASK) <= (unsigned short)63) {
263 tile &= LOMASK;
264 pix = -1;
265 } else if (tile & ZONEBIT) {
266 pix = (tile & PWRBIT) ? powered : unpowered;
267 } else {
268 if (tile & CONDBIT) {
269 pix = conductive;
270 } else {
271 tile = 0;
272 pix = -1;
273 }
274 }
275
276 if (pix < 0) {
277 mem = (unsigned QUAD *)&view->smalltiles[tile * 4 * 4 * pixelBytes];
278 ROW3
279 } else {
280 switch (view->x->depth) {
281
282 case 1:
283 case 8:
284 image[0] = image[1] = image[2] = pix;
285 image += lineBytes;
286 image[0] = image[1] = image[2] = pix;
287 image += lineBytes;
288 image[0] = image[1] = image[2] = pix;
289 image += lineBytes;
290 break;
291
292 case 15:
293 case 16:
294 {
295 unsigned short *p;
296 p = (short *)image;
297 p[0] = p[1] = p[2] = pix;
298 image += lineBytes;
299 p = (short *)image;
300 p[0] = p[1] = p[2] = pix;
301 image += lineBytes;
302 p = (short *)image;
303 p[0] = p[1] = p[2] = pix;
304 image += lineBytes;
305 }
306 break;
307
308 case 24:
309 case 32:
310 {
311 int x, y;
312 for (y = 0; y < 3; y++) {
313 unsigned char *img =
314 image;
315 for (x = 0; x < 4; x++) {
316 *(img++) = (pix >> 0) & 0xff;
317 *(img++) = (pix >> 8) & 0xff;
318 *(img++) = (pix >> 16) & 0xff;
319 if (pixelBytes == 4) {
320 img++;
321 } // if
322 } // for x
323 image += lineBytes;
324 } // for y
325 }
326 break;
327
328 default:
329 assert(0); /* Undefined depth */
330 break;
331
332 }
333 }
334 }
335 }
336}
337
338
339int dynamicFilter(int col, int row)
340{
341 int r, c, x;
342
343 r = row >>1;
344 c = col >>1;
345
346 if (((DynamicData[0] > DynamicData[1]) ||
347 ((x = PopDensity[c][r]) >= DynamicData[0]) &&
348 (x <= DynamicData[1])) &&
349 ((DynamicData[2] > DynamicData[3]) ||
350 ((x = RateOGMem[c>>2][r>>2]) >= ((2 * DynamicData[2]) - 256)) &&
351 (x <= ((2 * DynamicData[3]) - 256))) &&
352 ((DynamicData[4] > DynamicData[5]) ||
353 ((x = TrfDensity[c][r]) >= DynamicData[4]) &&
354 (x <= DynamicData[5])) &&
355 ((DynamicData[6] > DynamicData[7]) ||
356 ((x = PollutionMem[c][r]) >= DynamicData[6]) &&
357 (x <= DynamicData[7])) &&
358 ((DynamicData[8] > DynamicData[9]) ||
359 ((x = CrimeMem[c][r]) >= DynamicData[8]) &&
360 (x <= DynamicData[9])) &&
361 ((DynamicData[10] > DynamicData[11]) ||
362 ((x = LandValueMem[c][r]) >= DynamicData[10]) &&
363 (x <= DynamicData[11])) &&
364 ((DynamicData[12] > DynamicData[13]) ||
365 ((x = PoliceMapEffect[c>>2][r>>2]) >= DynamicData[12]) &&
366 (x <= DynamicData[13])) &&
367 ((DynamicData[14] > DynamicData[15]) ||
368 ((x = FireRate[c>>2][r>>2]) >= DynamicData[14]) &&
369 (x <= DynamicData[15]))) {
370 return 1;
371 } else {
372 return 0;
373 } // if
374}
375
376
377void drawDynamic(SimView *view)
378{
379 DRAW_BEGIN
380 if (tile > 63) {
381 if (!dynamicFilter(col, row)) {
382 tile = 0;
383 } // if
384 } // if
385 DRAW_END
386}
387
388
Impressum, Datenschutz