rnd-20100313-1-src
[rocksndiamonds.git] / src / game_sp / Infotrons.c
1 // ----------------------------------------------------------------------------
2 // Infotrons.c
3 // ----------------------------------------------------------------------------
4
5 #include "Infotrons.h"
6
7 // static char *VB_Name = "modInfotron";
8
9 // --- Option Explicit
10
11 // ==========================================================================
12 //                              SUBROUTINE
13 // Animate Infotrons (falling)
14 // ==========================================================================
15
16 int subAnimateInfotrons(int si)
17 {
18   int subAnimateInfotrons;
19
20   int tFld;
21
22   // PseudoRegisters:
23   // int ax, bx, cx, dx, di, X, Y;
24   // int ah, bh, ch, dh, al, bl, cl, dl;
25   int ax, bx, dx, X, Y;
26   int al, bl;
27
28   tFld = PlayField16[si];
29   if ((tFld & 0xFF) != fiInfotron)
30     return subAnimateInfotrons;
31
32   if (tFld == fiInfotron)
33   {
34     ax = PlayField16[si + FieldWidth]; // select case playfield16(si+60)
35     if (ax == 0)
36       goto loc_g_11D5;
37
38     if (ax == fiZonk)
39       goto loc_g_11A6;
40
41     if (ax == fiInfotron)
42       goto loc_g_11A6;
43
44     if (ax == fiRAM)
45       goto loc_g_11A6;
46
47     return subAnimateInfotrons;
48
49 loc_g_11A6: //        Case fiZonk, fiInfotron, fiRAM
50     ax = PlayField16[si + FieldWidth - 1];
51     if (ax == 0 || ax == 0x8888 || ax == 0xAAAA)
52       goto loc_g_11DC;
53
54 loc_g_11BD:
55     ax = PlayField16[si + FieldWidth + 1];
56     if (ax == 0 || ax == 0x8888 || ax == 0xAAAA)
57       goto loc_g_11F2;
58
59     return subAnimateInfotrons;
60
61 loc_g_11D5: //       Case fiSpace
62     MovHighByte(&PlayField16[si], 0x40);
63     goto loc_g_1207;
64
65 loc_g_11DC: // roll left?
66     if (PlayField16[si - 1] == 0)
67       goto loc_g_11E5;
68
69     goto loc_g_11BD;
70
71 loc_g_11E5:
72     MovHighByte(&PlayField16[si], 0x50);
73     PlayField16[si - 1] = 0x8888;
74     goto loc_g_1207;
75
76 loc_g_11F2: // roll right?
77     if (PlayField16[si + 1] == 0)
78       goto loc_g_11FA;
79
80     return subAnimateInfotrons;
81
82 loc_g_11FA:
83     MovHighByte(&PlayField16[si], 0x60);
84     PlayField16[si + 1] = 0x8888;
85   } // tFld = fiInfotron
86
87 loc_g_1207:
88   // from now on the infotron is definitely moving,
89   // maybe the sequence is in an advanced frame
90   // or just beeing initialized due to the code above
91   bl = HighByte(PlayField16[si]);
92   bx = 0;
93   MovLowByte(&bx, bl);
94   al = bl & 0xF0;
95   if (al == 0x10) // infotron comes falling from above
96     goto loc_g_1242;
97
98   if (al == 0x20) // infotron comes rolling from right to left
99     goto loc_g_138D;
100
101   if (al == 0x30) // infotron comes rolling from left to right
102     goto loc_g_13E9;
103
104   if (al == 0x40) // infotron falls straight down
105     goto loc_g_1444;
106
107   if (al == 0x50) // infotron rolls left
108     goto loc_g_1472;
109
110   if (al == 0x60) // infotron rolls right
111     goto loc_g_14E0;
112
113   if (al == 0x70) // intermediate state
114     goto loc_g_154E;
115
116   return subAnimateInfotrons;
117
118 loc_g_1242: // infotron comes falling from above
119   //      To Do: draw infotron falling from above
120   //      according to position in (bl And &H07)
121   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
122   X = GetStretchX(si);
123   Y = GetStretchY(si - FieldWidth);
124   dx = bl & 0x7;
125 #if 1
126   StretchedSprites.BltImg(X, Y, aniSpace, 0);
127   StretchedSprites.BltImg(X, Y + TwoPixels * (dx + 1), aniInfotron, dx);
128 #else
129   StretchedSprites.BltEx(X, Y, 0);
130   StretchedSprites.BltEx(X, Y + TwoPixels * (dx + 1), fiInfotron);
131 #endif
132   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
133   bl = HighByte(PlayField16[si]) + 1;
134   if (bl == 0x16)
135   {
136     MovHighByte(&PlayField16[si], bl);
137     subCleanUpForInfotronsAbove(si - FieldWidth);
138     return subAnimateInfotrons;
139   } // loc_g_1285:
140
141   if (bl < 0x18)
142   {
143     MovHighByte(&PlayField16[si], bl);
144     return subAnimateInfotrons;
145   } // loc_g_128F:
146
147   MovHighByte(&PlayField16[si], 0); // infotron arrived at the field
148
149   // now check if the zonk may go on falling somehow
150   ax = PlayField16[si + FieldWidth];
151   if (ax == 0) // below is empty!-> go on falling
152     goto loc_g_132D;
153
154   if (ax == 0x9999) // below is only temporarily used
155     goto loc_g_132D;
156
157   if ((ax & 0xFF) == fiMurphy) // Murphy dies
158     goto loc_g_1364;
159
160   if (ax == fiRedDisk) // red disk hit
161     goto loc_g_1386;
162
163   if ((ax & 0xFF) == fiSnikSnak) // SnikSnak dies
164     goto loc_g_1386;
165
166
167   if ((ax & 0xFF) == fiElectron) // Electron cracked!
168     goto loc_g_1386;
169
170   if (ax == fiYellowDisk) // yellow disk hit
171     goto loc_g_1386;
172
173   if (ax == fiOrangeDisk) // orange disk hit
174     goto loc_g_1386;
175
176 #if 1
177
178 #if 1
179   // play the infotron sound, 'cause infotron hits something "hard"
180   subSoundFX(si, fiInfotron, actImpact);
181 #else
182  // play the zonk sound, 'cause zonk hits something "hard"
183   subSoundFX(si, fiZonk, actImpact);
184 #endif
185
186 #else
187   subSoundFXZonk(); // play the zonk sound,'cause zonk hits something "hard"
188 #endif
189
190   if (! (ax == fiZonk || ax == fiInfotron || ax == fiRAM))
191     return subAnimateInfotrons;
192
193   // infotron rolls somewhere
194   ax = PlayField16[si + FieldWidth - 1];
195   if (ax == 0 || ax == 0x8888 || ax == 0xAAAA) // may roll left
196     goto loc_g_133A;
197
198   ax = PlayField16[si + FieldWidth + 1];
199   if (ax == 0 || ax == 0x8888 || ax == 0xAAAA) // may roll right
200     goto loc_g_1350;
201
202   return subAnimateInfotrons;
203
204 loc_g_132D:     // go on falling down?
205   PlayField16[si] = 0x7004; // go into intermediate waitstate
206   PlayField16[si + FieldWidth] = 0x9999; // mark as "zonk waiting to access"
207   return subAnimateInfotrons;
208
209 loc_g_133A:     // test if infotron may roll left
210   // This if(if true) jumps up far above
211   // to the according rountine for fixed infotrons!
212   if (PlayField16[si - 1] != 0) // Remarkable!!! ' loc_g_0EF4:
213     goto loc_g_11BD;
214
215   MovHighByte(&PlayField16[si], 0x50); // infotron rolls left
216   Mov(&PlayField16[si - 1], 0x8888);
217   return subAnimateInfotrons;
218
219 loc_g_1350:     // test if infotron may roll right
220   if (PlayField16[si + 1] != 0)
221     return subAnimateInfotrons;
222
223   MovHighByte(&PlayField16[si], 0x60); // infotron rolls right
224   Mov(&PlayField16[si + 1], 0x8888);
225   return subAnimateInfotrons;
226
227 loc_g_1364:     // Murphy dies, but not in any case
228   bl = HighByte(PlayField16[si + FieldWidth]);
229   if (bl == 0xE || bl == 0xF || bl == 0x28)
230     return subAnimateInfotrons;
231
232   if (bl == 0x29 || bl == 0x25 || bl == 0x26)
233     return subAnimateInfotrons;
234
235 loc_g_1386:     // someone dies/explodes immediately
236   si = si + FieldWidth;                 // 1 field down
237   ExplodeFieldSP(si);               // Explode
238   return subAnimateInfotrons;
239
240 loc_g_138D: // infotron comes rolling from right to left
241   //  To Do: draw infotron rolling from right
242   //  according to position in (bl And &H07)
243   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
244   X = GetStretchX(si + 1);
245   Y = GetStretchY(si);
246   dx = (bl & 0x7) + 1;
247 #if 1
248   StretchedSprites.BltImg(X, Y, aniSpace, 0);
249   StretchedSprites.BltImg(X - (TwoPixels * dx), Y, aniInfotronRollLeft, dx - 1);
250 #else
251   StretchedSprites.BltEx(X, Y, 0);
252   StretchedSprites.BltEx(X - (TwoPixels * dx), Y, aniFramesInfotronRollLeft[dx - 1]);
253 #endif
254   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
255   bl = HighByte(PlayField16[si]) + 1; // get and increment sequence#
256   if (bl == 0x24)
257     PlayField16[si + 1] = 0xAAAA;
258
259   if (bl == 0x26)
260   {
261     MovHighByte(&PlayField16[si], bl);
262     subCleanUpForInfotronsAbove(si + 1);
263   }
264   else if (bl < 0x28)
265   {
266     MovHighByte(&PlayField16[si], bl);
267   }
268   else
269   {
270     PlayField16[si] = 0x7004; // go into intermediate state
271   }
272
273   return subAnimateInfotrons;
274
275 loc_g_13E9: // infotron comes rolling from left to right
276   //  To Do: draw infotron rolling from left
277   //  according to position in (bl And &H07)
278   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
279   X = GetStretchX(si - 1);
280   Y = GetStretchY(si);
281   dx = (bl & 0x7) + 1;
282 #if 1
283   StretchedSprites.BltImg(X, Y, aniSpace, 0);
284   StretchedSprites.BltImg(X + (TwoPixels * dx), Y, aniInfotronRollRight, dx - 1);
285 #else
286   StretchedSprites.BltEx(X, Y, 0);
287   StretchedSprites.BltEx(X + (TwoPixels * dx), Y, aniFramesInfotronRollRight[dx - 1]);
288 #endif
289   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
290   bl = HighByte(PlayField16[si]) + 1;
291   if (bl == 0x34)
292     PlayField16[si - 1] = 0xAAAA;
293
294   if (bl == 0x36)
295   {
296     MovHighByte(&PlayField16[si], bl);
297     subCleanUpForInfotronsAbove(si - 1);
298   }
299   else if (bl < 0x38)
300   {
301     MovHighByte(&PlayField16[si], bl);
302   }
303   else
304   {
305     PlayField16[si] = 0x7004; // go into intermediate state
306   }
307
308   return subAnimateInfotrons;
309
310 loc_g_1444: // infotron falls straight down
311   bl = bl + 1;
312   if (bl < 0x42)
313   {
314     MovHighByte(&PlayField16[si], bl);
315   }
316   else if (PlayField16[si + FieldWidth] != 0)
317   {
318     bl = bl - 1; // stay waiting
319     MovHighByte(&PlayField16[si], bl);
320   }
321   else
322   {
323     PlayField16[si] = 0xFFFF;
324     si = si + FieldWidth;                 // 1 field down
325     PlayField16[si] = 0x1004; // go falling
326   }
327
328   return subAnimateInfotrons;
329
330 loc_g_1472: // infotron rolls left
331   //  To Do: draw infotron rolling to left
332   //  according to position in (bl And &H0F)
333   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
334   X = GetStretchX(si);
335   Y = GetStretchY(si);
336   dx = (bl & 0xF) + 1;
337 #if 1
338   StretchedSprites.BltImg(X, Y, aniSpace, 0);
339   StretchedSprites.BltImg(X - (TwoPixels * dx), Y, aniInfotronRollLeft, dx - 1);
340 #else
341   StretchedSprites.BltEx(X, Y, 0);
342   StretchedSprites.BltEx(X - (TwoPixels * dx), Y, aniFramesInfotronRollLeft[dx - 1]);
343 #endif
344   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
345   bl = HighByte(PlayField16[si]) + 1; // retrieve and increment sequence#
346   if (bl < 0x52)
347   {
348     MovHighByte(&PlayField16[si], bl);
349     return subAnimateInfotrons;
350   }
351
352   if (PlayField16[si + FieldWidth - 1] != 0)
353     goto loc_g_14D9;
354
355   if (PlayField16[si - 1] != 0)
356   {
357     if (PlayField16[si - 1] != 0x8888)
358       goto loc_g_14D9;
359   }
360
361   PlayField16[si] = 0xFFFF;
362   si = si - 1;                   // 1 field left
363   PlayField16[si] = 0x2204;
364   PlayField16[si + FieldWidth] = 0x9999;
365   return subAnimateInfotrons;
366
367 loc_g_14D9: // stay waiting
368   bl = bl - 1;
369   MovHighByte(&PlayField16[si], bl);
370   return subAnimateInfotrons;
371
372 loc_g_14E0: // infotron rolls right
373   //  To Do: draw infotron rolling to right
374   //  according to position in (bl And &H07)
375   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
376   X = GetStretchX(si);
377   Y = GetStretchY(si);
378   dx = (bl & 0x7) + 1;
379 #if 1
380   StretchedSprites.BltImg(X, Y, aniSpace, 0);
381   StretchedSprites.BltImg(X + (TwoPixels * dx), Y, aniInfotronRollRight, dx - 1);
382 #else
383   StretchedSprites.BltEx(X, Y, 0);
384   StretchedSprites.BltEx(X + (TwoPixels * dx), Y, aniFramesInfotronRollRight[dx - 1]);
385 #endif
386   // +++++++++++++++++++++++++++++++++++++++++++++++++++++
387   bl = HighByte(PlayField16[si]) + 1;
388   if (bl < 0x62)
389   {
390     MovHighByte(&PlayField16[si], bl);
391     return subAnimateInfotrons;
392   }
393
394   if (PlayField16[si + FieldWidth + 1] != 0)
395     goto loc_g_1547;
396
397   if (PlayField16[si + 1] != 0)
398   {
399     if (PlayField16[si + 1] != 0x8888)
400       goto loc_g_1547;
401   }
402
403   PlayField16[si] = 0xFFFF;
404   si = si + 1;
405   PlayField16[si] = 0x3204;
406   PlayField16[si + FieldWidth] = 0x9999;
407   return subAnimateInfotrons;
408
409 loc_g_1547: // stay waiting
410   bl = bl - 1;
411   MovHighByte(&PlayField16[si], bl);
412   return subAnimateInfotrons;
413
414 loc_g_154E: // intermediate state
415   ax = PlayField16[si + FieldWidth];
416   if (ax == 0 || ax == 0x9999)
417   {
418     PlayField16[si] = 0xFFFF;
419     si = si + FieldWidth;                 // 1 field down
420     PlayField16[si] = 0x1004; // start falling down
421     goto loc_g_1242;
422   }
423
424   return subAnimateInfotrons;
425 } // subAnimateInfotrons
426
427 int subCleanUpForInfotronsAbove(int si)
428 {
429   int subCleanUpForInfotronsAbove;
430
431   int ax;
432
433   if (LowByte(PlayField16[si]) != fiExplosion)
434     PlayField16[si] = 0;
435
436   if (PlayField16[si - FieldWidth] != 0)
437   {
438     if (PlayField16[si - FieldWidth] != 0x9999)
439       return subCleanUpForInfotronsAbove;
440
441     if (LowByte(PlayField16[si - 2 * FieldWidth]) != fiZonk)
442       return subCleanUpForInfotronsAbove;
443   }
444
445   if (PlayField16[si - FieldWidth - 1] == fiInfotron)
446     goto loc_g_16FE;
447
448 loc_g_16F6:
449   if (PlayField16[si - FieldWidth + 1] == fiInfotron)
450     goto loc_g_1722;
451
452   return subCleanUpForInfotronsAbove;
453
454 loc_g_16FE:
455   ax = PlayField16[si - 1];
456   if (ax == fiZonk || ax == fiInfotron || ax == fiRAM)
457   {
458     PlayField16[si - FieldWidth - 1] = 0x6004;
459     PlayField16[si - FieldWidth] = 0x8888;
460     return subCleanUpForInfotronsAbove;
461   }
462
463   goto loc_g_16F6;
464
465 loc_g_1722:
466   ax = PlayField16[si + 1];
467   if (ax == fiZonk || ax == fiInfotron || ax == fiRAM)
468   {
469     PlayField16[si - FieldWidth + 1] = 0x5004;
470     PlayField16[si - FieldWidth] = 0x8888;
471   }
472
473   return subCleanUpForInfotronsAbove;
474 } // subCleanUpForInfotronsAbove