82d3a0146a450d59a72e3da347fc1125b0a414ec
[rocksndiamonds.git] / src / game_sp / Globals.c
1 // ----------------------------------------------------------------------------
2 // Globals.c
3 // ----------------------------------------------------------------------------
4
5 #include "Globals.h"
6
7
8 void ReadLevel();
9
10 int LevelNumber;
11 boolean LevelLoaded;
12
13 boolean DemoAvailable;
14 boolean menBorder;
15
16 int FieldWidth; // = 60
17 int FieldHeight; // = 24
18 int HeaderSize; // = 96
19 int FieldMax, LevelMax;
20 long FileMax;
21 int *PlayField16;
22 byte *PlayField8;
23 byte *DisPlayField;
24
25 // Public DisplayMin%, DisplayMax%, DisplayWidth%, DisplayHeight%
26
27 int TimerVar;
28 #if 1
29 short RandomSeed;
30 #else
31 int RandomSeed;
32 #endif
33
34 int FreezeZonks;
35
36 LevelInfoType LInfo;
37
38 float Stretch = 1;      // , StretchWidth%, TwoPixels!
39
40 int ScrollMinX, ScrollMaxX, ScrollMinY, ScrollMaxY;
41 int ScrollX, ScrollY;
42
43 // constants for  Fixed Fields:
44 // --- const int fiSpace = 0; // &H00  space(28 = wall space ...)
45 // --- const int fiZonk = 1; // &H01  zonk
46 // --- const int fiBase = 2; // &H02  base
47 // --- const int fiMurphy = 3; // &H03  Murphy
48 // --- const int fiInfotron = 4; // &H04  infotron
49 // --- const int fiRAM = 5; // &H05  small RAM chip
50 // --- const int fiHardWare = 6; // &H06  hardware (square, standard pyramid shape)
51 // --- const int fiExit = 7; // &H07  exit
52 // --- const int fiOrangeDisk = 8; // &H08  brown/orange utility disk
53 // --- const int fiPortRight = 9; // &H09  port 1 left to right
54 // --- const int fiPortDown = 10; // &H0A  port 1 up to down
55 // --- const int fiPortLeft = 11; // &H0B  port 1 right to left
56 // --- const int fiPortUp = 12; // &H0C  port 1 down to up
57 // --- const int fiSpPortRight = 13; // &H0D  port 2 left to right (gravity change)
58 // --- const int fiSpPortDown = 14; // &H0E  port 2 up to down     (gravity change)
59 // --- const int fiSpPortLeft = 15; // &H0F  port 2 right to left (gravity change)
60 // --- const int fiSpPortUp = 16; // &H10  port 2 down to up     (gravity change)
61 // --- const int fiSnikSnak = 17; // &H11  snik snak
62 // --- const int fiYellowDisk = 18; // &H12  yellow utility disk
63 // --- const int fiTerminal = 19; // &H13  terminal
64 // --- const int fiRedDisk = 20; // &H14  red utility disk
65 // --- const int fiPortUpAndDown = 21; // &H15  vertical port
66 // --- const int fiPortLeftAndRight = 22; // &H16  horizontal port
67 // --- const int fiPortAllDirections = 23; // &H17  horizontal + vertical port
68 // --- const int fiElectron = 24; // &H18  electron
69 // --- const int fiBug = 25; // &H19  bug
70 // --- const int fiRAMLeft = 26; // &H1A  horizontal RAM chip, left (pin 1)
71 // --- const int fiRAMRight = 27; // &H1B  horizontal RAM chip, right
72 // --- const int fiHWFirst = 28; // &H1C  hardware (radial blue circular cap + coloured shapes)
73
74 // Public Const fiHW1% = 29               '  29 = 1D  hardware (green signal lamp)
75 // Public Const fiHW2% = 30               '  30 = 1E  hardware (blue signal lamp)
76 // Public Const fiHW3% = 31               '  31 = 1F  hardware (red signal lamp)
77 // Public Const fiHW4% = 32               '  32 = 20  hardware (yellow/black diagonal stripes)
78 // Public Const fiHW5% = 33               '  33 = 21  hardware (yellow resistor + blue + red shapes)
79 // Public Const fiHW6% = 34               '  34 = 22  hardware (horizontal red capacitor + smd shape)
80 // Public Const fiHW7% = 35               '  35 = 23  hardware (red + yellow + blue horizontal resistors)
81 // Public Const fiHW8% = 36               '  36 = 24  hardware (3 red vertical resistors)
82 // --- const int fiHWLast = 37;             //  37 = 25  hardware (3 yellow horizontal resistors)
83 // --- const int fiRAMTop = 38;             //  38 = 26  vertical RAM chip, top (pin 1)
84 // --- const int fiRAMBottom = 39;          //  39 = 27  vertical RAM chip, bottom
85
86 // Specials to experiment with ...
87 // --- const int fiWallSpace = 40;          //  40 = 28  invisible wall (can explode, zonks don't roll off)
88 // --- const int fiHWTrash1 = 41;           //  41 = 29  hardware trash
89 // --- const int fiHWTrash2 = 42;           //  42 = 2A  hardware trash
90 // --- const int fiHWMurphy = 43;           //  43 = 2B  hardware inverted Murphy ... (maybe nice for use?)
91
92 // --- const int fiExplosion = 0x1F;
93
94 // --- const int keyNone = 0;
95 // --- const int keyUp = 1;
96 // --- const int keyLeft = 2;
97 // --- const int keyDown = 3;
98 // --- const int keyRight = 4;
99 // --- const int keySpaceUp = 5;
100 // --- const int keySpaceLeft = 6;
101 // --- const int keySpaceDown = 7;
102 // --- const int keySpaceRight = 8;
103 // --- const int keySpace = 9;
104
105 #if 0
106 int aniFramesBug[] = { 74, 75, 76, 77, 78, 77, 76, 77, 78, 77, 76, 75, 74, 25 };
107 int aniFramesZonkRollRight[] = { 198, 197, 196, 195, 194, 193, 192, 1, -1 };
108 int aniFramesZonkRollLeft[] = { 192, 193, 194, 195, 196, 197, 198, 1, -1 };
109 int aniFramesInfotronRollRight[] = { 206, 205, 204, 203, 202, 201, 200, 4 };
110 int aniFramesInfotronRollLeft[] = { 200, 201, 202, 203, 204, 205, 206, 4 };
111 int aniFramesSnikSnak[] = { 121, 122, 123, 124, 125, 126, 127, 120, 121 };
112 int aniFramesElectron[] = { 144, 145, 146, 147, 148, 149, 150, 151, 144 };
113 int aniFramesExplosion[] = { 3, 103, 104, 105, 106, 107, 108, 109, 0 };
114 int aniFramesTouchBase[] = { 80, 81, 82, 83, 84, 85, 86, 0, -1 };
115 int aniFramesTouchInfotron[] = { 87, 88, 89, 91, 92, 93, 0, -1 }; // Only seven frames!!!!
116 int aniFramesTouchRedDisk[] = { 96, 97, 98, 99, 100, 101, 102, 0, -1 };
117 int aniFramesMurphyExit[] = { 46, 46, 46, 46, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 0, 0, 0, 0, -1 };
118 int aniFramesMurphyEatLeft[] = { 176, 177, 178, 179, 180, 181, 182, 183, -1 };
119 int aniFramesMurphyEatRight[] = { 184, 185, 186, 187, 188, 189, 190, 191, -1 };
120 int aniFramesMurphyEatUpLeft[] = { 183, 182, 181, 180, 179, 178, 177, 176, -1 };
121 int aniFramesMurphyEatUpRight[] = { 191, 190, 189, 188, 187, 186, 185, 184, -1 };
122   // aniFramesMurphyEatRightRedDisk = { 184, 184, 185, 186, 187, 188, 189, 190, 191, -1) '9 frames!
123 int aniFramesEatInfotronLeft[] = { 209, 211, 213, 215, 217, 219, 221, 223, -1 };
124 int aniFramesEatInfotronRight[] = { 224, 226, 228, 230, 232, 234, 236, 238, -1 };
125 int aniFramesSplitUpDown[] = { 3, 3, 3, 3, 3, 3, 3, 3, -1 };
126 int aniFramesYellowDisk[] = { 18, 18, 18, 18, 18, 18, 18, 18, -1 };
127 int aniFramesOrangeDisk[] = { 8, 8, 8, 8, 8, 8, 8, 8, -1 };
128 int aniFramesRedDisk[] = { 20, -1 };
129 #endif
130
131 int fiGraphic[] =
132 {
133   aniSpace,
134   aniZonk,
135   aniBase,
136   aniMurphy,
137   aniInfotron,
138   aniRAM,
139   aniHardWare,
140   aniExit,
141   aniOrangeDisk,
142   aniPortRight,
143   aniPortDown,
144   aniPortLeft,
145   aniPortUp,
146   aniSpPortRight,
147   aniSpPortDown,
148   aniSpPortLeft,
149   aniSpPortUp,
150   aniSnikSnak,
151   aniYellowDisk,
152   aniTerminal,
153   aniRedDisk,
154   aniPortUpAndDown,
155   aniPortLeftAndRight,
156   aniPortAllDirections,
157   aniElectron,
158   aniBug,
159   aniRAMLeft,
160   aniRAMRight,
161   aniHW0,
162   aniHW1,
163   aniHW2,
164   aniHW3,
165   aniHW4,
166   aniHW5,
167   aniHW6,
168   aniHW7,
169   aniHW8,
170   aniHW9,
171   aniRAMTop,
172   aniRAMBottom,
173   aniWallSpace
174 };
175
176 int aniSnikSnakTurningLeft[] =
177 {
178   aniSnikSnakTurnUpToLeft,
179   aniSnikSnakTurnLeftToDown,
180   aniSnikSnakTurnDownToRight,
181   aniSnikSnakTurnRightToUp
182 };
183
184 int aniSnikSnakTurningRight[] =
185 {
186   aniSnikSnakTurnUpToRight,
187   aniSnikSnakTurnRightToDown,
188   aniSnikSnakTurnDownToLeft,
189   aniSnikSnakTurnLeftToUp
190 };
191
192
193 int getSequenceLength(int sequence)
194 {
195   switch (sequence)
196   {
197     case aniBug:
198       return 14;
199
200     case aniElectron:
201     case aniExplosion:
202       return 9;
203
204     case aniTouchInfotron:
205       return 7;
206
207     case aniMurphyExit:
208       return 40;
209
210     case aniRedDisk:
211       return 1;
212
213     default:
214       return 8;
215   }
216 }
217
218 boolean isSnappingSequence(int sequence)
219 {
220   switch (sequence)
221   {
222     case aniTouchBase:
223     case aniTouchInfotron:
224     case aniTouchRedDisk:
225       return TRUE;
226
227     default:
228       return FALSE;
229   }
230 }
231
232 void InitGlobals()
233 {
234   AutoScrollFlag = True;
235   FreezeZonks = 0;
236   LevelLoaded = False;
237   FieldWidth = 60;
238   FieldHeight = 24;
239   HeaderSize = 96;
240   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
241   LevelMax = (FieldWidth * FieldHeight) - 1;
242   bPlaying = False;
243 }
244
245 int GetSI(int X, int Y)
246 {
247   return Y * FieldWidth + X;
248 }
249
250 int GetX(int si)
251 {
252   return si % FieldWidth;
253 }
254
255 int GetY(int si)
256 {
257   return si / FieldWidth;
258 }
259
260 int GetStretchX(int si)
261 {
262   return StretchWidth * (si % FieldWidth);
263 }
264
265 int GetStretchY(int si)
266 {
267   return StretchWidth * (si / FieldWidth);
268 }
269
270 void ReadLevel()
271 {
272   copyInternalEngineVars_SP();
273
274 #if 1
275   SetDisplayRegion();
276   SetScrollEdges();
277 #endif
278
279   LevelNumber = level_nr;
280
281   LevelLoaded = True;
282 }
283
284 void Trace(char *Source, char *Message)
285 {
286   printf("::: Trace: Source == '%s', Message == '%s'\n", Source, Message);
287 }
288
289 void ReportError(char *Source, char *Message)
290 {
291   printf("::: ReportError: Source == '%s', Message == '%s'\n", Source, Message);
292 }
293
294 int Min(int A, int B)
295 {
296   return (A < B ? A : B);
297 }
298
299 int Max(int A, int B)
300 {
301   return (A < B ? B : A);
302 }