1 // ----------------------------------------------------------------------------
2 // InitGameConditions.c
3 // ----------------------------------------------------------------------------
5 #include "InitGameConditions.h"
8 // ==========================================================================
10 // Init game conditions (variables)
11 // ==========================================================================
13 void subInitGameConditions()
17 MurphyVarFaceLeft = 0;
18 KillMurphyFlag = 0; // no "kill Murphy"
20 LeadOutCounter = 0; // quit flag: lead-out counter
21 RedDiskCount = 0; // Red disk counter
23 YawnSleepCounter = 0; // Wake up sleeping Murphy
25 ExplosionShake = 0; // Force explosion flag off
27 TerminalMaxCycles = 0x7F;
28 YellowDisksExploded = 0;
32 EnterRepeatCounter = 0; // restart Enter repeat counter
33 SnikSnaksElectronsFrozen = 0; // Snik-Snaks and Electrons move!
35 SplitMoveFlag = 0; // Reset Split-through-ports
36 RedDiskReleasePhase = 0; // (re-)enable red disk release
37 RedDiskReleaseMurphyPos = 0; // Red disk was released here
41 // ==========================================================================
43 // Locate Murphy and init location.
44 // ==========================================================================
50 for (si = 0; si <= LevelMax - 1; si++)
51 if (PlayField16[si] == fiMurphy)
59 void InitMurphyPosB(int si)
61 MurphyYPos = GetStretchY(si) / Stretch;
62 MurphyXPos = GetStretchX(si) / Stretch;
64 MurphyScreenXPos = GetStretchX(si); // Murphy's screen x-position
65 MurphyScreenYPos = GetStretchY(si); // Murphy's screen y-position
67 // To Do: draw Murphy in location ax
68 StretchedSprites.BltImg(MurphyScreenXPos, MurphyScreenYPos, aniMurphy, 0);
70 MurphyScreenXPos = MurphyScreenXPos / Stretch;
71 MurphyScreenYPos = MurphyScreenYPos / Stretch;
73 subCalculateScreenScrollPos(); // calculate screen start addrs
78 SoftScrollTo(ScreenScrollXPos, ScreenScrollYPos, 1000, 25);
80 ScrollTo(ScreenScrollXPos, ScreenScrollYPos);
85 // ==========================================================================
87 // Convert to easy symbols and reset Infotron count If not ThenVer62
88 // ==========================================================================
90 int subConvertToEasySymbols()
92 int ax, bx, cx, dx, i;
103 if (al == 0xF1) // converted explosion?
105 MovLowByte(&PlayField16[i], 0x1F); // restore explosions
109 if (LowByte(GameBusyFlag) != 1) // free screen write?
111 if (ax == fiInfotron) // Infotron? -> yes--count!
114 if (ax == fiSnikSnak) // Snik Snak? -> yes--rearrange
117 if (ax == fiElectron) // Electron? -> yes--rearrange
121 // test for fancy RAM Chips:
122 if (ax == fiRAMLeft || ax == fiRAMRight)
125 if (ax == fiRAMTop || ax == fiRAMBottom)
128 if (ax < fiHWFirst) // All but deco hardware?
131 if (ax < fiRAMTop) // Decorative hardware?
135 if (ax < fiSpPortRight) // Gravity change ports only?
138 if (ax < fiSnikSnak) // Gravity change port! 'loc_g_2702:
143 loc_g_2704: // INFOTRON
144 dx = dx + 1; // Count Infotrons
147 loc_g_2707: // DECO RAM CHIPS
148 PlayField16[i] = fiRAM; // Convert to standard RAM chip
151 loc_g_270D: // DECO HARDWARE
152 PlayField16[i] = fiHardWare; // Convert to standard hardware
155 loc_g_2713: // SNIK-SNAK
156 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
159 MovHighByte(&PlayField16[i], 1); // turn left, step = NorthWest
163 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
166 PlayField16[i - FieldWidth] = 0x1011; // SnikSnak accessing from below, step = 0
167 PlayField16[i] = 0xFFFF;
171 if (PlayField16[i + 1] != 0) // 1 field right empty? -> point up
174 PlayField16[i + 1] = 0x2811; // SnikSnak accessing from left, step = 0
175 PlayField16[i] = 0xFFFF;
178 loc_g_2741: // ELECTRON
179 if (PlayField16[i - 1] != 0) // 1 field left empty? -> no--try up
182 MovHighByte(&PlayField16[i], 1);
186 if (PlayField16[i - FieldWidth] != 0) // 1 field up empty? -> no--try right
189 PlayField16[i - FieldWidth] = 0x1018; // 1 field up
190 PlayField16[i] = 0xFFFF;
194 if (PlayField16[i + 1] != 0) // 1 field right empty? -> no--point down
197 PlayField16[i + 1] = 0x2818;
198 PlayField16[i] = 0xFFFF;
201 loc_g_276F: // GRAVITY CHANGING PORTS
202 PlayField16[i] = (ax - 4) | 0x100; // Convert to standard ports
206 i = i + 1; // Next field
209 if (0 < cx) // Until all done 'loc_g_2782:
212 return dx; // return InfotronCount
216 // ==========================================================================
218 // Reset Infotron count. Call immediately after subConvertToEasySymbols
219 // ==========================================================================
221 void ResetInfotronsNeeded(int dx)
223 if (LInfo.InfotronsNeeded != 0) // Jump If equal (autodetect)
224 dx = LInfo.InfotronsNeeded;
226 InfotronsNeeded = LowByte(dx); // Remaining Infotrons needed
227 TotalInfotronsNeeded = InfotronsNeeded; // Number of Infotrons needed
231 // ==========================================================================
233 // Fetch and initialize a level
234 // ==========================================================================
236 void subFetchAndInitLevelB()
238 boolean UpdatePlayTime;
241 UpdatePlayTime = (0 == demo_stopped ? True : False);
244 subFetchAndInitLevelA(UpdatePlayTime);
247 void subFetchAndInitLevelA(boolean UpdatePlayTime)
249 D_ModeFlag = 0; // 1=debug D pressed (CPU use)
250 if (0 != demo_stopped) // 1=demo, 0=game
253 GameBusyFlag = 0; // restore scissors too
255 subFetchAndInitLevel(); // Fetch and initialize a level
257 GameBusyFlag = 1; // no free screen write
259 if (1 <= demo_stopped)
261 if (1 == demo_stopped)
263 DemoFlag = 0; // 1=demo, 0=game
264 demo_stopped = demo_stopped + 1;
268 DemoFlag = 0; // 1=demo, 0=game
272 DemoKeyCode = 0; // delete last demo key!
273 if (DemoFlag != 0) // don't allow during game! only in Demo
275 DemoOffset = DemoPointer; // init demo pointer
276 DemoKeyRepeatCounter = 1;
277 subGetNextDemoKey(); // get next demo byte
281 void subFetchAndInitLevel()
283 int InfoCountInLevel;
285 ReadLevel(); // Read LEVELS.DAT
287 if (RecordDemoFlag == 1)
288 RecDemoRandomSeed = RandomSeed;
290 GameBusyFlag = -GameBusyFlag; // make <>1
292 InfoCountInLevel = subConvertToEasySymbols(); // Convert to easy symbols
293 GameBusyFlag = -GameBusyFlag; // restore
295 subDisplayLevel(); // Paint (Init) game field
297 ResetInfotronsNeeded(InfoCountInLevel); // and reset Infotron count
299 subInitGameConditions(); // Init game conditions (vars)
301 InitMurphyPos(); // Locate Murphy + screen pos