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)
29 if (bl >= 14) // bugs animation has 14 frames
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 = SgnHighByte(PlayField16[si]);
85 if (bl <= 0) /* return if random animation delay not yet reached */
87 MovHighByte(&PlayField16[si], bl);
92 /* calculate new random animation delay */
93 bl = -(subGetRandomNumber() & TerminalMaxCycles); // generate new random number
94 MovHighByte(&PlayField16[si], bl); // save new sequence number
96 /* check terminal state (active or inactive) */
97 bl = TerminalState[si] + 1;
103 TerminalState[si] = bl;
105 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107 graphic = (bl < 8 ? aniTerminal : aniTerminalActive);
109 if (game.use_native_sp_graphics_engine)
110 GfxFrame[lx][ly] += getGraphicInfo_Delay(graphic);
112 GfxGraphic[lx][ly] = (bl < 8 ? aniTerminal : aniTerminalActive);
114 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118 // ==========================================================================
120 // Randomize random number generator
121 // ==========================================================================
125 long Tick = MyGetTickCount();
127 RandomSeed = (Tick ^ (Tick >> 16)) & 0xFFFF;
131 // ==========================================================================
133 // Generate new random number, first method (see also sub_g_8580)
134 // ==========================================================================
136 int subGetRandomNumber()
138 RandomSeed = (RandomSeed * 0x5E5 + 0x31) & 0xFFFF;
140 return (RandomSeed >> 1);
142 // Mov ax, randomseed
144 // mul bx ' dx:ax = reg * ax
146 // Mov randomseed, ax