Micropolis
message.cpp
Go to the documentation of this file.
1 /* message.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 
85 
88 {
89  short PowerPop;
90  float TM;
91 
92  // Running a scenario, and waiting it to 'end' so we can give a score
93  if (scenario > SC_NONE && scoreType > SC_NONE && scoreWait > 0) {
94  scoreWait--;
95  if (scoreWait == 0) {
97  }
98  }
99 
100  checkGrowth();
101 
103  PowerPop = nuclearPowerPop + coalPowerPop;
104 
105  switch (cityTime & 63) {
106 
107  case 1:
108  if (totalZonePop / 4 >= resZonePop) {
110  }
111  break;
112 
113  case 5:
114  if (totalZonePop / 8 >= comZonePop) {
116  }
117  break;
118 
119  case 10:
120  if (totalZonePop / 8 >= indZonePop) {
122  }
123  break;
124 
125  case 14:
126  if (totalZonePop > 10 && totalZonePop * 2 > roadTotal) {
128  }
129  break;
130 
131  case 18:
132  if (totalZonePop > 50 && totalZonePop > railTotal) {
134  }
135  break;
136 
137  case 22:
138  if (totalZonePop > 10 && PowerPop == 0) {
140  }
141  break;
142 
143  case 26:
144  if (resPop > 500 && stadiumPop == 0) {
146  resCap = true;
147  } else {
148  resCap = false;
149  }
150  break;
151 
152  case 28:
153  if (indPop > 70 && seaportPop == 0) {
155  indCap = true;
156  } else {
157  indCap = false;
158  }
159  break;
160 
161  case 30:
162  if (comPop > 100 && airportPop == 0) {
164  comCap = true;
165  } else {
166  comCap = false;
167  }
168  break;
169 
170  case 32:
171  TM = (float)(unpoweredZoneCount + poweredZoneCount); /* dec score for unpowered zones */
172  if (TM > 0) {
173  if (poweredZoneCount / TM < 0.7) {
175  }
176  }
177  break;
178 
179  case 35:
180  if (pollutionAverage > /* 80 */ 60) {
181  sendMessage(MESSAGE_HIGH_POLLUTION, -1, -1, true);
182  }
183  break;
184 
185  case 42:
186  if (crimeAverage > 100) {
187  sendMessage(MESSAGE_HIGH_CRIME, -1, -1, true);
188  }
189  break;
190 
191  case 45:
192  if (totalPop > 60 && fireStationPop == 0) {
194  }
195  break;
196 
197  case 48:
198  if (totalPop > 60 && policeStationPop == 0) {
200  }
201  break;
202 
203  case 51:
204  if (cityTax > 12) {
206  }
207  break;
208 
209  case 54:
210  // If roadEffect < 5/8 of max effect
211  if (roadEffect < (5 * MAX_ROAD_EFFECT / 8) && roadTotal > 30) {
213  }
214  break;
215 
216  case 57:
217  // If fireEffect < 0.7 of max effect
218  if (fireEffect < (7 * MAX_FIRE_STATION_EFFECT / 10) && totalPop > 20) {
220  }
221  break;
222 
223  case 60:
224  // If policeEffect < 0.7 of max effect
225  if (policeEffect < (7 * MAX_POLICE_STATION_EFFECT / 10)
226  && totalPop > 20) {
228  }
229  break;
230 
231  case 63:
232  if (trafficAverage > 60) {
233  sendMessage(MESSAGE_TRAFFIC_JAMS, -1, -1, true);
234  }
235  break;
236 
237  }
238 }
239 
240 
251 {
252  if ((cityTime & 3) == 0) {
253  short category = 0;
254  Quad thisCityPop = getPopulation();
255 
256  if (cityPopLast > 0) {
257 
258  CityClass lastClass = getCityClass(cityPopLast);
259  CityClass newClass = getCityClass(thisCityPop);
260 
261  if (lastClass != newClass) {
262 
263  // Switched class, find appropiate message.
264  switch (newClass) {
265 
266  case CC_VILLAGE:
267  // Don't mention it.
268  break;
269 
270  case CC_TOWN:
271  category = MESSAGE_REACHED_TOWN;
272  break;
273 
274  case CC_CITY:
275  category = MESSAGE_REACHED_CITY;
276  break;
277 
278  case CC_CAPITAL:
279  category = MESSAGE_REACHED_CAPITAL;
280  break;
281 
282  case CC_METROPOLIS:
283  category = MESSAGE_REACHED_METROPOLIS;
284  break;
285 
286  case CC_MEGALOPOLIS:
287  category = MESSAGE_REACHED_MEGALOPOLIS;
288  break;
289 
290  default:
291  NOT_REACHED();
292  break;
293 
294  }
295  }
296  }
297 
298  if (category > 0 && category != categoryLast) {
299  sendMessage(category, NOWHERE, NOWHERE, true);
300  categoryLast = category;
301  }
302 
303  cityPopLast = thisCityPop;
304  }
305 }
306 
307 
314 {
315  short z = MESSAGE_SCENARIO_LOST; /* you lose */
316 
317  switch (type) {
318 
319  case SC_DULLSVILLE:
320  if (cityClass >= CC_METROPOLIS) {
322  }
323  break;
324 
325  case SC_SAN_FRANCISCO:
326  if (cityClass >= CC_METROPOLIS) {
328  }
329  break;
330 
331  case SC_HAMBURG:
332  if (cityClass >= CC_METROPOLIS) {
334  }
335  break;
336 
337  case SC_BERN:
338  if (trafficAverage < 80) {
340  }
341  break;
342 
343  case SC_TOKYO:
344  if (cityScore > 500) {
346  }
347  break;
348 
349  case SC_DETROIT:
350  if (crimeAverage < 60) {
352  }
353  break;
354 
355  case SC_BOSTON:
356  if (cityScore > 500) {
358  }
359  break;
360 
361  case SC_RIO:
362  if (cityScore > 500) {
364  }
365  break;
366 
367  default:
368  NOT_REACHED();
369  break;
370 
371  }
372 
373  sendMessage(z, NOWHERE, NOWHERE, true, true);
374 
375  if (z == MESSAGE_SCENARIO_LOST) {
376  doLoseGame();
377  }
378 }
379 
380 
390 void Micropolis::sendMessage(short messageIndex, short x, short y, bool picture, bool important)
391 {
392  callback->sendMessage(this, callbackVal, messageIndex, x, y, picture, important);
393 }
394 
395 
402 void Micropolis::doMakeSound(int mesgNum, int x, int y)
403 {
404  assert(mesgNum >= 0);
405 
406  switch (mesgNum) {
407 
409  if (getRandom(5) == 1) {
410  makeSound("city", "HonkHonkMed", x, y);
411  } else if (getRandom(5) == 1) {
412  makeSound("city", "HonkHonkLow", x, y);
413  } else if (getRandom(5) == 1) {
414  makeSound("city", "HonkHonkHigh", x, y);
415  }
416  break;
417 
418  case MESSAGE_HIGH_CRIME:
421  case MESSAGE_EARTHQUAKE:
426  makeSound("city", "Siren", x, y);
427  break;
428 
430  makeSound("city", "Monster", x, y);
431  break;
432 
433  case MESSAGE_FIREBOMBING:
434  makeSound("city", "ExplosionLow", x, y);
435  makeSound("city", "Siren", x, y);
436  break;
437 
439  makeSound("city", "ExplosionHigh", x, y);
440  makeSound("city", "ExplosionLow", x, y);
441  makeSound("city", "Siren", x, y);
442  break;
443 
445  makeSound("city", "Siren", x, y);
446  break;
447 
448  }
449 }
450 
457 void Micropolis::doAutoGoto(short x, short y, const std::string &message)
458 {
459  callback->autoGoto(this, callbackVal, x, y, message);
460 }
461 
462 
465 {
466  callback->didLoseGame(this, callbackVal);
467 }
468 
469 
472 {
473  callback->didWinGame(this, callbackVal);
474 }
475 
476 
void doScenarioScore(Scenario type)
Definition: message.cpp:313
Quad roadEffect
Definition: micropolis.h:1201
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
Scenario scoreType
The type of score table to use.
Definition: micropolis.h:2104
short crimeAverage
Definition: micropolis.h:1063
Scenario scenario
Scenario being played.
Definition: micropolis.h:2338
short poweredZoneCount
Number of powered tiles in all zone.
Definition: micropolis.h:2107
Quad policeEffect
Definition: micropolis.h:1206
void doLoseGame()
Definition: message.cpp:464
CityClass getCityClass(Quad cityPop)
Definition: evaluate.cpp:210
Callback * callback
Definition: micropolis.h:954
short unpoweredZoneCount
Number of unpowered tiles in all zones.
Definition: micropolis.h:2108
Quad cityTime
Definition: micropolis.h:1092
short resPop
Definition: micropolis.h:982
short getRandom(short range)
Definition: random.cpp:110
void sendMessages()
Definition: message.cpp:87
Quad cityPopLast
Population of last city class check.
Definition: micropolis.h:1951
Quad getPopulation()
Definition: evaluate.cpp:197
void doAutoGoto(short x, short y, const std::string &message)
Definition: message.cpp:457
short scoreWait
Time to wait before computing the score.
Definition: micropolis.h:2105
short totalZonePop
Definition: micropolis.h:1020
short resZonePop
Number of residential zones.
Definition: micropolis.h:1013
short pollutionAverage
Definition: micropolis.h:1072
bool indCap
Block industrial growth.
Definition: micropolis.h:2095
Quad fireEffect
Definition: micropolis.h:1211
bool resCap
Block residential growth.
Definition: micropolis.h:2093
short airportPop
Definition: micropolis.h:1055
short policeStationPop
Definition: micropolis.h:1030
short totalPop
Definition: micropolis.h:1004
void checkGrowth()
Definition: message.cpp:250
void doMakeSound(int mesgNum, int x, int y)
Definition: message.cpp:402
short coalPowerPop
Definition: micropolis.h:1040
short trafficAverage
Definition: micropolis.h:1618
void sendMessage(short Mnum, short x=NOWHERE, short y=NOWHERE, bool picture=false, bool important=false)
Definition: message.cpp:390
void makeSound(const std::string &channel, const std::string &sound, int x=-1, int y=-1)
short cityScore
Definition: micropolis.h:1604
short categoryLast
City class of last city class check.
Definition: micropolis.h:1952
bool comCap
Block commercial growth.
Definition: micropolis.h:2094
CityClass cityClass
City class, affected by city population.
Definition: micropolis.h:1593
short nuclearPowerPop
Definition: micropolis.h:1045
void doWinGame()
Definition: message.cpp:471
short fireStationPop
Definition: micropolis.h:1035
short comPop
Definition: micropolis.h:989
short cityTax
Definition: micropolis.h:1224
short railTotal
Definition: micropolis.h:970
short comZonePop
Number of commercial zones.
Definition: micropolis.h:1014
short seaportPop
Definition: micropolis.h:1050
short roadTotal
Definition: micropolis.h:963
Header file for Micropolis game engine.
Scenario
Definition: micropolis.h:697
@ SC_TOKYO
Tokyo (scary monster)
Definition: micropolis.h:704
@ SC_NONE
No scenario (free playing)
Definition: micropolis.h:698
@ SC_BOSTON
Boston (nuclear meltdown)
Definition: micropolis.h:706
@ SC_BERN
Bern (traffic)
Definition: micropolis.h:703
@ SC_SAN_FRANCISCO
San francisco (earthquake)
Definition: micropolis.h:701
@ SC_RIO
Rio (flooding)
Definition: micropolis.h:707
@ SC_HAMBURG
Hamburg (fire bombs)
Definition: micropolis.h:702
@ SC_DULLSVILLE
Dullsville (boredom)
Definition: micropolis.h:700
@ SC_DETROIT
Detroit (crime)
Definition: micropolis.h:705
#define NOT_REACHED()
Definition: micropolis.h:847
CityClass
Definition: micropolis.h:750
@ CC_CAPITAL
Capital, > 50000 citizens.
Definition: micropolis.h:754
@ CC_MEGALOPOLIS
Megalopolis, > 500000 citizens.
Definition: micropolis.h:756
@ CC_METROPOLIS
Metropolis, > 100000 citizens.
Definition: micropolis.h:755
@ CC_CITY
City, > 10000 citizens.
Definition: micropolis.h:753
@ CC_VILLAGE
Village.
Definition: micropolis.h:751
@ CC_TOWN
Town, > 2000 citizens.
Definition: micropolis.h:752
static const int MAX_FIRE_STATION_EFFECT
Definition: micropolis.h:263
static const int NOWHERE
Definition: micropolis.h:233
static const int MAX_ROAD_EFFECT
Definition: micropolis.h:253
static const int MAX_POLICE_STATION_EFFECT
Definition: micropolis.h:258
Defines string identification numbers for texts used in the Micropolis game engine.
@ MESSAGE_TAX_TOO_HIGH
Citizens upset. The tax rate is too high.
Definition: text.h:128
@ MESSAGE_SCENARIO_WON
You won the scenario.
Definition: text.h:159
@ MESSAGE_FIRE_REPORTED
20: Fire reported !
Definition: text.h:132
@ MESSAGE_SHIP_CRASHED
25: Shipwreck reported !
Definition: text.h:137
@ MESSAGE_REACHED_MEGALOPOLIS
Population has reached 500,000.
Definition: text.h:151
@ MESSAGE_PLANE_CRASHED
A plane has crashed !
Definition: text.h:136
@ MESSAGE_RIOTS_REPORTED
They're rioting in the streets !!
Definition: text.h:156
@ MESSAGE_SCENARIO_LOST
You lose the scenario.
Definition: text.h:160
@ MESSAGE_TRAIN_CRASHED
A train crashed !
Definition: text.h:138
@ MESSAGE_NEED_MORE_RAILS
5: Inadequate rail system.
Definition: text.h:117
@ MESSAGE_BLACKOUTS_REPORTED
15: Blackouts reported. Check power map.
Definition: text.h:127
@ MESSAGE_ROAD_NEEDS_FUNDING
Roads deteriorating, due to lack of funds.
Definition: text.h:129
@ MESSAGE_NEED_MORE_INDUSTRIAL
More industrial zones needed.
Definition: text.h:115
@ MESSAGE_HELICOPTER_CRASHED
A helicopter crashed !
Definition: text.h:139
@ MESSAGE_NUCLEAR_MELTDOWN
A Nuclear Meltdown has occurred !!!
Definition: text.h:155
@ MESSAGE_MONSTER_SIGHTED
A Monster has been sighted !!
Definition: text.h:133
@ MESSAGE_REACHED_TOWN
35: Population has reached 2,000.
Definition: text.h:147
@ MESSAGE_REACHED_METROPOLIS
Population has reached 100,000.
Definition: text.h:150
@ MESSAGE_NEED_MORE_ROADS
More roads required.
Definition: text.h:116
@ MESSAGE_TORNADO_SIGHTED
Tornado reported !!
Definition: text.h:134
@ MESSAGE_NEED_AIRPORT
Commerce requires an Airport.
Definition: text.h:121
@ MESSAGE_POLICE_NEEDS_FUNDING
Police departments need funding.
Definition: text.h:131
@ MESSAGE_NEED_POLICE_STATION
Citizens demand a Police Department.
Definition: text.h:126
@ MESSAGE_HIGH_CRIME
Crime very high.
Definition: text.h:123
@ MESSAGE_REACHED_CITY
Population has reached 10,000.
Definition: text.h:148
@ MESSAGE_REACHED_CAPITAL
Population has reached 50,000.
Definition: text.h:149
@ MESSAGE_FIREBOMBING
30: Firebombing reported !
Definition: text.h:142
@ MESSAGE_NEED_FIRE_STATION
Citizens demand a Fire Department.
Definition: text.h:125
@ MESSAGE_NEED_ELECTRICITY
Build a Power Plant.
Definition: text.h:118
@ MESSAGE_NEED_MORE_COMMERCIAL
More commercial zones needed.
Definition: text.h:114
@ MESSAGE_NEED_SEAPORT
Industry requires a Sea Port.
Definition: text.h:120
@ MESSAGE_FIRE_STATION_NEEDS_FUNDING
Fire departments need funding.
Definition: text.h:130
@ MESSAGE_HIGH_POLLUTION
10: Pollution very high.
Definition: text.h:122
@ MESSAGE_NEED_STADIUM
Residents demand a Stadium.
Definition: text.h:119
@ MESSAGE_TRAFFIC_JAMS
Frequent traffic jams reported.
Definition: text.h:124
@ MESSAGE_EARTHQUAKE
Major earthquake reported !!!
Definition: text.h:135
@ MESSAGE_NEED_MORE_RESIDENTIAL
More residential zones needed.
Definition: text.h:113