]>
Commit | Line | Data |
---|---|---|
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 | ||
65 | int 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 | case 32: \ | |
157 | ROW3_32 \ | |
158 | break; \ | |
159 | default: \ | |
160 | assert(0); /* Undefined depth */ \ | |
161 | break; \ | |
162 | } | |
163 | ||
164 | #define DRAW_END \ | |
165 | mem = (unsigned QUAD *)&view->smalltiles[tile * 4 * 4 * pixelBytes]; \ | |
166 | ROW3 \ | |
167 | } \ | |
168 | } | |
169 | ||
170 | ||
171 | void drawAll(SimView *view) | |
172 | { | |
173 | DRAW_BEGIN | |
174 | DRAW_END | |
175 | } | |
176 | ||
177 | ||
178 | void drawRes(SimView *view) | |
179 | { | |
180 | DRAW_BEGIN | |
181 | if (tile > 422) | |
182 | tile = 0; | |
183 | DRAW_END | |
184 | } | |
185 | ||
186 | ||
187 | void drawCom(SimView *view) | |
188 | { | |
189 | DRAW_BEGIN | |
190 | if ((tile > 609) || | |
191 | ((tile >= 232) && (tile < 423))) | |
192 | tile = 0; | |
193 | DRAW_END | |
194 | } | |
195 | ||
196 | ||
197 | void drawInd(SimView *view) | |
198 | { | |
199 | DRAW_BEGIN | |
200 | if (((tile >= 240) && (tile <= 611)) || | |
201 | ((tile >= 693) && (tile <= 851)) || | |
202 | ((tile >= 860) && (tile <= 883)) || | |
203 | (tile >= 932)) | |
204 | tile = 0; | |
205 | DRAW_END | |
206 | } | |
207 | ||
208 | ||
209 | void drawLilTransMap(SimView *view) | |
210 | { | |
211 | DRAW_BEGIN | |
212 | if ((tile >= 240) || | |
213 | ((tile >= 207) && tile <= 220) || | |
214 | (tile == 223)) | |
215 | tile = 0; | |
216 | DRAW_END | |
217 | } | |
218 | ||
219 | ||
220 | /* color pixel values */ | |
221 | #define UNPOWERED COLOR_LIGHTBLUE | |
222 | #define POWERED COLOR_RED | |
223 | #define CONDUCTIVE COLOR_LIGHTGRAY | |
224 | ||
225 | ||
226 | void drawPower(SimView *view) | |
227 | { | |
228 | short col, row; | |
229 | unsigned short tile; | |
230 | short *mp; | |
231 | unsigned char *image, *imageBase; | |
232 | unsigned QUAD *mem; | |
233 | unsigned QUAD l; | |
234 | int lineBytes = view->line_bytes8; | |
235 | int pixelBytes = view->pixel_bytes; | |
236 | ||
237 | int pix; | |
238 | int powered, unpowered, conductive; | |
239 | ||
240 | if (view->x->color) { | |
241 | powered = view->pixels[POWERED]; | |
242 | unpowered = view->pixels[UNPOWERED]; | |
243 | conductive = view->pixels[CONDUCTIVE]; | |
244 | } else { | |
245 | powered = 255; | |
246 | unpowered = 0; | |
247 | conductive = 127; | |
248 | } | |
249 | ||
250 | mp = &Map[0][0]; | |
251 | imageBase = view->x->color ? view->data : view->data8; | |
252 | ||
253 | for (col = 0; col < WORLD_X; col++) { | |
254 | image = imageBase + (3 * pixelBytes * col); | |
255 | for (row = 0; row < WORLD_Y; row++) { | |
256 | tile = *(mp++); | |
257 | ||
258 | if ((tile & LOMASK) >= TILE_COUNT) tile -= TILE_COUNT; | |
259 | ||
260 | if ((unsigned short)(tile & LOMASK) <= (unsigned short)63) { | |
261 | tile &= LOMASK; | |
262 | pix = -1; | |
263 | } else if (tile & ZONEBIT) { | |
264 | pix = (tile & PWRBIT) ? powered : unpowered; | |
265 | } else { | |
266 | if (tile & CONDBIT) { | |
267 | pix = conductive; | |
268 | } else { | |
269 | tile = 0; | |
270 | pix = -1; | |
271 | } | |
272 | } | |
273 | ||
274 | if (pix < 0) { | |
275 | mem = (unsigned QUAD *)&view->smalltiles[tile * 4 * 4 * pixelBytes]; | |
276 | ROW3 | |
277 | } else { | |
278 | switch (view->x->depth) { | |
279 | ||
280 | case 1: | |
281 | case 8: | |
282 | image[0] = image[1] = image[2] = pix; | |
283 | image += lineBytes; | |
284 | image[0] = image[1] = image[2] = pix; | |
285 | image += lineBytes; | |
286 | image[0] = image[1] = image[2] = pix; | |
287 | image += lineBytes; | |
288 | break; | |
289 | ||
290 | case 15: | |
291 | case 16: | |
292 | { | |
293 | unsigned short *p; | |
294 | p = (short *)image; | |
295 | p[0] = p[1] = p[2] = pix; | |
296 | image += lineBytes; | |
297 | p = (short *)image; | |
298 | p[0] = p[1] = p[2] = pix; | |
299 | image += lineBytes; | |
300 | p = (short *)image; | |
301 | p[0] = p[1] = p[2] = pix; | |
302 | image += lineBytes; | |
303 | } | |
304 | break; | |
305 | ||
306 | case 24: | |
307 | case 32: | |
308 | { | |
309 | int x, y; | |
310 | for (y = 0; y < 3; y++) { | |
311 | unsigned char *img = | |
312 | image; | |
313 | for (x = 0; x < 4; x++) { | |
314 | *(img++) = (pix >> 0) & 0xff; | |
315 | *(img++) = (pix >> 8) & 0xff; | |
316 | *(img++) = (pix >> 16) & 0xff; | |
317 | if (pixelBytes == 4) { | |
318 | img++; | |
319 | } // if | |
320 | } // for x | |
321 | image += lineBytes; | |
322 | } // for y | |
323 | } | |
324 | break; | |
325 | ||
326 | default: | |
327 | assert(0); /* Undefined depth */ | |
328 | break; | |
329 | ||
330 | } | |
331 | } | |
332 | } | |
333 | } | |
334 | } | |
335 | ||
336 | ||
337 | int dynamicFilter(int col, int row) | |
338 | { | |
339 | int r, c, x; | |
340 | ||
341 | r = row >>1; | |
342 | c = col >>1; | |
343 | ||
344 | if (((DynamicData[0] > DynamicData[1]) || | |
345 | ((x = PopDensity[c][r]) >= DynamicData[0]) && | |
346 | (x <= DynamicData[1])) && | |
347 | ((DynamicData[2] > DynamicData[3]) || | |
348 | ((x = RateOGMem[c>>2][r>>2]) >= ((2 * DynamicData[2]) - 256)) && | |
349 | (x <= ((2 * DynamicData[3]) - 256))) && | |
350 | ((DynamicData[4] > DynamicData[5]) || | |
351 | ((x = TrfDensity[c][r]) >= DynamicData[4]) && | |
352 | (x <= DynamicData[5])) && | |
353 | ((DynamicData[6] > DynamicData[7]) || | |
354 | ((x = PollutionMem[c][r]) >= DynamicData[6]) && | |
355 | (x <= DynamicData[7])) && | |
356 | ((DynamicData[8] > DynamicData[9]) || | |
357 | ((x = CrimeMem[c][r]) >= DynamicData[8]) && | |
358 | (x <= DynamicData[9])) && | |
359 | ((DynamicData[10] > DynamicData[11]) || | |
360 | ((x = LandValueMem[c][r]) >= DynamicData[10]) && | |
361 | (x <= DynamicData[11])) && | |
362 | ((DynamicData[12] > DynamicData[13]) || | |
363 | ((x = PoliceMapEffect[c>>2][r>>2]) >= DynamicData[12]) && | |
364 | (x <= DynamicData[13])) && | |
365 | ((DynamicData[14] > DynamicData[15]) || | |
366 | ((x = FireRate[c>>2][r>>2]) >= DynamicData[14]) && | |
367 | (x <= DynamicData[15]))) { | |
368 | return 1; | |
369 | } else { | |
370 | return 0; | |
371 | } // if | |
372 | } | |
373 | ||
374 | ||
375 | void drawDynamic(SimView *view) | |
376 | { | |
377 | DRAW_BEGIN | |
378 | if (tile > 63) { | |
379 | if (!dynamicFilter(col, row)) { | |
380 | tile = 0; | |
381 | } // if | |
382 | } // if | |
383 | DRAW_END | |
384 | } | |
385 | ||
386 |