Micropolis
simulate.cpp
Go to the documentation of this file.
1 /* simulate.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 
77 
78 
79 #include "micropolis.h"
80 #include "text.h"
81 
82 
84 // Constants
85 
90 static const int CENSUS_FREQUENCY_10 = 4;
91 
96 static const int CENSUS_FREQUENCY_120 = CENSUS_FREQUENCY_10 * 12;
97 
101 static const int TAX_FREQUENCY = 48;
102 
103 
105 
106 
107 /* comefrom: doEditWindow scoreDoer doMapInFront graphDoer doNilEvent */
108 void Micropolis::simFrame()
109 {
110 
111  if (simSpeed == 0) {
112  return;
113  }
114 
115  if (++speedCycle > 1023) {
116  speedCycle = 0;
117  }
118 
119  if (simSpeed == 1 && (speedCycle % 5) != 0) {
120  return;
121  }
122 
123  if (simSpeed == 2 && (speedCycle % 3) != 0) {
124  return;
125  }
126 
127  simulate();
128 }
129 
130 
131 /* comefrom: simFrame */
132 void Micropolis::simulate()
133 {
134  static const short speedPowerScan[3] =
135  { 2, 4, 5 };
136  static const short SpeedPollutionTerrainLandValueScan[3] =
137  { 2, 7, 17 };
138  static const short speedCrimeScan[3] =
139  { 1, 8, 18 };
140  static const short speedPopulationDensityScan[3] =
141  { 1, 9, 19 };
142  static const short speedFireAnalysis[3] =
143  { 1, 10, 20 };
144 
145  short speedIndex = clamp((short)(simSpeed - 1), (short)0, (short)2);
146 
147  // The simulator has 16 different phases, which we cycle through
148  // according to phaseCycle, which is incremented and wrapped at
149  // the end of this switch.
150 
151  if (initSimLoad) {
152  phaseCycle = 0;
153  } else {
154  phaseCycle &= 15;
155  }
156 
157  switch (phaseCycle) {
158 
159  case 0:
160 
161  if (++simCycle > 1023) {
162  simCycle = 0; // This is cosmic!
163  }
164 
165  if (doInitialEval) {
166  doInitialEval = false;
167  cityEvaluation();
168  }
169 
170  cityTime++;
171  cityTaxAverage += cityTax;
172 
173  if (!(simCycle & 1)) {
174  setValves();
175  }
176 
177  clearCensus();
178 
179  break;
180 
181  case 1:
182  case 2:
183  case 3:
184  case 4:
185  case 5:
186  case 6:
187  case 7:
188  case 8:
189 
190  // Scan 1/8 of the map for each of the 8 phases 1..8:
191  mapScan((phaseCycle - 1) * WORLD_W / 8, phaseCycle * WORLD_W / 8);
192 
193  break;
194 
195  case 9:
196  if (cityTime % CENSUS_FREQUENCY_10 == 0) {
197  take10Census();
198  }
199 
200  if (cityTime % CENSUS_FREQUENCY_120 == 0) {
201  take120Census();
202  }
203 
204  if (cityTime % TAX_FREQUENCY == 0) {
205  collectTax();
206  cityEvaluation();
207  }
208 
209  break;
210 
211  case 10:
212 
213  if (!(simCycle % 5)) {
215  }
216 
217  decTrafficMap();
218 
226 
227  sendMessages();
228 
229  break;
230 
231  case 11:
232 
233  if ((simCycle % speedPowerScan[speedIndex]) == 0) {
234  doPowerScan();
236  newPower = true; /* post-release change */
237  }
238 
239  break;
240 
241  case 12:
242 
243  if ((simCycle % SpeedPollutionTerrainLandValueScan[speedIndex]) == 0) {
244  pollutionTerrainLandValueScan();
245  }
246 
247  break;
248 
249  case 13:
250 
251  if ((simCycle % speedCrimeScan[speedIndex]) == 0) {
252  crimeScan();
253  }
254 
255  break;
256 
257  case 14:
258 
259  if ((simCycle % speedPopulationDensityScan[speedIndex]) == 0) {
261  }
262 
263  break;
264 
265  case 15:
266 
267  if ((simCycle % speedFireAnalysis[speedIndex]) == 0) {
268  fireAnalysis();
269  }
270 
271  doDisasters();
272 
273  break;
274 
275  }
276 
277  // Go on the the next phase.
278  phaseCycle = (phaseCycle + 1) & 15;
279 }
280 
281 
287 {
288  phaseCycle = 0;
289  simCycle = 0;
290 
291  if (initSimLoad == 2) {
292  /* if new city */
293  initSimMemory();
294  }
295 
296  if (initSimLoad == 1) {
297  /* if city just loaded */
298  simLoadInit();
299  }
300 
301  setValves();
302  clearCensus();
303  mapScan(0, WORLD_W);
304  doPowerScan();
305  newPower = true; /* post rel */
306  pollutionTerrainLandValueScan();
307  crimeScan();
309  fireAnalysis();
310  newMap = 1;
311  censusChanged = true;
312  totalPop = 1;
313  doInitialEval = true;
314 }
315 
316 
322 {
323  short x, y;
324 
325  for (x = 0; x < WORLD_W; x++) {
326  for (y = 0; y < WORLD_H; y++) {
327  MapValue z = map[x][y];
328  if (z & ZONEBIT) {
329  setZonePower(Position(x, y));
330  }
331  }
332  }
333 }
334 
335 
338 {
339  /* tends to empty trafficDensityMap */
340  short x, y, z;
341 
342  for (x = 0; x < WORLD_W; x += trafficDensityMap.MAP_BLOCKSIZE) {
343  for (y = 0; y < WORLD_H; y += trafficDensityMap.MAP_BLOCKSIZE) {
344  z = trafficDensityMap.worldGet(x, y);
345  if (z == 0) {
346  continue;
347  }
348 
349  if (z <= 24) {
350  trafficDensityMap.worldSet(x, y, 0);
351  continue;
352  }
353 
354  if (z > 200) {
355  trafficDensityMap.worldSet(x, y, z - 34);
356  } else {
357  trafficDensityMap.worldSet(x, y, z - 24);
358  }
359  }
360  }
361 }
362 
363 
370 {
371  /* tends to empty rateOfGrowthMap */
372  short x, y, z;
373 
374  for (x = 0; x < rateOfGrowthMap.MAP_W; x++) {
375  for (y = 0; y < rateOfGrowthMap.MAP_H; y++) {
376  z = rateOfGrowthMap.get(x, y);
377  if (z == 0) {
378  continue;
379  }
380 
381  if (z > 0) {
382  z--;
383  z = clamp(z, (short)-200, (short)200);
384  rateOfGrowthMap.set(x, y, z);
385  continue;
386  }
387 
388  if (z < 0) {
389  z++;
390  z = clamp(z, (short)-200, (short)200);
391  rateOfGrowthMap.set(x, y, z);
392  }
393  }
394  }
395 }
396 
397 
398 /* comefrom: doSimInit */
399 void Micropolis::initSimMemory()
400 {
401  setCommonInits();
402 
403  for (short x = 0; x < 240; x++) {
404  resHist[x] = 0;
405  comHist[x] = 0;
406  indHist[x] = 0;
407  moneyHist[x] = 128;
408  crimeHist[x] = 0;
409  pollutionHist[x] = 0;
410  }
411 
412  crimeRamp = 0;
413  pollutionRamp = 0;
414  totalPop = 0;
415  resValve = 0;
416  comValve = 0;
417  indValve = 0;
418  resCap = false; // Do not block residential growth
419  comCap = false; // Do not block commercial growth
420  indCap = false; // Do not block industrial growth
421 
422  externalMarket = 6.0;
424  scoreType = SC_NONE;
425 
426  /* This clears powermem */
427  powerStackPointer = 0;
428  doPowerScan();
429  newPower = true; /* post rel */
430 
431  initSimLoad = 0;
432 }
433 
434 
435 /* comefrom: doSimInit */
437 {
438  // Disaster delay table for each scenario
439  static const short disasterWaitTable[SC_COUNT] = {
440  0, // No scenario (free playing)
441  2, // Dullsville (boredom)
442  10, // San francisco (earth quake)
443  4 * 10, // Hamburg (fire bombs)
444  20, // Bern (traffic)
445  3, // Tokyo (scary monster)
446  5, // Detroit (crime)
447  5, // Boston (nuclear meltdown)
448  2 * 48, // Rio (flooding)
449  };
450 
451  // Time to wait before score calculation for each scenario
452  static const short scoreWaitTable[SC_COUNT] = {
453  0, // No scenario (free playing)
454  30 * 48, // Dullsville (boredom)
455  5 * 48, // San francisco (earth quake)
456  5 * 48, // Hamburg (fire bombs)
457  10 * 48, // Bern (traffic)
458  5 * 48, // Tokyo (scary monster)
459  10 * 48, // Detroit (crime)
460  5 * 48, // Boston (nuclear meltdown)
461  10 * 48, // Rio (flooding)
462  };
463 
464  externalMarket = (float)miscHist[1];
465  resPop = miscHist[2];
466  comPop = miscHist[3];
467  indPop = miscHist[4];
468  resValve = miscHist[5];
469  comValve = miscHist[6];
470  indValve = miscHist[7];
471  crimeRamp = miscHist[10];
472  pollutionRamp = miscHist[11];
474  crimeAverage = miscHist[13];
477 
478  if (cityTime < 0) {
479  cityTime = 0;
480  }
481 
482  if (!externalMarket) {
483  externalMarket = 4.0;
484  }
485 
486  // Set game level
489  }
491 
492  setCommonInits();
493 
494  // Load cityClass
495  cityClass = (CityClass)(miscHist[16]);
498  }
499 
500  cityScore = miscHist[17];
501  if (cityScore > 999 || cityScore < 1) {
502  cityScore = 500;
503  }
504 
505  resCap = false;
506  comCap = false;
507  indCap = false;
508 
509  cityTaxAverage = (cityTime % 48) * 7; /* post */
510 
511  // Set power map.
513  powerGridMap.fill(1);
514 
515  doNilPower();
516 
520  initSimLoad = 0;
521 
522  if (scenario >= SC_COUNT) {
523  scenario = SC_NONE;
524  }
525 
526  if (scenario != SC_NONE) {
527  assert(LENGTH_OF(disasterWaitTable) == SC_COUNT);
528  assert(LENGTH_OF(scoreWaitTable) == SC_COUNT);
529 
531  disasterWait = disasterWaitTable[disasterEvent];
533  scoreWait = scoreWaitTable[disasterEvent];
534 
536  } else {
538  disasterWait = 0;
539  scoreType = SC_NONE;
540  scoreWait = 0;
541  }
542 
543  doStartGame();
544 }
545 
546 
547 /* comefrom: initSimMemory simLoadInit */
548 void Micropolis::setCommonInits()
549 {
550  evalInit();
554  taxFlag = false;
555  taxFund = 0;
556 }
557 
558 
559 /* comefrom: simulate doSimInit */
561 {
563  static const short taxTable[21] = {
564  200, 150, 120, 100, 80, 50, 30, 0, -10, -40, -100,
565  -150, -200, -250, -300, -350, -400, -450, -500, -550, -600,
566  };
567  static const float extMarketParamTable[3] = {
568  1.2f, 1.1f, 0.98f,
569  };
570  assert(LEVEL_COUNT == LENGTH_OF(extMarketParamTable));
571 
573  short resPopDenom = 8;
574  float birthRate = 0.02;
575  float laborBaseMax = 1.3;
576  float internalMarketDenom = 3.7;
577  float projectedIndPopMin = 5.0;
578  float resRatioDefault = 1.3;
579  float resRatioMax = 2;
580  float comRatioMax = 2;
581  float indRatioMax = 2;
582  short taxMax = 20;
583  float taxTableScale = 600;
584 
587  float employment, migration, births, laborBase, internalMarket;
588  float resRatio, comRatio, indRatio;
589  float normalizedResPop, projectedResPop, projectedComPop, projectedIndPop;
590 
591  miscHist[1] = (short)externalMarket;
592  miscHist[2] = resPop;
593  miscHist[3] = comPop;
594  miscHist[4] = indPop;
595  miscHist[5] = resValve;
596  miscHist[6] = comValve;
597  miscHist[7] = indValve;
598  miscHist[10] = crimeRamp;
599  miscHist[11] = pollutionRamp;
601  miscHist[13] = crimeAverage;
603  miscHist[15] = gameLevel;
604  miscHist[16] = (short)cityClass;
605  miscHist[17] = cityScore;
606 
607  normalizedResPop = (float)resPop / (float)resPopDenom;
609  totalPop = (short)(normalizedResPop + comPop + indPop);
610 
611  if (resPop > 0) {
612  employment = (comHist[1] + indHist[1]) / normalizedResPop;
613  } else {
614  employment = 1;
615  }
616 
617  migration = normalizedResPop * (employment - 1);
618  births = normalizedResPop * birthRate;
619  projectedResPop = normalizedResPop + migration + births; // Projected res pop.
620 
621  // Compute laborBase
622  float temp = comHist[1] + indHist[1];
623  if (temp > 0.0) {
624  laborBase = (resHist[1] / temp);
625  } else {
626  laborBase = 1;
627  }
628  laborBase = clamp(laborBase, 0.0f, laborBaseMax);
629 
630  internalMarket = (float)(normalizedResPop + comPop + indPop) / internalMarketDenom;
631 
632  projectedComPop = internalMarket * laborBase;
633 
634  assert(gameLevel >= LEVEL_FIRST && gameLevel <= LEVEL_LAST);
635  projectedIndPop = indPop * laborBase * extMarketParamTable[gameLevel];
636  projectedIndPop = max(projectedIndPop, projectedIndPopMin);
637 
638  if (normalizedResPop > 0) {
639  resRatio = (float)projectedResPop / (float)normalizedResPop; // projected -vs- actual.
640  } else {
641  resRatio = resRatioDefault;
642  }
643 
644  if (comPop > 0) {
645  comRatio = (float)projectedComPop / (float)comPop;
646  } else {
647  comRatio = (float)projectedComPop;
648  }
649 
650  if (indPop > 0) {
651  indRatio = (float)projectedIndPop / (float)indPop;
652  } else {
653  indRatio = (float)projectedIndPop;
654  }
655 
656  resRatio = min(resRatio, resRatioMax);
657  comRatio = min(comRatio, comRatioMax);
658  resRatio = min(indRatio, indRatioMax);
659 
660  // Global tax and game level effects.
661  short z = min((short)(cityTax + gameLevel), taxMax);
662  resRatio = (resRatio - 1) * taxTableScale + taxTable[z];
663  comRatio = (comRatio - 1) * taxTableScale + taxTable[z];
664  indRatio = (indRatio - 1) * taxTableScale + taxTable[z];
665 
666  // Ratios are velocity changes to valves.
667  resValve = clamp(resValve + (short)resRatio, -RES_VALVE_RANGE, RES_VALVE_RANGE);
668  comValve = clamp(comValve + (short)comRatio, -COM_VALVE_RANGE, COM_VALVE_RANGE);
669  indValve = clamp(indValve + (short)indRatio, -IND_VALVE_RANGE, IND_VALVE_RANGE);
670 
671  if (resCap && resValve > 0) {
672  resValve = 0; // Need a stadium, so cap resValve.
673  }
674 
675  if (comCap && comValve > 0) {
676  comValve = 0; // Need a airport, so cap comValve.
677  }
678 
679  if (indCap && indValve > 0) {
680  indValve = 0; // Need an seaport, so cap indValve.
681  }
682 
683  valveFlag = true;
684 }
685 
686 
687 /* comefrom: simulate doSimInit */
688 void Micropolis::clearCensus()
689 {
690  poweredZoneCount = 0;
691  unpoweredZoneCount = 0;
692  firePop = 0;
693  roadTotal = 0;
694  railTotal = 0;
695  resPop = 0;
696  comPop = 0;
697  indPop = 0;
698  resZonePop = 0;
699  comZonePop = 0;
700  indZonePop = 0;
701  hospitalPop = 0;
702  churchPop = 0;
703  policeStationPop = 0;
704  fireStationPop = 0;
705  stadiumPop = 0;
706  coalPowerPop = 0;
707  nuclearPowerPop = 0;
708  seaportPop = 0;
709  airportPop = 0;
710  powerStackPointer = 0; /* Reset before Mapscan */
711 
713  //fireStationEffectMap.clear(); // Added in rev293
715  //policeStationEffectMap.clear(); // Added in rev293
716 
717 }
718 
719 
727 {
728  // TODO: Make configurable parameters.
729  int resPopDenom = 8;
730 
731  short x;
732 
733  /* put census#s in Historical Graphs and scroll data */
734  resHist10Max = 0;
735  comHist10Max = 0;
736  indHist10Max = 0;
737 
738  for (x = 118; x >= 0; x--) {
739 
743 
744  resHist[x + 1] = resHist[x];
745  comHist[x + 1] = comHist[x];
746  indHist[x + 1] = indHist[x];
747  crimeHist[x + 1] = crimeHist[x];
748  pollutionHist[x + 1] = pollutionHist[x];
749  moneyHist[x + 1] = moneyHist[x];
750 
751  }
752 
756 
757  resHist[0] = resPop / resPopDenom;
758  comHist[0] = comPop;
759  indHist[0] = indPop;
760 
761  crimeRamp += (crimeAverage - crimeRamp) / 4;
762  crimeHist[0] = min(crimeRamp, (short)255);
763 
764  pollutionRamp += (pollutionAverage - pollutionRamp) / 4;
765  pollutionHist[0] = min(pollutionRamp, (short)255);
766 
767  x = (cashFlow / 20) + 128; /* scale to 0..255 */
768  moneyHist[0] = clamp(x, (short)0, (short)255);
769 
770  changeCensus();
771 
772  short resPopScaled = resPop >> 8;
773 
774  if (hospitalPop < resPopScaled) {
775  needHospital = 1;
776  }
777 
778  if (hospitalPop > resPopScaled) {
779  needHospital = -1;
780  }
781 
782  if (hospitalPop == resPopScaled) {
783  needHospital = 0;
784  }
785 
786  int faithfulPop = resPopScaled + faith;
787 
788  if (churchPop < faithfulPop) {
789  needChurch = 1;
790  }
791 
792  if (churchPop > faithfulPop) {
793  needChurch = -1;
794  }
795 
796  if (churchPop == faithfulPop) {
797  needChurch = 0;
798  }
799 }
800 
801 
802 /* comefrom: simulate */
803 void Micropolis::take120Census()
804 {
805  // TODO: Make configurable parameters.
806  int resPopDenom = 8;
807 
808  /* Long Term Graphs */
809  short x;
810 
811  resHist120Max = 0;
812  comHist120Max = 0;
813  indHist120Max = 0;
814 
815  for (x = 238; x >= 120; x--) {
816 
820 
821  resHist[x + 1] = resHist[x];
822  comHist[x + 1] = comHist[x];
823  indHist[x + 1] = indHist[x];
824  crimeHist[x + 1] = crimeHist[x];
825  pollutionHist[x + 1] = pollutionHist[x];
826  moneyHist[x + 1] = moneyHist[x];
827 
828  }
829 
833 
834  resHist[120] = resPop / resPopDenom;
835  comHist[120] = comPop;
836  indHist[120] = indPop;
837  crimeHist[120] = crimeHist[0] ;
838  pollutionHist[120] = pollutionHist[0];
839  moneyHist[120] = moneyHist[0];
840  changeCensus();
841 }
842 
843 
853 {
854  short z;
855 
859  static const float RLevels[3] = { 0.7, 0.9, 1.2 };
860  static const float FLevels[3] = { 1.4, 1.2, 0.8 };
861 
862  assert(LEVEL_COUNT == LENGTH_OF(RLevels));
863  assert(LEVEL_COUNT == LENGTH_OF(FLevels));
864 
865  cashFlow = 0;
866 
873  if (!taxFlag) { // If the Tax Port is clear
874 
876  z = cityTaxAverage / 48; // post release
877 
878  cityTaxAverage = 0;
879 
880  policeFund = (long)policeStationPop * 100;
881  fireFund = (long)fireStationPop * 100;
882  roadFund = (long)((roadTotal + (railTotal * 2)) * RLevels[gameLevel]);
883  taxFund = (long)((((Quad)totalPop * landValueAverage) / 120) * cityTax * FLevels[gameLevel]);
884 
885  if (totalPop > 0) {
886  /* There are people to tax. */
887  cashFlow = (short)(taxFund - (policeFund + fireFund + roadFund));
888  doBudget();
889  } else {
890  /* Nobody lives here. */
894  }
895  }
896 }
897 
898 
909 {
910  // Compute road effects of funding
912  if (roadFund > 0) {
913  // Multiply with funding fraction
914  roadEffect = (short)((float)roadEffect * (float)roadSpend / (float)roadFund);
915  }
916 
917  // Compute police station effects of funding
919  if (policeFund > 0) {
920  // Multiply with funding fraction
921  policeEffect = (short)((float)policeEffect * (float)policeSpend / (float)policeFund);
922  }
923 
924  // Compute fire station effects of funding
926  if (fireFund > 0) {
927  // Multiply with funding fraction
928  fireEffect = (short)((float)fireEffect * (float)fireSpend / (float)fireFund);
929  }
930 
931 #if 0
932  printf("========== updateFundEffects road %d %d %d fire %d %d %d police %d %d %d\n",
933  (int)roadEffect, (int)roadSpend, (int)roadFund,
934  (int)fireEffect, (int)fireSpend, (int)fireFund,
935  (int)policeEffect, (int)policeSpend, (int)policeFund);
936 #endif
937 
938  mustDrawBudget = 1;
939 }
940 
941 
942 /* comefrom: simulate doSimInit */
943 void Micropolis::mapScan(int x1, int x2)
944 {
945  short x, y;
946 
947  for (x = x1; x < x2; x++) {
948  for (y = 0; y < WORLD_H; y++) {
949 
950  MapValue mapVal = map[x][y];
951  if (mapVal == DIRT) {
952  continue;
953  }
954 
955  MapTile tile = mapVal & LOMASK; /* Mask off status bits */
956 
957  if (tile < FLOOD) {
958  continue;
959  }
960 
961  // tile >= FLOOD
962 
963  Position pos(x, y);
964 
965 
966  if (tile < ROADBASE) {
967 
968  if (tile >= FIREBASE) {
969  firePop++;
970  if (!(getRandom16() & 3)) {
971  doFire(pos); /* 1 in 4 times */
972  }
973  continue;
974  }
975 
976  if (tile < RADTILE) {
977  doFlood(pos);
978  } else {
979  doRadTile(pos);
980  }
981 
982  continue;
983  }
984 
985  if (newPower && (mapVal & CONDBIT)) {
986  // Copy PWRBIT from powerGridMap
987  setZonePower(pos);
988  }
989 
990  if (tile >= ROADBASE && tile < POWERBASE) {
991  doRoad(pos);
992  continue;
993  }
994 
995  if (mapVal & ZONEBIT) { /* process Zones */
996  doZone(pos);
997  continue;
998  }
999 
1000  if (tile >= RAILBASE && tile < RESBASE) {
1001  doRail(pos);
1002  continue;
1003  }
1004 
1005  if (tile >= SOMETINYEXP && tile <= LASTTINYEXP) {
1006  /* clear AniRubble */
1007  map[x][y] = randomRubble();
1008  }
1009  }
1010  }
1011 }
1012 
1013 
1020 {
1021  railTotal++;
1022 
1023  generateTrain(pos.posX, pos.posY);
1024 
1025  if (roadEffect < (15 * MAX_ROAD_EFFECT / 16)) {
1026 
1027  // roadEffect < 15/16 of max road, enable deteriorating rail
1028  if (!(getRandom16() & 511)) {
1029 
1030  MapValue curValue = map[pos.posX][pos.posY];
1031  if (!(curValue & CONDBIT)) {
1032 
1033  // Otherwise the '(getRandom16() & 31)' makes no sense
1034  assert(MAX_ROAD_EFFECT == 32);
1035  if (roadEffect < (getRandom16() & 31)) {
1036  MapTile tile = curValue & LOMASK;
1037  if (tile < RAILBASE + 2) {
1038  map[pos.posX][pos.posY] = RIVER;
1039  } else {
1040  map[pos.posX][pos.posY] = randomRubble();
1041  }
1042  return;
1043  }
1044  }
1045  }
1046  }
1047 }
1048 
1049 
1055 {
1056  if ((getRandom16() & 4095) == 0) {
1057  map[pos.posX][pos.posY] = DIRT; /* Radioactive decay */
1058  }
1059 }
1060 
1061 
1067 {
1068  short tden, z;
1069  static const short densityTable[3] = { ROADBASE, LTRFBASE, HTRFBASE };
1070 
1071  roadTotal++;
1072 
1073  MapValue mapValue = map[pos.posX][pos.posY];
1074  MapTile tile = mapValue & LOMASK;
1075 
1076  /* generateBus(pos.posX, pos.posY); */
1077 
1078  if (roadEffect < (15 * MAX_ROAD_EFFECT / 16)) {
1079  // roadEffect < 15/16 of max road, enable deteriorating road
1080  if ((getRandom16() & 511) == 0) {
1081  if (!(mapValue & CONDBIT)) {
1082  assert(MAX_ROAD_EFFECT == 32); // Otherwise the '(getRandom16() & 31)' makes no sense
1083  if (roadEffect < (getRandom16() & 31)) {
1084  if ((tile & 15) < 2 || (tile & 15) == 15) {
1085  map[pos.posX][pos.posY] = RIVER;
1086  } else {
1087  map[pos.posX][pos.posY] = randomRubble();
1088  }
1089  return;
1090  }
1091  }
1092  }
1093  }
1094 
1095  if ((mapValue & BURNBIT) == 0) { /* If Bridge */
1096  roadTotal += 4; // Bridge counts as 4 road tiles
1097  if (doBridge(Position(pos.posX, pos.posY), tile)) {
1098  return;
1099  }
1100  }
1101 
1102  if (tile < LTRFBASE) {
1103  tden = 0;
1104  } else if (tile < HTRFBASE) {
1105  tden = 1;
1106  } else {
1107  roadTotal++; // Heavy traffic counts as 2 roads.
1108  tden = 2;
1109  }
1110 
1111  short trafficDensity = trafficDensityMap.worldGet(pos.posX, pos.posY) >>6;
1112 
1113  if (trafficDensity > 1) {
1114  trafficDensity--;
1115  }
1116 
1117  if (tden != trafficDensity) { /* tden 0..2 */
1118  z = ((tile - ROADBASE) & 15) + densityTable[trafficDensity];
1119  z |= mapValue & (ALLBITS - ANIMBIT);
1120 
1121  if (trafficDensity > 0) {
1122  z |= ANIMBIT;
1123  }
1124 
1125  map[pos.posX][pos.posY] = z;
1126  }
1127 }
1128 
1129 
1139 bool Micropolis::doBridge(const Position &pos, MapTile tile)
1140 {
1141  static short HDx[7] = { -2, 2, -2, -1, 0, 1, 2 };
1142  static short HDy[7] = { -1, -1, 0, 0, 0, 0, 0 };
1143  static short HBRTAB[7] = {
1144  HBRDG1 | BULLBIT, HBRDG3 | BULLBIT, HBRDG0 | BULLBIT,
1145  RIVER, BRWH | BULLBIT, RIVER, HBRDG2 | BULLBIT,
1146  };
1147  static short HBRTAB2[7] = {
1148  RIVER, RIVER, HBRIDGE | BULLBIT, HBRIDGE | BULLBIT, HBRIDGE | BULLBIT,
1150  };
1151  static short VDx[7] = { 0, 1, 0, 0, 0, 0, 1 };
1152  static short VDy[7] = { -2, -2, -1, 0, 1, 2, 2 };
1153  static short VBRTAB[7] = {
1154  VBRDG0 | BULLBIT, VBRDG1 | BULLBIT, RIVER, BRWV | BULLBIT,
1155  RIVER, VBRDG2 | BULLBIT, VBRDG3 | BULLBIT,
1156  };
1157  static short VBRTAB2[7] = {
1158  VBRIDGE | BULLBIT, RIVER, VBRIDGE | BULLBIT, VBRIDGE | BULLBIT,
1159  VBRIDGE | BULLBIT, VBRIDGE | BULLBIT, RIVER,
1160  };
1161  int z, x, y, MPtem;
1162 
1163  if (tile == BRWV) { /* Vertical bridge close */
1164 
1165  if ((!(getRandom16() & 3)) && getBoatDistance(pos) > 340) {
1166 
1167  for (z = 0; z < 7; z++) { /* Close */
1168 
1169  x = pos.posX + VDx[z];
1170  y = pos.posY + VDy[z];
1171 
1172  if (testBounds(x, y)) {
1173 
1174  if ((map[x][y] & LOMASK) == (VBRTAB[z] & LOMASK)) {
1175  map[x][y] = VBRTAB2[z];
1176  }
1177 
1178  }
1179  }
1180  }
1181  return true;
1182  }
1183 
1184  if (tile == BRWH) { /* Horizontal bridge close */
1185 
1186  if ((!(getRandom16() & 3)) && getBoatDistance(pos) > 340) {
1187 
1188  for (z = 0; z < 7; z++) { /* Close */
1189 
1190  x = pos.posX + HDx[z];
1191  y = pos.posY + HDy[z];
1192 
1193  if (testBounds(x, y)) {
1194 
1195  if ((map[x][y] & LOMASK) == (HBRTAB[z] & LOMASK)) {
1196 
1197  map[x][y] = HBRTAB2[z];
1198 
1199  }
1200  }
1201  }
1202  }
1203  return true;
1204  }
1205 
1206  if (getBoatDistance(pos) < 300 || (!(getRandom16() & 7))) {
1207  if (tile & 1) {
1208  if (pos.posX < WORLD_W - 1) {
1209  if (map[pos.posX + 1][pos.posY] == CHANNEL) { /* Vertical open */
1210 
1211  for (z = 0; z < 7; z++) {
1212 
1213  x = pos.posX + VDx[z];
1214  y = pos.posY + VDy[z];
1215 
1216  if (testBounds(x, y)) {
1217 
1218  MPtem = map[x][y];
1219  if (MPtem == CHANNEL || ((MPtem & 15) == (VBRTAB2[z] & 15))) {
1220  map[x][y] = VBRTAB[z];
1221  }
1222  }
1223  }
1224  return true;
1225  }
1226  }
1227  return false;
1228 
1229  } else {
1230 
1231  if (pos.posY > 0) {
1232  if (map[pos.posX][pos.posY - 1] == CHANNEL) {
1233 
1234  /* Horizontal open */
1235  for (z = 0; z < 7; z++) {
1236 
1237  x = pos.posX + HDx[z];
1238  y = pos.posY + HDy[z];
1239 
1240  if (testBounds(x, y)) {
1241 
1242  MPtem = map[x][y];
1243  if (((MPtem & 15) == (HBRTAB2[z] & 15)) || MPtem == CHANNEL) {
1244  map[x][y] = HBRTAB[z];
1245  }
1246  }
1247  }
1248  return true;
1249  }
1250  }
1251  return false;
1252  }
1253 
1254  }
1255  return false;
1256 }
1257 
1258 
1265 {
1266  int sprDist;
1267  SimSprite *sprite;
1268 
1269  int dist = 99999;
1270  int mx = pos.posX * 16 + 8;
1271  int my = pos.posY * 16 + 8;
1272 
1273  for (sprite = spriteList; sprite != NULL; sprite = sprite->next) {
1274  if (sprite->type == SPRITE_SHIP && sprite->frame != 0) {
1275 
1276  sprDist = absoluteValue(sprite->x + sprite->xHot - mx)
1277  + absoluteValue(sprite->y + sprite->yHot - my);
1278 
1279  dist = min(dist, sprDist);
1280  }
1281  }
1282  return dist;
1283 }
1284 
1285 
1295 {
1296  static const short DX[4] = { -1, 0, 1, 0 };
1297  static const short DY[4] = { 0, -1, 0, 1 };
1298 
1299  // Try to set neighbouring tiles on fire as well
1300  for (short z = 0; z < 4; z++) {
1301 
1302  if ((getRandom16() & 7) == 0) {
1303 
1304  short xTem = pos.posX + DX[z];
1305  short yTem = pos.posY + DY[z];
1306 
1307  if (testBounds(xTem, yTem)) {
1308 
1309  MapValue c = map[xTem][yTem];
1310  if (!(c & BURNBIT)) {
1311  continue;
1312  }
1313 
1314  if (c & ZONEBIT) {
1315  // Neighbour is a zone and burnable
1316  fireZone(Position(xTem, yTem), c);
1317 
1318  if ((c & LOMASK) > IZB) { /* Explode */
1319  makeExplosionAt(xTem *16 + 8, yTem * 16 + 8);
1320  }
1321  }
1322 
1323  map[xTem][yTem] = randomFire();
1324  }
1325  }
1326  }
1327 
1328  // Compute likelyhood of fire running out of fuel
1329  short rate = 10; // Likelyhood of extinguishing (bigger means less chance)
1330  short z = fireStationEffectMap.worldGet(pos.posX, pos.posY);
1331 
1332  if (z > 0) {
1333  rate = 3;
1334  if (z > 20) {
1335  rate = 2;
1336  }
1337  if (z > 100) {
1338  rate = 1;
1339  }
1340  }
1341 
1342  // Decide whether to put out the fire.
1343  if (getRandom(rate) == 0) {
1344  map[pos.posX][pos.posY] = randomRubble();
1345  }
1346 }
1347 
1348 
1358 {
1359  short XYmax;
1360 
1361  int value = rateOfGrowthMap.worldGet(pos.posX, pos.posY);
1362  value = clamp(value - 20, -200, 200);
1363  rateOfGrowthMap.worldSet(pos.posX, pos.posY, value);
1364 
1365  ch = ch & LOMASK;
1366 
1367  if (ch < PORTBASE) {
1368  XYmax = 2;
1369  } else {
1370  if (ch == AIRPORT) {
1371  XYmax = 5;
1372  } else {
1373  XYmax = 4;
1374  }
1375  }
1376 
1377  // Make remaining tiles of the zone bulldozable
1378  for (short x = -1; x < XYmax; x++) {
1379  for (short y = -1; y < XYmax; y++) {
1380 
1381  short xTem = pos.posX + x;
1382  short yTem = pos.posY + y;
1383 
1384  if (!testBounds(xTem, yTem)) {
1385  continue;
1386  }
1387 
1388  if ((MapTile)(map[xTem][yTem] & LOMASK) >= ROADBASE) {
1389  /* post release */
1390  map[xTem][yTem] |= BULLBIT;
1391  }
1392 
1393  }
1394  }
1395 }
1396 
1397 
1404 void Micropolis::repairZone(const Position &pos, MapTile zCent, short zSize)
1405 {
1406  MapTile tile = zCent - 2 - zSize;
1407 
1408  // y and x loops one position shifted to compensate for the center-tile position.
1409  for (short y = -1; y < zSize - 1; y++) {
1410  for (short x = -1; x < zSize - 1; x++) {
1411 
1412  int xx = pos.posX + x;
1413  int yy = pos.posY + y;
1414 
1415  tile++;
1416 
1417  if (testBounds(xx, yy)) {
1418 
1419  MapValue mapValue = map[xx][yy];
1420 
1421  if (mapValue & ZONEBIT) {
1422  continue;
1423  }
1424 
1425  if (mapValue & ANIMBIT) {
1426  continue;
1427  }
1428 
1429  MapTile mapTile = mapValue & LOMASK;
1430 
1431  if (mapTile < RUBBLE || mapTile >= ROADBASE) {
1432  map[xx][yy] = tile | CONDBIT | BURNBIT;
1433  }
1434  }
1435  }
1436  }
1437 }
1438 
1439 
1445 void Micropolis::doSpecialZone(const Position &pos, bool powerOn)
1446 {
1447  // Bigger numbers reduce chance of nuclear melt down
1448  static const short meltdownTable[3] = { 30000, 20000, 10000 };
1449 
1450  MapTile tile = map[pos.posX][pos.posY] & LOMASK;
1451 
1452  switch (tile) {
1453 
1454  case POWERPLANT:
1455 
1456  coalPowerPop++;
1457 
1458  if ((cityTime & 7) == 0) {
1459  repairZone(pos, POWERPLANT, 4); /* post */
1460  }
1461 
1462  pushPowerStack(pos);
1463  coalSmoke(pos);
1464 
1465  return;
1466 
1467  case NUCLEAR:
1468 
1469  assert(LEVEL_COUNT == LENGTH_OF(meltdownTable));
1470 
1471  if (enableDisasters && !getRandom(meltdownTable[gameLevel])) {
1472  doMeltdown(pos);
1473  return;
1474  }
1475 
1476  nuclearPowerPop++;
1477 
1478  if ((cityTime & 7) == 0) {
1479  repairZone(pos, NUCLEAR, 4); /* post */
1480  }
1481 
1482  pushPowerStack(pos);
1483 
1484  return;
1485 
1486  case FIRESTATION: {
1487 
1488  int z;
1489 
1490  fireStationPop++;
1491 
1492  if (!(cityTime & 7)) {
1493  repairZone(pos, FIRESTATION, 3); /* post */
1494  }
1495 
1496  if (powerOn) {
1497  z = fireEffect; /* if powered get effect */
1498  } else {
1499  z = fireEffect / 2; /* from the funding ratio */
1500  }
1501 
1502  Position pos2(pos);
1503  bool foundRoad = findPerimeterRoad(&pos2);
1504 
1505  if (!foundRoad) {
1506  z = z / 2; /* post FD's need roads */
1507  }
1508 
1509  int value = fireStationMap.worldGet(pos2.posX, pos2.posY);
1510  value += z;
1511  fireStationMap.worldSet(pos2.posX, pos2.posY, value);
1512 
1513  return;
1514  }
1515 
1516  case POLICESTATION: {
1517 
1518  int z;
1519 
1520  policeStationPop++;
1521 
1522  if (!(cityTime & 7)) {
1523  repairZone(pos, POLICESTATION, 3); /* post */
1524  }
1525 
1526  if (powerOn) {
1527  z = policeEffect;
1528  } else {
1529  z = policeEffect / 2;
1530  }
1531 
1532  Position pos2(pos);
1533  bool foundRoad = findPerimeterRoad(&pos2);
1534 
1535  if (!foundRoad) {
1536  z = z / 2; /* post PD's need roads */
1537  }
1538 
1539  int value = policeStationMap.worldGet(pos2.posX, pos2.posY);
1540  value += z;
1541  policeStationMap.worldSet(pos2.posX, pos2.posY, value);
1542 
1543  return;
1544  }
1545 
1546  case STADIUM: // Empty stadium
1547 
1548  stadiumPop++;
1549 
1550  if (!(cityTime & 15)) {
1551  repairZone(pos, STADIUM, 4);
1552  }
1553 
1554  if (powerOn) {
1555  // Every now and then, display a match
1556  if (((cityTime + pos.posX + pos.posY) & 31) == 0) {
1557  drawStadium(pos, FULLSTADIUM);
1558  map[pos.posX + 1][pos.posY] = FOOTBALLGAME1 + ANIMBIT;
1559  map[pos.posX + 1][pos.posY + 1] = FOOTBALLGAME2 + ANIMBIT;
1560  }
1561  }
1562 
1563  return;
1564 
1565  case FULLSTADIUM: // Full stadium
1566 
1567  stadiumPop++;
1568 
1569  if (((cityTime + pos.posX + pos.posY) & 7) == 0) {
1570  // Stop the match
1571  drawStadium(pos, STADIUM);
1572  }
1573 
1574  return;
1575 
1576  case AIRPORT:
1577 
1578  airportPop++;
1579 
1580  if ((cityTime & 7) == 0) {
1581  repairZone(pos, AIRPORT, 6);
1582  }
1583 
1584  // If powered, display a rotating radar
1585  if (powerOn) {
1586  if ((map[pos.posX + 1][pos.posY - 1] & LOMASK) == RADAR) {
1587  map[pos.posX + 1][pos.posY - 1] = RADAR0 + ANIMBIT + CONDBIT + BURNBIT;
1588  }
1589  } else {
1590  map[pos.posX + 1][pos.posY - 1] = RADAR + CONDBIT + BURNBIT;
1591  }
1592 
1593  if (powerOn) { // Handle the airport only if there is power
1594  doAirport(pos);
1595  }
1596 
1597  return;
1598 
1599  case PORT:
1600 
1601  seaportPop++;
1602 
1603  if ((cityTime & 15) == 0) {
1604  repairZone(pos, PORT, 4);
1605  }
1606 
1607  // If port has power and there is no ship, generate one
1608  if (powerOn && getSprite(SPRITE_SHIP) == NULL) {
1609  generateShip();
1610  }
1611 
1612  return;
1613  }
1614 }
1615 
1616 
1625 {
1626  int x, y;
1627 
1628  z = z - 5;
1629 
1630  for (y = center.posY - 1; y < center.posY + 3; y++) {
1631  for (x = center.posX - 1; x < center.posX + 3; x++) {
1632  map[x][y] = z | BNCNBIT;
1633  z++;
1634  }
1635  }
1636 
1637  map[center.posX][center.posY] |= ZONEBIT | PWRBIT;
1638 }
1639 
1640 
1646 {
1647  if (getRandom(5) == 0) {
1648  generatePlane(pos);
1649  return;
1650  }
1651 
1652  if (getRandom(12) == 0) {
1653  generateCopter(pos);
1654  }
1655 }
1656 
1657 
1663 {
1664  static const short SmTb[4] = {
1667  };
1668  static const short dx[4] = { 1, 2, 1, 2 };
1669  static const short dy[4] = { -1, -1, 0, 0 };
1670 
1671  for (short x = 0; x < 4; x++) {
1672  map[pos.posX + dx[x]][pos.posY + dy[x]] =
1673  SmTb[x] | ANIMBIT | CONDBIT | PWRBIT | BURNBIT;
1674  }
1675 }
1676 
1677 
1683 {
1684  makeExplosion(pos.posX - 1, pos.posY - 1);
1685  makeExplosion(pos.posX - 1, pos.posY + 2);
1686  makeExplosion(pos.posX + 2, pos.posY - 1);
1687  makeExplosion(pos.posX + 2, pos.posY + 2);
1688 
1689  // Whole power plant is at fire
1690  for (int x = pos.posX - 1; x < pos.posX + 3; x++) {
1691  for (int y = pos.posY - 1; y < pos.posY + 3; y++) {
1692  map[x][y] = randomFire();
1693  }
1694  }
1695 
1696  // Add lots of radiation tiles around the plant
1697  for (int z = 0; z < 200; z++) {
1698 
1699  int x = pos.posX - 20 + getRandom(40);
1700  int y = pos.posY - 15 + getRandom(30);
1701 
1702  if (!testBounds(x, y)) { // Ignore off-map positions
1703  continue;
1704  }
1705 
1706  MapValue t = map[x][y];
1707 
1708  if (t & ZONEBIT) {
1709  continue; // Ignore zones
1710  }
1711 
1712  if ((t & BURNBIT) || t == DIRT) {
1713  map[x][y] = RADTILE; // Make tile radio-active
1714  }
1715 
1716  }
1717 
1718  // Report disaster to the user
1719  sendMessage(MESSAGE_NUCLEAR_MELTDOWN, pos.posX, pos.posY, true, true);
1720 }
1721 
1722 
DATA worldGet(int x, int y) const
Definition: map_type.h:316
const int MAP_BLOCKSIZE
Definition: map_type.h:121
void set(int x, int y, DATA val)
Definition: map_type.h:248
const int MAP_W
Number of clusters in horizontal direction.
Definition: map_type.h:122
void clear()
Definition: map_type.h:222
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
void fill(DATA val)
Definition: map_type.h:208
void worldSet(int x, int y, DATA val)
Definition: map_type.h:297
Quad roadEffect
Definition: micropolis.h:1201
SimSprite * spriteList
List of active sprites.
Definition: micropolis.h:2213
void generateCopter(const Position &pos)
Definition: sprite.cpp:1969
bool doInitialEval
Need to perform initial city evaluation.
Definition: micropolis.h:2120
Quad roadFund
Definition: micropolis.h:1182
int mustDrawBudget
Definition: micropolis.h:1463
void doMeltdown(const Position &pos)
Definition: simulate.cpp:1682
short indPop
Definition: micropolis.h:996
short stadiumPop
Number of stadiums.
Definition: micropolis.h:1025
short indZonePop
Number of industrial zones.
Definition: micropolis.h:1015
void evalInit()
Definition: evaluate.cpp:136
Scenario scoreType
The type of score table to use.
Definition: micropolis.h:2104
void coalSmoke(const Position &pos)
Definition: simulate.cpp:1662
void doRadTile(const Position &pos)
Definition: simulate.cpp:1054
bool taxFlag
Definition: micropolis.h:1237
short indHist10Max
Definition: micropolis.h:1145
short crimeAverage
Definition: micropolis.h:1063
void doZone(const Position &pos)
Definition: zone.cpp:91
GameLevel gameLevel
Difficulty level of the game (0..2)
Definition: micropolis.h:2334
Scenario scenario
Scenario being played.
Definition: micropolis.h:2338
Quad fireFund
Definition: micropolis.h:1196
void simLoadInit()
Definition: simulate.cpp:436
short poweredZoneCount
Number of powered tiles in all zone.
Definition: micropolis.h:2107
Quad policeEffect
Definition: micropolis.h:1206
void take10Census()
Definition: simulate.cpp:726
void doSpecialZone(const Position &pos, bool PwrOn)
Definition: simulate.cpp:1445
short * resHist
Definition: micropolis.h:1341
void makeExplosion(int x, int y)
Definition: sprite.cpp:2020
void changeCensus()
Definition: graph.cpp:122
int powerStackPointer
Stack counter, points to top-most item.
Definition: micropolis.h:1993
short graph10Max
Definition: micropolis.h:1807
MapByte1 powerGridMap
Definition: micropolis.h:1281
short unpoweredZoneCount
Number of unpowered tiles in all zones.
Definition: micropolis.h:2108
bool setZonePower(const Position &pos)
Definition: zone.cpp:431
void doRoad(const Position &pos)
Definition: simulate.cpp:1066
short newMapFlags[MAP_TYPE_COUNT]
Definition: micropolis.h:2042
short churchPop
Number of churches.
Definition: micropolis.h:1023
short firePop
Definition: micropolis.h:975
short * moneyHist
Definition: micropolis.h:1356
Quad cityTime
Definition: micropolis.h:1092
Quad fireSpend
Definition: micropolis.h:1175
short faith
Faith bias.
Definition: micropolis.h:1024
MapShort8 fireStationEffectMap
Definition: micropolis.h:1306
short resPop
Definition: micropolis.h:982
short getRandom(short range)
Definition: random.cpp:110
void sendMessages()
Definition: message.cpp:87
void fireAnalysis()
Definition: scan.cpp:120
int getBoatDistance(const Position &pos)
Definition: simulate.cpp:1264
int getRandom16()
Definition: random.cpp:130
void decRateOfGrowthMap()
Definition: simulate.cpp:369
bool enableDisasters
Enable disasters.
Definition: micropolis.h:2346
short newMap
Definition: micropolis.h:2039
void generatePlane(const Position &pos)
Definition: sprite.cpp:1985
void setValves()
Definition: simulate.cpp:560
short graph120Max
Definition: micropolis.h:1812
short scoreWait
Time to wait before computing the score.
Definition: micropolis.h:2105
void fireZone(const Position &pos, MapValue ch)
Definition: simulate.cpp:1357
void doDisasters()
Definition: disasters.cpp:92
short resZonePop
Number of residential zones.
Definition: micropolis.h:1013
short pollutionAverage
Definition: micropolis.h:1072
void collectTax()
Definition: simulate.cpp:852
void drawStadium(const Position &center, MapTile z)
Definition: simulate.cpp:1624
void pushPowerStack(const Position &pos)
Definition: power.cpp:173
short resHist120Max
Definition: micropolis.h:1130
bool indCap
Block industrial growth.
Definition: micropolis.h:2095
Quad fireEffect
Definition: micropolis.h:1211
short totalPopLast
Definition: micropolis.h:1011
bool resCap
Block residential growth.
Definition: micropolis.h:2093
short * crimeHist
Definition: micropolis.h:1366
short * pollutionHist
Definition: micropolis.h:1361
short airportPop
Definition: micropolis.h:1055
Quad taxFund
Definition: micropolis.h:1219
Quad roadSpend
Definition: micropolis.h:1165
void generateShip()
Definition: sprite.cpp:1858
short policeStationPop
Definition: micropolis.h:1030
MapValue randomFire()
Definition: micropolis.h:2139
void repairZone(const Position &pos, MapTile zCent, short zSize)
Definition: simulate.cpp:1404
short disasterWait
Count-down timer for the disaster.
Definition: micropolis.h:2102
SimSprite * getSprite(int type)
Definition: sprite.cpp:338
MapShort8 fireStationMap
Definition: micropolis.h:1301
short totalPop
Definition: micropolis.h:1004
short landValueAverage
Definition: micropolis.h:1080
unsigned short * map[WORLD_W]
Definition: micropolis.h:1120
short coalPowerPop
Definition: micropolis.h:1040
void doStartGame()
short hospitalPop
Number of hospitals.
Definition: micropolis.h:1022
void crimeScan()
Definition: scan.cpp:413
bool censusChanged
Definition: micropolis.h:1157
short * indHist
Definition: micropolis.h:1351
void generateTrain(int x, int y)
Definition: sprite.cpp:1836
short comHist10Max
Definition: micropolis.h:1135
short * comHist
Definition: micropolis.h:1346
void sendMessage(short Mnum, short x=NOWHERE, short y=NOWHERE, bool picture=false, bool important=false)
Definition: message.cpp:390
void doAirport(const Position &pos)
Definition: simulate.cpp:1645
Scenario disasterEvent
The disaster for which a count-down is running.
Definition: micropolis.h:2101
MapShort8 policeStationMap
Definition: micropolis.h:1317
void setGameLevel(GameLevel level)
Definition: utilities.cpp:235
MapByte2 trafficDensityMap
Traffic density map.
Definition: micropolis.h:1245
short cityScore
Definition: micropolis.h:1604
bool comCap
Block commercial growth.
Definition: micropolis.h:2094
void decTrafficMap()
Definition: simulate.cpp:337
void doFire(const Position &pos)
Definition: simulate.cpp:1294
Quad policeSpend
Definition: micropolis.h:1170
CityClass cityClass
City class, affected by city population.
Definition: micropolis.h:1593
short nuclearPowerPop
Definition: micropolis.h:1045
static bool testBounds(int wx, int wy)
Definition: micropolis.h:2378
void makeExplosionAt(int x, int y)
Definition: sprite.cpp:2033
short fireStationPop
Definition: micropolis.h:1035
void doStartScenario(int scenario)
short comPop
Definition: micropolis.h:989
void doNilPower()
Definition: simulate.cpp:321
short needHospital
Definition: micropolis.h:1383
Quad policeFund
Definition: micropolis.h:1189
short needChurch
Definition: micropolis.h:1390
MapShort8 rateOfGrowthMap
Definition: micropolis.h:1290
bool doBridge(const Position &pos, MapTile tile)
Definition: simulate.cpp:1139
short cityTax
Definition: micropolis.h:1224
short railTotal
Definition: micropolis.h:970
MapValue randomRubble()
Definition: micropolis.h:2145
void doPowerScan()
Definition: power.cpp:125
short * miscHist
Definition: micropolis.h:1371
void updateFundEffects()
Definition: simulate.cpp:908
short comZonePop
Number of commercial zones.
Definition: micropolis.h:1014
void populationDensityScan()
Definition: scan.cpp:136
void doFlood(const Position &pos)
Definition: disasters.cpp:385
short seaportPop
Definition: micropolis.h:1050
short roadTotal
Definition: micropolis.h:963
void doRail(const Position &pos)
Definition: simulate.cpp:1019
short comHist120Max
Definition: micropolis.h:1140
void cityEvaluation()
Definition: evaluate.cpp:110
void doBudget()
Definition: budget.cpp:97
bool findPerimeterRoad(Position *pos)
Definition: traffic.cpp:239
void doSimInit()
Definition: simulate.cpp:286
short resHist10Max
Definition: micropolis.h:1125
short indHist120Max
Definition: micropolis.h:1150
int posY
Vertical coordnate of the position.
Definition: position.h:169
int posX
Horizontal coordinate of the position.
Definition: position.h:168
int x
X coordinate of the sprite in pixels?
Definition: micropolis.h:891
int yHot
Offset of the hot-spot relative to SimSprite::y?
Definition: micropolis.h:898
int type
Type of the sprite (TRA – BUS).
Definition: micropolis.h:889
SimSprite * next
Pointer to next SimSprite object in the list.
Definition: micropolis.h:887
int y
Y coordinate of the sprite in pixels?
Definition: micropolis.h:892
int frame
Frame (0 means non-active sprite)
Definition: micropolis.h:890
int xHot
Offset of the hot-spot relative to SimSprite::x?
Definition: micropolis.h:897
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.
@ SC_NONE
No scenario (free playing)
Definition: micropolis.h:698
@ SC_COUNT
Number of scenarios.
Definition: micropolis.h:709
@ MAP_TYPE_DYNAMIC
Dynamic filter.
Definition: micropolis.h:321
@ 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_TRAFFIC_DENSITY
Traffic.
Definition: micropolis.h:315
@ HTRFBASE
First tile with high traffic.
Definition: micropolis.h:452
@ HBRIDGE
Horizontal bridge.
Definition: micropolis.h:426
@ VBRIDGE
Vertical bridge.
Definition: micropolis.h:428
@ STADIUM
'Center tile' stadium.
Definition: micropolis.h:595
@ NUCLEAR
'Center' tile nuclear power plant.
Definition: micropolis.h:604
@ PORTBASE
Top-left tile of the seaport.
Definition: micropolis.h:567
@ IZB
Center tile of first non-empty industry zone.
Definition: micropolis.h:542
@ PORT
Center tile of the seaport.
Definition: micropolis.h:568
@ COALSMOKE3
927 last animation tile for chimney at coal power plant (2, 1).
Definition: micropolis.h:644
@ POWERPLANT
'Center' tile of coal power plant.
Definition: micropolis.h:580
@ COALSMOKE4
931 last animation tile for chimney at coal power plant (3, 1).
Definition: micropolis.h:647
@ RADTILE
Radio-active contaminated tile.
Definition: micropolis.h:415
@ FIRESTATION
'Center tile' of fire station.
Definition: micropolis.h:585
@ LTRFBASE
First tile with low traffic.
Definition: micropolis.h:443
@ DIRT
Clear tile.
Definition: micropolis.h:382
@ COALSMOKE1
919 last animation tile for chimney at coal power plant (2, 0).
Definition: micropolis.h:638
@ COALSMOKE2
923 last animation tile for chimney at coal power plant (3, 0).
Definition: micropolis.h:641
CityClass
Definition: micropolis.h:750
@ CC_MEGALOPOLIS
Megalopolis, > 500000 citizens.
Definition: micropolis.h:756
@ CC_VILLAGE
Village.
Definition: micropolis.h:751
static const int MAX_FIRE_STATION_EFFECT
Definition: micropolis.h:263
GameLevel
Definition: micropolis.h:762
@ LEVEL_FIRST
First game level value.
Definition: micropolis.h:769
@ LEVEL_LAST
Last game level value.
Definition: micropolis.h:770
@ LEVEL_COUNT
Number of game levels.
Definition: micropolis.h:767
static T min(const T a, const T b)
Definition: micropolis.h:783
static const int MAX_ROAD_EFFECT
Definition: micropolis.h:253
@ SPRITE_SHIP
Ship.
Definition: micropolis.h:334
#define LENGTH_OF(array)
Definition: micropolis.h:842
static const int MAX_POLICE_STATION_EFFECT
Definition: micropolis.h:258
static T clamp(const T val, const T lower, const T upper)
Definition: micropolis.h:808
static T absoluteValue(const T val)
Definition: micropolis.h:825
static T max(const T a, const T b)
Definition: micropolis.h:795
static const int CENSUS_FREQUENCY_10
Definition: simulate.cpp:90
static const int CENSUS_FREQUENCY_120
Definition: simulate.cpp:96
static const int TAX_FREQUENCY
Definition: simulate.cpp:101
Defines string identification numbers for texts used in the Micropolis game engine.
@ MESSAGE_NUCLEAR_MELTDOWN
A Nuclear Meltdown has occurred !!!
Definition: text.h:155
unsigned short MapTile
Definition: tool.h:108
@ BURNBIT
bit 13, tile can be lit.
Definition: tool.h:122
@ 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
@ BULLBIT
bit 12, tile is bulldozable.
Definition: tool.h:123
@ ANIMBIT
bit 11, tile is animated.
Definition: tool.h:124
@ ALLBITS
Mask for the bits-part of the tile.
Definition: tool.h:128
unsigned short MapValue
Definition: tool.h:94