Micropolis
update.cpp
Go to the documentation of this file.
1 /* update.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 
79 
80 
81 #include "micropolis.h"
82 #include "text.h"
83 
84 
86 
87 
88 void Micropolis::doUpdateHeads()
89 {
90  showValves();
91  doTimeStuff();
92  reallyUpdateFunds();
93  updateOptions();
94 }
95 
96 
97 void Micropolis::updateMaps()
98 {
100  doUpdateHeads();
101 }
102 
103 
104 void Micropolis::updateGraphs()
105 {
106  changeCensus();
107 }
108 
109 
110 void Micropolis::updateEvaluation()
111 {
112  changeEval();
113 }
114 
115 
116 void Micropolis::updateHeads()
117 {
118  mustUpdateFunds = true;
119  valveFlag = true;
120  cityTimeLast = cityYearLast = cityMonthLast = totalFundsLast =
121  resLast = comLast = indLast = -999999;
122  doUpdateHeads();
123 }
124 
125 
128 {
129  mustUpdateFunds = true;
130 }
131 
132 
133 void Micropolis::reallyUpdateFunds()
134 {
135  if (!mustUpdateFunds) {
136  return;
137  }
138 
139  mustUpdateFunds = false;
140 
141  if (totalFunds != totalFundsLast) {
142  totalFundsLast = totalFunds;
143 
144  callback->updateFunds(this, callbackVal, totalFunds);
145  }
146 
147 }
148 
149 
150 void Micropolis::doTimeStuff()
151 {
152  updateDate();
153 }
154 
155 
160 {
161  int megalinium = 1000000;
162 
163  cityTimeLast = cityTime >> 2;
164 
165  cityYear = ((int)cityTime / 48) + (int)startingYear;
166  cityMonth = ((int)cityTime % 48) >> 2;
167 
168  if (cityYear >= megalinium) {
169  setYear(startingYear);
172 
173  }
174 
175  if ((cityYearLast != cityYear) ||
176  (cityMonthLast != cityMonth)) {
177 
178  cityYearLast = cityYear;
179  cityMonthLast = cityMonth;
180 
181  callback->updateDate(this, callbackVal, cityYear, cityMonth);
182  }
183 }
184 
185 
186 void Micropolis::showValves()
187 {
188  if (valveFlag) {
189  drawValve();
190  valveFlag = false;
191  }
192 }
193 
194 
195 void Micropolis::drawValve()
196 {
197  float r, c, i;
198 
199  r = resValve;
200 
201  if (r < -1500) {
202  r = -1500;
203  }
204 
205  if (r > 1500) {
206  r = 1500;
207  }
208 
209  c = comValve;
210 
211  if (c < -1500) {
212  c = -1500;
213  }
214 
215  if (c > 1500) {
216  c = 1500;
217  }
218 
219  i = indValve;
220 
221  if (i < -1500) {
222  i = -1500;
223  }
224 
225  if (i > 1500) {
226  i = 1500;
227  }
228 
229  if ((r != resLast) ||
230  (c != comLast) ||
231  (i != indLast)) {
232 
233  resLast = (int)r;
234  comLast = (int)c;
235  indLast = (int)i;
236 
237  setDemand(r, c, i);
238  }
239 }
240 
241 
242 void Micropolis::setDemand(float r, float c, float i)
243 {
244  callback->updateDemand(this, callbackVal, r, c, i);
245 }
246 
247 
248 void Micropolis::updateOptions()
249 {
250  if (mustUpdateOptions) {
251  mustUpdateOptions = false;
252  callback->updateOptions(this, callbackVal);
253  }
254 }
255 
256 
262 {
264 
265  // city: after load file, load scenario, or generate city
266  // map: when small overall map changes
267  // editor: when large close-up map changes
268  // graph: when graph changes
269  // evaluation: when evaluation changes
270  // budget: when budget changes
271  // date: when date changes
272  // funds: when funds change
273  // demand: when demand changes
274  // level: when level changes
275  // speed: when speed changes
276  // delay: when delay changes
277  // option: when options change
278 }
279 
280 
void changeEval()
Definition: evaluate.cpp:507
void changeCensus()
Definition: graph.cpp:122
Callback * callback
Definition: micropolis.h:954
Quad cityTime
Definition: micropolis.h:1092
void updateUserInterface()
Definition: update.cpp:261
void updateFunds()
Definition: update.cpp:127
bool mustUpdateOptions
Options displayed at user need updating.
Definition: micropolis.h:2639
Quad cityMonth
Definition: micropolis.h:1098
short startingYear
Definition: micropolis.h:1109
void sendMessage(short Mnum, short x=NOWHERE, short y=NOWHERE, bool picture=false, bool important=false)
Definition: message.cpp:390
Quad cityYear
Definition: micropolis.h:1104
void invalidateMaps()
Quad totalFunds
Funds of the player.
Definition: micropolis.h:2315
void updateDate()
Definition: update.cpp:159
Header file for Micropolis game engine.
static const int NOWHERE
Definition: micropolis.h:233
Defines string identification numbers for texts used in the Micropolis game engine.
@ MESSAGE_NOT_ENOUGH_POWER
40: Brownouts, build another Power Plant.
Definition: text.h:152