Micropolis
map.cpp
Go to the documentation of this file.
1 /* map.cpp
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 
76 
77 
78 #include "micropolis.h"
79 
80 
81 // NOTE: This is disabled, and should be re-implementd in the front-end.
82 
83 
84 #if 0
85 
86 
88 // Disabled this small map drawing, filtering and overlaying code.
89 // Going to re-implement it in the tile engine and Python.
90 
91 
92 #define VAL_NONE 0
93 #define VAL_LOW 1
94 #define VAL_MEDIUM 2
95 #define VAL_HIGH 3
96 #define VAL_VERYHIGH 4
97 #define VAL_PLUS 5
98 #define VAL_VERYPLUS 6
99 #define VAL_MINUS 7
100 #define VAL_VERYMINUS 8
101 
102 
103 /* These are names of the 16 colors */
104 #define COLOR_WHITE 0
105 #define COLOR_YELLOW 1
106 #define COLOR_ORANGE 2
107 #define COLOR_RED 3
108 #define COLOR_DARKRED 4
109 #define COLOR_DARKBLUE 5
110 #define COLOR_LIGHTBLUE 6
111 #define COLOR_BROWN 7
112 #define COLOR_LIGHTGREEN 8
113 #define COLOR_DARKGREEN 9
114 #define COLOR_OLIVE 10
115 #define COLOR_LIGHTBROWN 11
116 #define COLOR_LIGHTGRAY 12
117 #define COLOR_MEDIUMGRAY 13
118 #define COLOR_DARKGRAY 14
119 #define COLOR_BLACK 15
120 
121 
122 /*
123 
124 static short valMap[] = {
125  -1, // VAL_NONE
126  COLOR_LIGHTGRAY, // VAL_LOW
127  COLOR_YELLOW, // VAL_MEDIUM
128  COLOR_ORANGE, // VAL_HIGH
129  COLOR_RED, // VAL_VERYHIGH
130  COLOR_DARKGREEN, // VAL_PLUS
131  COLOR_LIGHTGREEN, // VAL_VERYPLUS
132  COLOR_ORANGE, // VAL_MINUS
133  COLOR_YELLOW, // VAL_VERYMINUS
134 };
135 
136 
137 static short valGrayMap[] = {
138  -1, 31, 127, 191, 255,
139  223, 255, 31, 0
140 };
141 
142 */
143 
144 
145 /* color pixel values */
146 #define UNPOWERED COLOR_LIGHTBLUE
147 #define POWERED COLOR_RED
148 #define CONDUCTIVE COLOR_LIGHTGRAY
149 
150 
151 #define DRAW_BEGIN \
152  int col, row; \
153  unsigned short tile; \
154  short *mp; \
155  unsigned char *imageBase; \
156  unsigned char *image; \
157  UQuad *mem; \
158  UQuad m; \
159  int lineBytes = view->line_bytes8; \
160  int pixelBytes = view->pixel_bytes; \
161  mp = &map[0][0]; \
162  imageBase = view->x->color ? view->data : view->data8; \
163  for (col = 0; col < WORLD_W; col++) { \
164  image = imageBase + (3 * pixelBytes * col); \
165  for (row = 0; row < WORLD_H; row++) { \
166  tile = *(mp++) & LOMASK; \
167  if (tile >= TILE_COUNT) { \
168  tile -= TILE_COUNT; \
169  }
170 
171 
172 #ifdef IS_INTEL
173 
174 #define ROW1_8(n) \
175  m = mem[n]; \
176  image[0] = (unsigned char)(m); \
177  image[1] = (unsigned char)(m >>8); \
178  image[2] = (unsigned char)(m >>16); \
179  image += lineBytes;
180 
181 #define ROW1_16(n) \
182  memcpy((char *)image, ((char *)mem) + (n * 4 * 2), (3 * 2)); \
183  image += lineBytes;
184 
185 #define ROW1_24(n) \
186  memcpy((char *)image, ((char *)mem) + (n * 4 * 3), (3 * 3)); \
187  image += lineBytes;
188 
189 #define ROW1_32(n) \
190  memcpy((char *)image, ((char *)mem) + (n * 4 * 4), (3 * 4)); \
191  image += lineBytes;
192 
193 #else
194 
195 #define ROW1_8(n) \
196  m = (UQuad)(mem[n]); \
197  image[0] = (unsigned char)(m >>24); \
198  image[1] = (unsigned char)(m >>16); \
199  image[2] = (unsigned char)(m >>8); \
200  image += lineBytes;
201 
202 #define ROW1_16(n) \
203  m = (UQuad)mem[n]; /* XXX: WRONG. handle depth */ \
204  image[0] = (unsigned char)(m >>24); \
205  image[1] = (unsigned char)(m >>16); \
206  image[2] = (unsigned char)(m >>8); \
207  image += lineBytes;
208 
209 #define ROW1_24(n) \
210  m = (UQuad)mem[n]; /* XXX: WRONG. handle depth */ \
211  image[0] = (unsigned char)(m >>24); \
212  image[1] = (unsigned char)(m >>16); \
213  image[2] = (unsigned char)(m >>8); \
214  image += lineBytes;
215 
216 #define ROW1_32(n) \
217  m = (UQuad)mem[n]; /* XXX: WRONG. handle depth */ \
218  image[0] = (unsigned char)(m >>24); \
219  image[1] = (unsigned char)(m >>16); \
220  image[2] = (unsigned char)(m >>8); \
221  image += lineBytes;
222 
223 #endif
224 
225 #define ROW3_8 ROW1_8(0) ROW1_8(1) ROW1_8(2)
226 #define ROW3_16 ROW1_16(0) ROW1_16(1) ROW1_16(2)
227 #define ROW3_24 ROW1_24(0) ROW1_24(1) ROW1_24(2)
228 #define ROW3_32 ROW1_32(0) ROW1_32(1) ROW1_32(2)
229 
230 #define ROW3 \
231  switch (view->x->depth) { \
232  case 1: \
233  case 8: \
234  ROW3_8 \
235  break; \
236  case 15: \
237  case 16: \
238  ROW3_16 \
239  break; \
240  case 24: \
241  ROW3_24 \
242  break; \
243  case 32: \
244  ROW3_32 \
245  break; \
246  default: \
247  assert(0); /* Undefined depth */ \
248  break; \
249  }
250 
251 #define DRAW_END \
252  mem = (UQuad *)&view->smalltiles[tile * 4 * 4 * pixelBytes]; \
253  ROW3 \
254  } \
255  }
256 
257 
258 void Micropolis::drawAll()
259 {
260  DRAW_BEGIN
261  DRAW_END
262 }
263 
264 
265 void Micropolis::drawRes()
266 {
267  DRAW_BEGIN
268  if (tile >= COMBASE) {
269  tile = DIRT;
270  }
271  DRAW_END
272 }
273 
274 
275 void Micropolis::drawCom()
276 {
277  DRAW_BEGIN
278  if ((tile > COMLAST) ||
279  ((tile >= LVRAIL6) &&
280  (tile < COMBASE))) {
281  tile = DIRT;
282  }
283  DRAW_END
284 }
285 
286 
287 void Micropolis::drawInd()
288 
289 {
290  DRAW_BEGIN
291  if (((tile >= RESBASE) && (tile < INDBASE)) ||
292  ((tile >= PORTBASE) && (tile < SMOKEBASE)) ||
293  ((tile >= TINYEXP) && (tile <= TINYEXPLAST)) ||
294  (tile >= FOOTBALLGAME1)) {
295  tile = DIRT;
296  }
297  DRAW_END
298 }
299 
300 
301 void Micropolis::drawLilTransMap()
302 {
303  DRAW_BEGIN
304  if ((tile >= RESBASE) ||
305  ((tile >= BRWXXX7) && (tile <= LVPOWER10)) ||
306  (tile == UNUSED_TRASH6)) {
307  tile = DIRT;
308  }
309  DRAW_END
310 }
311 
312 
313 void Micropolis::drawPowerGrid()
314 {
315  short col, row;
316  unsigned short tile;
317  short *mp;
318  unsigned char *image, *imageBase;
319  UQuad *mem;
320  UQuad m;
321  int lineBytes = view->line_bytes8;
322  int pixelBytes = view->pixel_bytes;
323 
324  int pix;
325  int powered, unpowered, conductive;
326 
327  if (view->x->color) {
328  powered = view->pixels[POWERED];
329  unpowered = view->pixels[UNPOWERED];
330  conductive = view->pixels[CONDUCTIVE];
331  } else {
332  powered = 255;
333  unpowered = 0;
334  conductive = 127;
335  }
336 
337  mp =
338  &map[0][0];
339  imageBase =
340  view->x->color ? view->data : view->data8;
341 
342  for (col = 0; col < WORLD_W; col++) {
343 
344  image =
345  imageBase + (3 * pixelBytes * col);
346 
347  for (row = 0; row < WORLD_H; row++) {
348  tile = *(mp++);
349 
350  if ((tile & LOMASK) >= TILE_COUNT) {
351  tile -= TILE_COUNT;
352  }
353 
354  if ((tile & LOMASK) <= LASTFIRE) {
355  tile &= LOMASK;
356  pix = -1;
357  } else if (tile & ZONEBIT) {
358  pix = (tile & PWRBIT) ? powered : unpowered;
359  } else {
360  if (tile & CONDBIT) {
361  pix = conductive;
362  } else {
363  tile = DIRT;
364  pix = -1;
365  }
366  }
367 
368  if (pix < 0) {
369  mem = (UQuad *)&view->smalltiles[tile * 4 * 4 * pixelBytes];
370  ROW3
371  } else {
372  switch (view->x->depth) {
373 
374  case 1:
375  case 8:
376  image[0] = image[1] = image[2] = pix;
377  image += lineBytes;
378  image[0] = image[1] = image[2] = pix;
379  image += lineBytes;
380  image[0] = image[1] = image[2] = pix;
381  image += lineBytes;
382  break;
383 
384  case 15:
385  case 16: {
386  unsigned short *p;
387  p = (unsigned short *)image;
388  p[0] = p[1] = p[2] = pix;
389  image += lineBytes;
390  p = (unsigned short *)image;
391  p[0] = p[1] = p[2] = pix;
392  image += lineBytes;
393  p = (unsigned short *)image;
394  p[0] = p[1] = p[2] = pix;
395  image += lineBytes;
396  break;
397  }
398 
399  case 24:
400  case 32: {
401  int x, y;
402  for (y = 0; y < 3; y++) {
403  unsigned char *img = image;
404  for (x = 0; x < 4; x++) {
405  *(img++) = (pix >> 0) & 0xff;
406  *(img++) = (pix >> 8) & 0xff;
407  *(img++) = (pix >> 16) & 0xff;
408  if (pixelBytes == 4) {
409  img++;
410  } // if
411  } // for x
412  image += lineBytes;
413  } // for y
414  break;
415  }
416 
417  default:
418  assert(0); /* Undefined depth */
419  break;
420 
421  }
422  }
423  }
424  }
425 }
426 
427 
428 bool Micropolis::dynamicFilter(
429  int col,
430  int row)
431 {
432  int populationDensity = populationDensityMap.worldGet(col, row);
433  int rateOfGrowth = rateOfGrowthMap.worldGet(col, row);
434  int traffic = trafficDensityMap.worldGet(col, row);
435  int pollution = pollutionDensityMap.worldGet(col, row);
436  int crime = crimeRateMap.worldGet(col, row);
437  int landValue = landValueMap.worldGet(col, row);
438  int police = policeStationEffectMap.worldGet(col, row);
439  int fire = fireStationEffectMap.worldGet(col, row);
440 
441 
442  return (
443  ((dynamicData[0] > dynamicData[1]) ||
444  (populationDensity >= dynamicData[0]) &&
445  (populationDensity <= dynamicData[1])) &&
446  ((dynamicData[2] > dynamicData[3]) ||
447  (rateOfGrowth >= ((2 * dynamicData[2]) - 256)) &&
448  (rateOfGrowth <= ((2 * dynamicData[3]) - 256))) &&
449  ((dynamicData[4] > dynamicData[5]) ||
450  (traffic >= dynamicData[4]) &&
451  (traffic <= dynamicData[5])) &&
452  ((dynamicData[6] > dynamicData[7]) ||
453  (pollution >= dynamicData[6]) &&
454  (pollution <= dynamicData[7])) &&
455  ((dynamicData[8] > dynamicData[9]) ||
456  (crime >= dynamicData[8]) &&
457  (crime <= dynamicData[9])) &&
458  ((dynamicData[10] > dynamicData[11]) ||
459  (landValue >= dynamicData[10]) &&
460  (landValue <= dynamicData[11])) &&
461  ((dynamicData[12] > dynamicData[13]) ||
462  (police >= dynamicData[12]) &&
463  (police <= dynamicData[13])) &&
464  ((dynamicData[14] > dynamicData[15]) ||
465  (fire >= dynamicData[14]) &&
466  (fire <= dynamicData[15])));
467 }
468 
469 
470 void Micropolis::drawDynamic()
471 {
472  DRAW_BEGIN
473  if (tile > LASTFIRE) {
474  if (!dynamicFilter(col, row)) {
475  tile = DIRT;
476  } // if
477  } // if
478  DRAW_END
479 }
480 
481 
482 short Micropolis::getCI(short x)
483 {
484  if (x < 50) {
485  return VAL_NONE;
486  }
487  if (x < 100) {
488  return VAL_LOW;
489  }
490  if (x < 150) {
491  return VAL_MEDIUM;
492  }
493  if (x < 200) {
494  return VAL_HIGH;
495  }
496  return VAL_VERYHIGH;
497 }
498 
500 void Micropolis::drawPopulationDensity()
501 {
502  short x, y;
503 
504  drawAll();
505  for (x = 0; x < WORLD_W; x += populationDensityMap.MAP_BLOCKSIZE) {
506  for (y = 0; y < WORLD_H; y += populationDensityMap.MAP_BLOCKSIZE) {
507  maybeDrawRect(
508  getCI(populationDensityMap.worldGet(x, y)),
509  x * 3,
510  y * 3,
513  }
514  }
515 }
516 
517 
518 void Micropolis::drawRateOfGrowth()
519 {
520  short x, y;
521 
522  drawAll();
523 
524  for (x = 0; x < rateOfGrowthMap.MAP_W; x++) {
525  for (y = 0; y < rateOfGrowthMap.MAP_H; y++) {
526  short val;
527  short z = rateOfGrowthMap.get(x, y);
528  if (z > 100) {
529  val = VAL_VERYPLUS;
530  } else {
531  if (z > 20) {
532  val = VAL_PLUS;
533  } else {
534  if (z < -100) {
535  val = VAL_VERYMINUS;
536  } else {
537  if (z < -20) {
538  val = VAL_MINUS;
539  } else {
540  val = VAL_NONE;
541  }
542  }
543  }
544  }
545  maybeDrawRect(
546  val,
547  x * 24,
548  y * 24,
549  24,
550  24);
551  }
552  }
553 }
554 
555 
557 void Micropolis::drawTrafficDensityMap()
558 {
559  short x;
560  short y;
561 
562  drawLilTransMap();
563 
564  for (x = 0; x < WORLD_W; x += trafficDensityMap.MAP_BLOCKSIZE) {
565  for (y = 0; y < WORLD_H; y += trafficDensityMap.MAP_BLOCKSIZE) {
566  maybeDrawRect(
567  getCI(trafficDensityMap.worldGet(x, y)),
568  x * 3,
569  y * 3,
572  }
573  }
574 }
575 
576 
578 void Micropolis::drawPollutionMap()
579 {
580  short x, y;
581 
582  drawAll(view);
583 
584  for (x = 0; x < WORLD_W; x += pollutionDensityMap.MAP_BLOCKSIZE) {
585  for (y = 0; y < WORLD_H; y += pollutionDensityMap.MAP_BLOCKSIZE) {
586  maybeDrawRect(
587  getCI(10 + pollutionDensityMap.worldGet(x, y)),
588  x * 3,
589  y * 3,
592  }
593  }
594 }
595 
596 
598 void Micropolis::drawCrimeRateMap()
599 {
600  short x, y;
601 
602  drawAll();
603 
604  for (x = 0; x < WORLD_W; x += crimeRateMap.MAP_BLOCKSIZE) {
605  for (y = 0; y < WORLD_H; y += crimeRateMap.MAP_BLOCKSIZE) {
606  maybeDrawRect(
607  getCI(crimeRateMap.worldGet(x, y)),
608  x * 3,
609  y * 3,
612  }
613  }
614 }
615 
616 
617 void Micropolis::drawLandValueMap()
618 {
619  short x, y;
620 
621  drawAll();
622 
623  for (x = 0; x < landValueMap.MAP_W; x++) {
624  for (y = 0; y < landValueMap.MAP_H; y++) {
625  maybeDrawRect(
626  view,
627  getCI(landValueMap.get(x, y)),
628  x * 6,
629  y * 6,
630  6,
631  6);
632  }
633  }
634 }
635 
636 
637 void Micropolis::drawFireRadius()
638 {
639  short x, y;
640 
641  drawAll();
642  for (x = 0; x < fireStationEffectMap.MAP_W; x++) {
643  for (y = 0; y < fireStationEffectMap.MAP_H; y++) {
644  maybeDrawRect(
645  getCI(fireStationEffectMap.get(x, y)),
646  x * 24,
647  y * 24,
648  24,
649  24);
650  }
651  }
652 }
653 
654 
655 void Micropolis::drawPoliceRadius()
656 {
657  short x, y;
658 
659  drawAll();
660  for (x = 0; x < policeStationEffectMap.MAP_W; x++) {
661  for (y = 0; y < policeStationEffectMap.MAP_H; y++) {
662  maybeDrawRect(
663  getCI(policeStationEffectMap.get(x, y)),
664  x * 24,
665  y * 24,
666  24,
667  24);
668  }
669  }
670 }
671 
672 
673 void Micropolis::memDrawMap()
674 {
675 
676  switch (view->map_state) {
677 
678  case MAP_TYPE_ALL:
679  drawAll(view);
680  break;
681 
682  case MAP_TYPE_RES:
683  drawRes(view);
684  break;
685 
686  case MAP_TYPE_COM:
687  drawCom(view);
688  break;
689 
690  case MAP_TYPE_IND:
691  drawInd(view);
692  break;
693 
694  case MAP_TYPE_POWER:
695  drawPowerGrid(view);
696  break;
697 
698  case MAP_TYPE_ROAD:
699  drawLilTransMap(view);
700  break;
701 
703  drawPopulationDensity(view);
704  break;
705 
707  drawRateOfGrowth(view);
708  break;
709 
710  case MAP_TYPE_TRAFFIC:
711  drawTrafficDensityMap(view);
712  break;
713 
714  case MAP_TYPE_POLLUTION:
715  drawPollutionDensityMap(view);
716  break;
717 
718  case MAP_TYPE_CRIME:
719  drawCrimeRateMap(view);
720  break;
721 
722  case MAP_TYPE_LAND_VALUE:
723  drawLandValueMap(view);
724  break;
725 
727  drawFireRadius(view);
728  break;
729 
731  drawPoliceRadius(view);
732  break;
733 
734  case MAP_TYPE_DYNAMIC:
735  drawDynamic(view);
736  break;
737 
738  default:
739  assert(0); /* Undefined map */
740  break;
741 
742  }
743 
744  /*
745  if (!view->x->color) {
746  ditherMap(view);
747  XSetForeground(view->x->dpy, view->x->gc, view->pixels[COLOR_BLACK]);
748  XSetBackground(view->x->dpy, view->x->gc, view->pixels[COLOR_WHITE]);
749  XPutImage(view->x->dpy, view->pixmap, view->x->gc, view->image,
750  0, 0, 0, 0, view->m_width, view->m_height);
751  }
752  */
753 
754 }
755 
756 
757 void Micropolis::ditherMap()
758 {
759 /*
760  int i, x, y, width, height;
761  int err, pixel1, pixel8;
762  int line_bytes1 = view->line_bytes;
763  int line_bytes8 = view->line_bytes8;
764  unsigned char *image1 = view->data;
765  unsigned char *image8 = view->data8;
766  int *errors;
767 
768  width = view->m_width;
769  height = view->m_height;
770 
771  errors = (int *)newPtr(sizeof(int) * width);
772 
773  for (i = 0; i < width; i++) {
774  errors[i] = (getRandom16() & 15) - 7;
775  }
776 
777  err = (getRandom16() & 15) - 7;
778 
779  for (y = 0; y < height; y += 2) {
780  unsigned char *i1 = image1;
781  unsigned char *i8 = image8;
782 
783  image1 += line_bytes1;
784  image8 += line_bytes8;
785 
786  for (x = 0; x < width; x += 8) {
787  pixel1 = 0;
788  for (i = 0; i < 8; i++) {
789  pixel1 <<= 1;
790  pixel8 = *(i8++) + err + errors[x + i];
791  if (pixel8 > 127) {
792  err = pixel8 - 255;
793  } else {
794  pixel1 |= 1;
795  err = pixel8;
796  }
797  errors[x + i] = err/2;
798  err = err/2;
799  }
800  *(i1++) = pixel1;
801  }
802 
803  i1 = image1 + (width / 8) - 1;
804  i8 = image8 + width - 1;
805 
806  image1 += line_bytes1;
807  image8 += line_bytes8;
808 
809  for (x = width - 8; x >= 0; x -= 8) {
810  pixel1 = 0;
811  for (i = 7; i >= 0; i--) {
812  pixel1 >>= 1;
813  pixel8 = *(i8--) + err + errors[x + i];
814  if (pixel8 > 127) {
815  err = pixel8 - 255;
816  } else {
817  pixel1 |= 128;
818  err = pixel8;
819  }
820  errors[x + i] = err/2;
821  err = err/2;
822  }
823  *(i1--) = pixel1;
824  }
825  }
826 
827  freePtr(errors);
828 */
829 }
830 
831 
832 void Micropolis::maybeDrawRect(
833  int val,
834  int x,
835  int y,
836  int w,
837  int h)
838 {
839  if (val == VAL_NONE) {
840  return;
841  }
842 
843 /*
844  if (view->x->color) {
845  drawRect(view, view->pixels[valMap[val]], 0, x, y, w, h);
846  } else {
847  drawRect(view, valGrayMap[val], 1, x, y, w, h);
848  }
849 */
850 }
851 
852 
853 void Micropolis::drawRect(
854  int pixel,
855  int solid,
856  int x,
857  int y,
858  int w,
859  int h)
860 {
861 /*
862  int W = view->m_width, H = view->m_height;
863 
864  if (x < 0) {
865  if ((w += x) < 0) {
866  w = 0;
867  }
868  x = 0;
869  } else if (x > W) {
870  x = 0;
871  w = 0;
872  }
873  if (x + w > W) {
874  w = W - x;
875  }
876  if (y < 0) {
877  if ((h += y) < 0) {
878  h = 0;
879  }
880  y = 0;
881  } else if (y > H) {
882  y = 0;
883  h = 0;
884  }
885  if (y + h > H) {
886  h = H - y;
887  }
888 
889  if (w && h) {
890  int i, j, stipple = (x ^ y) & 1;
891  unsigned char *data =
892  view->x->color ? view->data : view->data8;
893 
894  // In the case of black and white, we use an 8 bit buffer and dither it.
895  int pixelBytes =
896  view->x->color ? view->pixel_bytes : 1;
897  Quad line =
898  view->x->color ? view->line_bytes : view->line_bytes8;
899 
900  unsigned char *image =
901  &(data[(line * y) + (x * pixelBytes)]);
902 
903  switch (pixelBytes) {
904 
905  case 1: {
906  unsigned char *data =
907  view->data8;
908  unsigned char *image =
909  &data[(line * y) + (x * pixelBytes)];
910 
911  if (solid) {
912  for (i = h; i > 0; i--) {
913  for (j = w; j > 0; j--) {
914  *image = pixel;
915  image++;
916  }
917  image += line - w;
918  }
919  } else {
920  for (i = h; i > 0; i--) {
921  for (j = w; j > 0; j--) {
922  if (stipple++ & 1) {
923  *image = pixel;
924  }
925  image++;
926  }
927  if (!(w & 1))
928  stipple++;
929  image += line - w;
930  }
931  }
932  break;
933  }
934 
935  case 2: {
936  unsigned short *data =
937  (unsigned short *)view->data;
938  unsigned short *image;
939  line >>= 1; // Convert from byte offset to short offset
940  image =
941  &data[(line * y) + x];
942 
943  if (solid) {
944  for (i = h; i > 0; i--) {
945  for (j = w; j > 0; j--) {
946  *image = pixel;
947  image++;
948  }
949  image += line - w;
950  }
951  } else {
952  for (i = h; i > 0; i--) {
953  for (j = w; j > 0; j--) {
954  if (stipple++ & 1) {
955  *image = pixel;
956  }
957  image++;
958  }
959  if (!(w & 1)) {
960  stipple++;
961  }
962  image += line - w;
963  }
964  }
965  break;
966  }
967 
968  case 3:
969  case 4: {
970  unsigned char *data =
971  (unsigned char *)view->data;
972  unsigned char *image;
973  int bitmapPad = view->x->small_tile_image->bitmap_pad;
974  int rowBytes = view->x->small_tile_image->bytes_per_line;
975  line = rowBytes >> 1; // Convert from byte offset to short offset
976  image = &data[(line * y) + x];
977 
978  if (solid) {
979  for (i = h; i > 0; i--) {
980  for (j = w; j > 0; j--) {
981  *(image++) = (pixel >> 0) & 0xff;
982  *(image++) = (pixel >> 8) & 0xff;
983  *(image++) = (pixel >> 16) & 0xff;
984  if (bitmapPad == 32) {
985  image++;
986  }
987  }
988  image += line - w;
989  }
990  } else {
991  for (i = h; i > 0; i--) {
992  for (j = w; j > 0; j--) {
993  if (stipple++ & 1) {
994  *(image++) = (pixel >> 0) & 0xff;
995  *(image++) = (pixel >> 8) & 0xff;
996  *(image++) = (pixel >> 16) & 0xff;
997  if (bitmapPad == 32) {
998  image++;
999  }
1000  }
1001  }
1002  if (!(w & 1)) {
1003  stipple++;
1004  }
1005  image += line - w;
1006  }
1007  }
1008  break;
1009  }
1010 
1011  default:
1012  assert(0); // Undefined depth
1013  break;
1014 
1015  }
1016 
1017  }
1018 */
1019 }
1020 
1021 
1022 #endif
1023 
1024 
DATA worldGet(int x, int y) const
Definition: map_type.h:316
const int MAP_BLOCKSIZE
Definition: map_type.h:121
const int MAP_W
Number of clusters in horizontal direction.
Definition: map_type.h:122
const int MAP_H
Number of clusters in vertical direction.
Definition: map_type.h:123
DATA get(int x, int y) const
Definition: map_type.h:265
MapShort8 policeStationEffectMap
Definition: micropolis.h:1322
MapByte2 crimeRateMap
Crime rate map.
Definition: micropolis.h:1248
MapShort8 fireStationEffectMap
Definition: micropolis.h:1306
unsigned short * map[WORLD_W]
Definition: micropolis.h:1120
MapByte2 pollutionDensityMap
Pollution density map.
Definition: micropolis.h:1246
MapByte2 trafficDensityMap
Traffic density map.
Definition: micropolis.h:1245
MapByte2 populationDensityMap
Population density map.
Definition: micropolis.h:1244
MapByte2 landValueMap
Land value map.
Definition: micropolis.h:1247
MapShort8 rateOfGrowthMap
Definition: micropolis.h:1290
static const int WORLD_H
Definition: map_type.h:95
static const int WORLD_W
Definition: map_type.h:90
Header file for Micropolis game engine.
@ MAP_TYPE_POLLUTION
Pollution.
Definition: micropolis.h:316
@ MAP_TYPE_POPULATION_DENSITY
Population density.
Definition: micropolis.h:313
@ MAP_TYPE_DYNAMIC
Dynamic filter.
Definition: micropolis.h:321
@ MAP_TYPE_LAND_VALUE
Land value.
Definition: micropolis.h:318
@ MAP_TYPE_FIRE_RADIUS
Fire station coverage radius.
Definition: micropolis.h:319
@ MAP_TYPE_CRIME
Crime rate.
Definition: micropolis.h:317
@ MAP_TYPE_ALL
All zones.
Definition: micropolis.h:307
@ MAP_TYPE_IND
Industrial zones.
Definition: micropolis.h:310
@ MAP_TYPE_COM
Commercial zones.
Definition: micropolis.h:309
@ MAP_TYPE_RES
Residential zones.
Definition: micropolis.h:308
@ MAP_TYPE_ROAD
Roads.
Definition: micropolis.h:312
@ MAP_TYPE_POWER
Power connectivity.
Definition: micropolis.h:311
@ MAP_TYPE_RATE_OF_GROWTH
Rate of growth.
Definition: micropolis.h:314
@ MAP_TYPE_POLICE_RADIUS
Police station coverage radius.
Definition: micropolis.h:320
@ PORTBASE
Top-left tile of the seaport.
Definition: micropolis.h:567
@ DIRT
Clear tile.
Definition: micropolis.h:382
@ INDBASE
Top-left tile of empty industrial zone.
Definition: micropolis.h:536
@ LOMASK
Mask for the Tiles part of the tile.
Definition: tool.h:129
@ ZONEBIT
bit 10, tile is the center tile of the zone.
Definition: tool.h:125
@ CONDBIT
bit 14. tile can conduct electricity.
Definition: tool.h:121
@ PWRBIT
bit 15, tile has power.
Definition: tool.h:120