rnd-20100317-1-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 int *PlayField16;
19 byte *PlayField8;
20 byte *DisPlayField;
21
22 int TimerVar;
23 #if 1
24 short RandomSeed;
25 #else
26 int RandomSeed;
27 #endif
28
29 int FreezeZonks;
30
31 LevelInfoType LInfo;
32
33 int ScrollMinX, ScrollMaxX, ScrollMinY, ScrollMaxY;
34 int ScrollX, ScrollY;
35
36 int fiGraphic[] =
37 {
38   aniSpace,
39   aniZonk,
40   aniBase,
41   aniMurphy,
42   aniInfotron,
43   aniRAM,
44   aniHardWare,
45   aniExit,
46   aniOrangeDisk,
47   aniPortRight,
48   aniPortDown,
49   aniPortLeft,
50   aniPortUp,
51   aniSpPortRight,
52   aniSpPortDown,
53   aniSpPortLeft,
54   aniSpPortUp,
55   aniSnikSnak,
56   aniYellowDisk,
57   aniTerminal,
58   aniRedDisk,
59   aniPortUpAndDown,
60   aniPortLeftAndRight,
61   aniPortAllDirections,
62   aniElectron,
63   aniBug,
64   aniRAMLeft,
65   aniRAMRight,
66   aniHW0,
67   aniHW1,
68   aniHW2,
69   aniHW3,
70   aniHW4,
71   aniHW5,
72   aniHW6,
73   aniHW7,
74   aniHW8,
75   aniHW9,
76   aniRAMTop,
77   aniRAMBottom,
78   aniWallSpace
79 };
80
81 int aniSnikSnakTurningLeft[] =
82 {
83   aniSnikSnakTurnUpToLeft,
84   aniSnikSnakTurnLeftToDown,
85   aniSnikSnakTurnDownToRight,
86   aniSnikSnakTurnRightToUp
87 };
88
89 int aniSnikSnakTurningRight[] =
90 {
91   aniSnikSnakTurnUpToRight,
92   aniSnikSnakTurnRightToDown,
93   aniSnikSnakTurnDownToLeft,
94   aniSnikSnakTurnLeftToUp
95 };
96
97
98 int getSequenceLength(int sequence)
99 {
100   switch (sequence)
101   {
102     case aniBug:
103       return 14;
104
105     case aniElectron:
106     case aniExplosion:
107       return 9;
108
109     case aniTouchInfotron:
110       return 7;
111
112     case aniMurphyExit:
113       return 40;
114
115     case aniRedDisk:
116       return 1;
117
118     default:
119       return 8;
120   }
121 }
122
123 boolean isSnappingSequence(int sequence)
124 {
125   switch (sequence)
126   {
127     case aniTouchBase:
128     case aniTouchInfotron:
129     case aniTouchRedDisk:
130       return TRUE;
131
132     default:
133       return FALSE;
134   }
135 }
136
137 void InitGlobals()
138 {
139   AutoScrollFlag = True;
140   FreezeZonks = 0;
141   LevelLoaded = False;
142   FieldWidth = 60;
143   FieldHeight = 24;
144   HeaderSize = 96;
145   FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1;
146   LevelMax = (FieldWidth * FieldHeight) - 1;
147   bPlaying = False;
148   menBorder = False;
149 }
150
151 int GetSI(int X, int Y)
152 {
153   return Y * FieldWidth + X;
154 }
155
156 int GetX(int si)
157 {
158   return si % FieldWidth;
159 }
160
161 int GetY(int si)
162 {
163   return si / FieldWidth;
164 }
165
166 int GetStretchX(int si)
167 {
168   return StretchWidth * (si % FieldWidth);
169 }
170
171 int GetStretchY(int si)
172 {
173   return StretchWidth * (si / FieldWidth);
174 }
175
176 void PrepareLevel()
177 {
178   copyInternalEngineVars_SP();
179
180 #if 1
181   SetDisplayRegion();
182   SetScrollEdges();
183 #endif
184
185   LevelLoaded = True;
186 }
187
188 void Trace(char *Source, char *Message)
189 {
190   printf("::: Trace: Source == '%s', Message == '%s'\n", Source, Message);
191 }
192
193 void ReportError(char *Source, char *Message)
194 {
195   printf("::: ReportError: Source == '%s', Message == '%s'\n", Source, Message);
196 }
197
198 int Min(int A, int B)
199 {
200   return (A < B ? A : B);
201 }
202
203 int Max(int A, int B)
204 {
205   return (A < B ? B : A);
206 }