1 // ----------------------------------------------------------------------------
2 // InitGameConditions.c
3 // ----------------------------------------------------------------------------
5 #include "InitGameConditions.h"
8 // ==========================================================================
10 // Init game conditions (variables)
11 // ==========================================================================
13 void subInitGameConditions()
17 MurphyVar0DAC = MurphyYPos;
18 MurphyVar0DAE = MurphyXPos;
19 MurphyVarFaceLeft = 0;
20 KillMurphyFlag = 0; // no "kill Murphy"
22 LeadOutCounter = 0; // quit flag: lead-out counter
23 RedDiskCount = 0; // Red disk counter
25 // ShowRedDiskCounter = 0; // show-red-disk time-out
27 YawnSleepCounter = 0; // Wake up sleeping Murphy
29 ExplosionShake = 0; // Force explosion flag off
31 TerminalMaxCycles = 0x7F;
32 YellowDisksExploded = 0;
36 // ShowPanel = 1 ' Force Panel on
37 // MainForm.PanelVisible = True;
39 EnterRepeatCounter = 0; // restart Enter repeat counter
40 SnikSnaksElectronsFrozen = 0; // Snik-Snaks and Electr. move!
42 SplitMoveFlag = 0; // Reset Split-through-ports
43 RedDiskReleasePhase = 0; // (re-)enable red disk release
44 RedDiskReleaseMurphyPos = 0; // Red disk was released here
48 // ==========================================================================
50 // Locate Murphy and init location.
51 // ==========================================================================
57 for (si = 0; si <= LevelMax - 1; si++)
58 if (PlayField16[si] == fiMurphy)
66 void InitMurphyPosB(int si)
68 MurphyYPos = GetStretchY(si) / Stretch;
69 MurphyXPos = GetStretchX(si) / Stretch;
71 MurphyScreenXPos = GetStretchX(si); // Murphy's screen x-position
72 MurphyScreenYPos = GetStretchY(si); // Murphy's screen y-position
74 // To Do: draw Murphy in location ax
75 StretchedSprites.BltImg(MurphyScreenXPos, MurphyScreenYPos, aniMurphy, 0);
77 MurphyScreenXPos = MurphyScreenXPos / Stretch;
78 MurphyScreenYPos = MurphyScreenYPos / Stretch;
80 subCalculateScreenScrollPos(); // calculate screen start addrs
85 SoftScrollTo(ScreenScrollXPos, ScreenScrollYPos, 1000, 25);
87 ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
92 // ==========================================================================
94 // Convert to easy symbols and reset Infotron count If not ThenVer62
95 // ==========================================================================
97 int subConvertToEasySymbols()
99 int ax, bx, cx, dx, i;
110 if (al == 0xF1) // converted explosion?
112 MovLowByte(&PlayField16[i], 0x1F); // restore explosions
116 if (LowByte(GameBusyFlag) != 1) // free screen write?
118 if (ax == fiInfotron) // Infotron? -> yes--count!
121 if (ax == fiSnikSnak) // Snik Snak? -> yes--rearrange
124 if (ax == fiElectron) // Electron? -> yes--rearrange
128 // test for fancy RAM Chips:
129 if (ax == fiRAMLeft || ax == fiRAMRight)
132 if (ax == fiRAMTop || ax == fiRAMBottom)
135 if (ax < fiHWFirst) // All but deco hardware?
138 if (ax < fiRAMTop) // Decorative hardware?
142 if (ax < fiSpPortRight) // Gravity change ports only?
145 if (ax < fiSnikSnak) // Gravity change port! 'loc_g_2702:
150 loc_g_2704: // INFOTRON
151 dx = dx + 1; // Count Infotrons
154 loc_g_2707: // DECO RAM CHIPS
155 PlayField16[i] = fiRAM; // Convert to standard RAM chip
158 loc_g_270D: // DECO HARDWARE
159 PlayField16[i] = fiHardWare; // Convert to standard hardware
162 loc_g_2713: // SNIK-SNAK
163 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
166 MovHighByte(&PlayField16[i], 1); // turn left, step = NorthWest
170 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
173 PlayField16[i - FieldWidth] = 0x1011; // SnikSnak accessing from below, step = 0
174 PlayField16[i] = 0xFFFF;
178 if (PlayField16[i + 1] != 0) // 1 field right empty? -> point up
181 PlayField16[i + 1] = 0x2811; // SnikSnak accessing from left, step = 0
182 PlayField16[i] = 0xFFFF;
185 loc_g_2741: // ELECTRON
186 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
189 MovHighByte(&PlayField16[i], 1);
193 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
196 PlayField16[i - FieldWidth] = 0x1018; // 1 field up
197 PlayField16[i] = 0xFFFF;
201 if (PlayField16[i + 1] != 0) // 1 field right empty? -> no--point down
204 PlayField16[i + 1] = 0x2818;
205 PlayField16[i] = 0xFFFF;
208 loc_g_276F: // GRAVITY CHANGING PORTS
209 PlayField16[i] = (ax - 4) | 0x100; // Convert to standard ports
213 i = i + 1; // Next field
216 if (0 < cx) // Until all done 'loc_g_2782:
219 return dx; // return InfotronCount
223 // ==========================================================================
225 // Reset Infotron count. Call immediately after subConvertToEasySymbols
226 // ==========================================================================
228 void ResetInfotronsNeeded(int dx)
230 if (LInfo.InfotronsNeeded != 0) // Jump If equal (autodetect)
232 dx = LInfo.InfotronsNeeded;
235 InfotronsNeeded = LowByte(dx); // Remaining Infotrons needed
236 TotalInfotronsNeeded = InfotronsNeeded; // Number of Infotrons needed
240 // ==========================================================================
242 // Fetch and initialize a level
243 // ==========================================================================
245 void subFetchAndInitLevelB()
247 boolean UpdatePlayTime;
250 UpdatePlayTime = (0 == demo_stopped ? True : False);
253 subFetchAndInitLevelA(UpdatePlayTime);
256 void subFetchAndInitLevelA(boolean UpdatePlayTime)
258 if (UpdatePlayTime && (0 == demo_stopped))
260 subUpdatePlayingTime(); // update playing time
263 D_ModeFlag = 0; // 1=debug D pressed (CPU use)
264 if (0 != demo_stopped) // 1=demo, 0=game
267 GameBusyFlag = 0; // restore scissors too
269 subFetchAndInitLevel(); // Fetch and initialize a level
271 GameBusyFlag = 1; // no free screen write
273 if (1 <= demo_stopped)
275 if (1 == demo_stopped)
277 DemoFlag = 0; // 1=demo, 0=game
278 demo_stopped = demo_stopped + 1;
282 DemoFlag = 0; // 1=demo, 0=game
286 DemoKeyCode = 0; // delete last demo key!
287 if (DemoFlag != 0) // don't allow during game! only in Demo
289 DemoOffset = DemoPointer; // init demo pointer
290 DemoKeyRepeatCounter = 1;
291 subGetNextDemoKey(); // get next demo byte
295 void subFetchAndInitLevel()
297 int InfoCountInLevel;
299 Trace("modInitGameConditions", "--> subFetchAndInitLevel");
300 Trace("modInitGameConditions", "Call ReadLevel");
302 ReadLevel(); // Read LEVELS.DAT
304 Trace("modInitGameConditions", "ReadLevel return subFetchAndInitLeveled");
306 if (RecordDemoFlag == 1)
307 RecDemoRandomSeed = RandomSeed;
309 GameBusyFlag = -GameBusyFlag; // make <>1
311 Trace("modInitGameConditions", "subConvertToEasySymbols");
313 InfoCountInLevel = subConvertToEasySymbols(); // Convert to easy symbols
314 GameBusyFlag = -GameBusyFlag; // restore
316 Trace("modInitGameConditions", "subDisplayLevel");
318 subDisplayLevel(); // Paint (Init) game field
320 ResetInfotronsNeeded(InfoCountInLevel); // and reset Infotron count
324 Trace("modInitGameConditions", "subInitGameConditions");
326 subInitGameConditions(); // Init game conditions (vars)
328 InitMurphyPos(); // Locate Murphy + screen pos
330 Trace("modInitGameConditions", "<-- subFetchAndInitLevel");