1 // ----------------------------------------------------------------------------
2 // InitGameConditions.c
3 // ----------------------------------------------------------------------------
5 #include "InitGameConditions.h"
7 // static char *VB_Name = "modInitGameConditions";
11 // ==========================================================================
13 // Init game conditions (variables)
14 // ==========================================================================
16 int subInitGameConditions()
18 int subInitGameConditions;
22 MurphyVar0DAC = MurphyYPos;
23 MurphyVar0DAE = MurphyXPos;
24 MurphyVarFaceLeft = 0;
25 KillMurphyFlag = 0; // no "kill Murphy"
27 LeadOutCounter = 0; // quit flag: lead-out counter
28 RedDiskCount = 0; // Red disk counter
29 ShowRedDiskCounter = 0; // show-red-disk time-out
31 YawnSleepCounter = 0; // Wake up sleeping Murphy
45 ExplosionShake = 0; // Force explosion flag off
47 TerminalMaxCycles = 0x7F;
48 YellowDisksExploded = 0;
51 // ShowPanel = 1 ' Force Panel on
52 // MainForm.PanelVisible = True;
53 EnterRepeatCounter = 0; // restart Enter repeat counter
54 SnikSnaksElectronsFrozen = 0; // Snik-Snaks and Electr. move!
56 SplitMoveFlag = 0; // Reset Split-through-ports
57 RedDiskReleasePhase = 0; // (re-)enable red disk release
58 RedDiskReleaseMurphyPos = 0; // Red disk was released here
61 return subInitGameConditions;
62 } // subInitGameConditions
65 // ==========================================================================
67 // Locate Murphy and init location.
68 // ==========================================================================
76 for (si = 0; si <= LevelMax - 1; si++)
78 if (PlayField16[si] == fiMurphy)
88 int InitMurphyPosB(int si)
92 MurphyYPos = GetStretchY(si) / Stretch;
93 MurphyXPos = GetStretchX(si) / Stretch;
95 MurphyScreenXPos = GetStretchX(si); // Murphy's screen x-position
96 MurphyScreenYPos = GetStretchY(si); // Murphy's screen y-position
98 // To Do: draw Murphy in location ax
99 StretchedSprites.BltEx(MurphyScreenXPos, MurphyScreenYPos, fiMurphy);
101 MurphyScreenXPos = MurphyScreenXPos / Stretch;
102 MurphyScreenYPos = MurphyScreenYPos / Stretch;
104 subCalculateScreenScrollPos(); // calculate screen start addrs
110 SoftScrollTo(ScreenScrollXPos, ScreenScrollYPos, 1000, 25);
114 ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
118 return InitMurphyPosB;
121 // ==========================================================================
123 // Convert to easy symbols and reset Infotron count If not ThenVer62
124 // ==========================================================================
126 int subConvertToEasySymbols()
128 int subConvertToEasySymbols;
130 // int ax, bx, cx, dx, di, X, Y, i;
131 // int ah, bh, ch, dh, al, bl, cl, dl, ZF;
132 int ax, bx, cx, dx, i;
143 if (al == 0xF1) // converted explosion?
145 MovLowByte(&PlayField16[i], 0x1F); // restore explosions
149 if (LowByte(GameBusyFlag) != 1) // free screen write?
151 if (ax == fiInfotron) // Infotron? -> yes--count!
154 if (ax == fiSnikSnak) // Snik Snak? -> yes--rearrange
157 if (ax == fiElectron) // Electron? -> yes--rearrange
161 // test for fancy RAM Chips:
162 if (ax == fiRAMLeft || ax == fiRAMRight)
165 if (ax == fiRAMTop || ax == fiRAMBottom)
168 if (ax < fiHWFirst) // All but deco hardware?
171 if (ax < fiRAMTop) // Decorative hardware?
175 if (ax < fiSpPortRight) // Gravity change ports only?
178 if (ax < fiSnikSnak) // Gravity change port! 'loc_g_2702:
183 loc_g_2704: // INFOTRON
184 dx = dx + 1; // Count Infotrons
187 loc_g_2707: // DECO RAM CHIPS
188 PlayField16[i] = fiRAM; // Convert to standard RAM chip
191 loc_g_270D: // DECO HARDWARE
192 PlayField16[i] = fiHardWare; // Convert to standard hardware
195 loc_g_2713: // SNIK-SNAK
196 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
199 MovHighByte(&PlayField16[i], 1); // turn left, step = NorthWest
203 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
206 PlayField16[i - FieldWidth] = 0x1011; // SnikSnak accessing from below, step = 0
207 PlayField16[i] = 0xFFFF;
211 if (PlayField16[i + 1] != 0) // 1 field right empty? -> point up
214 PlayField16[i + 1] = 0x2811; // SnikSnak accessing from left, step = 0
215 PlayField16[i] = 0xFFFF;
218 loc_g_2741: // ELECTRON
219 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
222 MovHighByte(&PlayField16[i], 1);
226 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
229 PlayField16[i - FieldWidth] = 0x1018; // 1 field up
230 PlayField16[i] = 0xFFFF;
234 if (PlayField16[i + 1] != 0) // 1 field right empty? -> no--point down
237 PlayField16[i + 1] = 0x2818;
238 PlayField16[i] = 0xFFFF;
241 loc_g_276F: // GRAVITY CHANGING PORTS
242 PlayField16[i] = (ax - 4) | 0x100; // Convert to standard ports
246 i = i + 1; // Next field
249 if (0 < cx) // Until all done 'loc_g_2782:
252 subConvertToEasySymbols = dx; // return InfotronCount
254 return subConvertToEasySymbols;
255 } // subConvertToEasySymbols
257 // ==========================================================================
259 // Reset Infotron count. Call immediately after subConvertToEasySymbols
260 // ==========================================================================
262 int ResetInfotronsNeeded(int dx)
264 int ResetInfotronsNeeded;
266 if (LInfo.InfotronsNeeded != 0) // Jump If equal (autodetect)
268 dx = LInfo.InfotronsNeeded;
271 InfotronsNeeded = LowByte(dx); // Remaining Infotrons needed
272 TotalInfotronsNeeded = InfotronsNeeded; // Number of Infotrons needed
273 subDisplayInfotronsNeeded();
275 return ResetInfotronsNeeded;
276 } // ResetInfotronsNeeded
279 // ==========================================================================
281 // Fetch and initialize a level
282 // ==========================================================================
284 int subFetchAndInitLevelB()
286 int subFetchAndInitLevelB;
288 boolean UpdatePlayTime;
290 MovLowByte(&data_SPtorunavail, 0); // no SP file
292 UpdatePlayTime = (0 == demo_stopped ? True : False);
294 subFetchAndInitLevelA(UpdatePlayTime);
296 return subFetchAndInitLevelB;
297 } // subFetchAndInitLevelb
299 int subFetchAndInitLevelA(boolean UpdatePlayTime)
301 int subFetchAndInitLevelA;
303 if (UpdatePlayTime && (0 == demo_stopped))
305 subUpdatePlayingTime(); // update playing time
308 D_ModeFlag = 0; // 1=debug D pressed (CPU use)
309 if (0 != demo_stopped) // 1=demo, 0=game
312 GameBusyFlag = 0; // restore scissors too
314 subFetchAndInitLevel(); // Fetch and initialize a level
316 GameBusyFlag = 1; // no free screen write
318 if (1 <= demo_stopped)
320 if (1 == demo_stopped)
322 DemoFlag = 0; // 1=demo, 0=game
323 demo_stopped = demo_stopped + 1;
327 DemoFlag = 0; // 1=demo, 0=game
331 DemoKeyCode = 0; // delete last demo key!
332 if (DemoFlag != 0) // don't allow during game! only in Demo
334 DemoOffset = DemoPointer; // init demo pointer
335 DemoKeyRepeatCounter = 1;
336 subGetNextDemoKey(); // get next demo byte
339 return subFetchAndInitLevelA;
340 } // subFetchAndInitLevela
342 int subFetchAndInitLevel()
344 int subFetchAndInitLevel;
346 int InfoCountInLevel;
348 Trace("modInitGameConditions", "--> subFetchAndInitLevel");
349 Trace("modInitGameConditions", "Call ReadLevel");
351 ReadLevel(); // Read LEVELS.DAT
353 Trace("modInitGameConditions", "ReadLevel return subFetchAndInitLeveled");
355 if (RecordDemoFlag == 1)
357 RecDemoRandomSeed = RandomSeed;
358 // Debug.Print "FetchRec: " & Hex(RandomSeed)
361 // If DemoFlag = 1 Then
362 // Debug.Print "FetchPlay: " & Hex(RandomSeed)
364 GameBusyFlag = -GameBusyFlag; // make <>1
366 Trace("modInitGameConditions", "subConvertToEasySymbols");
368 InfoCountInLevel = subConvertToEasySymbols(); // Convert to easy symbols
369 GameBusyFlag = -GameBusyFlag; // restore
371 Trace("modInitGameConditions", "subDisplayLevel");
373 subDisplayLevel(); // Paint (Init) game field
374 subDisplayPanel(); // Paint (Init) Panel
376 ResetInfotronsNeeded(InfoCountInLevel); // and reset Infotron count
380 Trace("modInitGameConditions", "subInitGameConditions");
382 subInitGameConditions(); // Init game conditions (vars)
384 InitMurphyPos(); // Locate Murphy + screen pos
386 Trace("modInitGameConditions", "<-- subFetchAndInitLevel");
388 return subFetchAndInitLevel;
389 } // subFetchAndInitLevel