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