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
100 StretchedSprites.BltImg(MurphyScreenXPos, MurphyScreenYPos, aniMurphy, 0);
102 StretchedSprites.BltEx(MurphyScreenXPos, MurphyScreenYPos, fiMurphy);
105 MurphyScreenXPos = MurphyScreenXPos / Stretch;
106 MurphyScreenYPos = MurphyScreenYPos / Stretch;
108 subCalculateScreenScrollPos(); // calculate screen start addrs
111 printf(":1: %d, %d [%d, %d] [%d, %d] [%d, %d]\n",
113 mScrollX_last, mScrollY_last,
114 ScreenScrollXPos, ScreenScrollYPos,
122 SoftScrollTo(ScreenScrollXPos, ScreenScrollYPos, 1000, 25);
126 ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
131 printf(":2: %d, %d [%d, %d] [%d, %d] [%d, %d]\n",
133 mScrollX_last, mScrollY_last,
134 ScreenScrollXPos, ScreenScrollYPos,
138 return InitMurphyPosB;
141 // ==========================================================================
143 // Convert to easy symbols and reset Infotron count If not ThenVer62
144 // ==========================================================================
146 int subConvertToEasySymbols()
148 int subConvertToEasySymbols;
150 // int ax, bx, cx, dx, di, X, Y, i;
151 // int ah, bh, ch, dh, al, bl, cl, dl, ZF;
152 int ax, bx, cx, dx, i;
163 if (al == 0xF1) // converted explosion?
165 MovLowByte(&PlayField16[i], 0x1F); // restore explosions
169 if (LowByte(GameBusyFlag) != 1) // free screen write?
171 if (ax == fiInfotron) // Infotron? -> yes--count!
174 if (ax == fiSnikSnak) // Snik Snak? -> yes--rearrange
177 if (ax == fiElectron) // Electron? -> yes--rearrange
181 // test for fancy RAM Chips:
182 if (ax == fiRAMLeft || ax == fiRAMRight)
185 if (ax == fiRAMTop || ax == fiRAMBottom)
188 if (ax < fiHWFirst) // All but deco hardware?
191 if (ax < fiRAMTop) // Decorative hardware?
195 if (ax < fiSpPortRight) // Gravity change ports only?
198 if (ax < fiSnikSnak) // Gravity change port! 'loc_g_2702:
203 loc_g_2704: // INFOTRON
204 dx = dx + 1; // Count Infotrons
207 loc_g_2707: // DECO RAM CHIPS
208 PlayField16[i] = fiRAM; // Convert to standard RAM chip
211 loc_g_270D: // DECO HARDWARE
212 PlayField16[i] = fiHardWare; // Convert to standard hardware
215 loc_g_2713: // SNIK-SNAK
216 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
219 MovHighByte(&PlayField16[i], 1); // turn left, step = NorthWest
223 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
226 PlayField16[i - FieldWidth] = 0x1011; // SnikSnak accessing from below, step = 0
227 PlayField16[i] = 0xFFFF;
231 if (PlayField16[i + 1] != 0) // 1 field right empty? -> point up
234 PlayField16[i + 1] = 0x2811; // SnikSnak accessing from left, step = 0
235 PlayField16[i] = 0xFFFF;
238 loc_g_2741: // ELECTRON
239 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
242 MovHighByte(&PlayField16[i], 1);
246 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
249 PlayField16[i - FieldWidth] = 0x1018; // 1 field up
250 PlayField16[i] = 0xFFFF;
254 if (PlayField16[i + 1] != 0) // 1 field right empty? -> no--point down
257 PlayField16[i + 1] = 0x2818;
258 PlayField16[i] = 0xFFFF;
261 loc_g_276F: // GRAVITY CHANGING PORTS
262 PlayField16[i] = (ax - 4) | 0x100; // Convert to standard ports
266 i = i + 1; // Next field
269 if (0 < cx) // Until all done 'loc_g_2782:
272 subConvertToEasySymbols = dx; // return InfotronCount
274 return subConvertToEasySymbols;
275 } // subConvertToEasySymbols
277 // ==========================================================================
279 // Reset Infotron count. Call immediately after subConvertToEasySymbols
280 // ==========================================================================
282 int ResetInfotronsNeeded(int dx)
284 int ResetInfotronsNeeded;
286 if (LInfo.InfotronsNeeded != 0) // Jump If equal (autodetect)
288 dx = LInfo.InfotronsNeeded;
291 InfotronsNeeded = LowByte(dx); // Remaining Infotrons needed
292 TotalInfotronsNeeded = InfotronsNeeded; // Number of Infotrons needed
293 subDisplayInfotronsNeeded();
295 return ResetInfotronsNeeded;
296 } // ResetInfotronsNeeded
299 // ==========================================================================
301 // Fetch and initialize a level
302 // ==========================================================================
304 int subFetchAndInitLevelB()
306 int subFetchAndInitLevelB;
308 boolean UpdatePlayTime;
310 MovLowByte(&data_SPtorunavail, 0); // no SP file
312 UpdatePlayTime = (0 == demo_stopped ? True : False);
314 subFetchAndInitLevelA(UpdatePlayTime);
316 return subFetchAndInitLevelB;
317 } // subFetchAndInitLevelb
319 int subFetchAndInitLevelA(boolean UpdatePlayTime)
321 int subFetchAndInitLevelA;
323 if (UpdatePlayTime && (0 == demo_stopped))
325 subUpdatePlayingTime(); // update playing time
328 D_ModeFlag = 0; // 1=debug D pressed (CPU use)
329 if (0 != demo_stopped) // 1=demo, 0=game
332 GameBusyFlag = 0; // restore scissors too
334 subFetchAndInitLevel(); // Fetch and initialize a level
336 GameBusyFlag = 1; // no free screen write
338 if (1 <= demo_stopped)
340 if (1 == demo_stopped)
342 DemoFlag = 0; // 1=demo, 0=game
343 demo_stopped = demo_stopped + 1;
347 DemoFlag = 0; // 1=demo, 0=game
351 DemoKeyCode = 0; // delete last demo key!
352 if (DemoFlag != 0) // don't allow during game! only in Demo
354 DemoOffset = DemoPointer; // init demo pointer
355 DemoKeyRepeatCounter = 1;
356 subGetNextDemoKey(); // get next demo byte
359 return subFetchAndInitLevelA;
360 } // subFetchAndInitLevela
362 int subFetchAndInitLevel()
364 int subFetchAndInitLevel;
366 int InfoCountInLevel;
368 Trace("modInitGameConditions", "--> subFetchAndInitLevel");
369 Trace("modInitGameConditions", "Call ReadLevel");
371 ReadLevel(); // Read LEVELS.DAT
373 Trace("modInitGameConditions", "ReadLevel return subFetchAndInitLeveled");
375 if (RecordDemoFlag == 1)
377 RecDemoRandomSeed = RandomSeed;
378 // Debug.Print "FetchRec: " & Hex(RandomSeed)
381 // If DemoFlag = 1 Then
382 // Debug.Print "FetchPlay: " & Hex(RandomSeed)
384 GameBusyFlag = -GameBusyFlag; // make <>1
386 Trace("modInitGameConditions", "subConvertToEasySymbols");
388 InfoCountInLevel = subConvertToEasySymbols(); // Convert to easy symbols
389 GameBusyFlag = -GameBusyFlag; // restore
391 Trace("modInitGameConditions", "subDisplayLevel");
393 subDisplayLevel(); // Paint (Init) game field
394 subDisplayPanel(); // Paint (Init) Panel
396 ResetInfotronsNeeded(InfoCountInLevel); // and reset Infotron count
400 Trace("modInitGameConditions", "subInitGameConditions");
402 subInitGameConditions(); // Init game conditions (vars)
404 InitMurphyPos(); // Locate Murphy + screen pos
406 Trace("modInitGameConditions", "<-- subFetchAndInitLevel");
408 return subFetchAndInitLevel;
409 } // subFetchAndInitLevel