1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "BugsTerminals.h"
12 // ==========================================================================
15 // ==========================================================================
17 void subAnimateBugs(int si)
21 if (fiBug != LowByte(PlayField16[si]))
24 bl = SgnHighByte(PlayField16[si]); // get and increment sequence number
26 if ((TimerVar & 3) == 0)
31 bl = subGetRandomNumber(); // generate new random number
32 bl = -((bl & 0x3F) + 0x20);
35 MovHighByte(&PlayField16[si], bl); // save sequence number
38 if (bl < 0) // bug sleeps / is inactive
41 // now the bug is active! Beware Murphy!
42 if ((TimerVar & 3) == 0 &&
43 (LowByte(PlayField16[si - FieldWidth - 1]) == fiMurphy ||
44 LowByte(PlayField16[si - FieldWidth]) == fiMurphy ||
45 LowByte(PlayField16[si - FieldWidth + 1]) == fiMurphy ||
46 LowByte(PlayField16[si - 1]) == fiMurphy ||
47 LowByte(PlayField16[si + 1]) == fiMurphy ||
48 LowByte(PlayField16[si + FieldWidth - 1]) == fiMurphy ||
49 LowByte(PlayField16[si + FieldWidth]) == fiMurphy ||
50 LowByte(PlayField16[si + FieldWidth + 1]) == fiMurphy))
51 subSoundFX(si, fiBug, actActive); // play dangerous sound
53 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54 GfxGraphic[GetX(si)][GetY(si)] = (bl == 0 ? aniBugActivating :
55 bl == 12 ? aniBugDeactivating :
56 bl == 13 ? aniBug : aniBugActive);
57 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
61 // ==========================================================================
64 // ==========================================================================
66 void subAnimateTerminals(int si)
74 if (LowByte(PlayField16[si]) != fiTerminal)
77 /* use native frame handling (undo frame incrementation in main loop) */
78 if (game.use_native_sp_graphics_engine)
81 /* get last random animation delay */
82 bl = HighByte(PlayField16[si]);
83 if ((bl & 0x80) == 0x80)
87 if (bl <= 0) /* return if random animation delay not yet reached */
89 MovHighByte(&PlayField16[si], bl);
94 /* calculate new random animation delay */
95 bl = -(subGetRandomNumber() & TerminalMaxCycles); // generate new random number
96 MovHighByte(&PlayField16[si], bl); // save new sequence number
98 /* check terminal state (active or inactive) */
99 bl = TerminalState[si] + 1;
105 TerminalState[si] = bl;
107 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
109 graphic = (bl < 8 ? aniTerminal : aniTerminalActive);
111 if (game.use_native_sp_graphics_engine)
112 GfxFrame[lx][ly] += getGraphicInfo_Delay(graphic);
114 GfxGraphic[lx][ly] = (bl < 8 ? aniTerminal : aniTerminalActive);
116 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
120 // ==========================================================================
122 // Randomize random number generator
123 // ==========================================================================
127 long Tick = MyGetTickCount();
129 RandomSeed = (Tick ^ (Tick >> 16)) & 0xFFFF;
133 // ==========================================================================
135 // Generate new random number, first method (see also sub_g_8580)
136 // ==========================================================================
138 int subGetRandomNumber()
140 RandomSeed = (RandomSeed * 0x5E5 + 0x31) & 0xFFFF;
142 return (RandomSeed >> 1);
144 // Mov ax, randomseed
146 // mul bx ' dx:ax = reg * ax
148 // Mov randomseed, ax