fix 24bit wire mode
[micropolis] / src / sim / headers / sim.h
CommitLineData
6a5fa4e0
MG
1/* sim.h: Main include file
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
63/* workaround sun c compiler junk */
64
65#ifdef sun
66
67#define _TTYCHARS_
68#define CTRL(c) (#c[0]&037)
69
70#ifndef SOLARIS2
71#define __sys_ioccom_h
72#define _IOCPARM_MASK 0xff /* parameters must be < 256 bytes */
73#define _IOC_VOID 0x20000000 /* no parameters */
74#define _IOC_OUT 0x40000000 /* copy out parameters */
75#define _IOC_IN 0x80000000 /* copy in parameters */
76#define _IOC_INOUT (_IOC_IN|_IOC_OUT)
77#define _IO(x,y) (_IOC_VOID|(#x[0]<<8)|y)
78#define _IOR(x,y,t) (_IOC_OUT|((sizeof(t)&_IOCPARM_MASK)<<16)|(#x[0]<<8)|y)
79#define _IORN(x,y,t) (_IOC_OUT|(((t)&_IOCPARM_MASK)<<16)|(#x[0]<<8)|y)
80#define _IOW(x,y,t) (_IOC_IN|((sizeof(t)&_IOCPARM_MASK)<<16)|(#x[0]<<8)|y)
81#define _IOWN(x,y,t) (_IOC_IN|(((t)&_IOCPARM_MASK)<<16)|(#x[0]<<8)|y)
82#define _IOWR(x,y,t) (_IOC_INOUT|((sizeof(t)&_IOCPARM_MASK)<<16)|(#x[0]<<8)|y)
83#define _IOWRN(x,y,t) (_IOC_INOUT|(((t)&_IOCPARM_MASK)<<16)|(#x[0]<<8)|y)
84#endif
85
86#endif
87
88
89#include <stdio.h>
90#include <stdlib.h>
91#include <assert.h>
92#include <ctype.h>
93#include <setjmp.h>
6a5fa4e0
MG
94#include <errno.h>
95#include <signal.h>
96#include <math.h>
97#include <unistd.h>
98#include <sys/types.h>
99#include <sys/time.h>
100#include <sys/stat.h>
101#include <sys/file.h>
102#include <sys/ioctl.h>
103#include <sys/resource.h>
104#ifndef MSDOS
105#ifndef HPUX
106#include <alloca.h>
107#endif
108#include <sys/mman.h>
109#include <netinet/in.h>
110#include <arpa/inet.h>
111#endif
112
113#ifdef sun
114#ifdef SOLARIS2
115#include <sys/systeminfo.h>
116#else
117#include <sys/vadvise.h>
118#endif
119#endif
120
121#ifdef sgi
122#if 0
123#include <audio.h>
124#endif
125#endif
126
127#include <sys/ipc.h>
128#include <sys/shm.h>
129#include <X11/Xlib.h>
130#include <X11/Xutil.h>
131#include <X11/Xatom.h>
132#include <X11/extensions/XShm.h>
133
134//#include <xpmtk.h>
135#include <X11/xpm.h>
136
137/* gcc compat workaround! */
138#define _STDDEF_H
139
140#include "tclxtend.h"
141#include "tclint.h"
142#include "tclunix.h"
143#include "tkconfig.h"
144#include "tkint.h"
145
146#include "mac.h"
147#include "view.h"
148#include "macros.h"
149
150/* Constants */
151
152#define TRUE 1
153#define FALSE 0
154
155#ifdef MEGA
156#define SimWidth (120 * MEGA)
157#define SimHeight (100 * MEGA)
158#else
159#define SimWidth 120
160#define SimHeight 100
161#endif
162
163#define WORLD_X SimWidth
164#define WORLD_Y SimHeight
165#define HWLDX (SimWidth >>1)
166#define HWLDY (SimHeight >>1)
167#define QWX (SimWidth >>2)
168#define QWY (SimHeight >>2)
169#define SmX (SimWidth >>3)
170#define SmY ((SimHeight + 7) >>3)
171
172#define EDITOR_W (WORLD_X * 16)
173#define EDITOR_H (WORLD_Y * 16)
174#define MAP_W (WORLD_X * 3)
175#define MAP_H (WORLD_Y * 3)
176
177#define NIL 0
178#define HORIZ 1
179#define VERT 0
180
181#define PROBNUM 10
182
183#define HISTLEN 480
184#define MISCHISTLEN 240
185
186#define POWERMAPROW ((WORLD_X + 15) / 16)
187
188#ifdef MEGA
189#define POWERMAPLEN ((QUAD)(2 * POWERMAPROW * WORLD_Y))
190#define POWERWORD(x, y) ((((QUAD)(x)) >>4) + (((QUAD)(y)) * POWERMAPROW))
191#else
192#define POWERMAPLEN 1700 /* ??? PWRMAPSIZE */
193#define POWERWORD(x, y) (((x) >>4) + ((y) <<3))
194#endif
195
196#define SETPOWERBIT(x, y) PowerMap[POWERWORD((x), (y))] |= 1 << ((x) & 15)
197#define PWRMAPSIZE (POWERMAPROW * WORLD_Y)
198#define PWRSTKSIZE ((WORLD_X * WORLD_Y) / 4)
199
200#define ALMAP 0 /* all */
201#define REMAP 1 /* residential */
202#define COMAP 2 /* commercial */
203#define INMAP 3 /* industrial */
204
205#define PRMAP 4 /* power */
206#define RDMAP 5 /* road */
207
208#define PDMAP 6 /* population density */
209#define RGMAP 7 /* rate of growth */
210
211#define TDMAP 8 /* traffic density */
212#define PLMAP 9 /* pollution */
213#define CRMAP 10 /* crime */
214#define LVMAP 11 /* land value */
215
216#define FIMAP 12 /* fire radius */
217#define POMAP 13 /* police radius */
218#define DYMAP 14 /* dynamic */
219
220#define NMAPS 15
221
222/* These adjust frequency in Simulate() */
223
224#define VALVERATE 2
225#define CENSUSRATE 4
226#define TAXFREQ 48
227
228/* These are names of the 16 colors */
229#define COLOR_WHITE 0
230#define COLOR_YELLOW 1
231#define COLOR_ORANGE 2
232#define COLOR_RED 3
233#define COLOR_DARKRED 4
234#define COLOR_DARKBLUE 5
235#define COLOR_LIGHTBLUE 6
236#define COLOR_BROWN 7
237#define COLOR_LIGHTGREEN 8
238#define COLOR_DARKGREEN 9
239#define COLOR_OLIVE 10
240#define COLOR_LIGHTBROWN 11
241#define COLOR_LIGHTGRAY 12
242#define COLOR_MEDIUMGRAY 13
243#define COLOR_DARKGRAY 14
244#define COLOR_BLACK 15
245
246/* Status Bits */
247
248#define PWRBIT 32768 /*20 bit 15 */
249#define CONDBIT 16384 /*10 bit 14 */
250#define BURNBIT 8192 /*8 bit 13 */
251#define BULLBIT 4096 /*4 bit 12 */
252#define ANIMBIT 2048 /*2 bit 11 */
253#define ZONEBIT 1024 /*1 bit 10 */
254#define ALLBITS 64512 /* mask for upper 6 bits */
255#define LOMASK 1023 /* mask for low 10 bits */
256
257#define BLBNBIT (BULLBIT+BURNBIT)
258#define BLBNCNBIT (BULLBIT+BURNBIT+CONDBIT)
259#define BNCNBIT (BURNBIT+CONDBIT)
260
261/* Object & Sound Numbers */
262
263#define TRA 1
264#define COP 2
265#define AIR 3
266#define SHI 4
267#define GOD 5
268#define TOR 6
269#define EXP 7
270#define BUS 8
271
272/* Max # of Objects */
273
274#define OBJN 9
275
276/* Graph Histories */
277#define RES_HIST 0
278#define COM_HIST 1
279#define IND_HIST 2
280#define MONEY_HIST 3
281#define CRIME_HIST 4
282#define POLLUTION_HIST 5
283#define HISTORIES 6
284#define ALL_HISTORIES ((1 <<HISTORIES) - 1)
285
286/* Character Mapping */
287
288#define DIRT 0
289#define RIVER 2
290#define REDGE 3
291#define CHANNEL 4
292#define FIRSTRIVEDGE 5
293#define LASTRIVEDGE 20
294#define TREEBASE 21
295#define LASTTREE 36
296#define WOODS 37
297#define UNUSED_TRASH1 38
298#define UNUSED_TRASH2 39
299#define WOODS2 40
300#define WOODS3 41
301#define WOODS4 42
302#define WOODS5 43
303#define RUBBLE 44
304#define LASTRUBBLE 47
305#define FLOOD 48
306#define LASTFLOOD 51
307#define RADTILE 52
308#define UNUSED_TRASH3 53
309#define UNUSED_TRASH4 54
310#define UNUSED_TRASH5 55
311#define FIRE 56
312#define FIREBASE 56
313#define LASTFIRE 63
314#define ROADBASE 64
315#define HBRIDGE 64
316#define VBRIDGE 65
317#define ROADS 66
318#define INTERSECTION 76
319#define HROADPOWER 77
320#define VROADPOWER 78
321#define BRWH 79
322#define LTRFBASE 80
323#define BRWV 95
324#define BRWXXX1 111
325#define BRWXXX2 127
326#define BRWXXX3 143
327#define HTRFBASE 144
328#define BRWXXX4 159
329#define BRWXXX5 175
330#define BRWXXX6 191
331#define LASTROAD 206
332#define BRWXXX7 207
333#define POWERBASE 208
334#define HPOWER 208
335#define VPOWER 209
336#define LHPOWER 210
337#define LVPOWER 211
338#define RAILHPOWERV 221
339#define RAILVPOWERH 222
340#define LASTPOWER 222
341#define UNUSED_TRASH6 223
342#define RAILBASE 224
343#define HRAIL 224
344#define VRAIL 225
345#define LHRAIL 226
346#define LVRAIL 227
347#define HRAILROAD 237
348#define VRAILROAD 238
349#define LASTRAIL 238
350#define ROADVPOWERH 239 /* bogus? */
351#define RESBASE 240
352#define FREEZ 244
353#define HOUSE 249
354#define LHTHR 249
355#define HHTHR 260
356#define RZB 265
357#define HOSPITAL 409
358#define CHURCH 418
359#define COMBASE 423
360#define COMCLR 427
361#define CZB 436
362#define INDBASE 612
363#define INDCLR 616
364#define LASTIND 620
365#define IND1 621
366#define IZB 625
367#define IND2 641
368#define IND3 644
369#define IND4 649
370#define IND5 650
371#define IND6 676
372#define IND7 677
373#define IND8 686
374#define IND9 689
375#define PORTBASE 693
376#define PORT 698
377#define LASTPORT 708
378#define AIRPORTBASE 709
379#define RADAR 711
380#define AIRPORT 716
381#define COALBASE 745
382#define POWERPLANT 750
383#define LASTPOWERPLANT 760
384#define FIRESTBASE 761
385#define FIRESTATION 765
386#define POLICESTBASE 770
387#define POLICESTATION 774
388#define STADIUMBASE 779
389#define STADIUM 784
390#define FULLSTADIUM 800
391#define NUCLEARBASE 811
392#define NUCLEAR 816
393#define LASTZONE 826
394#define LIGHTNINGBOLT 827
395#define HBRDG0 828
396#define HBRDG1 829
397#define HBRDG2 830
398#define HBRDG3 831
399#define RADAR0 832
400#define RADAR1 833
401#define RADAR2 834
402#define RADAR3 835
403#define RADAR4 836
404#define RADAR5 837
405#define RADAR6 838
406#define RADAR7 839
407#define FOUNTAIN 840
408#define INDBASE2 844
409#define TELEBASE 844
410#define TELELAST 851
411#define SMOKEBASE 852
412#define TINYEXP 860
413#define SOMETINYEXP 864
414#define LASTTINYEXP 867
415#define COALSMOKE1 916
416#define COALSMOKE2 920
417#define COALSMOKE3 924
418#define COALSMOKE4 928
419#define FOOTBALLGAME1 932
420#define FOOTBALLGAME2 940
421#define VBRDG0 948
422#define VBRDG1 949
423#define VBRDG2 950
424#define VBRDG3 951
425
426#define TILE_COUNT 960
427
428/*
429 * These describe the wand values, the object dragged around on the screen.
430 */
431
432#define residentialState 0
433#define commercialState 1
434#define industrialState 2
435#define fireState 3
436#define queryState 4
437#define policeState 5
438#define wireState 6
439#define dozeState 7
440#define rrState 8
441#define roadState 9
442#define chalkState 10
443#define eraserState 11
444#define stadiumState 12
445#define parkState 13
446#define seaportState 14
447#define powerState 15
448#define nuclearState 16
449#define airportState 17
450#define networkState 18
451
452
453#define firstState residentialState
454#define lastState networkState
455
456#if 0
457#define specialState 16
458#define monsterGoalState 17
459#define helicopterGoalState 18
460#define blackState 19
461#define whiteState 20
462#define redState 21
463#define orangeState 23
464#define blueState 24
465#define greenState 25
466#define brownState 26
467#endif
468
469
470#define STATE_CMD 0
471#define STATE_TILES 1
472#define STATE_OVERLAYS 2
473#define STATE_GRAPHS 3
474
475
476extern short *Map[WORLD_X]; /* Main Map 120 x 100 */
477extern Byte *PopDensity[HWLDX]; /* 2X2 Maps 60 x 50 */
478extern Byte *TrfDensity[HWLDX];
479extern Byte *PollutionMem[HWLDX];
480extern Byte *LandValueMem[HWLDX];
481extern Byte *CrimeMem[HWLDX];
482extern Byte *tem[HWLDX];
483extern Byte *tem2[HWLDX];
484extern Byte *TerrainMem[QWX]; /* 4X4 Maps 30 x 25 */
485extern Byte *Qtem[QWX];
486extern short RateOGMem[SmX][SmY];
487extern short FireStMap[SmX][SmY]; /* 8X8 Maps 15 x 13 */
488extern short PoliceMap[SmX][SmY];
489extern short PoliceMapEffect[SmX][SmY];
490extern short ComRate[SmX][SmY];
491extern short FireRate[SmX][SmY];
492extern short STem[SmX][SmY];
493extern short SpriteXOffset[OBJN];
494extern short SpriteYOffset[OBJN];
495extern short SMapX, SMapY;
496extern short CChr, CChr9;
497extern short RoadTotal, RailTotal, FirePop;
498extern short ResPop, ComPop, IndPop, TotalPop, LastTotalPop;
499extern short ResZPop, ComZPop, IndZPop, TotalZPop;
500extern short HospPop, ChurchPop, StadiumPop;
501extern short PolicePop, FireStPop;
502extern short CoalPop, NuclearPop, PortPop, APortPop;
503extern short NeedHosp, NeedChurch;
504extern short CrimeAverage, PolluteAverage, LVAverage;
505extern char *MicropolisVersion;
506extern char *CityName;
507extern char *CityFileName;
508extern char *StartupName;
509extern short StartingYear;
510extern QUAD CityTime;
511extern QUAD LastCityTime;
512extern QUAD LastCityMonth;
513extern QUAD LastCityYear;
514extern QUAD LastFunds;
515extern QUAD LastR, LastC, LastI;
516extern short GameLevel;
517extern short Cycle;
518extern short ScenarioID;
519extern short ShakeNow;
520extern QUAD DonDither;
521extern int DoOverlay;
522
523extern short *ResHis, ResHisMax;
524extern short *ComHis, ComHisMax;
525extern short *IndHis, IndHisMax;
526extern short *MoneyHis, *CrimeHis, *PollutionHis, *MiscHis;
527extern short *PowerMap;
528
529extern float roadPercent, policePercent, firePercent;
530extern QUAD RoadSpend, PoliceSpend, FireSpend;
531extern QUAD roadMaxValue, policeMaxValue, fireMaxValue;
532extern QUAD TaxFund, RoadFund, PoliceFund, FireFund;
533extern short RoadEffect, PoliceEffect, FireEffect;
534extern short TaxFlag, CityTax;
535extern QUAD TotalFunds;
536
537extern QUAD costOf[];
538
539extern short flagBlink;
540extern unsigned char tileSynch;
541extern short aniTile[];
542extern unsigned char aniSynch[];
543extern int TilesAnimated;
544extern int DoAnimation;
545extern int DoMessages;
546extern int DoNotices;
547extern unsigned char ColorIntensities[];
548
549extern short MesX, MesY;
550extern short MesNum, MessagePort;
551extern QUAD LastMesTime;
552
553extern short SimSpeed;
554extern short SimMetaSpeed;
555extern short NoDisasters;
556extern short autoBulldoze;
557extern short autoBudget;
558extern short autoGo;
559extern short UserSoundOn;
560
561extern short DisasterEvent;
562extern short DisasterWait;
563
564extern short ResCap, ComCap, IndCap;
565extern short RValve, CValve, IValve;
566extern short PwrdZCnt;
567extern short unPwrdZCnt;
568
569extern char *HomeDir, *ResourceDir, *HostName;
570
571extern short Graph10Max, Graph120Max;
572extern short Res2HisMax, Com2HisMax, Ind2HisMax;
573extern unsigned char *History10[HISTORIES], *History120[HISTORIES];
574extern short CityScore;
575extern short deltaCityScore;
576extern short ScoreType;
577extern short ScoreWait;
578extern short CityClass;
579extern short PolMaxX, PolMaxY;
580extern int PowerStackNum;
581extern short TrafficAverage;
582extern short PosStackN;
583extern short SMapXStack[], SMapYStack[];
584extern short Zsource;
585extern short HaveLastMessage;
586extern short PdestX, PdestY;
587extern short CdestX, CdestY;
588extern int absDist;
589extern short CopFltCnt;
590extern short GodCnt;
591extern short GdestX, GdestY;
592extern short GorgX, GorgY;
593extern short GodControl;
594extern short CopControl;
595extern short CdestX, CdestY;
596extern short TrafMaxX, TrafMaxY;
597extern short CrimeMaxX, CrimeMaxY;
598extern short FloodX, FloodY;
599extern short CrashX, CrashY;
600extern short CCx, CCy;
601extern QUAD CityPop, deltaCityPop;
602extern char *cityClassStr[6];
603extern short CityYes, CityNo;
604extern short ProblemTable[PROBNUM];
605extern short ProblemVotes[PROBNUM];
606extern short ProblemOrder[4];
607extern QUAD CityAssValue;
608
609extern short InitSimLoad;
610extern short DoInitialEval;
611extern int Startup;
612extern int StartupGameLevel;
613extern int PerformanceTiming;
614extern double FlushTime;
615
616extern char *optarg;
617extern int optind;
618extern struct timeval start_time, now_time, beat_time, last_now_time;
619extern Sim *sim;
620extern int WireMode;
621extern int MultiPlayerMode;
622extern int SugarMode;
623extern int sim_delay;
624extern int sim_skips;
625extern int sim_skip;
626extern int sim_paused;
627extern int sim_paused_speed;
628extern int sim_tty;
629#ifdef CAM
630extern int sim_just_cam;
631#endif
632extern int heat_steps;
633extern int heat_flow;
634extern int heat_rule;
635extern int UpdateDelayed;
636extern int DynamicData[32];
637extern int Players;
638extern int Votes;
639extern int BobHeight;
640extern int OverRide;
641extern int Expensive;
642extern int PendingTool;
643extern int PendingX;
644extern int PendingY;
645extern int TreeLevel;
646extern int LakeLevel;
647extern int CurveLevel;
648extern int CreateIsland;
649extern short specialBase;
650extern short PunishCnt;
651extern short Dozing;
652extern short toolSize[];
653extern short toolOffset[];
654extern QUAD toolColors[];
655extern char *Displays;
656extern char *FirstDisplay;
657extern char *dateStr[12];
658
659extern short NewMap;
660extern short NewMapFlags[NMAPS];
661extern short NewGraph;
662extern short ValveFlag;
663extern short MustUpdateFunds;
664extern short MustUpdateOptions;
665extern short CensusChanged;
666extern short EvalChanged;
667extern short MeltX, MeltY;
668extern int NeedRest;
669extern int ExitReturn;
670
671extern Tcl_Interp *tk_mainInterp;
672extern Tk_Window MainWindow;
673extern int FlushStyle;
674extern int GotXError;
675
676extern short Rand(short range);
677extern short RandInt(void);
678
679extern Sim *MakeNewSim();
680extern SimView *MakeNewView();
681extern SimSprite *GetSprite();
682extern SimSprite *MakeSprite();
683extern SimSprite *MakeNewSprite();
684
685extern int setSpeed(short speed);
686extern int setSkips(int skips);
687extern int SetGameLevel(short level);
688extern int SetGameLevelFunds(short level);
689
690extern struct XDisplay *XDisplays;
Impressum, Datenschutz