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
106 printf("::: InitGameConditions.c: ScreenScroll{X,Y}Pos %d, %d\n",
107 ScreenScrollXPos, ScreenScrollYPos);
113 SoftScrollTo(ScreenScrollXPos, ScreenScrollYPos, 1000, 25);
117 ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
121 return InitMurphyPosB;
124 // ==========================================================================
126 // Convert to easy symbols and reset Infotron count If not ThenVer62
127 // ==========================================================================
129 int subConvertToEasySymbols()
131 int subConvertToEasySymbols;
133 // int ax, bx, cx, dx, di, X, Y, i;
134 // int ah, bh, ch, dh, al, bl, cl, dl, ZF;
135 int ax, bx, cx, dx, i;
146 if (al == 0xF1) // converted explosion?
148 MovLowByte(&PlayField16[i], 0x1F); // restore explosions
152 if (LowByte(GameBusyFlag) != 1) // free screen write?
154 if (ax == fiInfotron) // Infotron? -> yes--count!
157 if (ax == fiSnikSnak) // Snik Snak? -> yes--rearrange
160 if (ax == fiElectron) // Electron? -> yes--rearrange
164 // test for fancy RAM Chips:
165 if (ax == fiRAMLeft || ax == fiRAMRight)
168 if (ax == fiRAMTop || ax == fiRAMBottom)
171 if (ax < fiHWFirst) // All but deco hardware?
174 if (ax < fiRAMTop) // Decorative hardware?
178 if (ax < fiSpPortRight) // Gravity change ports only?
181 if (ax < fiSnikSnak) // Gravity change port! 'loc_g_2702:
186 loc_g_2704: // INFOTRON
187 dx = dx + 1; // Count Infotrons
190 loc_g_2707: // DECO RAM CHIPS
191 PlayField16[i] = fiRAM; // Convert to standard RAM chip
194 loc_g_270D: // DECO HARDWARE
195 PlayField16[i] = fiHardWare; // Convert to standard hardware
198 loc_g_2713: // SNIK-SNAK
199 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
202 MovHighByte(&PlayField16[i], 1); // turn left, step = NorthWest
206 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
209 PlayField16[i - FieldWidth] = 0x1011; // SnikSnak accessing from below, step = 0
210 PlayField16[i] = 0xFFFF;
214 if (PlayField16[i + 1] != 0) // 1 field right empty? -> point up
217 PlayField16[i + 1] = 0x2811; // SnikSnak accessing from left, step = 0
218 PlayField16[i] = 0xFFFF;
221 loc_g_2741: // ELECTRON
222 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
225 MovHighByte(&PlayField16[i], 1);
229 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
232 PlayField16[i - FieldWidth] = 0x1018; // 1 field up
233 PlayField16[i] = 0xFFFF;
237 if (PlayField16[i + 1] != 0) // 1 field right empty? -> no--point down
240 PlayField16[i + 1] = 0x2818;
241 PlayField16[i] = 0xFFFF;
244 loc_g_276F: // GRAVITY CHANGING PORTS
245 PlayField16[i] = (ax - 4) | 0x100; // Convert to standard ports
249 i = i + 1; // Next field
252 if (0 < cx) // Until all done 'loc_g_2782:
255 subConvertToEasySymbols = dx; // return InfotronCount
257 return subConvertToEasySymbols;
258 } // subConvertToEasySymbols
260 // ==========================================================================
262 // Reset Infotron count. Call immediately after subConvertToEasySymbols
263 // ==========================================================================
265 int ResetInfotronsNeeded(int dx)
267 int ResetInfotronsNeeded;
269 if (LInfo.InfotronsNeeded != 0) // Jump If equal (autodetect)
271 dx = LInfo.InfotronsNeeded;
274 InfotronsNeeded = LowByte(dx); // Remaining Infotrons needed
275 TotalInfotronsNeeded = InfotronsNeeded; // Number of Infotrons needed
276 subDisplayInfotronsNeeded();
278 return ResetInfotronsNeeded;
279 } // ResetInfotronsNeeded
282 // ==========================================================================
284 // Fetch and initialize a level
285 // ==========================================================================
287 int subFetchAndInitLevelB()
289 int subFetchAndInitLevelB;
291 boolean UpdatePlayTime;
293 MovLowByte(&data_SPtorunavail, 0); // no SP file
295 UpdatePlayTime = (0 == demo_stopped ? True : True);
297 subFetchAndInitLevelA(UpdatePlayTime);
299 return subFetchAndInitLevelB;
300 } // subFetchAndInitLevelb
302 int subFetchAndInitLevelA(boolean UpdatePlayTime)
304 int subFetchAndInitLevelA;
306 if (UpdatePlayTime && (0 == demo_stopped))
308 subUpdatePlayingTime(); // update playing time
311 D_ModeFlag = 0; // 1=debug D pressed (CPU use)
312 if (0 != demo_stopped) // 1=demo, 0=game
315 GameBusyFlag = 0; // restore scissors too
317 subFetchAndInitLevel(); // Fetch and initialize a level
319 GameBusyFlag = 1; // no free screen write
321 if (1 <= demo_stopped)
323 if (1 == demo_stopped)
325 DemoFlag = 0; // 1=demo, 0=game
326 demo_stopped = demo_stopped + 1;
330 DemoFlag = 0; // 1=demo, 0=game
334 DemoKeyCode = 0; // delete last demo key!
335 if (DemoFlag != 0) // don't allow during game! only in Demo
337 DemoOffset = DemoPointer; // init demo pointer
338 DemoKeyRepeatCounter = 1;
339 subGetNextDemoKey(); // get next demo byte
342 return subFetchAndInitLevelA;
343 } // subFetchAndInitLevela
345 int subFetchAndInitLevel()
347 int subFetchAndInitLevel;
349 int InfoCountInLevel;
351 Trace("modInitGameConditions", "--> subFetchAndInitLevel");
352 Trace("modInitGameConditions", "Call ReadLevel");
354 ReadLevel(); // Read LEVELS.DAT
356 Trace("modInitGameConditions", "ReadLevel return subFetchAndInitLeveled");
358 if (RecordDemoFlag == 1)
360 RecDemoRandomSeed = RandomSeed;
361 // Debug.Print "FetchRec: " & Hex(RandomSeed)
364 // If DemoFlag = 1 Then
365 // Debug.Print "FetchPlay: " & Hex(RandomSeed)
367 GameBusyFlag = -GameBusyFlag; // make <>1
369 Trace("modInitGameConditions", "subConvertToEasySymbols");
371 InfoCountInLevel = subConvertToEasySymbols(); // Convert to easy symbols
372 GameBusyFlag = -GameBusyFlag; // restore
374 Trace("modInitGameConditions", "subDisplayLevel");
376 subDisplayLevel(); // Paint (Init) game field
377 subDisplayPanel(); // Paint (Init) Panel
379 ResetInfotronsNeeded(InfoCountInLevel); // and reset Infotron count
383 Trace("modInitGameConditions", "subInitGameConditions");
385 subInitGameConditions(); // Init game conditions (vars)
387 InitMurphyPos(); // Locate Murphy + screen pos
389 Trace("modInitGameConditions", "<-- subFetchAndInitLevel");
391 return subFetchAndInitLevel;
392 } // subFetchAndInitLevel