rnd-20090623-1-src
[rocksndiamonds.git] / src / game_sp / DoGameStuff.c
1 // ----------------------------------------------------------------------------
2 // DoGameStuff.c
3 // ----------------------------------------------------------------------------
4
5 #include "DoGameStuff.h"
6
7 static void CallAnimation(int si, byte bl);
8 static boolean IsToBeAnimated(int bl);
9
10 static char *VB_Name = "modDoGameStuff";
11 // --- Option Explicit
12
13 int *AnimationPosTable;
14 byte *AnimationSubTable;
15
16 // ==========================================================================
17 //                              SUBROUTINE
18 // Do game stuff
19 // ==========================================================================
20
21 int subDoGameStuff()
22 {
23   int subDoGameStuff;
24
25   int si, cx, dx, bl;
26
27   subAnimateMurphy(MurphyPosIndex);       // move Murphy in any direction
28
29   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30   // Build a database of locations and subs-to-call of animatable fields only:
31   // Make a snapshot from the field before the animation cycle starts.
32   // first and last line are not animated.
33   si = FieldWidth + 1;
34   cx = LevelMax - 2 * FieldWidth - 1;
35   dx = 0;
36   do // locloop_g_2282:
37   {
38     bl = LowByte(PlayField16[si]);
39     if (((bl & 0xD) != 0) && (bl < 0x20)) // all animatables have 1's in &H0D' above &H1F? (&H1F=explosion!)
40     {
41       if (IsToBeAnimated(bl))
42       {
43         AnimationPosTable[dx] = si;
44         AnimationSubTable[dx] = bl;
45         dx = dx + 1; // count database entries
46       }
47     }
48
49     si = si + 1; // next field
50     cx = cx - 1;
51   }
52   while (0 < cx); // locloop_g_2282' until all lines scanned(not top- and bottom edge)
53
54   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55   // Now use the database to animate all animatables the fastest way.
56   // All the other fields are not checked anymore: those have no database entry.
57   // The field from before animation is frozen in the database in order not to
58   // do follow-up animations in the same loop.
59   if (dx != 0) // any database entries?
60   {
61     dx = dx - 1;
62     for (cx = 0; cx <= dx; cx++)
63     {
64       CallAnimation(AnimationPosTable[cx], AnimationSubTable[cx]);
65     } // loop    locloop_g_22B8          ' until all animatables done
66   }
67
68   // All animations are done now
69   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70   if (KillMurphyFlag == 1 || MurphyMoveCounter == 0)
71   {
72     if (LeadOutCounter == 0)
73     {
74       KillMurphyFlag = 0;             // no more "kill Murphy"
75       ExplodeFieldSP(MurphyExplodePos);                 // Explode
76       LeadOutCounter = 0x40;           // quit: start lead-out
77     }
78   } //  loc_g_22FB:
79
80
81   return subDoGameStuff;
82 } // subDoGameStuff
83
84 static boolean IsToBeAnimated(int bl)
85 {
86   static boolean IsToBeAnimated;
87
88   switch (bl)
89   {
90     case fiZonk:
91     case fiInfotron:
92     case fiOrangeDisk:
93     case fiSnikSnak:
94     case fiTerminal:
95     case fiElectron:
96     case fiBug:
97     case fiExplosion:
98       IsToBeAnimated = True;
99       break;
100
101     default:
102       IsToBeAnimated = False;
103       break;
104   }
105
106   return IsToBeAnimated;
107 }
108
109 static void CallAnimation(int si, byte bl)
110 {
111   switch (bl)
112   {
113     case fiZonk:
114       subAnimateZonks(si);
115       break;
116
117     case fiInfotron:
118       subAnimateInfotrons(si);
119       break;
120
121     case fiOrangeDisk:
122       subAnimateOrangeDisks(si);
123       break;
124
125     case fiSnikSnak:
126       subAnimateSnikSnaks(si);
127       break;
128
129     case fiTerminal:
130       subAnimateTerminals(si);
131       break;
132
133     case fiElectron:
134       subAnimateElectrons(si);
135       break;
136
137     case fiBug:
138       subAnimateBugs(si);
139       break;
140
141     case fiExplosion:
142       subAnimateExplosion(si);
143       break;
144
145     default:
146       // Debug.Assert(False);
147       break;
148   }
149 }
150