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
109 SoftScrollTo(ScreenScrollXPos, ScreenScrollYPos, 1000, 25);
113 ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
117 return InitMurphyPosB;
120 // ==========================================================================
122 // Convert to easy symbols and reset Infotron count If not ThenVer62
123 // ==========================================================================
125 int subConvertToEasySymbols()
127 int subConvertToEasySymbols;
129 // int ax, bx, cx, dx, di, X, Y, i;
130 // int ah, bh, ch, dh, al, bl, cl, dl, ZF;
131 int ax, bx, cx, dx, i;
142 if (al == 0xF1) // converted explosion?
144 MovLowByte(&PlayField16[i], 0x1F); // restore explosions
148 if (LowByte(GameBusyFlag) != 1) // free screen write?
150 if (ax == fiInfotron) // Infotron? -> yes--count!
153 if (ax == fiSnikSnak) // Snik Snak? -> yes--rearrange
156 if (ax == fiElectron) // Electron? -> yes--rearrange
160 // test for fancy RAM Chips:
161 if (ax == fiRAMLeft || ax == fiRAMRight)
164 if (ax == fiRAMTop || ax == fiRAMBottom)
167 if (ax < fiHWFirst) // All but deco hardware?
170 if (ax < fiRAMTop) // Decorative hardware?
174 if (ax < fiSpPortRight) // Gravity change ports only?
177 if (ax < fiSnikSnak) // Gravity change port! 'loc_g_2702:
182 loc_g_2704: // INFOTRON
183 dx = dx + 1; // Count Infotrons
186 loc_g_2707: // DECO RAM CHIPS
187 PlayField16[i] = fiRAM; // Convert to standard RAM chip
190 loc_g_270D: // DECO HARDWARE
191 PlayField16[i] = fiHardWare; // Convert to standard hardware
194 loc_g_2713: // SNIK-SNAK
195 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
198 MovHighByte(&PlayField16[i], 1); // turn left, step = NorthWest
202 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
205 PlayField16[i - FieldWidth] = 0x1011; // SnikSnak accessing from below, step = 0
206 PlayField16[i] = 0xFFFF;
210 if (PlayField16[i + 1] != 0) // 1 field right empty? -> point up
213 PlayField16[i + 1] = 0x2811; // SnikSnak accessing from left, step = 0
214 PlayField16[i] = 0xFFFF;
217 loc_g_2741: // ELECTRON
218 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
221 MovHighByte(&PlayField16[i], 1);
225 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
228 PlayField16[i - FieldWidth] = 0x1018; // 1 field up
229 PlayField16[i] = 0xFFFF;
233 if (PlayField16[i + 1] != 0) // 1 field right empty? -> no--point down
236 PlayField16[i + 1] = 0x2818;
237 PlayField16[i] = 0xFFFF;
240 loc_g_276F: // GRAVITY CHANGING PORTS
241 PlayField16[i] = (ax - 4) | 0x100; // Convert to standard ports
245 i = i + 1; // Next field
248 if (0 < cx) // Until all done 'loc_g_2782:
251 subConvertToEasySymbols = dx; // return InfotronCount
253 return subConvertToEasySymbols;
254 } // subConvertToEasySymbols
256 // ==========================================================================
258 // Reset Infotron count. Call immediately after subConvertToEasySymbols
259 // ==========================================================================
261 int ResetInfotronsNeeded(int dx)
263 int ResetInfotronsNeeded;
265 if (LInfo.InfotronsNeeded != 0) // Jump If equal (autodetect)
267 dx = LInfo.InfotronsNeeded;
270 InfotronsNeeded = LowByte(dx); // Remaining Infotrons needed
271 TotalInfotronsNeeded = InfotronsNeeded; // Number of Infotrons needed
272 subDisplayInfotronsNeeded();
274 return ResetInfotronsNeeded;
275 } // ResetInfotronsNeeded
278 // ==========================================================================
280 // Fetch and initialize a level
281 // ==========================================================================
283 int subFetchAndInitLevelB()
285 int subFetchAndInitLevelB;
287 boolean UpdatePlayTime;
289 MovLowByte(&data_SPtorunavail, 0); // no SP file
291 UpdatePlayTime = (0 == demo_stopped ? True : True);
293 subFetchAndInitLevelA(UpdatePlayTime);
295 return subFetchAndInitLevelB;
296 } // subFetchAndInitLevelb
298 int subFetchAndInitLevelA(boolean UpdatePlayTime)
300 int subFetchAndInitLevelA;
302 if (UpdatePlayTime && (0 == demo_stopped))
304 subUpdatePlayingTime(); // update playing time
307 D_ModeFlag = 0; // 1=debug D pressed (CPU use)
308 if (0 != demo_stopped) // 1=demo, 0=game
311 GameBusyFlag = 0; // restore scissors too
313 subFetchAndInitLevel(); // Fetch and initialize a level
315 GameBusyFlag = 1; // no free screen write
317 if (1 <= demo_stopped)
319 if (1 == demo_stopped)
321 DemoFlag = 0; // 1=demo, 0=game
322 demo_stopped = demo_stopped + 1;
326 DemoFlag = 0; // 1=demo, 0=game
330 DemoKeyCode = 0; // delete last demo key!
331 if (DemoFlag != 0) // don't allow during game! only in Demo
333 DemoOffset = DemoPointer; // init demo pointer
334 DemoKeyRepeatCounter = 1;
335 subGetNextDemoKey(); // get next demo byte
338 return subFetchAndInitLevelA;
339 } // subFetchAndInitLevela
341 int subFetchAndInitLevel()
343 int subFetchAndInitLevel;
345 int InfoCountInLevel;
347 Trace("modInitGameConditions", "--> subFetchAndInitLevel");
348 Trace("modInitGameConditions", "Call ReadLevel");
350 ReadLevel(); // Read LEVELS.DAT
352 Trace("modInitGameConditions", "ReadLevel return subFetchAndInitLeveled");
354 if (RecordDemoFlag == 1)
356 RecDemoRandomSeed = RandomSeed;
357 // Debug.Print "FetchRec: " & Hex(RandomSeed)
360 // If DemoFlag = 1 Then
361 // Debug.Print "FetchPlay: " & Hex(RandomSeed)
363 GameBusyFlag = -GameBusyFlag; // make <>1
365 Trace("modInitGameConditions", "subConvertToEasySymbols");
367 InfoCountInLevel = subConvertToEasySymbols(); // Convert to easy symbols
368 GameBusyFlag = -GameBusyFlag; // restore
370 Trace("modInitGameConditions", "subDisplayLevel");
372 subDisplayLevel(); // Paint (Init) game field
373 subDisplayPanel(); // Paint (Init) Panel
375 ResetInfotronsNeeded(InfoCountInLevel); // and reset Infotron count
379 Trace("modInitGameConditions", "subInitGameConditions");
381 subInitGameConditions(); // Init game conditions (vars)
383 InitMurphyPos(); // Locate Murphy + screen pos
385 Trace("modInitGameConditions", "<-- subFetchAndInitLevel");
387 return subFetchAndInitLevel;
388 } // subFetchAndInitLevel