]>
Commit | Line | Data |
---|---|---|
1 | /* w_sim.c | |
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 | #include "sim.h" | |
63 | ||
64 | ||
65 | Tcl_HashTable SimCmds; | |
66 | ||
67 | ||
68 | #define SIMCMD_CALL(proc) \ | |
69 | int SimCmd##proc(ARGS) { proc(); return (TCL_OK); } | |
70 | ||
71 | #define SIMCMD_CALL_KICK(proc) \ | |
72 | int SimCmd##proc(ARGS) { proc(); Kick(); return (TCL_OK); } | |
73 | ||
74 | #define SIMCMD_CALL_INT(proc) \ | |
75 | int SimCmd##proc(ARGS) { \ | |
76 | int val; \ | |
77 | if (argc != 3) return (TCL_ERROR); \ | |
78 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK)) return (TCL_ERROR); \ | |
79 | proc(val); \ | |
80 | return (TCL_OK); \ | |
81 | } | |
82 | ||
83 | #define SIMCMD_CALL_STR(proc) \ | |
84 | int SimCmd##proc(ARGS) { \ | |
85 | if (argc != 3) return (TCL_ERROR); \ | |
86 | proc(argv[2]); \ | |
87 | return (TCL_OK); \ | |
88 | } | |
89 | ||
90 | #define SIMCMD_CALL_TILEXY(proc) \ | |
91 | int SimCmd##proc(ARGS) { \ | |
92 | int x, y; \ | |
93 | if (argc != 4) return (TCL_ERROR); \ | |
94 | if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK) || \ | |
95 | (x < 0) || (x >= WORLD_X)) return (TCL_ERROR); \ | |
96 | if ((Tcl_GetInt(interp, argv[3], &y) != TCL_OK) || \ | |
97 | (y < 0) || (y >= WORLD_Y)) return (TCL_ERROR); \ | |
98 | proc(x, y); \ | |
99 | return (TCL_OK); \ | |
100 | } | |
101 | ||
102 | #define SIMCMD_ACCESS_INT(var) \ | |
103 | int SimCmd##var(ARGS) { \ | |
104 | int val; \ | |
105 | if ((argc != 2) && (argc != 3)) return (TCL_ERROR); \ | |
106 | if (argc == 3) { \ | |
107 | if (Tcl_GetInt(interp, argv[2], &val) != TCL_OK) return (TCL_ERROR); \ | |
108 | var = val; \ | |
109 | } \ | |
110 | sprintf(interp->result, "%d", var); \ | |
111 | return (TCL_OK); \ | |
112 | } | |
113 | ||
114 | #define SIMCMD_GET_INT(var) \ | |
115 | int SimCmd##var(ARGS) { \ | |
116 | sprintf(interp->result, "%d", var); \ | |
117 | return (TCL_OK); \ | |
118 | } | |
119 | ||
120 | #define SIMCMD_GET_STR(var) \ | |
121 | int SimCmd##var(ARGS) { \ | |
122 | sprintf(interp->result, "%s", var); \ | |
123 | return (TCL_OK); \ | |
124 | } | |
125 | ||
126 | ||
127 | SIMCMD_CALL_KICK(GameStarted) | |
128 | SIMCMD_CALL_KICK(InitGame) | |
129 | SIMCMD_CALL(SaveCity) | |
130 | SIMCMD_CALL(ReallyQuit) | |
131 | SIMCMD_CALL_KICK(UpdateHeads) | |
132 | SIMCMD_CALL_KICK(UpdateMaps) | |
133 | SIMCMD_CALL_KICK(UpdateEditors) | |
134 | SIMCMD_CALL_KICK(RedrawMaps) | |
135 | SIMCMD_CALL_KICK(RedrawEditors) | |
136 | SIMCMD_CALL_KICK(UpdateGraphs) | |
137 | SIMCMD_CALL_KICK(UpdateEvaluation) | |
138 | SIMCMD_CALL_KICK(UpdateBudget) | |
139 | SIMCMD_CALL_KICK(UpdateBudgetWindow) | |
140 | SIMCMD_CALL_KICK(DoBudget) | |
141 | SIMCMD_CALL_KICK(DoBudgetFromMenu) | |
142 | SIMCMD_CALL_KICK(Pause) | |
143 | SIMCMD_CALL_KICK(Resume) | |
144 | SIMCMD_CALL(StartBulldozer) | |
145 | SIMCMD_CALL(StopBulldozer) | |
146 | SIMCMD_CALL(MakeFire) | |
147 | SIMCMD_CALL(MakeFlood) | |
148 | SIMCMD_CALL(MakeAirCrash) | |
149 | SIMCMD_CALL(MakeTornado) | |
150 | SIMCMD_CALL(MakeEarthquake) | |
151 | SIMCMD_CALL(MakeMonster) | |
152 | SIMCMD_CALL(MakeMeltdown) | |
153 | SIMCMD_CALL(FireBomb) | |
154 | SIMCMD_CALL(SoundOff) | |
155 | SIMCMD_CALL(GenerateNewCity) | |
156 | SIMCMD_CALL_INT(GenerateSomeCity) | |
157 | SIMCMD_ACCESS_INT(LakeLevel) | |
158 | SIMCMD_ACCESS_INT(TreeLevel) | |
159 | SIMCMD_ACCESS_INT(CurveLevel) | |
160 | SIMCMD_ACCESS_INT(CreateIsland) | |
161 | SIMCMD_CALL_KICK(SmoothTrees) | |
162 | SIMCMD_CALL_KICK(SmoothWater) | |
163 | SIMCMD_CALL_KICK(SmoothRiver) | |
164 | SIMCMD_CALL_KICK(ClearMap) | |
165 | SIMCMD_CALL_KICK(ClearUnnatural) | |
166 | SIMCMD_CALL_INT(LoadScenario) | |
167 | SIMCMD_CALL_STR(LoadCity) | |
168 | SIMCMD_CALL_STR(SaveCityAs) | |
169 | SIMCMD_CALL_TILEXY(MakeExplosion) | |
170 | SIMCMD_CALL(EraseOverlay) | |
171 | SIMCMD_ACCESS_INT(OverRide) | |
172 | SIMCMD_ACCESS_INT(Expensive) | |
173 | SIMCMD_ACCESS_INT(Players) | |
174 | SIMCMD_ACCESS_INT(Votes) | |
175 | SIMCMD_ACCESS_INT(BobHeight) | |
176 | SIMCMD_ACCESS_INT(PendingTool) | |
177 | SIMCMD_ACCESS_INT(PendingX) | |
178 | SIMCMD_ACCESS_INT(PendingY) | |
179 | SIMCMD_GET_STR(Displays) | |
180 | ||
181 | ||
182 | int SimCmdCityName(ARGS) | |
183 | { | |
184 | if ((argc != 2) && (argc != 3)) { | |
185 | return (TCL_ERROR); | |
186 | } | |
187 | ||
188 | if (argc == 3) { | |
189 | setCityName(argv[2]); | |
190 | } | |
191 | ||
192 | sprintf(interp->result, "%s", CityName); | |
193 | return (TCL_OK); | |
194 | } | |
195 | ||
196 | ||
197 | int SimCmdCityFileName(ARGS) | |
198 | { | |
199 | if ((argc != 2) && (argc != 3)) { | |
200 | return (TCL_ERROR); | |
201 | } | |
202 | ||
203 | if (argc == 3) { | |
204 | if (CityFileName != NULL) { | |
205 | ckfree(CityFileName); | |
206 | CityFileName = NULL; | |
207 | } | |
208 | if (argv[2][0] != '\0') { | |
209 | CityFileName = (char *)ckalloc(strlen(argv[0]) + 1); | |
210 | strcpy(CityFileName, argv[2]); | |
211 | } | |
212 | } | |
213 | ||
214 | sprintf(interp->result, "%s", CityFileName ? CityFileName : ""); | |
215 | return (TCL_OK); | |
216 | } | |
217 | ||
218 | ||
219 | int SimCmdGameLevel(ARGS) | |
220 | { | |
221 | int level; | |
222 | ||
223 | if ((argc != 2) && (argc != 3)) { | |
224 | return (TCL_ERROR); | |
225 | } | |
226 | ||
227 | if (argc == 3) { | |
228 | if ((Tcl_GetInt(interp, argv[2], &level) != TCL_OK) || | |
229 | (level < 0) || (level > 2)) { | |
230 | return (TCL_ERROR); | |
231 | } | |
232 | SetGameLevelFunds(level); | |
233 | } | |
234 | ||
235 | sprintf(interp->result, "%d", GameLevel); | |
236 | return (TCL_OK); | |
237 | } | |
238 | ||
239 | ||
240 | int SimCmdSpeed(ARGS) | |
241 | { | |
242 | int speed; | |
243 | ||
244 | if ((argc != 2) && (argc != 3)) { | |
245 | return (TCL_ERROR); | |
246 | } | |
247 | ||
248 | if (argc == 3) { | |
249 | if ((Tcl_GetInt(interp, argv[2], &speed) != TCL_OK) || | |
250 | (speed < 0) || (speed > 7)) { | |
251 | return (TCL_ERROR); | |
252 | } | |
253 | setSpeed(speed); Kick(); | |
254 | } | |
255 | ||
256 | sprintf(interp->result, "%d", SimSpeed); | |
257 | return (TCL_OK); | |
258 | } | |
259 | ||
260 | ||
261 | int SimCmdSkips(ARGS) | |
262 | { | |
263 | int skips; | |
264 | ||
265 | if ((argc != 2) && (argc != 3)) { | |
266 | return (TCL_ERROR); | |
267 | } | |
268 | ||
269 | if (argc == 3) { | |
270 | if ((Tcl_GetInt(interp, argv[2], &skips) != TCL_OK) || | |
271 | (skips < 0)) { | |
272 | return (TCL_ERROR); | |
273 | } | |
274 | setSkips(skips); Kick(); | |
275 | } | |
276 | ||
277 | sprintf(interp->result, "%d", sim_skips); | |
278 | ||
279 | return (TCL_OK); | |
280 | } | |
281 | ||
282 | ||
283 | int SimCmdSkip(ARGS) | |
284 | { | |
285 | int skip; | |
286 | ||
287 | if ((argc != 2) && (argc != 3)) { | |
288 | return (TCL_ERROR); | |
289 | } | |
290 | ||
291 | if (argc == 3) { | |
292 | if ((Tcl_GetInt(interp, argv[2], &skip) != TCL_OK) || | |
293 | (skip < 0)) { | |
294 | return (TCL_ERROR); | |
295 | } | |
296 | sim_skip = skip; | |
297 | } | |
298 | ||
299 | sprintf(interp->result, "%d", sim_skip); | |
300 | ||
301 | return (TCL_OK); | |
302 | } | |
303 | ||
304 | ||
305 | int SimCmdDelay(ARGS) | |
306 | { | |
307 | int delay; | |
308 | ||
309 | if ((argc != 2) && (argc != 3)) { | |
310 | return (TCL_ERROR); | |
311 | } | |
312 | ||
313 | if (argc == 3) { | |
314 | if ((Tcl_GetInt(interp, argv[2], &delay) != TCL_OK) || | |
315 | (delay < 0)) { | |
316 | return (TCL_ERROR); | |
317 | } | |
318 | sim_delay = delay; Kick(); | |
319 | } | |
320 | ||
321 | sprintf(interp->result, "%d", sim_delay); | |
322 | return (TCL_OK); | |
323 | } | |
324 | ||
325 | ||
326 | int SimCmdWorldX(ARGS) | |
327 | { | |
328 | int val; | |
329 | ||
330 | if (argc != 2) { | |
331 | return (TCL_ERROR); | |
332 | } | |
333 | ||
334 | sprintf(interp->result, "%d", WORLD_X); | |
335 | return (TCL_OK); | |
336 | } | |
337 | ||
338 | ||
339 | int SimCmdWorldY(ARGS) | |
340 | { | |
341 | int val; | |
342 | ||
343 | if (argc != 2) { | |
344 | return (TCL_ERROR); | |
345 | } | |
346 | ||
347 | sprintf(interp->result, "%d", WORLD_Y); | |
348 | return (TCL_OK); | |
349 | } | |
350 | ||
351 | ||
352 | int SimCmdHeatSteps(ARGS) | |
353 | { | |
354 | int steps; | |
355 | ||
356 | if ((argc != 2) && (argc != 3)) { | |
357 | return (TCL_ERROR); | |
358 | } | |
359 | ||
360 | if (argc == 3) { | |
361 | if ((Tcl_GetInt(interp, argv[2], &steps) != TCL_OK) || | |
362 | (steps < 0)) { | |
363 | return (TCL_ERROR); | |
364 | } | |
365 | heat_steps = steps; Kick(); | |
366 | } | |
367 | ||
368 | sprintf(interp->result, "%d", heat_steps); | |
369 | return (TCL_OK); | |
370 | } | |
371 | ||
372 | ||
373 | int SimCmdHeatFlow(ARGS) | |
374 | { | |
375 | int flow; | |
376 | ||
377 | if ((argc != 2) && (argc != 3)) { | |
378 | return (TCL_ERROR); | |
379 | } | |
380 | ||
381 | if (argc == 3) { | |
382 | if (Tcl_GetInt(interp, argv[2], &flow) != TCL_OK) { | |
383 | return (TCL_ERROR); | |
384 | } | |
385 | heat_flow = flow; | |
386 | } | |
387 | ||
388 | sprintf(interp->result, "%d", heat_flow); | |
389 | return (TCL_OK); | |
390 | } | |
391 | ||
392 | ||
393 | int SimCmdHeatRule(ARGS) | |
394 | { | |
395 | int rule; | |
396 | ||
397 | if ((argc != 2) && (argc != 3)) { | |
398 | return (TCL_ERROR); | |
399 | } | |
400 | ||
401 | if (argc == 3) { | |
402 | if (Tcl_GetInt(interp, argv[2], &rule) != TCL_OK) { | |
403 | return (TCL_ERROR); | |
404 | } | |
405 | heat_rule = rule; | |
406 | } | |
407 | ||
408 | sprintf(interp->result, "%d", heat_rule); | |
409 | return (TCL_OK); | |
410 | } | |
411 | ||
412 | ||
413 | #ifdef CAM | |
414 | ||
415 | int SimCmdJustCam(ARGS) | |
416 | { | |
417 | int cam; | |
418 | ||
419 | if ((argc != 2) && (argc != 3)) { | |
420 | return (TCL_ERROR); | |
421 | } | |
422 | ||
423 | if (argc == 3) { | |
424 | if (Tcl_GetInt(interp, argv[2], &cam) != TCL_OK) { | |
425 | return (TCL_ERROR); | |
426 | } | |
427 | sim_just_cam = cam; | |
428 | } | |
429 | ||
430 | sprintf(interp->result, "%d", sim_just_cam); | |
431 | return (TCL_OK); | |
432 | } | |
433 | ||
434 | #endif | |
435 | ||
436 | ||
437 | #ifdef NET | |
438 | ||
439 | int SimCmdListenTo(ARGS) | |
440 | { | |
441 | int port, sock; | |
442 | ||
443 | if (argc != 3) { | |
444 | return (TCL_ERROR); | |
445 | } | |
446 | ||
447 | if (Tcl_GetInt(interp, argv[2], &port) != TCL_OK) { | |
448 | return (TCL_ERROR); | |
449 | } | |
450 | ||
451 | #ifdef NET | |
452 | sock = udp_listen(port); | |
453 | #endif | |
454 | ||
455 | sprintf(interp->result, "%d", sock); | |
456 | ||
457 | return (TCL_OK); | |
458 | } | |
459 | ||
460 | ||
461 | int SimCmdHearFrom(ARGS) | |
462 | { | |
463 | int sock; | |
464 | ||
465 | if (argc != 3) { | |
466 | return (TCL_ERROR); | |
467 | } | |
468 | ||
469 | if ((argv[2][0] != 'f') || | |
470 | (argv[2][1] != 'i') || | |
471 | (argv[2][2] != 'l') || | |
472 | (argv[2][3] != 'e') || | |
473 | (Tcl_GetInt(interp, argv[2] + 4, &sock) != TCL_OK)) { | |
474 | return (TCL_ERROR); | |
475 | } | |
476 | ||
477 | #ifdef NET | |
478 | udp_hear(sock); | |
479 | #endif | |
480 | ||
481 | return (TCL_OK); | |
482 | } | |
483 | ||
484 | #endif /* NET */ | |
485 | ||
486 | ||
487 | int SimCmdFunds(ARGS) | |
488 | { | |
489 | int funds; | |
490 | ||
491 | if ((argc != 2) && (argc != 3)) { | |
492 | return (TCL_ERROR); | |
493 | } | |
494 | ||
495 | if (argc == 3) { | |
496 | if ((Tcl_GetInt(interp, argv[2], &funds) != TCL_OK) || | |
497 | (funds < 0)) { | |
498 | return (TCL_ERROR); | |
499 | } | |
500 | TotalFunds = funds; | |
501 | MustUpdateFunds = 1; | |
502 | Kick(); | |
503 | } | |
504 | ||
505 | sprintf(interp->result, "%d", TotalFunds); | |
506 | return (TCL_OK); | |
507 | } | |
508 | ||
509 | ||
510 | int SimCmdTaxRate(ARGS) | |
511 | { | |
512 | int tax; | |
513 | ||
514 | if ((argc != 2) && (argc != 3)) { | |
515 | return (TCL_ERROR); | |
516 | } | |
517 | ||
518 | if (argc == 3) { | |
519 | if ((Tcl_GetInt(interp, argv[2], &tax) != TCL_OK) || | |
520 | (tax < 0) || (tax > 20)) { | |
521 | return (TCL_ERROR); | |
522 | } | |
523 | CityTax = tax; | |
524 | drawBudgetWindow(); Kick(); | |
525 | } | |
526 | ||
527 | sprintf(interp->result, "%d", CityTax); | |
528 | return (TCL_OK); | |
529 | } | |
530 | ||
531 | ||
532 | int SimCmdFireFund(ARGS) | |
533 | { | |
534 | int percent; | |
535 | ||
536 | if ((argc != 2) && (argc != 3)) { | |
537 | return (TCL_ERROR); | |
538 | } | |
539 | ||
540 | if (argc == 3) { | |
541 | if ((Tcl_GetInt(interp, argv[2], &percent) != TCL_OK) || | |
542 | (percent < 0) || (percent > 100)) { | |
543 | return (TCL_ERROR); | |
544 | } | |
545 | firePercent = percent / 100.0; | |
546 | FireSpend = (fireMaxValue * percent) / 100; | |
547 | UpdateFundEffects(); Kick(); | |
548 | } | |
549 | ||
550 | sprintf(interp->result, "%d", (int)(firePercent * 100.0)); | |
551 | return (TCL_OK); | |
552 | } | |
553 | ||
554 | ||
555 | int SimCmdPoliceFund(ARGS) | |
556 | { | |
557 | int percent; | |
558 | ||
559 | if ((argc != 2) && (argc != 3)) { | |
560 | return (TCL_ERROR); | |
561 | } | |
562 | ||
563 | if (argc == 3) { | |
564 | if ((Tcl_GetInt(interp, argv[2], &percent) != TCL_OK) || | |
565 | (percent < 0) || (percent > 100)) { | |
566 | return (TCL_ERROR); | |
567 | } | |
568 | policePercent = percent / 100.0; | |
569 | PoliceSpend = (policeMaxValue * percent) / 100; | |
570 | UpdateFundEffects(); Kick(); | |
571 | } | |
572 | ||
573 | sprintf(interp->result, "%d", (int)(policePercent * 100.0)); | |
574 | return (TCL_OK); | |
575 | } | |
576 | ||
577 | ||
578 | int SimCmdRoadFund(ARGS) | |
579 | { | |
580 | int percent; | |
581 | ||
582 | if ((argc != 2) && (argc != 3)) { | |
583 | return (TCL_ERROR); | |
584 | } | |
585 | ||
586 | if (argc == 3) { | |
587 | if ((Tcl_GetInt(interp, argv[2], &percent) != TCL_OK) || | |
588 | (percent < 0) || (percent > 100)) { | |
589 | return (TCL_ERROR); | |
590 | } | |
591 | roadPercent = percent / 100.0; | |
592 | RoadSpend = (roadMaxValue * percent) / 100; | |
593 | UpdateFundEffects(); Kick(); | |
594 | } | |
595 | ||
596 | sprintf(interp->result, "%d", (int)(roadPercent * 100.0)); | |
597 | return (TCL_OK); | |
598 | } | |
599 | ||
600 | ||
601 | int SimCmdYear(ARGS) | |
602 | { | |
603 | int year; | |
604 | ||
605 | if ((argc != 2) && (argc != 3)) { | |
606 | return (TCL_ERROR); | |
607 | } | |
608 | ||
609 | if (argc == 3) { | |
610 | if ((Tcl_GetInt(interp, argv[2], &year) != TCL_OK)) { | |
611 | return (TCL_ERROR); | |
612 | } | |
613 | SetYear(year); | |
614 | } | |
615 | ||
616 | sprintf(interp->result, "%d", CurrentYear()); | |
617 | return (TCL_OK); | |
618 | } | |
619 | ||
620 | ||
621 | int SimCmdAutoBudget(ARGS) | |
622 | { | |
623 | int val; | |
624 | ||
625 | if ((argc != 2) && (argc != 3)) { | |
626 | return (TCL_ERROR); | |
627 | } | |
628 | ||
629 | if (argc == 3) { | |
630 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK) || | |
631 | (val < 0) || (val > 1)) { | |
632 | return (TCL_ERROR); | |
633 | } | |
634 | autoBudget = val; | |
635 | MustUpdateOptions = 1; Kick(); | |
636 | UpdateBudget(); | |
637 | } | |
638 | ||
639 | sprintf(interp->result, "%d", autoBudget); | |
640 | return (TCL_OK); | |
641 | } | |
642 | ||
643 | ||
644 | int SimCmdAutoGoto(ARGS) | |
645 | { | |
646 | int val; | |
647 | ||
648 | if ((argc != 2) && (argc != 3)) { | |
649 | return (TCL_ERROR); | |
650 | } | |
651 | ||
652 | if (argc == 3) { | |
653 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK) || | |
654 | (val < 0) || (val > 1)) { | |
655 | return (TCL_ERROR); | |
656 | } | |
657 | autoGo = val; | |
658 | MustUpdateOptions = 1; Kick(); | |
659 | } | |
660 | ||
661 | sprintf(interp->result, "%d", autoGo); | |
662 | return (TCL_OK); | |
663 | } | |
664 | ||
665 | ||
666 | int SimCmdAutoBulldoze(ARGS) | |
667 | { | |
668 | int val; | |
669 | ||
670 | if ((argc != 2) && (argc != 3)) { | |
671 | return (TCL_ERROR); | |
672 | } | |
673 | ||
674 | if (argc == 3) { | |
675 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK) || | |
676 | (val < 0) || (val > 1)) { | |
677 | return (TCL_ERROR); | |
678 | } | |
679 | autoBulldoze = val; | |
680 | MustUpdateOptions = 1; Kick(); | |
681 | } | |
682 | ||
683 | sprintf(interp->result, "%d", autoBulldoze); | |
684 | return (TCL_OK); | |
685 | } | |
686 | ||
687 | ||
688 | int SimCmdDisasters(ARGS) | |
689 | { | |
690 | int val; | |
691 | ||
692 | if ((argc != 2) && (argc != 3)) { | |
693 | return (TCL_ERROR); | |
694 | } | |
695 | ||
696 | if (argc == 3) { | |
697 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK) || | |
698 | (val < 0) || (val > 1)) { | |
699 | return (TCL_ERROR); | |
700 | } | |
701 | NoDisasters = val ? 0 : 1; | |
702 | MustUpdateOptions = 1; Kick(); | |
703 | } | |
704 | ||
705 | sprintf(interp->result, "%d", NoDisasters ? 0 : 1); | |
706 | return (TCL_OK); | |
707 | } | |
708 | ||
709 | ||
710 | int SimCmdSound(ARGS) | |
711 | { | |
712 | int val; | |
713 | ||
714 | if ((argc != 2) && (argc != 3)) { | |
715 | return (TCL_ERROR); | |
716 | } | |
717 | ||
718 | if (argc == 3) { | |
719 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK) || | |
720 | (val < 0) || (val > 1)) { | |
721 | return (TCL_ERROR); | |
722 | } | |
723 | UserSoundOn = val; | |
724 | MustUpdateOptions = 1; Kick(); | |
725 | } | |
726 | ||
727 | sprintf(interp->result, "%d", UserSoundOn); | |
728 | return (TCL_OK); | |
729 | } | |
730 | ||
731 | ||
732 | int SimCmdFlush(ARGS) | |
733 | { | |
734 | int style; | |
735 | ||
736 | if (argc != 2) { | |
737 | return (TCL_ERROR); | |
738 | } | |
739 | ||
740 | return (TCL_OK); | |
741 | } | |
742 | ||
743 | ||
744 | int SimCmdFlushStyle(ARGS) | |
745 | { | |
746 | int style; | |
747 | ||
748 | if ((argc != 2) && (argc != 3)) { | |
749 | return (TCL_ERROR); | |
750 | } | |
751 | ||
752 | if (argc == 3) { | |
753 | if ((Tcl_GetInt(interp, argv[2], &style) != TCL_OK) || | |
754 | (style < 0)) { | |
755 | return (TCL_ERROR); | |
756 | } | |
757 | FlushStyle = style; | |
758 | } | |
759 | ||
760 | sprintf(interp->result, "%d", FlushStyle); | |
761 | return (TCL_OK); | |
762 | } | |
763 | ||
764 | ||
765 | int SimCmdDonDither(ARGS) | |
766 | { | |
767 | int dd; | |
768 | ||
769 | if ((argc != 2) && (argc != 3)) { | |
770 | return (TCL_ERROR); | |
771 | } | |
772 | ||
773 | if (argc == 3) { | |
774 | if ((Tcl_GetInt(interp, argv[2], &dd) != TCL_OK) || | |
775 | (dd < 0)) { | |
776 | return (TCL_ERROR); | |
777 | } | |
778 | DonDither = dd; | |
779 | } | |
780 | ||
781 | sprintf(interp->result, "%d", DonDither); | |
782 | return (TCL_OK); | |
783 | } | |
784 | ||
785 | ||
786 | int SimCmdDoOverlay(ARGS) | |
787 | { | |
788 | int dd; | |
789 | ||
790 | if ((argc != 2) && (argc != 3)) { | |
791 | return (TCL_ERROR); | |
792 | } | |
793 | ||
794 | if (argc == 3) { | |
795 | if ((Tcl_GetInt(interp, argv[2], &dd) != TCL_OK) || | |
796 | (dd < 0)) { | |
797 | return (TCL_ERROR); | |
798 | } | |
799 | DoOverlay = dd; | |
800 | } | |
801 | ||
802 | sprintf(interp->result, "%d", DoOverlay); | |
803 | return (TCL_OK); | |
804 | } | |
805 | ||
806 | ||
807 | int SimCmdMonsterGoal(ARGS) | |
808 | { | |
809 | SimSprite *sprite; | |
810 | int x, y; | |
811 | ||
812 | if (argc != 4) { | |
813 | return (TCL_ERROR); | |
814 | } | |
815 | ||
816 | if (Tcl_GetInt(interp, argv[2], &x) != TCL_OK) { | |
817 | return (TCL_ERROR); | |
818 | } | |
819 | if (Tcl_GetInt(interp, argv[3], &y) != TCL_OK) { | |
820 | return (TCL_ERROR); | |
821 | } | |
822 | if ((sprite = GetSprite(GOD)) == NULL) { | |
823 | MakeMonster(); | |
824 | if ((sprite = GetSprite(GOD)) == NULL) | |
825 | return (TCL_ERROR); | |
826 | } | |
827 | sprite->dest_x = x; | |
828 | sprite->dest_y = y; | |
829 | sprite->control = -2; | |
830 | sprite->count = -1; | |
831 | ||
832 | return (TCL_OK); | |
833 | } | |
834 | ||
835 | ||
836 | int SimCmdHelicopterGoal(ARGS) | |
837 | { | |
838 | int x, y; | |
839 | SimSprite *sprite; | |
840 | ||
841 | if (argc != 4) { | |
842 | return (TCL_ERROR); | |
843 | } | |
844 | ||
845 | if (Tcl_GetInt(interp, argv[2], &x) != TCL_OK) { | |
846 | return (TCL_ERROR); | |
847 | } | |
848 | if (Tcl_GetInt(interp, argv[3], &y) != TCL_OK) { | |
849 | return (TCL_ERROR); | |
850 | } | |
851 | ||
852 | if ((sprite = GetSprite(COP)) == NULL) { | |
853 | GenerateCopter(x, y); | |
854 | if ((sprite = GetSprite(COP)) == NULL) { | |
855 | return (TCL_ERROR); | |
856 | } | |
857 | } | |
858 | sprite->dest_x = x; | |
859 | sprite->dest_y = y; | |
860 | ||
861 | return (TCL_OK); | |
862 | } | |
863 | ||
864 | ||
865 | int SimCmdMonsterDirection(ARGS) | |
866 | { | |
867 | int dir; | |
868 | SimSprite *sprite; | |
869 | ||
870 | if (argc != 3) { | |
871 | return (TCL_ERROR); | |
872 | } | |
873 | ||
874 | if ((Tcl_GetInt(interp, argv[2], &dir) != TCL_OK) || | |
875 | (dir < -1) || (dir > 7)) { | |
876 | return (TCL_ERROR); | |
877 | } | |
878 | if ((sprite = GetSprite(GOD)) == NULL) { | |
879 | MakeMonster(); | |
880 | if ((sprite = GetSprite(GOD)) == NULL) { | |
881 | return (TCL_ERROR); | |
882 | } | |
883 | } | |
884 | sprite->control = dir; | |
885 | ||
886 | return (TCL_OK); | |
887 | } | |
888 | ||
889 | ||
890 | int SimCmdTile(ARGS) | |
891 | { | |
892 | int x, y, tile; | |
893 | ||
894 | if ((argc != 4) && (argc != 5)) { | |
895 | return (TCL_ERROR); | |
896 | } | |
897 | if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK) || | |
898 | (x < 0) || | |
899 | (x >= WORLD_X) || | |
900 | (Tcl_GetInt(interp, argv[3], &y) != TCL_OK) || | |
901 | (y < 0) || | |
902 | (y >= WORLD_Y)) { | |
903 | return (TCL_ERROR); | |
904 | } | |
905 | if (argc == 5) { | |
906 | if (Tcl_GetInt(interp, argv[4], &tile) != TCL_OK) { | |
907 | return (TCL_ERROR); | |
908 | } | |
909 | Map[x][y] = tile; | |
910 | } | |
911 | sprintf(interp->result, "%d", Map[x][y]); | |
912 | return (TCL_OK); | |
913 | } | |
914 | ||
915 | ||
916 | int SimCmdFill(ARGS) | |
917 | { | |
918 | int tile, x, y; | |
919 | ||
920 | if (argc != 3) { | |
921 | return (TCL_ERROR); | |
922 | } | |
923 | if (Tcl_GetInt(interp, argv[2], &tile) != TCL_OK) { | |
924 | return (TCL_ERROR); | |
925 | } | |
926 | for (x = 0; x < WORLD_X; x++) { | |
927 | for (y = 0; y < WORLD_Y; y++) { | |
928 | Map[x][y] = tile; | |
929 | } | |
930 | } | |
931 | sprintf(interp->result, "%d", tile); | |
932 | return (TCL_OK); | |
933 | } | |
934 | ||
935 | ||
936 | int SimCmdDynamicData(ARGS) | |
937 | { | |
938 | int index, val; | |
939 | ||
940 | if ((argc != 3) && (argc != 4)) { | |
941 | return (TCL_ERROR); | |
942 | } | |
943 | ||
944 | if ((Tcl_GetInt(interp, argv[2], &index) != TCL_OK) || | |
945 | (index < 0) || | |
946 | (index >= 32)) { | |
947 | return (TCL_ERROR); | |
948 | } | |
949 | ||
950 | if (argc == 4) { | |
951 | int val; | |
952 | ||
953 | if (Tcl_GetInt(interp, argv[3], &val) != TCL_OK) { | |
954 | return (TCL_ERROR); | |
955 | } | |
956 | DynamicData[index] = val; | |
957 | NewMapFlags[DYMAP] = 1; | |
958 | Kick(); | |
959 | } | |
960 | ||
961 | sprintf(interp->result, "%d", DynamicData[index]); | |
962 | return (TCL_OK); | |
963 | } | |
964 | ||
965 | ||
966 | int SimCmdResetDynamic(ARGS) | |
967 | { | |
968 | int i; | |
969 | ||
970 | for (i = 0; i < 16; i++) { | |
971 | DynamicData[i] = (i & 1) ? 99999 : -99999; | |
972 | } | |
973 | NewMapFlags[DYMAP] = 1; | |
974 | Kick(); | |
975 | return (TCL_OK); | |
976 | } | |
977 | ||
978 | ||
979 | int SimCmdPerformance(ARGS) | |
980 | { | |
981 | SimView *view; | |
982 | ||
983 | PerformanceTiming = 1; | |
984 | FlushTime = 0.0; | |
985 | for (view = sim->editor; view != NULL; view = view->next) { | |
986 | view->updates = 0; | |
987 | view->update_real = view->update_user = view->update_system = 0.0; | |
988 | } | |
989 | return (TCL_OK); | |
990 | } | |
991 | ||
992 | ||
993 | int SimCmdCollapseMotion(ARGS) | |
994 | { | |
995 | int val; | |
996 | ||
997 | if ((argc != 2) && (argc != 3)) { | |
998 | return (TCL_ERROR); | |
999 | } | |
1000 | ||
1001 | if (argc == 3) { | |
1002 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK)) { | |
1003 | return (TCL_ERROR); | |
1004 | } | |
1005 | tkCollapseMotion = val; | |
1006 | } | |
1007 | ||
1008 | sprintf(interp->result, "%d", tkCollapseMotion); | |
1009 | return (TCL_OK); | |
1010 | } | |
1011 | ||
1012 | ||
1013 | int SimCmdUpdate(ARGS) | |
1014 | { | |
1015 | sim_update(); | |
1016 | return (TCL_OK); | |
1017 | } | |
1018 | ||
1019 | ||
1020 | int SimCmdLandValue(ARGS) | |
1021 | { | |
1022 | int val; | |
1023 | ||
1024 | if (argc != 2) { | |
1025 | return (TCL_ERROR); | |
1026 | } | |
1027 | ||
1028 | sprintf(interp->result, "%d", LVAverage); | |
1029 | return (TCL_OK); | |
1030 | } | |
1031 | ||
1032 | ||
1033 | int SimCmdTraffic(ARGS) | |
1034 | { | |
1035 | int val; | |
1036 | ||
1037 | if (argc != 2) { | |
1038 | return (TCL_ERROR); | |
1039 | } | |
1040 | ||
1041 | sprintf(interp->result, "%d", AverageTrf()); | |
1042 | return (TCL_OK); | |
1043 | } | |
1044 | ||
1045 | ||
1046 | int SimCmdCrime(ARGS) | |
1047 | { | |
1048 | int val; | |
1049 | ||
1050 | if (argc != 2) { | |
1051 | return (TCL_ERROR); | |
1052 | } | |
1053 | ||
1054 | sprintf(interp->result, "%d", CrimeAverage); | |
1055 | return (TCL_OK); | |
1056 | } | |
1057 | ||
1058 | ||
1059 | int SimCmdUnemployment(ARGS) | |
1060 | { | |
1061 | int val; | |
1062 | ||
1063 | if (argc != 2) { | |
1064 | return (TCL_ERROR); | |
1065 | } | |
1066 | ||
1067 | sprintf(interp->result, "%d", GetUnemployment()); | |
1068 | return (TCL_OK); | |
1069 | } | |
1070 | ||
1071 | ||
1072 | int SimCmdFires(ARGS) | |
1073 | { | |
1074 | int val; | |
1075 | ||
1076 | if (argc != 2) { | |
1077 | return (TCL_ERROR); | |
1078 | } | |
1079 | ||
1080 | sprintf(interp->result, "%d", GetFire()); | |
1081 | return (TCL_OK); | |
1082 | } | |
1083 | ||
1084 | ||
1085 | int SimCmdPollution(ARGS) | |
1086 | { | |
1087 | int val; | |
1088 | ||
1089 | if (argc != 2) { | |
1090 | return (TCL_ERROR); | |
1091 | } | |
1092 | ||
1093 | sprintf(interp->result, "%d", PolluteAverage); | |
1094 | return (TCL_OK); | |
1095 | } | |
1096 | ||
1097 | ||
1098 | int SimCmdPolMaxX(ARGS) | |
1099 | { | |
1100 | int val; | |
1101 | ||
1102 | if (argc != 2) { | |
1103 | return (TCL_ERROR); | |
1104 | } | |
1105 | ||
1106 | sprintf(interp->result, "%d", (PolMaxX <<4) + 8); | |
1107 | return (TCL_OK); | |
1108 | } | |
1109 | ||
1110 | ||
1111 | int SimCmdPolMaxY(ARGS) | |
1112 | { | |
1113 | int val; | |
1114 | ||
1115 | if (argc != 2) { | |
1116 | return (TCL_ERROR); | |
1117 | } | |
1118 | ||
1119 | sprintf(interp->result, "%d", (PolMaxY <<4) + 8); | |
1120 | return (TCL_OK); | |
1121 | } | |
1122 | ||
1123 | ||
1124 | int SimCmdTrafMaxX(ARGS) | |
1125 | { | |
1126 | int val; | |
1127 | ||
1128 | if (argc != 2) { | |
1129 | return (TCL_ERROR); | |
1130 | } | |
1131 | ||
1132 | sprintf(interp->result, "%d", TrafMaxX); | |
1133 | return (TCL_OK); | |
1134 | } | |
1135 | ||
1136 | ||
1137 | int SimCmdTrafMaxY(ARGS) | |
1138 | { | |
1139 | int val; | |
1140 | ||
1141 | if (argc != 2) { | |
1142 | return (TCL_ERROR); | |
1143 | } | |
1144 | ||
1145 | sprintf(interp->result, "%d", TrafMaxY); | |
1146 | return (TCL_OK); | |
1147 | } | |
1148 | ||
1149 | ||
1150 | int SimCmdMeltX(ARGS) | |
1151 | { | |
1152 | int val; | |
1153 | ||
1154 | if (argc != 2) { | |
1155 | return (TCL_ERROR); | |
1156 | } | |
1157 | ||
1158 | sprintf(interp->result, "%d", (MeltX <<4) + 8); | |
1159 | return (TCL_OK); | |
1160 | } | |
1161 | ||
1162 | ||
1163 | int SimCmdMeltY(ARGS) | |
1164 | { | |
1165 | int val; | |
1166 | ||
1167 | if (argc != 2) { | |
1168 | return (TCL_ERROR); | |
1169 | } | |
1170 | ||
1171 | sprintf(interp->result, "%d", (MeltY <<4) + 8); | |
1172 | return (TCL_OK); | |
1173 | } | |
1174 | ||
1175 | ||
1176 | int SimCmdCrimeMaxX(ARGS) | |
1177 | { | |
1178 | int val; | |
1179 | ||
1180 | if (argc != 2) { | |
1181 | return (TCL_ERROR); | |
1182 | } | |
1183 | ||
1184 | sprintf(interp->result, "%d", (CrimeMaxX <<4) + 8); | |
1185 | return (TCL_OK); | |
1186 | } | |
1187 | ||
1188 | ||
1189 | int SimCmdCrimeMaxY(ARGS) | |
1190 | { | |
1191 | int val; | |
1192 | ||
1193 | if (argc != 2) { | |
1194 | return (TCL_ERROR); | |
1195 | } | |
1196 | ||
1197 | sprintf(interp->result, "%d", (CrimeMaxY <<4) + 8); | |
1198 | return (TCL_OK); | |
1199 | } | |
1200 | ||
1201 | ||
1202 | int SimCmdCenterX(ARGS) | |
1203 | { | |
1204 | int val; | |
1205 | ||
1206 | if (argc != 2) { | |
1207 | return (TCL_ERROR); | |
1208 | } | |
1209 | ||
1210 | sprintf(interp->result, "%d", (CCx <<4) + 8); | |
1211 | return (TCL_OK); | |
1212 | } | |
1213 | ||
1214 | ||
1215 | int SimCmdCenterY(ARGS) | |
1216 | { | |
1217 | int val; | |
1218 | ||
1219 | if (argc != 2) { | |
1220 | return (TCL_ERROR); | |
1221 | } | |
1222 | ||
1223 | sprintf(interp->result, "%d", (CCy <<4) + 8); | |
1224 | return (TCL_OK); | |
1225 | } | |
1226 | ||
1227 | ||
1228 | int SimCmdFloodX(ARGS) | |
1229 | { | |
1230 | int val; | |
1231 | ||
1232 | if (argc != 2) { | |
1233 | return (TCL_ERROR); | |
1234 | } | |
1235 | ||
1236 | sprintf(interp->result, "%d", (FloodX <<4) + 8); | |
1237 | return (TCL_OK); | |
1238 | } | |
1239 | ||
1240 | ||
1241 | int SimCmdFloodY(ARGS) | |
1242 | { | |
1243 | int val; | |
1244 | ||
1245 | if (argc != 2) { | |
1246 | return (TCL_ERROR); | |
1247 | } | |
1248 | ||
1249 | sprintf(interp->result, "%d", (FloodY <<4) + 8); | |
1250 | return (TCL_OK); | |
1251 | } | |
1252 | ||
1253 | ||
1254 | int SimCmdCrashX(ARGS) | |
1255 | { | |
1256 | int val; | |
1257 | ||
1258 | if (argc != 2) { | |
1259 | return (TCL_ERROR); | |
1260 | } | |
1261 | ||
1262 | sprintf(interp->result, "%d", (CrashX <<4) + 8); | |
1263 | return (TCL_OK); | |
1264 | } | |
1265 | ||
1266 | ||
1267 | int SimCmdCrashY(ARGS) | |
1268 | { | |
1269 | int val; | |
1270 | ||
1271 | if (argc != 2) { | |
1272 | return (TCL_ERROR); | |
1273 | } | |
1274 | ||
1275 | sprintf(interp->result, "%d", (CrashY <<4) + 8); | |
1276 | return (TCL_OK); | |
1277 | } | |
1278 | ||
1279 | ||
1280 | int SimCmdDollars(ARGS) | |
1281 | { | |
1282 | int val; | |
1283 | ||
1284 | if (argc != 2) { | |
1285 | return (TCL_ERROR); | |
1286 | } | |
1287 | ||
1288 | makeDollarDecimalStr(argv[1], interp->result); | |
1289 | return (TCL_OK); | |
1290 | } | |
1291 | ||
1292 | ||
1293 | int SimCmdDoAnimation(ARGS) | |
1294 | { | |
1295 | int val; | |
1296 | ||
1297 | if ((argc != 2) && (argc != 3)) { | |
1298 | return (TCL_ERROR); | |
1299 | } | |
1300 | ||
1301 | if (argc == 3) { | |
1302 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK)) { | |
1303 | return (TCL_ERROR); | |
1304 | } | |
1305 | DoAnimation = val; | |
1306 | MustUpdateOptions = 1; Kick(); | |
1307 | } | |
1308 | ||
1309 | sprintf(interp->result, "%d", DoAnimation); | |
1310 | return (TCL_OK); | |
1311 | } | |
1312 | ||
1313 | ||
1314 | int SimCmdDoMessages(ARGS) | |
1315 | { | |
1316 | int val; | |
1317 | ||
1318 | if ((argc != 2) && (argc != 3)) { | |
1319 | return (TCL_ERROR); | |
1320 | } | |
1321 | ||
1322 | if (argc == 3) { | |
1323 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK)) { | |
1324 | return (TCL_ERROR); | |
1325 | } | |
1326 | DoMessages = val; | |
1327 | MustUpdateOptions = 1; Kick(); | |
1328 | } | |
1329 | ||
1330 | sprintf(interp->result, "%d", DoMessages); | |
1331 | return (TCL_OK); | |
1332 | } | |
1333 | ||
1334 | ||
1335 | int SimCmdDoNotices(ARGS) | |
1336 | { | |
1337 | int val; | |
1338 | ||
1339 | if ((argc != 2) && (argc != 3)) { | |
1340 | return (TCL_ERROR); | |
1341 | } | |
1342 | ||
1343 | if (argc == 3) { | |
1344 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK)) { | |
1345 | return (TCL_ERROR); | |
1346 | } | |
1347 | DoNotices = val; | |
1348 | MustUpdateOptions = 1; Kick(); | |
1349 | } | |
1350 | ||
1351 | sprintf(interp->result, "%d", DoNotices); | |
1352 | return (TCL_OK); | |
1353 | } | |
1354 | ||
1355 | ||
1356 | int SimCmdRand(ARGS) | |
1357 | { | |
1358 | int val, r; | |
1359 | ||
1360 | if ((argc != 2) && (argc != 3)) { | |
1361 | return (TCL_ERROR); | |
1362 | } | |
1363 | ||
1364 | if (argc == 3) { | |
1365 | if ((Tcl_GetInt(interp, argv[2], &val) != TCL_OK)) { | |
1366 | return (TCL_ERROR); | |
1367 | } | |
1368 | r = Rand(val); | |
1369 | } else { | |
1370 | r = Rand16(); | |
1371 | } | |
1372 | ||
1373 | sprintf(interp->result, "%d", r); | |
1374 | return (TCL_OK); | |
1375 | } | |
1376 | ||
1377 | ||
1378 | int SimCmdPlatform(ARGS) | |
1379 | { | |
1380 | ||
1381 | #ifdef MSDOS | |
1382 | sprintf(interp->result, "msdos"); | |
1383 | #else | |
1384 | sprintf(interp->result, "unix"); | |
1385 | #endif | |
1386 | ||
1387 | return (TCL_OK); | |
1388 | } | |
1389 | ||
1390 | ||
1391 | int SimCmdVersion(ARGS) | |
1392 | { | |
1393 | sprintf(interp->result, MicropolisVersion); | |
1394 | ||
1395 | return (TCL_OK); | |
1396 | } | |
1397 | ||
1398 | ||
1399 | int SimCmdOpenWebBrowser(ARGS) | |
1400 | { | |
1401 | int result = 1; | |
1402 | char buf[512]; | |
1403 | ||
1404 | if ((argc != 3) || | |
1405 | (strlen(argv[2]) > 255)) { | |
1406 | return (TCL_ERROR); | |
1407 | } | |
1408 | ||
1409 | sprintf(buf, | |
1410 | "netscape -no-about-splash '%s' &", | |
1411 | argv[2]); | |
1412 | ||
1413 | result = system(buf); | |
1414 | ||
1415 | sprintf(interp->result, "%d", result); | |
1416 | ||
1417 | return (TCL_OK); | |
1418 | } | |
1419 | ||
1420 | ||
1421 | int SimCmdQuoteURL(ARGS) | |
1422 | { | |
1423 | int result = 1; | |
1424 | char buf[2048]; | |
1425 | char *from, *to; | |
1426 | int ch; | |
1427 | static char *hexDigits = | |
1428 | "0123456789ABCDEF"; | |
1429 | ||
1430 | if ((argc != 3) || | |
1431 | (strlen(argv[2]) > 255)) { | |
1432 | return (TCL_ERROR); | |
1433 | } | |
1434 | ||
1435 | from = argv[2]; | |
1436 | to = buf; | |
1437 | ||
1438 | while ((ch = *(from++)) != '\0') { | |
1439 | if ((ch < 32) || | |
1440 | (ch >= 128) || | |
1441 | (ch == '+') || | |
1442 | (ch == '%') || | |
1443 | (ch == '&') || | |
1444 | (ch == '<') || | |
1445 | (ch == '>') || | |
1446 | (ch == '"') || | |
1447 | (ch == '\'')) { | |
1448 | *to++ = '%'; | |
1449 | *to++ = hexDigits[(ch >> 4) & 0x0f]; | |
1450 | *to++ = hexDigits[ch & 0x0f]; | |
1451 | } else if (ch == 32) { | |
1452 | *to++ = '+'; | |
1453 | } else { | |
1454 | *to++ = ch; | |
1455 | } // if | |
1456 | } // while | |
1457 | ||
1458 | *to = '\0'; | |
1459 | ||
1460 | sprintf(interp->result, "%s", buf); | |
1461 | ||
1462 | return (TCL_OK); | |
1463 | } | |
1464 | ||
1465 | ||
1466 | int SimCmdNeedRest(ARGS) | |
1467 | { | |
1468 | int needRest; | |
1469 | ||
1470 | if ((argc != 2) && (argc != 3)) { | |
1471 | return (TCL_ERROR); | |
1472 | } | |
1473 | ||
1474 | if (argc == 3) { | |
1475 | if (Tcl_GetInt(interp, argv[2], &needRest) != TCL_OK) { | |
1476 | return (TCL_ERROR); | |
1477 | } | |
1478 | NeedRest = needRest; | |
1479 | } | |
1480 | ||
1481 | sprintf(interp->result, "%d", NeedRest); | |
1482 | return (TCL_OK); | |
1483 | } | |
1484 | ||
1485 | ||
1486 | int SimCmdMultiPlayerMode(ARGS) | |
1487 | { | |
1488 | /* This is read-only because it's specified on | |
1489 | the command line and effects how the user | |
1490 | interface is initialized. */ | |
1491 | ||
1492 | if (argc != 2) { | |
1493 | return (TCL_ERROR); | |
1494 | } | |
1495 | ||
1496 | sprintf(interp->result, "%d", MultiPlayerMode); | |
1497 | return (TCL_OK); | |
1498 | } | |
1499 | ||
1500 | ||
1501 | int SimCmdSugarMode(ARGS) | |
1502 | { | |
1503 | /* This is read-only because it's specified on | |
1504 | the command line and effects how the user | |
1505 | interface is initialized. */ | |
1506 | ||
1507 | if (argc != 2) { | |
1508 | return (TCL_ERROR); | |
1509 | } | |
1510 | ||
1511 | sprintf(interp->result, "%d", SugarMode); | |
1512 | return (TCL_OK); | |
1513 | } | |
1514 | ||
1515 | int SimCmdHasAirCrash(ARGS) | |
1516 | { | |
1517 | int aircrash = 0; | |
1518 | ||
1519 | if (argc != 2) { | |
1520 | return (TCL_ERROR); | |
1521 | } | |
1522 | ||
1523 | #ifndef NO_AIRCRASH | |
1524 | aircrash = 1; | |
1525 | #endif | |
1526 | ||
1527 | sprintf(interp->result, "%d", aircrash); | |
1528 | return (TCL_OK); | |
1529 | } | |
1530 | ||
1531 | ||
1532 | /************************************************************************/ | |
1533 | ||
1534 | int | |
1535 | SimCmd(CLIENT_ARGS) | |
1536 | { | |
1537 | Tcl_HashEntry *ent; | |
1538 | int result = TCL_OK; | |
1539 | int (*cmd)(); | |
1540 | ||
1541 | if (argc < 2) { | |
1542 | return TCL_ERROR; | |
1543 | } | |
1544 | ||
1545 | if (ent = Tcl_FindHashEntry(&SimCmds, argv[1])) { | |
1546 | cmd = (int (*)())ent->clientData; | |
1547 | result = cmd(interp, argc, argv); | |
1548 | } else { | |
1549 | result = TCL_ERROR; | |
1550 | } | |
1551 | return result; | |
1552 | } | |
1553 | ||
1554 | ||
1555 | sim_command_init() | |
1556 | { | |
1557 | int new; | |
1558 | ||
1559 | Tcl_CreateCommand(tk_mainInterp, "sim", SimCmd, | |
1560 | (ClientData)MainWindow, (void (*)()) NULL); | |
1561 | ||
1562 | Tcl_InitHashTable(&SimCmds, TCL_STRING_KEYS); | |
1563 | ||
1564 | #define SIM_CMD(name) HASHED_CMD(Sim, name) | |
1565 | ||
1566 | SIM_CMD(GameStarted); | |
1567 | SIM_CMD(InitGame); | |
1568 | SIM_CMD(SaveCity); | |
1569 | SIM_CMD(ReallyQuit); | |
1570 | SIM_CMD(UpdateHeads); | |
1571 | SIM_CMD(UpdateMaps); | |
1572 | SIM_CMD(RedrawEditors); | |
1573 | SIM_CMD(RedrawMaps); | |
1574 | SIM_CMD(UpdateEditors); | |
1575 | SIM_CMD(UpdateGraphs); | |
1576 | SIM_CMD(UpdateEvaluation); | |
1577 | SIM_CMD(UpdateBudget); | |
1578 | SIM_CMD(UpdateBudgetWindow); | |
1579 | SIM_CMD(DoBudget); | |
1580 | SIM_CMD(DoBudgetFromMenu); | |
1581 | SIM_CMD(Pause); | |
1582 | SIM_CMD(Resume); | |
1583 | SIM_CMD(StartBulldozer); | |
1584 | SIM_CMD(StopBulldozer); | |
1585 | SIM_CMD(MakeFire); | |
1586 | SIM_CMD(MakeFlood); | |
1587 | SIM_CMD(MakeAirCrash); | |
1588 | SIM_CMD(MakeTornado); | |
1589 | SIM_CMD(MakeEarthquake); | |
1590 | SIM_CMD(MakeMonster); | |
1591 | SIM_CMD(MakeMeltdown); | |
1592 | SIM_CMD(FireBomb); | |
1593 | SIM_CMD(SoundOff); | |
1594 | SIM_CMD(GenerateNewCity); | |
1595 | SIM_CMD(GenerateSomeCity); | |
1596 | SIM_CMD(TreeLevel); | |
1597 | SIM_CMD(LakeLevel); | |
1598 | SIM_CMD(CurveLevel); | |
1599 | SIM_CMD(CreateIsland); | |
1600 | SIM_CMD(ClearMap); | |
1601 | SIM_CMD(ClearUnnatural); | |
1602 | SIM_CMD(SmoothTrees); | |
1603 | SIM_CMD(SmoothWater); | |
1604 | SIM_CMD(SmoothRiver); | |
1605 | SIM_CMD(LoadScenario); | |
1606 | SIM_CMD(LoadCity); | |
1607 | SIM_CMD(SaveCityAs); | |
1608 | SIM_CMD(MakeExplosion); | |
1609 | SIM_CMD(CityName); | |
1610 | SIM_CMD(CityFileName); | |
1611 | SIM_CMD(GameLevel); | |
1612 | SIM_CMD(Speed); | |
1613 | SIM_CMD(Skips); | |
1614 | SIM_CMD(Skip); | |
1615 | SIM_CMD(WorldX); | |
1616 | SIM_CMD(WorldY); | |
1617 | SIM_CMD(Delay); | |
1618 | SIM_CMD(HeatSteps); | |
1619 | SIM_CMD(HeatFlow); | |
1620 | SIM_CMD(HeatRule); | |
1621 | #ifdef CAM | |
1622 | SIM_CMD(JustCam); | |
1623 | #endif | |
1624 | #ifdef NET | |
1625 | SIM_CMD(ListenTo); | |
1626 | SIM_CMD(HearFrom); | |
1627 | #endif | |
1628 | SIM_CMD(Funds); | |
1629 | SIM_CMD(TaxRate); | |
1630 | SIM_CMD(FireFund); | |
1631 | SIM_CMD(PoliceFund); | |
1632 | SIM_CMD(RoadFund); | |
1633 | SIM_CMD(Year); | |
1634 | SIM_CMD(AutoBudget); | |
1635 | SIM_CMD(AutoGoto); | |
1636 | SIM_CMD(AutoBulldoze); | |
1637 | SIM_CMD(Disasters); | |
1638 | SIM_CMD(Sound); | |
1639 | SIM_CMD(Flush); | |
1640 | SIM_CMD(FlushStyle); | |
1641 | SIM_CMD(DonDither); | |
1642 | SIM_CMD(DoOverlay); | |
1643 | SIM_CMD(MonsterGoal); | |
1644 | SIM_CMD(HelicopterGoal); | |
1645 | SIM_CMD(MonsterDirection); | |
1646 | SIM_CMD(EraseOverlay); | |
1647 | SIM_CMD(Tile); | |
1648 | SIM_CMD(Fill); | |
1649 | SIM_CMD(DynamicData); | |
1650 | SIM_CMD(ResetDynamic); | |
1651 | SIM_CMD(Performance); | |
1652 | SIM_CMD(CollapseMotion); | |
1653 | SIM_CMD(Update); | |
1654 | SIM_CMD(OverRide); | |
1655 | SIM_CMD(Expensive); | |
1656 | SIM_CMD(Players); | |
1657 | SIM_CMD(Votes); | |
1658 | SIM_CMD(BobHeight); | |
1659 | SIM_CMD(PendingTool); | |
1660 | SIM_CMD(PendingX); | |
1661 | SIM_CMD(PendingY); | |
1662 | SIM_CMD(Displays); | |
1663 | SIM_CMD(LandValue); | |
1664 | SIM_CMD(Traffic); | |
1665 | SIM_CMD(Crime); | |
1666 | SIM_CMD(Unemployment); | |
1667 | SIM_CMD(Fires); | |
1668 | SIM_CMD(Pollution); | |
1669 | SIM_CMD(PolMaxX); | |
1670 | SIM_CMD(PolMaxY); | |
1671 | SIM_CMD(TrafMaxX); | |
1672 | SIM_CMD(TrafMaxY); | |
1673 | SIM_CMD(MeltX); | |
1674 | SIM_CMD(MeltY); | |
1675 | SIM_CMD(CrimeMaxX); | |
1676 | SIM_CMD(CrimeMaxY); | |
1677 | SIM_CMD(CenterX); | |
1678 | SIM_CMD(CenterY); | |
1679 | SIM_CMD(FloodX); | |
1680 | SIM_CMD(FloodY); | |
1681 | SIM_CMD(CrashX); | |
1682 | SIM_CMD(CrashY); | |
1683 | SIM_CMD(Dollars); | |
1684 | SIM_CMD(DoAnimation); | |
1685 | SIM_CMD(DoMessages); | |
1686 | SIM_CMD(DoNotices); | |
1687 | SIM_CMD(Rand); | |
1688 | SIM_CMD(Platform); | |
1689 | SIM_CMD(Version); | |
1690 | SIM_CMD(OpenWebBrowser); | |
1691 | SIM_CMD(QuoteURL); | |
1692 | SIM_CMD(NeedRest); | |
1693 | SIM_CMD(MultiPlayerMode); | |
1694 | SIM_CMD(SugarMode); | |
1695 | SIM_CMD(HasAirCrash); | |
1696 | } |