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