rnd-20091022-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
12 // --- Option Explicit
13
14 int *AnimationPosTable;
15 byte *AnimationSubTable;
16
17 // ==========================================================================
18 //                              SUBROUTINE
19 // Do game stuff
20 // ==========================================================================
21
22 int subDoGameStuff()
23 {
24   int subDoGameStuff;
25
26   int si, cx, dx, bl;
27
28   subAnimateMurphy(&MurphyPosIndex);       // move Murphy in any direction
29
30   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31   // Build a database of locations and subs-to-call of animatable fields only:
32   // Make a snapshot from the field before the animation cycle starts.
33   // first and last line are not animated.
34   si = FieldWidth + 1;
35   cx = LevelMax - 2 * FieldWidth - 1;
36   dx = 0;
37   do // locloop_g_2282:
38   {
39     bl = LowByte(PlayField16[si]);
40     if (((bl & 0xD) != 0) && (bl < 0x20)) // all animatables have 1's in &H0D' above &H1F? (&H1F=explosion!)
41     {
42       if (IsToBeAnimated(bl))
43       {
44         AnimationPosTable[dx] = si;
45         AnimationSubTable[dx] = bl;
46         dx = dx + 1; // count database entries
47       }
48     }
49
50     si = si + 1; // next field
51     cx = cx - 1;
52   }
53   while (0 < cx); // locloop_g_2282' until all lines scanned(not top- and bottom edge)
54
55   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56   // Now use the database to animate all animatables the fastest way.
57   // All the other fields are not checked anymore: those have no database entry.
58   // The field from before animation is frozen in the database in order not to
59   // do follow-up animations in the same loop.
60   if (dx != 0) // any database entries?
61   {
62     dx = dx - 1;
63     for (cx = 0; cx <= dx; cx++)
64     {
65       CallAnimation(AnimationPosTable[cx], AnimationSubTable[cx]);
66     } // loop    locloop_g_22B8          ' until all animatables done
67   }
68
69 #if 0
70   printf("::: DoGameStuff.c: KillMurphyFlag == %d [%d]\n",
71          KillMurphyFlag, MurphyMoveCounter);
72 #endif
73
74   // All animations are done now
75   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76   if (KillMurphyFlag == 1 || MurphyMoveCounter == 0)
77   {
78 #if 1
79     if (LeadOutCounter == 0 &&
80         !game_sp_info.LevelSolved &&
81         !game_sp_info.GameOver)
82 #else
83     if (LeadOutCounter == 0)
84 #endif
85     {
86 #if 0
87       printf("::: DoGameStuff.c: killing murphy [%d] ...\n", KillMurphyFlag);
88 #endif
89
90       KillMurphyFlag = 0;             // no more "kill Murphy"
91       ExplodeFieldSP(MurphyExplodePos);                 // Explode
92       LeadOutCounter = 0x40;           // quit: start lead-out
93
94 #if 1
95 #if 1
96       printf("::: DoGameStuff.c: !!!!!!!!!! GAME OVER !!!!!!!!!!\n");
97 #endif
98
99       game_sp_info.GameOver = TRUE;
100 #endif
101     }
102
103 #if 1
104 #if 0
105     printf("::: *** %d, %d, %d\n", KillMurphyFlag,
106            game_sp_info.LevelSolved, game_sp_info.GameOver);
107 #endif
108
109 #if 0
110     if (KillMurphyFlag == 1 &&
111         !game_sp_info.LevelSolved &&
112         !game_sp_info.GameOver)
113     {
114 #if 1
115       printf("::: DoGameStuff.c: !!!!!!!!!! GAME OVER !!!!!!!!!!\n");
116 #endif
117
118       game_sp_info.GameOver = TRUE;
119     }
120 #endif
121 #endif
122
123   } //  loc_g_22FB:
124
125
126   return subDoGameStuff;
127 } // subDoGameStuff
128
129 static boolean IsToBeAnimated(int bl)
130 {
131   static boolean IsToBeAnimated;
132
133   switch (bl)
134   {
135     case fiZonk:
136     case fiInfotron:
137     case fiOrangeDisk:
138     case fiSnikSnak:
139     case fiTerminal:
140     case fiElectron:
141     case fiBug:
142     case fiExplosion:
143       IsToBeAnimated = True;
144       break;
145
146     default:
147       IsToBeAnimated = False;
148       break;
149   }
150
151   return IsToBeAnimated;
152 }
153
154 static void CallAnimation(int si, byte bl)
155 {
156   switch (bl)
157   {
158     case fiZonk:
159       subAnimateZonks(si);
160       break;
161
162     case fiInfotron:
163       subAnimateInfotrons(si);
164       break;
165
166     case fiOrangeDisk:
167       subAnimateOrangeDisks(si);
168       break;
169
170     case fiSnikSnak:
171       subAnimateSnikSnaks(si);
172       break;
173
174     case fiTerminal:
175       subAnimateTerminals(si);
176       break;
177
178     case fiElectron:
179       subAnimateElectrons(si);
180       break;
181
182     case fiBug:
183       subAnimateBugs(si);
184       break;
185
186     case fiExplosion:
187       subAnimateExplosion(si);
188       break;
189
190     default:
191       // Debug.Assert(False);
192       break;
193   }
194 }
195