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