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