1 // ----------------------------------------------------------------------------
2 // InitGameConditions.c
3 // ----------------------------------------------------------------------------
5 #include "InitGameConditions.h"
7 static char *VB_Name = "modInitGameConditions";
10 // ==========================================================================
12 // Init game conditions (variables)
13 // ==========================================================================
15 int subInitGameConditions()
17 int subInitGameConditions;
21 MurphyVar0DAC = MurphyYPos;
22 MurphyVar0DAE = MurphyXPos;
23 MurphyVarFaceLeft = 0;
24 KillMurphyFlag = 0; // no "kill Murphy"
26 LeadOutCounter = 0; // quit flag: lead-out counter
27 RedDiskCount = 0; // Red disk counter
28 ShowRedDiskCounter = 0; // show-red-disk time-out
30 YawnSleepCounter = 0; // Wake up sleeping Murphy
44 ExplosionShake = 0; // Force explosion flag off
46 TerminalMaxCycles = 0x7F;
47 YellowDisksExploded = 0;
50 // ShowPanel = 1 ' Force Panel on
51 // MainForm.PanelVisible = True;
52 EnterRepeatCounter = 0; // restart Enter repeat counter
53 SnikSnaksElectronsFrozen = 0; // Snik-Snaks and Electr. move!
55 SplitMoveFlag = 0; // Reset Split-through-ports
56 RedDiskReleasePhase = 0; // (re-)enable red disk release
57 RedDiskReleaseMurphyPos = 0; // Red disk was released here
60 return subInitGameConditions;
61 } // subInitGameConditions
64 // ==========================================================================
66 // Locate Murphy and init location.
67 // ==========================================================================
75 for (si = 0; si <= LevelMax - 1; si++)
77 if (PlayField16[si] == fiMurphy)
87 int InitMurphyPosB(int si)
91 MurphyYPos = GetStretchY(si) / Stretch;
92 MurphyXPos = GetStretchX(si) / Stretch;
94 MurphyScreenXPos = GetStretchX(si); // Murphy's screen x-position
95 MurphyScreenYPos = GetStretchY(si); // Murphy's screen y-position
97 // To Do: draw Murphy in location ax
98 StretchedSprites.BltEx(MurphyScreenXPos, MurphyScreenYPos, fiMurphy);
100 MurphyScreenXPos = MurphyScreenXPos / Stretch;
101 MurphyScreenYPos = MurphyScreenYPos / Stretch;
103 subCalculateScreenScrollPos(); // calculate screen start addrs
108 SoftScrollTo(ScreenScrollXPos, ScreenScrollYPos, 1000, 25);
112 ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
116 return InitMurphyPosB;
119 // ==========================================================================
121 // Convert to easy symbols and reset Infotron count If not ThenVer62
122 // ==========================================================================
124 int subConvertToEasySymbols()
126 int subConvertToEasySymbols;
128 int ax, bx, cx, dx, di, X, Y, i;
129 int ah, bh, ch, dh, al, bl, cl, dl, ZF;
139 if (al == 0xF1) // converted explosion?
141 MovLowByte(&PlayField16[i], 0x1F); // restore explosions
145 if (LowByte(GameBusyFlag) != 1) // free screen write?
147 if (ax == fiInfotron) // Infotron? -> yes--count!
150 if (ax == fiSnikSnak) // Snik Snak? -> yes--rearrange
153 if (ax == fiElectron) // Electron? -> yes--rearrange
157 // test for fancy RAM Chips:
158 if (ax == fiRAMLeft || ax == fiRAMRight)
161 if (ax == fiRAMTop || ax == fiRAMBottom)
164 if (ax < fiHWFirst) // All but deco hardware?
167 if (ax < fiRAMTop) // Decorative hardware?
171 if (ax < fiSpPortRight) // Gravity change ports only?
174 if (ax < fiSnikSnak) // Gravity change port! 'loc_g_2702:
179 loc_g_2704: // INFOTRON
180 dx = dx + 1; // Count Infotrons
183 loc_g_2707: // DECO RAM CHIPS
184 PlayField16[i] = fiRAM; // Convert to standard RAM chip
187 loc_g_270D: // DECO HARDWARE
188 PlayField16[i] = fiHardWare; // Convert to standard hardware
191 loc_g_2713: // SNIK-SNAK
192 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
195 MovHighByte(&PlayField16[i], 1); // turn left, step = NorthWest
199 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
202 PlayField16[i - FieldWidth] = 0x1011; // SnikSnak accessing from below, step = 0
203 PlayField16[i] = 0xFFFF;
207 if (PlayField16[i + 1] != 0) // 1 field right empty? -> point up
210 PlayField16[i + 1] = 0x2811; // SnikSnak accessing from left, step = 0
211 PlayField16[i] = 0xFFFF;
214 loc_g_2741: // ELECTRON
215 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
218 MovHighByte(&PlayField16[i], 1);
222 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
225 PlayField16[i - FieldWidth] = 0x1018; // 1 field up
226 PlayField16[i] = 0xFFFF;
230 if (PlayField16[i + 1] != 0) // 1 field right empty? -> no--point down
233 PlayField16[i + 1] = 0x2818;
234 PlayField16[i] = 0xFFFF;
237 loc_g_276F: // GRAVITY CHANGING PORTS
238 PlayField16[i] = (ax - 4) | 0x100; // Convert to standard ports
242 i = i + 1; // Next field
245 if (0 < cx) // Until all done 'loc_g_2782:
248 subConvertToEasySymbols = dx; // return InfotronCount
250 return subConvertToEasySymbols;
251 } // subConvertToEasySymbols
253 // ==========================================================================
255 // Reset Infotron count. Call immediately after subConvertToEasySymbols
256 // ==========================================================================
258 int ResetInfotronsNeeded(int dx)
260 int ResetInfotronsNeeded;
262 if (LInfo.InfotronsNeeded != 0) // Jump If equal (autodetect)
264 dx = LInfo.InfotronsNeeded;
267 InfotronsNeeded = LowByte(dx); // Remaining Infotrons needed
268 TotalInfotronsNeeded = InfotronsNeeded; // Number of Infotrons needed
269 subDisplayInfotronsNeeded();
271 return ResetInfotronsNeeded;
272 } // ResetInfotronsNeeded
275 // ==========================================================================
277 // Fetch and initialize a level
278 // ==========================================================================
280 int subFetchAndInitLevelB()
282 int subFetchAndInitLevelB;
284 boolean UpdatePlayTime;
286 MovLowByte(&data_SPtorunavail, 0); // no SP file
288 UpdatePlayTime = (0 == demo_stopped ? True : True);
290 subFetchAndInitLevelA(UpdatePlayTime);
292 return subFetchAndInitLevelB;
293 } // subFetchAndInitLevelb
295 int subFetchAndInitLevelA(boolean UpdatePlayTime)
297 int subFetchAndInitLevelA;
299 if (UpdatePlayTime && (0 == demo_stopped))
301 subUpdatePlayingTime(); // update playing time
304 D_ModeFlag = 0; // 1=debug D pressed (CPU use)
305 if (0 != demo_stopped) // 1=demo, 0=game
308 GameBusyFlag = 0; // restore scissors too
309 subFetchAndInitLevel(); // Fetch and initialize a level
310 GameBusyFlag = 1; // no free screen write
311 if (1 <= demo_stopped)
313 if (1 == demo_stopped)
315 DemoFlag = 0; // 1=demo, 0=game
316 demo_stopped = demo_stopped + 1;
320 DemoFlag = 0; // 1=demo, 0=game
324 DemoKeyCode = 0; // delete last demo key!
325 if (DemoFlag != 0) // don't allow during game! only in Demo
327 DemoOffset = DemoPointer; // init demo pointer
328 DemoKeyRepeatCounter = 1;
329 subGetNextDemoKey(); // get next demo byte
332 return subFetchAndInitLevelA;
333 } // subFetchAndInitLevela
335 int subFetchAndInitLevel()
337 int subFetchAndInitLevel;
339 int InfoCountInLevel;
341 Trace("modInitGameConditions", "--> subFetchAndInitLevel");
342 Trace("modInitGameConditions", "Call ReadLevel");
343 ReadLevel(); // Read LEVELS.DAT
344 Trace("modInitGameConditions", "ReadLevel return subFetchAndInitLeveled");
346 if (RecordDemoFlag == 1)
348 RecDemoRandomSeed = RandomSeed;
349 // Debug.Print "FetchRec: " & Hex(RandomSeed)
352 // If DemoFlag = 1 Then
353 // Debug.Print "FetchPlay: " & Hex(RandomSeed)
355 GameBusyFlag = -GameBusyFlag; // make <>1
356 Trace("modInitGameConditions", "subConvertToEasySymbols");
357 InfoCountInLevel = subConvertToEasySymbols(); // Convert to easy symbols
358 GameBusyFlag = -GameBusyFlag; // restore
359 Trace("modInitGameConditions", "subDisplayLevel");
360 subDisplayLevel(); // Paint (Init) game field
361 subDisplayPanel(); // Paint (Init) Panel
362 ResetInfotronsNeeded(InfoCountInLevel); // and reset Infotron count
364 Trace("modInitGameConditions", "subInitGameConditions");
365 subInitGameConditions(); // Init game conditions (vars)
366 InitMurphyPos(); // Locate Murphy + screen pos
367 Trace("modInitGameConditions", "<-- subFetchAndInitLevel");
369 return subFetchAndInitLevel;
370 } // subFetchAndInitLevel