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
107 printf(":1: %d, %d [%d, %d] [%d, %d] [%d, %d]\n",
109 mScrollX_last, mScrollY_last,
110 ScreenScrollXPos, ScreenScrollYPos,
118 SoftScrollTo(ScreenScrollXPos, ScreenScrollYPos, 1000, 25);
122 ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
127 printf(":2: %d, %d [%d, %d] [%d, %d] [%d, %d]\n",
129 mScrollX_last, mScrollY_last,
130 ScreenScrollXPos, ScreenScrollYPos,
134 return InitMurphyPosB;
137 // ==========================================================================
139 // Convert to easy symbols and reset Infotron count If not ThenVer62
140 // ==========================================================================
142 int subConvertToEasySymbols()
144 int subConvertToEasySymbols;
146 // int ax, bx, cx, dx, di, X, Y, i;
147 // int ah, bh, ch, dh, al, bl, cl, dl, ZF;
148 int ax, bx, cx, dx, i;
159 if (al == 0xF1) // converted explosion?
161 MovLowByte(&PlayField16[i], 0x1F); // restore explosions
165 if (LowByte(GameBusyFlag) != 1) // free screen write?
167 if (ax == fiInfotron) // Infotron? -> yes--count!
170 if (ax == fiSnikSnak) // Snik Snak? -> yes--rearrange
173 if (ax == fiElectron) // Electron? -> yes--rearrange
177 // test for fancy RAM Chips:
178 if (ax == fiRAMLeft || ax == fiRAMRight)
181 if (ax == fiRAMTop || ax == fiRAMBottom)
184 if (ax < fiHWFirst) // All but deco hardware?
187 if (ax < fiRAMTop) // Decorative hardware?
191 if (ax < fiSpPortRight) // Gravity change ports only?
194 if (ax < fiSnikSnak) // Gravity change port! 'loc_g_2702:
199 loc_g_2704: // INFOTRON
200 dx = dx + 1; // Count Infotrons
203 loc_g_2707: // DECO RAM CHIPS
204 PlayField16[i] = fiRAM; // Convert to standard RAM chip
207 loc_g_270D: // DECO HARDWARE
208 PlayField16[i] = fiHardWare; // Convert to standard hardware
211 loc_g_2713: // SNIK-SNAK
212 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
215 MovHighByte(&PlayField16[i], 1); // turn left, step = NorthWest
219 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
222 PlayField16[i - FieldWidth] = 0x1011; // SnikSnak accessing from below, step = 0
223 PlayField16[i] = 0xFFFF;
227 if (PlayField16[i + 1] != 0) // 1 field right empty? -> point up
230 PlayField16[i + 1] = 0x2811; // SnikSnak accessing from left, step = 0
231 PlayField16[i] = 0xFFFF;
234 loc_g_2741: // ELECTRON
235 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
238 MovHighByte(&PlayField16[i], 1);
242 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
245 PlayField16[i - FieldWidth] = 0x1018; // 1 field up
246 PlayField16[i] = 0xFFFF;
250 if (PlayField16[i + 1] != 0) // 1 field right empty? -> no--point down
253 PlayField16[i + 1] = 0x2818;
254 PlayField16[i] = 0xFFFF;
257 loc_g_276F: // GRAVITY CHANGING PORTS
258 PlayField16[i] = (ax - 4) | 0x100; // Convert to standard ports
262 i = i + 1; // Next field
265 if (0 < cx) // Until all done 'loc_g_2782:
268 subConvertToEasySymbols = dx; // return InfotronCount
270 return subConvertToEasySymbols;
271 } // subConvertToEasySymbols
273 // ==========================================================================
275 // Reset Infotron count. Call immediately after subConvertToEasySymbols
276 // ==========================================================================
278 int ResetInfotronsNeeded(int dx)
280 int ResetInfotronsNeeded;
282 if (LInfo.InfotronsNeeded != 0) // Jump If equal (autodetect)
284 dx = LInfo.InfotronsNeeded;
287 InfotronsNeeded = LowByte(dx); // Remaining Infotrons needed
288 TotalInfotronsNeeded = InfotronsNeeded; // Number of Infotrons needed
289 subDisplayInfotronsNeeded();
291 return ResetInfotronsNeeded;
292 } // ResetInfotronsNeeded
295 // ==========================================================================
297 // Fetch and initialize a level
298 // ==========================================================================
300 int subFetchAndInitLevelB()
302 int subFetchAndInitLevelB;
304 boolean UpdatePlayTime;
306 MovLowByte(&data_SPtorunavail, 0); // no SP file
308 UpdatePlayTime = (0 == demo_stopped ? True : False);
310 subFetchAndInitLevelA(UpdatePlayTime);
312 return subFetchAndInitLevelB;
313 } // subFetchAndInitLevelb
315 int subFetchAndInitLevelA(boolean UpdatePlayTime)
317 int subFetchAndInitLevelA;
319 if (UpdatePlayTime && (0 == demo_stopped))
321 subUpdatePlayingTime(); // update playing time
324 D_ModeFlag = 0; // 1=debug D pressed (CPU use)
325 if (0 != demo_stopped) // 1=demo, 0=game
328 GameBusyFlag = 0; // restore scissors too
330 subFetchAndInitLevel(); // Fetch and initialize a level
332 GameBusyFlag = 1; // no free screen write
334 if (1 <= demo_stopped)
336 if (1 == demo_stopped)
338 DemoFlag = 0; // 1=demo, 0=game
339 demo_stopped = demo_stopped + 1;
343 DemoFlag = 0; // 1=demo, 0=game
347 DemoKeyCode = 0; // delete last demo key!
348 if (DemoFlag != 0) // don't allow during game! only in Demo
350 DemoOffset = DemoPointer; // init demo pointer
351 DemoKeyRepeatCounter = 1;
352 subGetNextDemoKey(); // get next demo byte
355 return subFetchAndInitLevelA;
356 } // subFetchAndInitLevela
358 int subFetchAndInitLevel()
360 int subFetchAndInitLevel;
362 int InfoCountInLevel;
364 Trace("modInitGameConditions", "--> subFetchAndInitLevel");
365 Trace("modInitGameConditions", "Call ReadLevel");
367 ReadLevel(); // Read LEVELS.DAT
369 Trace("modInitGameConditions", "ReadLevel return subFetchAndInitLeveled");
371 if (RecordDemoFlag == 1)
373 RecDemoRandomSeed = RandomSeed;
374 // Debug.Print "FetchRec: " & Hex(RandomSeed)
377 // If DemoFlag = 1 Then
378 // Debug.Print "FetchPlay: " & Hex(RandomSeed)
380 GameBusyFlag = -GameBusyFlag; // make <>1
382 Trace("modInitGameConditions", "subConvertToEasySymbols");
384 InfoCountInLevel = subConvertToEasySymbols(); // Convert to easy symbols
385 GameBusyFlag = -GameBusyFlag; // restore
387 Trace("modInitGameConditions", "subDisplayLevel");
389 subDisplayLevel(); // Paint (Init) game field
390 subDisplayPanel(); // Paint (Init) Panel
392 ResetInfotronsNeeded(InfoCountInLevel); // and reset Infotron count
396 Trace("modInitGameConditions", "subInitGameConditions");
398 subInitGameConditions(); // Init game conditions (vars)
400 InitMurphyPos(); // Locate Murphy + screen pos
402 Trace("modInitGameConditions", "<-- subFetchAndInitLevel");
404 return subFetchAndInitLevel;
405 } // subFetchAndInitLevel