1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "BugsTerminals.h"
9 byte TerminalState[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE];
14 int TerminalMaxCycles;
17 // ==========================================================================
20 // ==========================================================================
22 void subAnimateBugs(int si)
26 if (fiBug != LowByte(PlayField16[si]))
29 bl = SgnHighByte(PlayField16[si]); // get and increment sequence number
31 if ((TimerVar & 3) == 0)
34 if (bl >= 14) // bugs animation has 14 frames
36 bl = subGetRandomNumber(); // generate new random number
37 bl = -((bl & 0x3F) + 0x20);
40 MovHighByte(&PlayField16[si], bl); // save sequence number
43 if (bl < 0) // bug sleeps / is inactive
46 // now the bug is active! Beware Murphy!
47 if ((TimerVar & 3) == 0 &&
48 (LowByte(PlayField16[si - FieldWidth - 1]) == fiMurphy ||
49 LowByte(PlayField16[si - FieldWidth]) == fiMurphy ||
50 LowByte(PlayField16[si - FieldWidth + 1]) == fiMurphy ||
51 LowByte(PlayField16[si - 1]) == fiMurphy ||
52 LowByte(PlayField16[si + 1]) == fiMurphy ||
53 LowByte(PlayField16[si + FieldWidth - 1]) == fiMurphy ||
54 LowByte(PlayField16[si + FieldWidth]) == fiMurphy ||
55 LowByte(PlayField16[si + FieldWidth + 1]) == fiMurphy))
56 subSoundFX(si, fiBug, actActive); // play dangerous sound
58 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
59 GfxGraphic[GetX(si)][GetY(si)] = (bl == 0 ? aniBugActivating :
60 bl == 12 ? aniBugDeactivating :
61 bl == 13 ? aniBug : aniBugActive);
62 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 // ==========================================================================
69 // ==========================================================================
71 void subAnimateTerminals(int si)
79 if (LowByte(PlayField16[si]) != fiTerminal)
82 /* use native frame handling (undo frame incrementation in main loop) */
83 if (game.use_native_sp_graphics_engine)
86 /* get last random animation delay */
87 bl = SgnHighByte(PlayField16[si]);
90 if (bl <= 0) /* return if random animation delay not yet reached */
92 MovHighByte(&PlayField16[si], bl);
97 /* calculate new random animation delay */
98 bl = -(subGetRandomNumber() & TerminalMaxCycles); // generate new random number
99 MovHighByte(&PlayField16[si], bl); // save new sequence number
101 /* check terminal state (active or inactive) */
102 bl = TerminalState[si] + 1;
108 TerminalState[si] = bl;
110 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112 graphic = (bl < 8 ? aniTerminal : aniTerminalActive);
114 if (game.use_native_sp_graphics_engine)
115 GfxFrame[lx][ly] += getGraphicInfo_Delay(graphic);
117 GfxGraphic[lx][ly] = (bl < 8 ? aniTerminal : aniTerminalActive);
119 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123 // ==========================================================================
125 // Randomize random number generator
126 // ==========================================================================
130 int Tick = MyGetTickCount();
132 RandomSeed = (Tick ^ (Tick >> 16)) & 0xFFFF;
136 // ==========================================================================
138 // Generate new random number, first method (see also sub_g_8580)
139 // ==========================================================================
141 int subGetRandomNumber()
143 RandomSeed = (RandomSeed * 0x5E5 + 0x31) & 0xFFFF;
145 return (RandomSeed >> 1);
147 // Mov ax, randomseed
149 // mul bx ' dx:ax = reg * ax
151 // Mov randomseed, ax