1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "BugsTerminals.h"
8 byte TerminalState[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE];
10 int TerminalMaxCycles;
13 // ==========================================================================
16 // ==========================================================================
18 void subAnimateBugs(int si)
22 if (fiBug != LowByte(PlayField16[si]))
25 bl = SgnHighByte(PlayField16[si]); // get and increment sequence number
27 if ((TimerVar & 3) == 0)
30 if (bl >= 14) // bugs animation has 14 frames
32 bl = subGetRandomNumber(); // generate new random number
33 bl = -((bl & 0x3F) + 0x20);
36 MovHighByte(&PlayField16[si], bl); // save sequence number
39 if (bl < 0) // bug sleeps / is inactive
42 // now the bug is active! Beware Murphy!
43 if ((TimerVar & 3) == 0 &&
44 (LowByte(PlayField16[si - FieldWidth - 1]) == fiMurphy ||
45 LowByte(PlayField16[si - FieldWidth]) == fiMurphy ||
46 LowByte(PlayField16[si - FieldWidth + 1]) == fiMurphy ||
47 LowByte(PlayField16[si - 1]) == fiMurphy ||
48 LowByte(PlayField16[si + 1]) == fiMurphy ||
49 LowByte(PlayField16[si + FieldWidth - 1]) == fiMurphy ||
50 LowByte(PlayField16[si + FieldWidth]) == fiMurphy ||
51 LowByte(PlayField16[si + FieldWidth + 1]) == fiMurphy))
52 subSoundFX(si, fiBug, actActive); // play dangerous sound
54 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55 GfxGraphic[GetX(si)][GetY(si)] = (bl == 0 ? aniBugActivating :
56 bl == 12 ? aniBugDeactivating :
57 bl == 13 ? aniBug : aniBugActive);
58 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
62 // ==========================================================================
65 // ==========================================================================
67 void subAnimateTerminals(int si)
75 if (LowByte(PlayField16[si]) != fiTerminal)
78 /* use native frame handling (undo frame incrementation in main loop) */
79 if (game.use_native_sp_graphics_engine)
82 /* get last random animation delay */
83 bl = SgnHighByte(PlayField16[si]);
86 if (bl <= 0) /* return if random animation delay not yet reached */
88 MovHighByte(&PlayField16[si], bl);
93 /* calculate new random animation delay */
94 bl = -(subGetRandomNumber() & TerminalMaxCycles); // generate new random number
95 MovHighByte(&PlayField16[si], bl); // save new sequence number
97 /* check terminal state (active or inactive) */
98 bl = TerminalState[si] + 1;
104 TerminalState[si] = bl;
106 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
108 graphic = (bl < 8 ? aniTerminal : aniTerminalActive);
110 if (game.use_native_sp_graphics_engine)
111 GfxFrame[lx][ly] += getGraphicInfo_Delay(graphic);
113 GfxGraphic[lx][ly] = (bl < 8 ? aniTerminal : aniTerminalActive);
115 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
119 // ==========================================================================
121 // Randomize random number generator
122 // ==========================================================================
126 int Tick = MyGetTickCount();
128 RandomSeed = (Tick ^ (Tick >> 16)) & 0xFFFF;
132 // ==========================================================================
134 // Generate new random number, first method (see also sub_g_8580)
135 // ==========================================================================
137 int subGetRandomNumber()
139 RandomSeed = (RandomSeed * 0x5E5 + 0x31) & 0xFFFF;
141 return (RandomSeed >> 1);
143 // Mov ax, randomseed
145 // mul bx ' dx:ax = reg * ax
147 // Mov randomseed, ax