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