Micropolis
callback.cpp
Go to the documentation of this file.
1/* callback.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 <emscripten.h>
83
84
85ConsoleCallback::~ConsoleCallback() {
86 EM_ASM_({
87 console.log('~ConsoleCallback destructor');
88 });
89}
90
91void ConsoleCallback::autoGoto(Micropolis *micropolis, emscripten::val callbackVal, int x, int y, std::string message) {
92 EM_ASM_({
93 console.log('autoGoto:', 'x:', $0, 'y:', $1, 'message:', UTF8ToString($2));
94 }, x, y, message.c_str());
95}
96
97void ConsoleCallback::didGenerateMap(Micropolis *micropolis, emscripten::val callbackVal, int seed) {
98 EM_ASM_({
99 console.log('didGenerateMap:', 'seed:', $0);
100 }, seed);
101}
102
103void ConsoleCallback::didLoadCity(Micropolis *micropolis, emscripten::val callbackVal, std::string filename) {
104 EM_ASM_({
105 console.log('didLoadCity:', 'filename:', UTF8ToString($0));
106 }, filename.c_str());
107}
108
109void ConsoleCallback::didLoadScenario(Micropolis *micropolis, emscripten::val callbackVal, std::string name, std::string fname) {
110 EM_ASM_({
111 console.log('didLoadScenario:', 'name:', UTF8ToString($0), 'fname:', UTF8ToString($1));
112 }, name.c_str(), fname.c_str());
113}
114
115void ConsoleCallback::didLoseGame(Micropolis *micropolis, emscripten::val callbackVal) {
116 EM_ASM_({
117 console.log('didLoseGame');
118 });
119}
120
121void ConsoleCallback::didSaveCity(Micropolis *micropolis, emscripten::val callbackVal, std::string filename) {
122 EM_ASM_({
123 console.log('didSaveCity:', 'filename:', UTF8ToString($0));
124 }, filename.c_str());
125}
126
127void ConsoleCallback::didTool(Micropolis *micropolis, emscripten::val callbackVal, std::string name, int x, int y) {
128 EM_ASM_({
129 console.log('didTool:', 'name:', UTF8ToString($0), 'x:', $1, 'y:', $2);
130 }, name.c_str(), x, y);
131}
132
133void ConsoleCallback::didWinGame(Micropolis *micropolis, emscripten::val callbackVal) {
134 EM_ASM_({
135 console.log('didWinGame');
136 });
137}
138
139void ConsoleCallback::didntLoadCity(Micropolis *micropolis, emscripten::val callbackVal, std::string filename) {
140 EM_ASM_({
141 console.log('didntLoadCity:', 'filename:', UTF8ToString($0));
142 }, filename.c_str());
143}
144
145void ConsoleCallback::didntSaveCity(Micropolis *micropolis, emscripten::val callbackVal, std::string filename) {
146 EM_ASM_({
147 console.log('didntSaveCity:', 'filename:', UTF8ToString($0));
148 }, filename.c_str());
149}
150
151void ConsoleCallback::makeSound(Micropolis *micropolis, emscripten::val callbackVal, std::string channel, std::string sound, int x, int y) {
152 EM_ASM_({
153 console.log('makeSound:', 'channel:', UTF8ToString($0), 'sound:', UTF8ToString($1), 'x:', $2, 'y:', $3);
154 }, channel.c_str(), sound.c_str(), x, y);
155}
156
157void ConsoleCallback::newGame(Micropolis *micropolis, emscripten::val callbackVal) {
158 EM_ASM_({
159 console.log('newGame');
160 });
161}
162
163void ConsoleCallback::saveCityAs(Micropolis *micropolis, emscripten::val callbackVal, std::string filename) {
164 EM_ASM_({
165 console.log('saveCityAs:', 'filename:', UTF8ToString($0));
166 }, filename.c_str());
167}
168
169void ConsoleCallback::sendMessage(Micropolis *micropolis, emscripten::val callbackVal, int messageIndex, int x, int y, bool picture, bool important) {
170 EM_ASM_({
171 console.log('sendMessage:', 'messageIndex:', $0, 'x:', $1, 'y:', $2, 'picture:', $3, 'important:', $4);
172 }, messageIndex, x, y, picture, important);
173}
174
175void ConsoleCallback::showBudgetAndWait(Micropolis *micropolis, emscripten::val callbackVal) {
176 EM_ASM_({
177 console.log('showBudgetAndWait');
178 });
179}
180
181void ConsoleCallback::showZoneStatus(Micropolis *micropolis, emscripten::val callbackVal, int tileCategoryIndex, int populationDensityIndex, int landValueIndex, int crimeRateIndex, int pollutionIndex, int growthRateIndex, int x, int y) {
182 EM_ASM_({
183 console.log('showZoneStatus:', 'tileCategoryIndex:', $0, 'populationDensityIndex:', $1, 'landValueIndex:', $2, 'crimeRateIndex:', $3, 'pollutionIndex:', $4, 'growthRateIndex:', $5, 'x:', $6, 'y:', $7);
184 }, tileCategoryIndex, populationDensityIndex, landValueIndex, crimeRateIndex, pollutionIndex, growthRateIndex, x, y);
185}
186
187void ConsoleCallback::simulateRobots(Micropolis *micropolis, emscripten::val callbackVal) {
188 EM_ASM_({
189 console.log('simulateRobots');
190 });
191}
192
193void ConsoleCallback::simulateChurch(Micropolis *micropolis, emscripten::val callbackVal, int posX, int posY, int churchNumber) {
194 EM_ASM_({
195 console.log('simulateChurch:', 'posX:', $0, 'posY:', $1, 'churchNumber:', $2);
196 }, posX, posY, churchNumber);
197}
198
199void ConsoleCallback::startEarthquake(Micropolis *micropolis, emscripten::val callbackVal, int strength) {
200 EM_ASM_({
201 console.log('startEarthquake:', 'strength:', $0);
202 }, strength);
203}
204
205void ConsoleCallback::startGame(Micropolis *micropolis, emscripten::val callbackVal) {
206 EM_ASM_({
207 console.log('startGame');
208 });
209}
210
211void ConsoleCallback::startScenario(Micropolis *micropolis, emscripten::val callbackVal, int scenario) {
212 EM_ASM_({
213 console.log('startScenario:', 'scenario:', $0);
214 }, scenario);
215}
216
217void ConsoleCallback::updateBudget(Micropolis *micropolis, emscripten::val callbackVal) {
218 EM_ASM_({
219 console.log('updateBudget');
220 });
221}
222
223void ConsoleCallback::updateCityName(Micropolis *micropolis, emscripten::val callbackVal, std::string cityName) {
224 EM_ASM_({
225 console.log('updateCityName:', 'cityName:', UTF8ToString($0));
226 }, cityName.c_str());
227}
228
229void ConsoleCallback::updateDate(Micropolis *micropolis, emscripten::val callbackVal, int cityYear, int cityMonth) {
230 EM_ASM_({
231 console.log('updateDate:', 'cityYear:', $0, 'cityMonth:', $1);
232 }, cityYear, cityMonth);
233}
234
235void ConsoleCallback::updateDemand(Micropolis *micropolis, emscripten::val callbackVal, float r, float c, float i) {
236 EM_ASM_({
237 console.log('updateDemand:', 'r:', $0, 'c:', $1, 'i:', $2);
238 }, r, c, i);
239}
240
241void ConsoleCallback::updateEvaluation(Micropolis *micropolis, emscripten::val callbackVal) {
242 EM_ASM({
243 console.log('updateEvaluation');
244 });
245}
246
247void ConsoleCallback::updateFunds(Micropolis *micropolis, emscripten::val callbackVal, int totalFunds) {
248 EM_ASM_({
249 console.log('updateFunds:', 'totalFunds:', $0);
250 }, totalFunds);
251}
252
253void ConsoleCallback::updateGameLevel(Micropolis *micropolis, emscripten::val callbackVal, int gameLevel) {
254 EM_ASM_({
255 console.log('updateGameLevel:', 'gameLevel:', $0);
256 }, gameLevel);
257}
258
259void ConsoleCallback::updateHistory(Micropolis *micropolis, emscripten::val callbackVal) {
260 EM_ASM({
261 console.log('updateHistory');
262 });
263}
264
265void ConsoleCallback::updateMap(Micropolis *micropolis, emscripten::val callbackVal) {
266 EM_ASM({
267 console.log('updateMap');
268 });
269}
270
271void ConsoleCallback::updateOptions(Micropolis *micropolis, emscripten::val callbackVal) {
272 EM_ASM({
273 console.log('updateOptions');
274 });
275}
276
277void ConsoleCallback::updatePasses(Micropolis *micropolis, emscripten::val callbackVal, int passes) {
278 EM_ASM_({
279 console.log('updatePasses:', 'passes:', $0);
280 }, passes);
281}
282
283void ConsoleCallback::updatePaused(Micropolis *micropolis, emscripten::val callbackVal, bool simPaused) {
284 EM_ASM_({
285 console.log('updatePaused:', 'simPaused:', $0);
286 }, simPaused);
287}
288
289void ConsoleCallback::updateSpeed(Micropolis *micropolis, emscripten::val callbackVal, int speed) {
290 EM_ASM_({
291 console.log('updateSpeed:', 'speed:', $0);
292 }, speed);
293}
294
295void ConsoleCallback::updateTaxRate(Micropolis *micropolis, emscripten::val callbackVal, int cityTax) {
296 EM_ASM_({
297 console.log('updateTaxRate:', 'cityTax:', $0);
298 }, cityTax);
299}
300
301
Header file for Micropolis game engine.