rocksndiamonds-3.3.0.0
[rocksndiamonds.git] / src / game_sp / Globals.c
1 // ----------------------------------------------------------------------------
2 // Globals.c
3 // ----------------------------------------------------------------------------
4
5 #include "Globals.h"
6
7
8 boolean LevelLoaded;
9
10 boolean DemoAvailable;
11 boolean menBorder;
12
13 int FieldWidth;         // standard size = 60
14 int FieldHeight;        // standard size = 24
15 int HeaderSize;         // standard size = 96
16 int FieldMax, LevelMax;
17 long FileMax;
18
19 #if 1
20 int PlayField16[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE];
21 byte PlayField8[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE];
22 byte DisPlayField[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE];
23 #else
24 int *PlayField16;
25 byte *PlayField8;
26 byte *DisPlayField;
27 #endif
28
29 int TimerVar;
30 #if 1
31 short RandomSeed;
32 #else
33 int RandomSeed;
34 #endif
35
36 int FreezeZonks;
37
38 LevelInfoType LInfo;
39
40 int ScrollMinX, ScrollMaxX, ScrollMinY, ScrollMaxY;
41 int ScrollX, ScrollY;
42
43 int MurphyPosIndex, MurphyXPos, MurphyYPos;
44 int MurphyScreenXPos, MurphyScreenYPos;
45 int MurphyExplodePos, SplitMoveFlag, RedDiskReleaseMurphyPos;
46 int KillMurphyFlag, MurphyMoveCounter;
47 long YawnSleepCounter;
48 int MurphyVarFaceLeft;
49 int ScratchGravity, GravityFlag;
50 int RedDiskReleaseFlag, MovingPictureSequencePhase;
51
52 int YellowDisksExploded;
53 int AllowRedDiskCheat, AllowEatRightRedDiskBug;
54
55 int GameBusyFlag;
56 int InfotronsNeeded, TotalInfotronsNeeded;
57 int RedDiskCount;
58 int SnikSnaksElectronsFrozen;
59
60 int DemoKeyCode;
61
62 int RedDiskReleasePhase;
63
64 int fiGraphic[] =
65 {
66   aniSpace,
67   aniZonk,
68   aniBase,
69   aniMurphy,
70   aniInfotron,
71   aniRAM,
72   aniHardWare,
73   aniExit,
74   aniOrangeDisk,
75   aniPortRight,
76   aniPortDown,
77   aniPortLeft,
78   aniPortUp,
79   aniSpPortRight,
80   aniSpPortDown,
81   aniSpPortLeft,
82   aniSpPortUp,
83   aniSnikSnak,
84   aniYellowDisk,
85   aniTerminal,
86   aniRedDisk,
87   aniPortUpAndDown,
88   aniPortLeftAndRight,
89   aniPortAllDirections,
90   aniElectron,
91   aniBug,
92   aniRAMLeft,
93   aniRAMRight,
94   aniHW0,
95   aniHW1,
96   aniHW2,
97   aniHW3,
98   aniHW4,
99   aniHW5,
100   aniHW6,
101   aniHW7,
102   aniHW8,
103   aniHW9,
104   aniRAMTop,
105   aniRAMBottom,
106   aniWallSpace
107 };
108
109 int aniSnikSnakTurningLeft[] =
110 {
111   aniSnikSnakTurnUpToLeft,
112   aniSnikSnakTurnLeftToDown,
113   aniSnikSnakTurnDownToRight,
114   aniSnikSnakTurnRightToUp
115 };
116
117 int aniSnikSnakTurningRight[] =
118 {
119   aniSnikSnakTurnUpToRight,
120   aniSnikSnakTurnRightToDown,
121   aniSnikSnakTurnDownToLeft,
122   aniSnikSnakTurnLeftToUp
123 };
124
125
126 int getSequenceLength(int sequence)
127 {
128   switch (sequence)
129   {
130     case aniBug:
131       return 14;
132
133     case aniElectron:
134     case aniExplosion:
135       return 9;
136
137     case aniTouchInfotron:
138       return 7;
139
140     case aniMurphyExit:
141       return 40;
142
143     case aniRedDisk:
144       return 1;
145
146     default:
147       return 8;
148   }
149 }
150
151 boolean isSnappingSequence(int sequence)
152 {
153   switch (sequence)
154   {
155     case aniTouchBase:
156     case aniTouchInfotron:
157     case aniTouchRedDisk:
158       return TRUE;
159
160     default:
161       return FALSE;
162   }
163 }
164
165 void InitGlobals()
166 {
167   AutoScrollFlag = True;
168   FreezeZonks = 0;
169   LevelLoaded = False;
170   FieldWidth = 60;
171   FieldHeight = 24;
172   HeaderSize = 96;
173   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
174   LevelMax = (FieldWidth * FieldHeight) - 1;
175   bPlaying = False;
176   menBorder = False;
177
178 #if 0
179   /* these defaults will be changed after reading a Supaplex level file */
180   PlayField8 = REDIM_1D(sizeof(byte), 0, FieldMax);
181   DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax);
182   PlayField16 = REDIM_1D(sizeof(int), 0, FieldMax);
183
184   AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax);
185   AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax);
186   TerminalState = REDIM_1D(sizeof(byte), 0, FieldMax);
187 #endif
188 }
189
190 int GetSI(int X, int Y)
191 {
192   return Y * FieldWidth + X;
193 }
194
195 int GetX(int si)
196 {
197   return si % FieldWidth;
198 }
199
200 int GetY(int si)
201 {
202   return si / FieldWidth;
203 }
204
205 int GetStretchX(int si)
206 {
207   return StretchWidth * (si % FieldWidth);
208 }
209
210 int GetStretchY(int si)
211 {
212   return StretchWidth * (si / FieldWidth);
213 }
214
215 void PrepareLevel()
216 {
217   copyInternalEngineVars_SP();
218
219 #if 1
220   SetDisplayRegion();
221   SetScrollEdges();
222 #endif
223
224   LevelLoaded = True;
225 }
226
227 #if 0
228 void Trace(char *Source, char *Message)
229 {
230   printf("::: Trace: Source == '%s', Message == '%s'\n", Source, Message);
231 }
232
233 void ReportError(char *Source, char *Message)
234 {
235   printf("::: ReportError: Source == '%s', Message == '%s'\n", Source, Message);
236 }
237 #endif
238
239 int Min(int A, int B)
240 {
241   return (A < B ? A : B);
242 }
243
244 int Max(int A, int B)
245 {
246   return (A < B ? B : A);
247 }