90edcdc280f382d86e4573421e1901089bcd5763
[crow/jumpnbump.git] / main.c
1 #include "globals.h"
2
3 #ifndef M_PI
4 #define M_PI            3.14159265358979323846
5 #endif
6
7 char *object_gobs;
8 char *number_gobs;
9
10 unsigned int ban_map[17][22] = {
11         {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
12         {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0},
13         {1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
14         {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1},
15         {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
16         {1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
17         {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1},
18         {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
19         {1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
20         {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 1},
21         {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1},
22         {1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1},
23         {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
24         {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
25         {2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 1, 3, 3, 3, 1, 1, 1},
26         {2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
27         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
28 };
29
30 struct {
31         int num_frames;
32         int restart_frame;
33         struct {
34                 int image;
35                 int ticks;
36         } frame[10];
37 } object_anims[8] = {
38         {
39                 6, 0, {
40                         {
41                         0, 3}, {
42                         1, 3}, {
43                         2, 3}, {
44                         3, 3}, {
45                         4, 3}, {
46                         5, 3}, {
47                         0, 0}, {
48                         0, 0}, {
49                         0, 0}, {
50                         0, 0}
51                 }
52         }, {
53                 9, 0, {
54                         {
55                         6, 2}, {
56                         7, 2}, {
57                         8, 2}, {
58                         9, 2}, {
59                         10, 2}, {
60                         11, 2}, {
61                         12, 2}, {
62                         13, 2}, {
63                         14, 2}, {
64                         0, 0}
65                 }
66         }, {
67                 5, 0, {
68                         {
69                         15, 3}, {
70                         16, 3}, {
71                         16, 3}, {
72                         17, 3}, {
73                         18, 3}, {
74                         19, 3}, {
75                         0, 0}, {
76                         0, 0}, {
77                         0, 0}, {
78                         0, 0}
79                 }
80         }, {
81                 10, 0, {
82                         {
83                         20, 2}, {
84                         21, 2}, {
85                         22, 2}, {
86                         23, 2}, {
87                         24, 2}, {
88                         25, 2}, {
89                         24, 2}, {
90                         23, 2}, {
91                         22, 2}, {
92                         21, 2}
93                 }
94         }, {
95                 10, 0, {
96                         {
97                         26, 2}, {
98                         27, 2}, {
99                         28, 2}, {
100                         29, 2}, {
101                         30, 2}, {
102                         31, 2}, {
103                         30, 2}, {
104                         29, 2}, {
105                         28, 2}, {
106                         27, 2}
107                 }
108         }, {
109                 10, 0, {
110                         {
111                         32, 2}, {
112                         33, 2}, {
113                         34, 2}, {
114                         35, 2}, {
115                         36, 2}, {
116                         37, 2}, {
117                         36, 2}, {
118                         35, 2}, {
119                         34, 2}, {
120                         33, 2}
121                 }
122         }, {
123                 10, 0, {
124                         {
125                         38, 2}, {
126                         39, 2}, {
127                         40, 2}, {
128                         41, 2}, {
129                         42, 2}, {
130                         43, 2}, {
131                         42, 2}, {
132                         41, 2}, {
133                         40, 2}, {
134                         39, 2}
135                 }
136         }, {
137                 4, 0, {
138                         {
139                         76, 4}, {
140                         77, 4}, {
141                         78, 4}, {
142                         79, 4}, {
143                         0, 0}, {
144                         0, 0}, {
145                         0, 0}, {
146                         0, 0}, {
147                         0, 0}, {
148                         0, 0}
149                 }
150         }
151 };
152
153 struct {
154         int x, y;
155         int old_x, old_y;
156         char back[2], back_defined[2];
157 } flies[NUM_FLIES];
158
159 struct {
160         struct {
161                 short num_pobs;
162                 struct {
163                         int x, y;
164                         int image;
165                         char *pob_data;
166                 } pobs[NUM_LEFTOVERS];
167         } page[2];
168 } leftovers;
169
170 char pogostick, bunnies_in_space, jetpack, lord_of_the_flies, blood_is_thicker_than_water;
171
172 int main(int argc, char *argv[])
173 {
174         FILE *handle;
175         int c1, c2 = 0, c3, c4;
176         int l1;
177         int s1, s2, s3, s4;
178         int closest_player = 0, dist, cur_dist;
179         char end_loop_flag, fade_flag;
180         char mod_vol, sfx_vol, mod_fade_direction;
181         char *ptr1 = (char *) NULL;
182         char str1[100];
183         char pal[768];
184         char cur_pal[768];
185
186         if (init_program(argc, argv, pal) != 0)
187                 deinit_program();
188
189         if (main_info.fireworks == 1) {
190                 fireworks();
191                 deinit_program();
192         }
193
194         while (1) {
195
196                 if (menu() != 0)
197                         deinit_program();
198
199                 if (key_pressed(1) == 1) {
200                         break;
201                 }
202                 if (init_level(0, pal) != 0) {
203                         deinit_level();
204                         deinit_program();
205                 }
206
207                 memset(cur_pal, 0, 768);
208                 setpalette(0, 256, cur_pal);
209
210                 flippage(1);
211                 register_background(background_pic);
212                 flippage(0);
213
214                 s1 = rnd(250) + 50;
215                 s2 = rnd(150) + 50;
216                 for (c1 = 0; c1 < NUM_FLIES; c1++) {
217                         while (1) {
218                                 flies[c1].x = s1 + rnd(101) - 50;
219                                 flies[c1].y = s2 + rnd(101) - 50;
220                                 if (ban_map[flies[c1].y >> 4][flies[c1].x >> 4] == BAN_VOID)
221                                         break;
222                         }
223                         flies[c1].back_defined[0] = 0;
224                         flies[c1].back_defined[1] = 0;
225                 }
226
227                 mod_vol = sfx_vol = 10;
228                 mod_fade_direction = 1;
229                 dj_ready_mod(MOD_GAME);
230                 dj_set_mod_volume(mod_vol);
231                 dj_set_sfx_volume(mod_vol);
232                 dj_start_mod();
233                 dj_play_sfx(SFX_FLY, SFX_FLY_FREQ, 0, 0, 0, 4);
234                 dj_set_nosound(0);
235
236                 lord_of_the_flies = bunnies_in_space = jetpack = pogostick = blood_is_thicker_than_water = 0;
237                 end_loop_flag = 0;
238                 main_info.page_info[0].num_pobs = 0;
239                 main_info.page_info[1].num_pobs = 0;
240                 main_info.view_page = 0;
241                 main_info.draw_page = 1;
242
243                 while (1) {
244
245                         if (key_pressed(1) == 1) {
246                                 end_loop_flag = 1;
247                                 memset(pal, 0, 768);
248                                 mod_fade_direction = 0;
249                         }
250
251                         if (strncmp(last_keys, "kcitsogop", strlen("kcitsogop")) == 0) {
252                                 pogostick ^= 1;
253                                 last_keys[0] = 0;
254                         }
255                         if (strncmp(last_keys, "ecapsniseinnub", strlen("ecapsniseinnub")) == 0) {
256                                 bunnies_in_space ^= 1;
257                                 last_keys[0] = 0;
258                         }
259                         if (strncmp(last_keys, "kcaptej", strlen("kcaptej")) == 0) {
260                                 jetpack ^= 1;
261                                 last_keys[0] = 0;
262                         }
263                         if (strncmp(last_keys, "seilfehtfodrol", strlen("seilfehtfodrol")) == 0) {
264                                 lord_of_the_flies ^= 1;
265                                 last_keys[0] = 0;
266                         }
267                         if (strncmp(last_keys, "retawnahtrekcihtsidoolb", strlen("retawnahtrekcihtsidoolb")) == 0) {
268                                 blood_is_thicker_than_water ^= 1;
269                                 if (blood_is_thicker_than_water == 1) {
270                                         pal[432] = 63;
271                                         pal[433] = 32;
272                                         pal[434] = 32;
273                                         pal[435] = 53;
274                                         pal[436] = 17;
275                                         pal[437] = 17;
276                                         pal[438] = 42;
277                                         pal[439] = 7;
278                                         pal[440] = 7;
279                                         pal[441] = 28;
280                                         pal[442] = 0;
281                                         pal[443] = 0;
282                                         pal[444] = 24;
283                                         pal[445] = 0;
284                                         pal[446] = 0;
285                                         pal[447] = 19;
286                                         pal[448] = 0;
287                                         pal[449] = 0;
288                                         pal[450] = 12;
289                                         pal[451] = 0;
290                                         pal[452] = 0;
291                                         pal[453] = 7;
292                                         pal[454] = 0;
293                                         pal[455] = 0;
294                                 } else {
295                                         pal[432] = 63;
296                                         pal[433] = 63;
297                                         pal[434] = 63;
298                                         pal[435] = 40;
299                                         pal[436] = 53;
300                                         pal[437] = 62;
301                                         pal[438] = 19;
302                                         pal[439] = 42;
303                                         pal[440] = 60;
304                                         pal[441] = 0;
305                                         pal[442] = 33;
306                                         pal[443] = 60;
307                                         pal[444] = 3;
308                                         pal[445] = 32;
309                                         pal[446] = 46;
310                                         pal[447] = 3;
311                                         pal[448] = 26;
312                                         pal[449] = 33;
313                                         pal[450] = 3;
314                                         pal[451] = 19;
315                                         pal[452] = 21;
316                                         pal[453] = 1;
317                                         pal[454] = 8;
318                                         pal[455] = 8;
319                                 }
320                                 last_keys[0] = 0;
321                         }
322
323                         steer_players();
324
325                         dj_mix();
326
327                         for (c3 = 0; c3 < 6; c3++) {
328                                 if (c3 == 0) {
329                                         c1 = 0;
330                                         c2 = 1;
331                                 } else if (c3 == 1) {
332                                         c1 = 0;
333                                         c2 = 2;
334                                 } else if (c3 == 2) {
335                                         c1 = 0;
336                                         c2 = 3;
337                                 } else if (c3 == 3) {
338                                         c1 = 1;
339                                         c2 = 2;
340                                 } else if (c3 == 4) {
341                                         c1 = 1;
342                                         c2 = 3;
343                                 } else if (c3 == 5) {
344                                         c1 = 2;
345                                         c2 = 3;
346                                 }
347                                 if (player[c1].enabled == 1 && player[c2].enabled == 1) {
348                                         if (labs(player[c1].x - player[c2].x) < (12L << 16) && labs(player[c1].y - player[c2].y) < (12L << 16)) {
349                                                 if ((labs(player[c1].y - player[c2].y) >> 16) > 5) {
350                                                         if (player[c1].y < player[c2].y) {
351                                                                 if (player[c1].y_add >= 0) {
352                                                                         player[c1].y_add = -player[c1].y_add;
353                                                                         if (player[c1].y_add > -262144L)
354                                                                                 player[c1].y_add = -262144L;
355                                                                         player[c1].jump_abort = 1;
356                                                                         player[c2].dead_flag = 1;
357                                                                         if (player[c2].anim != 6) {
358                                                                                 player[c2].anim = 6;
359                                                                                 player[c2].frame = 0;
360                                                                                 player[c2].frame_tick = 0;
361                                                                                 player[c2].image = player_anims[player[c2].anim].frame[player[c2].frame].image + player[c2].direction * 9;
362                                                                                 if (main_info.no_gore == 0) {
363                                                                                         for (c4 = 0; c4 < 6; c4++)
364                                                                                                 add_object(OBJ_FUR, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 44 + c2 * 8);
365                                                                                         for (c4 = 0; c4 < 6; c4++)
366                                                                                                 add_object(OBJ_FLESH, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 76);
367                                                                                         for (c4 = 0; c4 < 6; c4++)
368                                                                                                 add_object(OBJ_FLESH, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 77);
369                                                                                         for (c4 = 0; c4 < 8; c4++)
370                                                                                                 add_object(OBJ_FLESH, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 78);
371                                                                                         for (c4 = 0; c4 < 10; c4++)
372                                                                                                 add_object(OBJ_FLESH, (player[c2].x >> 16) + 6 + rnd(5), (player[c2].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 79);
373                                                                                 }
374                                                                                 dj_play_sfx(SFX_DEATH, (unsigned short)(SFX_DEATH_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
375                                                                                 player[c1].bumps++;
376                                                                                 player[c1].bumped[c2]++;
377                                                                                 s1 = player[c1].bumps % 100;
378                                                                                 add_leftovers(0, 360, 34 + c1 * 64, s1 / 10, number_gobs);
379                                                                                 add_leftovers(1, 360, 34 + c1 * 64, s1 / 10, number_gobs);
380                                                                                 add_leftovers(0, 376, 34 + c1 * 64, s1 - (s1 / 10) * 10, number_gobs);
381                                                                                 add_leftovers(1, 376, 34 + c1 * 64, s1 - (s1 / 10) * 10, number_gobs);
382                                                                         }
383                                                                 } else {
384                                                                         if (player[c2].y_add < 0)
385                                                                                 player[c2].y_add = 0;
386                                                                 }
387                                                         } else {
388                                                                 if (player[c2].y_add >= 0) {
389                                                                         player[c2].y_add = -player[c2].y_add;
390                                                                         if (player[c2].y_add > -262144L)
391                                                                                 player[c2].y_add = -262144L;
392                                                                         player[c2].jump_abort = 1;
393                                                                         player[c1].dead_flag = 1;
394                                                                         if (player[c1].anim != 6) {
395                                                                                 player[c1].anim = 6;
396                                                                                 player[c1].frame = 0;
397                                                                                 player[c1].frame_tick = 0;
398                                                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
399                                                                                 if (main_info.no_gore == 0) {
400                                                                                         for (c4 = 0; c4 < 6; c4++)
401                                                                                                 add_object(OBJ_FUR, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 44 + c1 * 8);
402                                                                                         for (c4 = 0; c4 < 6; c4++)
403                                                                                                 add_object(OBJ_FLESH, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 76);
404                                                                                         for (c4 = 0; c4 < 7; c4++)
405                                                                                                 add_object(OBJ_FLESH, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 77);
406                                                                                         for (c4 = 0; c4 < 8; c4++)
407                                                                                                 add_object(OBJ_FLESH, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 78);
408                                                                                         for (c4 = 0; c4 < 10; c4++)
409                                                                                                 add_object(OBJ_FLESH, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 6 + rnd(5), (rnd(65535) - 32768) * 3, (rnd(65535) - 32768) * 3, 0, 79);
410                                                                                 }
411                                                                                 dj_play_sfx(SFX_DEATH, (unsigned short)(SFX_DEATH_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
412                                                                                 player[c2].bumps++;
413                                                                                 player[c2].bumped[c1]++;
414                                                                                 s1 = player[c2].bumps % 100;
415                                                                                 add_leftovers(0, 360, 34 + c2 * 64, s1 / 10, number_gobs);
416                                                                                 add_leftovers(1, 360, 34 + c2 * 64, s1 / 10, number_gobs);
417                                                                                 add_leftovers(0, 376, 34 + c2 * 64, s1 - (s1 / 10) * 10, number_gobs);
418                                                                                 add_leftovers(1, 376, 34 + c2 * 64, s1 - (s1 / 10) * 10, number_gobs);
419                                                                         }
420                                                                 } else {
421                                                                         if (player[c1].y_add < 0)
422                                                                                 player[c1].y_add = 0;
423                                                                 }
424                                                         }
425                                                 } else {
426                                                         if (player[c1].x < player[c2].x) {
427                                                                 if (player[c1].x_add > 0)
428                                                                         player[c1].x = player[c2].x - (12L << 16);
429                                                                 else if (player[c2].x_add < 0)
430                                                                         player[c2].x = player[c1].x + (12L << 16);
431                                                                 else {
432                                                                         player[c1].x -= player[c1].x_add;
433                                                                         player[c2].x -= player[c2].x_add;
434                                                                 }
435                                                                 l1 = player[c2].x_add;
436                                                                 player[c2].x_add = player[c1].x_add;
437                                                                 player[c1].x_add = l1;
438                                                                 if (player[c1].x_add > 0)
439                                                                         player[c1].x_add = -player[c1].x_add;
440                                                                 if (player[c2].x_add < 0)
441                                                                         player[c2].x_add = -player[c2].x_add;
442                                                         } else {
443                                                                 if (player[c1].x_add > 0)
444                                                                         player[c2].x = player[c1].x - (12L << 16);
445                                                                 else if (player[c2].x_add < 0)
446                                                                         player[c1].x = player[c2].x + (12L << 16);
447                                                                 else {
448                                                                         player[c1].x -= player[c1].x_add;
449                                                                         player[c2].x -= player[c2].x_add;
450                                                                 }
451                                                                 l1 = player[c2].x_add;
452                                                                 player[c2].x_add = player[c1].x_add;
453                                                                 player[c1].x_add = l1;
454                                                                 if (player[c1].x_add < 0)
455                                                                         player[c1].x_add = -player[c1].x_add;
456                                                                 if (player[c2].x_add > 0)
457                                                                         player[c2].x_add = -player[c2].x_add;
458                                                         }
459                                                 }
460                                         }
461                                 }
462                         }
463
464                         dj_mix();
465
466                         main_info.page_info[main_info.draw_page].num_pobs = 0;
467                         for (c1 = 0; c1 < 4; c1++) {
468                                 if (player[c1].enabled == 1)
469                                         main_info.page_info[main_info.draw_page].num_pobs++;
470                         }
471
472                         update_objects();
473
474                         dj_mix();
475
476                         /* get center of fly swarm */
477                         s1 = s2 = 0;
478                         for (c1 = 0; c1 < NUM_FLIES; c1++) {
479                                 s1 += flies[c1].x;
480                                 s2 += flies[c1].y;
481                         }
482                         s1 /= NUM_FLIES;
483                         s2 /= NUM_FLIES;
484
485                         /* get closest player to fly swarm */
486                         dist = 0x7fff;
487                         for (c1 = 0; c1 < 4; c1++) {
488                                 if (player[c1].enabled == 1) {
489                                         cur_dist = (int)sqrt((s1 - ((player[c1].x >> 16) + 8)) * (s1 - ((player[c1].x >> 16) + 8)) + (s2 - ((player[c1].y >> 16) + 8)) * (s2 - ((player[c1].y >> 16) + 8)));
490                                         if (cur_dist < dist) {
491                                                 closest_player = c1;
492                                                 dist = cur_dist;
493                                         }
494                                 }
495                         }
496                         /* update fly swarm sound */
497                         s3 = 32 - dist / 3;
498                         if (s3 < 0)
499                                 s3 = 0;
500                         dj_set_sfx_channel_volume(4, (char)(s3));
501
502                         for (c1 = 0; c1 < NUM_FLIES; c1++) {
503                                 /* get closest player to fly */
504                                 dist = 0x7fff;
505                                 for (c2 = 0; c2 < 4; c2++) {
506                                         if (player[c2].enabled == 1) {
507                                                 cur_dist = (int)sqrt((flies[c1].x - ((player[c2].x >> 16) + 8)) * (flies[c1].x - ((player[c2].x >> 16) + 8)) + (flies[c1].y - ((player[c2].y >> 16) + 8)) * (flies[c1].y - ((player[c2].y >> 16) + 8)));
508                                                 if (cur_dist < dist) {
509                                                         closest_player = c2;
510                                                         dist = cur_dist;
511                                                 }
512                                         }
513                                 }
514                                 flies[c1].old_x = flies[c1].x;
515                                 flies[c1].old_y = flies[c1].y;
516                                 s3 = 0;
517                                 if ((s1 - flies[c1].x) > 30)
518                                         s3 += 1;
519                                 else if ((s1 - flies[c1].x) < -30)
520                                         s3 -= 1;
521                                 if (dist < 30) {
522                                         if (((player[closest_player].x >> 16) + 8) > flies[c1].x) {
523                                                 if (lord_of_the_flies == 0)
524                                                         s3 -= 1;
525                                                 else
526                                                         s3 += 1;
527                                         } else {
528                                                 if (lord_of_the_flies == 0)
529                                                         s3 += 1;
530                                                 else
531                                                         s3 -= 1;
532                                         }
533                                 }
534                                 s4 = rnd(3) - 1 + s3;
535                                 if ((flies[c1].x + s4) < 16)
536                                         s4 = 0;
537                                 if ((flies[c1].x + s4) > 351)
538                                         s4 = 0;
539                                 if (ban_map[flies[c1].y >> 4][(flies[c1].x + s4) >> 4] != BAN_VOID)
540                                         s4 = 0;
541                                 flies[c1].x += s4;
542                                 s3 = 0;
543                                 if ((s2 - flies[c1].y) > 30)
544                                         s3 += 1;
545                                 else if ((s2 - flies[c1].y) < -30)
546                                         s3 -= 1;
547                                 if (dist < 30) {
548                                         if (((player[closest_player].y >> 16) + 8) > flies[c1].y) {
549                                                 if (lord_of_the_flies == 0)
550                                                         s3 -= 1;
551                                                 else
552                                                         s3 += 1;
553                                         } else {
554                                                 if (lord_of_the_flies == 0)
555                                                         s3 += 1;
556                                                 else
557                                                         s3 -= 1;
558                                         }
559                                 }
560                                 s4 = rnd(3) - 1 + s3;
561                                 if ((flies[c1].y + s4) < 0)
562                                         s4 = 0;
563                                 if ((flies[c1].y + s4) > 239)
564                                         s4 = 0;
565                                 if (ban_map[(flies[c1].y + s4) >> 4][flies[c1].x >> 4] != BAN_VOID)
566                                         s4 = 0;
567                                 flies[c1].y += s4;
568                         }
569
570                         dj_mix();
571
572                         s1 = 0;
573                         for (c1 = 0; c1 < 4; c1++) {
574                                 if (player[c1].enabled == 1) {
575                                         main_info.page_info[main_info.draw_page].pobs[s1].x = player[c1].x >> 16;
576                                         main_info.page_info[main_info.draw_page].pobs[s1].y = player[c1].y >> 16;
577                                         main_info.page_info[main_info.draw_page].pobs[s1].image = player[c1].image + c1 * 18;
578                                         main_info.page_info[main_info.draw_page].pobs[s1].pob_data = rabbit_gobs;
579                                         s1++;
580                                 }
581                         }
582
583                         draw_begin();
584
585                         draw_pobs(main_info.draw_page);
586
587                         dj_mix();
588
589                         draw_flies(main_info.draw_page);
590
591                         draw_end();
592
593                         if (mod_fade_direction == 1) {
594                                 if (mod_vol < 30) {
595                                         mod_vol++;
596                                         dj_set_mod_volume(mod_vol);
597                                 }
598                         } else {
599                                 if (mod_vol > 0) {
600                                         mod_vol--;
601                                         dj_set_mod_volume(mod_vol);
602                                 }
603                         }
604
605                         if (mod_fade_direction == 1) {
606                                 if (sfx_vol < 64) {
607                                         sfx_vol++;
608                                         dj_set_sfx_volume(sfx_vol);
609                                 }
610                         } else {
611                                 if (sfx_vol > 0) {
612                                         sfx_vol--;
613                                         dj_set_sfx_volume(sfx_vol);
614                                 }
615                         }
616
617                         fade_flag = 0;
618                         for (c1 = 0; c1 < 768; c1++) {
619                                 if (cur_pal[c1] < pal[c1]) {
620                                         cur_pal[c1]++;
621                                         fade_flag = 1;
622                                 } else if (cur_pal[c1] > pal[c1]) {
623                                         cur_pal[c1]--;
624                                         fade_flag = 1;
625                                 }
626                         }
627                         if (fade_flag == 0 && end_loop_flag == 1)
628                                 break;
629
630                         main_info.draw_page ^= 1;
631                         main_info.view_page ^= 1;
632
633                         flippage(main_info.view_page);
634
635                         wait_vrt(1);
636
637                         if (fade_flag == 1)
638                                 setpalette(0, 256, cur_pal);
639
640                         draw_begin();
641
642                         redraw_flies_background(main_info.draw_page);
643
644                         redraw_pob_backgrounds(main_info.draw_page);
645
646                         draw_leftovers(main_info.draw_page);
647
648                         draw_end();
649
650                         intr_sysupdate();
651
652                 }
653
654                 main_info.view_page = 0;
655                 main_info.draw_page = 1;
656
657                 dj_stop_sfx_channel(4);
658
659                 deinit_level();
660
661                 memset(mask_pic, 0, 102400L);
662
663                 register_background(NULL);
664
665                 draw_begin();
666
667                 put_text(main_info.view_page, 100, 50, "DOTT", 2);
668                 put_text(main_info.view_page, 160, 50, "JIFFY", 2);
669                 put_text(main_info.view_page, 220, 50, "FIZZ", 2);
670                 put_text(main_info.view_page, 280, 50, "MIJJI", 2);
671                 put_text(main_info.view_page, 40, 80, "DOTT", 2);
672                 put_text(main_info.view_page, 40, 110, "JIFFY", 2);
673                 put_text(main_info.view_page, 40, 140, "FIZZ", 2);
674                 put_text(main_info.view_page, 40, 170, "MIJJI", 2);
675
676                 for (c1 = 0; c1 < 4; c1++) {
677                         for (c2 = 0; c2 < 4; c2++) {
678                                 if (c2 != c1) {
679                                         sprintf(str1, "%d", player[c1].bumped[c2]);
680                                         put_text(main_info.view_page, 100 + c2 * 60, 80 + c1 * 30, str1, 2);
681                                 } else
682                                         put_text(main_info.view_page, 100 + c2 * 60, 80 + c1 * 30, "-", 2);
683                         }
684                         sprintf(str1, "%d", player[c1].bumps);
685                         put_text(main_info.view_page, 350, 80 + c1 * 30, str1, 2);
686                 }
687
688                 put_text(main_info.view_page, 200, 230, "Press ESC to continue", 2);
689
690                 draw_end();
691
692                 flippage(main_info.view_page);
693
694                 if ((handle = dat_open("menu.pcx", datfile_name, "rb")) == 0) {
695                         strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
696                         return 1;
697                 }
698                 if (read_pcx(handle, background_pic, 102400L, pal) != 0) {
699                         strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
700                         return 1;
701                 }
702                 fclose(handle);
703
704                 memset(cur_pal, 0, 768);
705
706                 setpalette(0, 256, cur_pal);
707
708                 mod_vol = 0;
709                 dj_ready_mod(MOD_SCORES);
710                 dj_set_mod_volume(mod_vol);
711                 dj_start_mod();
712                 dj_set_nosound(0);
713
714                 while (key_pressed(1) == 0) {
715                         if (mod_vol < 35)
716                                 mod_vol++;
717                         dj_set_mod_volume(mod_vol);
718                         for (c1 = 0; c1 < 768; c1++) {
719                                 if (cur_pal[c1] < pal[c1])
720                                         cur_pal[c1]++;
721                         }
722                         dj_mix();
723                         intr_sysupdate();
724                         wait_vrt(0);
725                         setpalette(0, 256, cur_pal);
726                         flippage(main_info.view_page);
727                 }
728                 while (key_pressed(1) == 1) {
729                         dj_mix();
730                         intr_sysupdate();
731                 }
732
733                 memset(pal, 0, 768);
734
735                 while (mod_vol > 0) {
736                         mod_vol--;
737                         dj_set_mod_volume(mod_vol);
738                         for (c1 = 0; c1 < 768; c1++) {
739                                 if (cur_pal[c1] > pal[c1])
740                                         cur_pal[c1]--;
741                         }
742                         dj_mix();
743                         wait_vrt(0);
744                         setpalette(0, 256, cur_pal);
745                         flippage(main_info.view_page);
746                 }
747
748                 fillpalette(0, 0, 0);
749
750                 dj_set_nosound(1);
751                 dj_stop_mod();
752
753         }
754
755         deinit_program();
756
757         return 0;
758 }
759
760
761 void steer_players(void)
762 {
763         int c1, c2;
764         int s1 = 0, s2 = 0;
765
766         update_player_actions();
767
768         for (c1 = 0; c1 < 4; c1++) {
769
770                 if (player[c1].enabled == 1) {
771
772                         if (player[c1].dead_flag == 0) {
773
774                                 if (player[c1].action_left && player[c1].action_right) {
775                                         if (player[c1].direction == 0) {
776                                                 if (player[c1].action_right) {
777                                                         s1 = (player[c1].x >> 16);
778                                                         s2 = (player[c1].y >> 16);
779                                                         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_ICE) {
780                                                                 if (player[c1].x_add < 0)
781                                                                         player[c1].x_add += 1024;
782                                                                 else
783                                                                         player[c1].x_add += 768;
784                                                         } else if ((ban_map[(s2 + 16) >> 4][s1 >> 4] != BAN_SOLID && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == BAN_ICE) || (ban_map[(s2 + 16) >> 4][s1 >> 4] == BAN_ICE && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != BAN_SOLID)) {
785                                                                 if (player[c1].x_add > 0)
786                                                                         player[c1].x_add += 1024;
787                                                                 else
788                                                                         player[c1].x_add += 768;
789                                                         } else {
790                                                                 if (player[c1].x_add < 0) {
791                                                                         player[c1].x_add += 16384;
792                                                                         if (player[c1].x_add < 98304L && player[c1].in_water == 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_SOLID)
793                                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
794                                                                 } else
795                                                                         player[c1].x_add += 12288;
796                                                         }
797                                                         if (player[c1].x_add > 98304L)
798                                                                 player[c1].x_add = 98304L;
799                                                         player[c1].direction = 0;
800                                                         if (player[c1].anim == 0) {
801                                                                 player[c1].anim = 1;
802                                                                 player[c1].frame = 0;
803                                                                 player[c1].frame_tick = 0;
804                                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
805                                                         }
806                                                 }
807                                         } else {
808                                                 if (player[c1].action_left) {
809                                                         s1 = (player[c1].x >> 16);
810                                                         s2 = (player[c1].y >> 16);
811                                                         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_ICE) {
812                                                                 if (player[c1].x_add > 0)
813                                                                         player[c1].x_add -= 1024;
814                                                                 else
815                                                                         player[c1].x_add -= 768;
816                                                         } else if ((ban_map[(s2 + 16) >> 4][s1 >> 4] != BAN_SOLID && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == BAN_ICE) || (ban_map[(s2 + 16) >> 4][s1 >> 4] == BAN_ICE && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != BAN_SOLID)) {
817                                                                 if (player[c1].x_add > 0)
818                                                                         player[c1].x_add -= 1024;
819                                                                 else
820                                                                         player[c1].x_add -= 768;
821                                                         } else {
822                                                                 if (player[c1].x_add > 0) {
823                                                                         player[c1].x_add -= 16384;
824                                                                         if (player[c1].x_add > -98304L && player[c1].in_water == 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_SOLID)
825                                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
826                                                                 } else
827                                                                         player[c1].x_add -= 12288;
828                                                         }
829                                                         if (player[c1].x_add < -98304L)
830                                                                 player[c1].x_add = -98304L;
831                                                         player[c1].direction = 1;
832                                                         if (player[c1].anim == 0) {
833                                                                 player[c1].anim = 1;
834                                                                 player[c1].frame = 0;
835                                                                 player[c1].frame_tick = 0;
836                                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
837                                                         }
838                                                 }
839                                         }
840                                 } else if (player[c1].action_left) {
841                                         s1 = (player[c1].x >> 16);
842                                         s2 = (player[c1].y >> 16);
843                                         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_ICE) {
844                                                 if (player[c1].x_add > 0)
845                                                         player[c1].x_add -= 1024;
846                                                 else
847                                                         player[c1].x_add -= 768;
848                                         } else if ((ban_map[(s2 + 16) >> 4][s1 >> 4] != BAN_SOLID && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == BAN_ICE) || (ban_map[(s2 + 16) >> 4][s1 >> 4] == BAN_ICE && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != BAN_SOLID)) {
849                                                 if (player[c1].x_add > 0)
850                                                         player[c1].x_add -= 1024;
851                                                 else
852                                                         player[c1].x_add -= 768;
853                                         } else {
854                                                 if (player[c1].x_add > 0) {
855                                                         player[c1].x_add -= 16384;
856                                                         if (player[c1].x_add > -98304L && player[c1].in_water == 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_SOLID)
857                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
858                                                 } else
859                                                         player[c1].x_add -= 12288;
860                                         }
861                                         if (player[c1].x_add < -98304L)
862                                                 player[c1].x_add = -98304L;
863                                         player[c1].direction = 1;
864                                         if (player[c1].anim == 0) {
865                                                 player[c1].anim = 1;
866                                                 player[c1].frame = 0;
867                                                 player[c1].frame_tick = 0;
868                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
869                                         }
870                                 } else if (player[c1].action_right) {
871                                         s1 = (player[c1].x >> 16);
872                                         s2 = (player[c1].y >> 16);
873                                         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_ICE) {
874                                                 if (player[c1].x_add < 0)
875                                                         player[c1].x_add += 1024;
876                                                 else
877                                                         player[c1].x_add += 768;
878                                         } else if ((ban_map[(s2 + 16) >> 4][s1 >> 4] != BAN_SOLID && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == BAN_ICE) || (ban_map[(s2 + 16) >> 4][s1 >> 4] == BAN_ICE && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != BAN_SOLID)) {
879                                                 if (player[c1].x_add > 0)
880                                                         player[c1].x_add += 1024;
881                                                 else
882                                                         player[c1].x_add += 768;
883                                         } else {
884                                                 if (player[c1].x_add < 0) {
885                                                         player[c1].x_add += 16384;
886                                                         if (player[c1].x_add < 98304L && player[c1].in_water == 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_SOLID)
887                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
888                                                 } else
889                                                         player[c1].x_add += 12288;
890                                         }
891                                         if (player[c1].x_add > 98304L)
892                                                 player[c1].x_add = 98304L;
893                                         player[c1].direction = 0;
894                                         if (player[c1].anim == 0) {
895                                                 player[c1].anim = 1;
896                                                 player[c1].frame = 0;
897                                                 player[c1].frame_tick = 0;
898                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
899                                         }
900                                 } else if ((!player[c1].action_left) && (!player[c1].action_right)) {
901                                         s1 = (player[c1].x >> 16);
902                                         s2 = (player[c1].y >> 16);
903                                         if (ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_SOLID || ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_SPRING || (((ban_map[(s2 + 16) >> 4][s1 >> 4] == BAN_SOLID || ban_map[(s2 + 16) >> 4][s1 >> 4] == BAN_SPRING) && ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] != BAN_ICE) || (ban_map[(s2 + 16) >> 4][s1 >> 4] != BAN_ICE && (ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == BAN_SPRING)))) {
904                                                 if (player[c1].x_add < 0) {
905                                                         player[c1].x_add += 16384;
906                                                         if (player[c1].x_add > 0)
907                                                                 player[c1].x_add = 0;
908                                                 } else {
909                                                         player[c1].x_add -= 16384;
910                                                         if (player[c1].x_add < 0)
911                                                                 player[c1].x_add = 0;
912                                                 }
913                                                 if (player[c1].x_add != 0 && ban_map[(s2 + 16) >> 4][(s1 + 8) >> 4] == BAN_SOLID)
914                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
915                                         }
916                                         if (player[c1].anim == 1) {
917                                                 player[c1].anim = 0;
918                                                 player[c1].frame = 0;
919                                                 player[c1].frame_tick = 0;
920                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
921                                         }
922                                 }
923                                 if (jetpack == 0) {
924                                         if (pogostick == 1 || (player[c1].jump_ready == 1 && player[c1].action_up)) {
925                                                 s1 = (player[c1].x >> 16);
926                                                 s2 = (player[c1].y >> 16);
927                                                 if (s2 < -16)
928                                                         s2 = -16;
929                                                 if (ban_map[(s2 + 16) >> 4][s1 >> 4] == BAN_SOLID || ban_map[(s2 + 16) >> 4][s1 >> 4] == BAN_ICE || ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[(s2 + 16) >> 4][(s1 + 15) >> 4] == BAN_ICE) {
930                                                         player[c1].y_add = -280000L;
931                                                         player[c1].anim = 2;
932                                                         player[c1].frame = 0;
933                                                         player[c1].frame_tick = 0;
934                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
935                                                         player[c1].jump_ready = 0;
936                                                         player[c1].jump_abort = 1;
937                                                         if (pogostick == 0)
938                                                                 dj_play_sfx(SFX_JUMP, (unsigned short)(SFX_JUMP_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
939                                                         else
940                                                                 dj_play_sfx(SFX_SPRING, (unsigned short)(SFX_SPRING_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
941                                                 }
942                                                 if ((ban_map[(s2 + 7) >> 4][s1 >> 4] == BAN_VOID || ban_map[(s2 + 7) >> 4][(s1 + 15) >> 4] == BAN_VOID) && (ban_map[(s2 + 8) >> 4][s1 >> 4] == BAN_WATER || ban_map[(s2 + 8) >> 4][(s1 + 15) >> 4] == BAN_WATER)) {
943                                                         player[c1].y_add = -196608L;
944                                                         player[c1].in_water = 0;
945                                                         player[c1].anim = 2;
946                                                         player[c1].frame = 0;
947                                                         player[c1].frame_tick = 0;
948                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
949                                                         player[c1].jump_ready = 0;
950                                                         player[c1].jump_abort = 1;
951                                                         if (pogostick == 0)
952                                                                 dj_play_sfx(SFX_JUMP, (unsigned short)(SFX_JUMP_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
953                                                         else
954                                                                 dj_play_sfx(SFX_SPRING, (unsigned short)(SFX_SPRING_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
955                                                 }
956                                         }
957                                         if (pogostick == 0 && (!player[c1].action_up)) {
958                                                 player[c1].jump_ready = 1;
959                                                 if (player[c1].in_water == 0 && player[c1].y_add < 0 && player[c1].jump_abort == 1) {
960                                                         if (bunnies_in_space == 0)
961                                                                 player[c1].y_add += 32768;
962                                                         else
963                                                                 player[c1].y_add += 16384;
964                                                         if (player[c1].y_add > 0)
965                                                                 player[c1].y_add = 0;
966                                                 }
967                                         }
968                                 } else {
969
970                                         if (player[c1].action_up) {
971                                                 player[c1].y_add -= 16384;
972                                                 if (player[c1].y_add < -400000L)
973                                                         player[c1].y_add = -400000L;
974                                                 if ((ban_map[(s2 + 7) >> 4][s1 >> 4] == BAN_VOID || ban_map[(s2 + 7) >> 4][(s1 + 15) >> 4] == BAN_VOID) && (ban_map[(s2 + 8) >> 4][s1 >> 4] == BAN_WATER || ban_map[(s2 + 8) >> 4][(s1 + 15) >> 4] == BAN_WATER))
975                                                         player[c1].in_water = 0;
976                                                 if (rnd(100) < 50)
977                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 6 + rnd(5), (player[c1].y >> 16) + 10 + rnd(5), 0, 16384 + rnd(8192), OBJ_ANIM_SMOKE, 0);
978                                         }
979
980                                 }
981
982                                 player[c1].x += player[c1].x_add;
983                                 if ((player[c1].x >> 16) < 0) {
984                                         player[c1].x = 0;
985                                         player[c1].x_add = 0;
986                                 }
987                                 if ((player[c1].x >> 16) + 15 > 351) {
988                                         player[c1].x = 336L << 16;
989                                         player[c1].x_add = 0;
990                                 }
991                                 if (player[c1].y > 0) {
992                                         s1 = (player[c1].x >> 16);
993                                         s2 = (player[c1].y >> 16);
994                                         if (ban_map[s2 >> 4][s1 >> 4] == BAN_SOLID || ban_map[s2 >> 4][s1 >> 4] == BAN_ICE || ban_map[s2 >> 4][s1 >> 4] == BAN_SPRING || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SOLID || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_ICE || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SPRING) {
995                                                 player[c1].x = (((s1 + 16) & 0xfff0)) << 16;
996                                                 player[c1].x_add = 0;
997                                         }
998                                         s1 = (player[c1].x >> 16);
999                                         s2 = (player[c1].y >> 16);
1000                                         if (ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_ICE || ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_SPRING || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_ICE || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SPRING) {
1001                                                 player[c1].x = (((s1 + 16) & 0xfff0) - 16) << 16;
1002                                                 player[c1].x_add = 0;
1003                                         }
1004                                 } else {
1005                                         s1 = (player[c1].x >> 16);
1006                                         s2 = 0;
1007                                         if (ban_map[s2 >> 4][s1 >> 4] == BAN_SOLID || ban_map[s2 >> 4][s1 >> 4] == BAN_ICE || ban_map[s2 >> 4][s1 >> 4] == BAN_SPRING || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SOLID || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_ICE || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SPRING) {
1008                                                 player[c1].x = (((s1 + 16) & 0xfff0)) << 16;
1009                                                 player[c1].x_add = 0;
1010                                         }
1011                                         s1 = (player[c1].x >> 16);
1012                                         s2 = 0;
1013                                         if (ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_ICE || ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_SPRING || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_ICE || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SPRING) {
1014                                                 player[c1].x = (((s1 + 16) & 0xfff0) - 16) << 16;
1015                                                 player[c1].x_add = 0;
1016                                         }
1017                                 }
1018
1019                                 player[c1].y += player[c1].y_add;
1020
1021                                 s1 = (player[c1].x >> 16);
1022                                 s2 = (player[c1].y >> 16);
1023                                 if (ban_map[(s2 + 15) >> 4][(s1 + 8) >> 4] == BAN_SPRING || ((ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SPRING && ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] != BAN_SOLID) || (ban_map[(s2 + 15) >> 4][s1 >> 4] != BAN_SOLID && ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SPRING))) {
1024                                         player[c1].y = ((player[c1].y >> 16) & 0xfff0) << 16;
1025                                         player[c1].y_add = -400000L;
1026                                         player[c1].anim = 2;
1027                                         player[c1].frame = 0;
1028                                         player[c1].frame_tick = 0;
1029                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1030                                         player[c1].jump_ready = 0;
1031                                         player[c1].jump_abort = 0;
1032                                         for (c2 = 0; c2 < NUM_OBJECTS; c2++) {
1033                                                 if (objects[c2].used == 1 && objects[c2].type == OBJ_SPRING) {
1034                                                         if (ban_map[(s2 + 15) >> 4][(s1 + 8) >> 4] == BAN_SPRING) {
1035                                                                 if ((objects[c2].x >> 20) == ((s1 + 8) >> 4) && (objects[c2].y >> 20) == ((s2 + 15) >> 4)) {
1036                                                                         objects[c2].frame = 0;
1037                                                                         objects[c2].ticks = object_anims[objects[c2].anim].frame[objects[c2].frame].ticks;
1038                                                                         objects[c2].image = object_anims[objects[c2].anim].frame[objects[c2].frame].image;
1039                                                                         break;
1040                                                                 }
1041                                                         } else {
1042                                                                 if (ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SPRING) {
1043                                                                         if ((objects[c2].x >> 20) == (s1 >> 4) && (objects[c2].y >> 20) == ((s2 + 15) >> 4)) {
1044                                                                                 objects[c2].frame = 0;
1045                                                                                 objects[c2].ticks = object_anims[objects[c2].anim].frame[objects[c2].frame].ticks;
1046                                                                                 objects[c2].image = object_anims[objects[c2].anim].frame[objects[c2].frame].image;
1047                                                                                 break;
1048                                                                         }
1049                                                                 } else if (ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SPRING) {
1050                                                                         if ((objects[c2].x >> 20) == ((s1 + 15) >> 4) && (objects[c2].y >> 20) == ((s2 + 15) >> 4)) {
1051                                                                                 objects[c2].frame = 0;
1052                                                                                 objects[c2].ticks = object_anims[objects[c2].anim].frame[objects[c2].frame].ticks;
1053                                                                                 objects[c2].image = object_anims[objects[c2].anim].frame[objects[c2].frame].image;
1054                                                                                 break;
1055                                                                         }
1056                                                                 }
1057                                                         }
1058                                                 }
1059                                         }
1060                                         dj_play_sfx(SFX_SPRING, (unsigned short)(SFX_SPRING_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
1061                                 }
1062                                 s1 = (player[c1].x >> 16);
1063                                 s2 = (player[c1].y >> 16);
1064                                 if (s2 < 0)
1065                                         s2 = 0;
1066                                 if (ban_map[s2 >> 4][s1 >> 4] == BAN_SOLID || ban_map[s2 >> 4][s1 >> 4] == BAN_ICE || ban_map[s2 >> 4][s1 >> 4] == BAN_SPRING || ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_ICE || ban_map[s2 >> 4][(s1 + 15) >> 4] == BAN_SPRING) {
1067                                         player[c1].y = (((s2 + 16) & 0xfff0)) << 16;
1068                                         player[c1].y_add = 0;
1069                                         player[c1].anim = 0;
1070                                         player[c1].frame = 0;
1071                                         player[c1].frame_tick = 0;
1072                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1073                                 }
1074                                 s1 = (player[c1].x >> 16);
1075                                 s2 = (player[c1].y >> 16);
1076                                 if (s2 < 0)
1077                                         s2 = 0;
1078                                 if (ban_map[(s2 + 8) >> 4][(s1 + 8) >> 4] == BAN_WATER) {
1079                                         if (player[c1].in_water == 0) {
1080                                                 player[c1].in_water = 1;
1081                                                 player[c1].anim = 4;
1082                                                 player[c1].frame = 0;
1083                                                 player[c1].frame_tick = 0;
1084                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1085                                                 if (player[c1].y_add >= 32768) {
1086                                                         add_object(OBJ_SPLASH, (player[c1].x >> 16) + 8, ((player[c1].y >> 16) & 0xfff0) + 15, 0, 0, OBJ_ANIM_SPLASH, 0);
1087                                                         if (blood_is_thicker_than_water == 0)
1088                                                                 dj_play_sfx(SFX_SPLASH, (unsigned short)(SFX_SPLASH_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
1089                                                         else
1090                                                                 dj_play_sfx(SFX_SPLASH, (unsigned short)(SFX_SPLASH_FREQ + rnd(2000) - 5000), 64, 0, 0, -1);
1091                                                 }
1092                                         }
1093                                         player[c1].y_add -= 1536;
1094                                         if (player[c1].y_add < 0 && player[c1].anim != 5) {
1095                                                 player[c1].anim = 5;
1096                                                 player[c1].frame = 0;
1097                                                 player[c1].frame_tick = 0;
1098                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1099                                         }
1100                                         if (player[c1].y_add < -65536L)
1101                                                 player[c1].y_add = -65536L;
1102                                         if (player[c1].y_add > 65535L)
1103                                                 player[c1].y_add = 65535L;
1104                                         if (ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SOLID || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_ICE || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_ICE) {
1105                                                 player[c1].y = (((s2 + 16) & 0xfff0) - 16) << 16;
1106                                                 player[c1].y_add = 0;
1107                                         }
1108                                 } else if (ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SOLID || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_ICE || ban_map[(s2 + 15) >> 4][s1 >> 4] == BAN_SPRING || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SOLID || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_ICE || ban_map[(s2 + 15) >> 4][(s1 + 15) >> 4] == BAN_SPRING) {
1109                                         player[c1].in_water = 0;
1110                                         player[c1].y = (((s2 + 16) & 0xfff0) - 16) << 16;
1111                                         player[c1].y_add = 0;
1112                                         if (player[c1].anim != 0 && player[c1].anim != 1) {
1113                                                 player[c1].anim = 0;
1114                                                 player[c1].frame = 0;
1115                                                 player[c1].frame_tick = 0;
1116                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1117                                         }
1118                                 } else {
1119                                         if (player[c1].in_water == 0) {
1120                                                 if (bunnies_in_space == 0)
1121                                                         player[c1].y_add += 12288;
1122                                                 else
1123                                                         player[c1].y_add += 6144;
1124                                                 if (player[c1].y_add > 327680L)
1125                                                         player[c1].y_add = 327680L;
1126                                         } else {
1127                                                 player[c1].y = (player[c1].y & 0xffff0000) + 0x10000;
1128                                                 player[c1].y_add = 0;
1129                                         }
1130                                         player[c1].in_water = 0;
1131                                 }
1132                                 if (player[c1].y_add > 36864 && player[c1].anim != 3 && player[c1].in_water == 0) {
1133                                         player[c1].anim = 3;
1134                                         player[c1].frame = 0;
1135                                         player[c1].frame_tick = 0;
1136                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1137                                 }
1138
1139                         }
1140
1141                         player[c1].frame_tick++;
1142                         if (player[c1].frame_tick >= player_anims[player[c1].anim].frame[player[c1].frame].ticks) {
1143                                 player[c1].frame++;
1144                                 if (player[c1].frame >= player_anims[player[c1].anim].num_frames) {
1145                                         if (player[c1].anim != 6)
1146                                                 player[c1].frame = player_anims[player[c1].anim].restart_frame;
1147                                         else
1148                                                 position_player(c1);
1149                                 }
1150                                 player[c1].frame_tick = 0;
1151                         }
1152                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
1153
1154                 }
1155
1156         }
1157
1158 }
1159
1160
1161 void position_player(int player_num)
1162 {
1163         int c1;
1164         int s1, s2;
1165
1166         while (1) {
1167                 while (1) {
1168                         s1 = rnd(22);
1169                         s2 = rnd(16);
1170                         if (ban_map[s2][s1] == BAN_VOID && (ban_map[s2 + 1][s1] == BAN_SOLID || ban_map[s2 + 1][s1] == BAN_ICE))
1171                                 break;
1172                 }
1173                 for (c1 = 0; c1 < 4; c1++) {
1174                         if (c1 != player_num && player[c1].enabled == 1) {
1175                                 if (abs((s1 << 4) - (player[c1].x >> 16)) < 32 && abs((s2 << 4) - (player[c1].y >> 16)) < 32)
1176                                         break;
1177                         }
1178                 }
1179                 if (c1 == 4) {
1180                         player[player_num].dead_flag = 0;
1181                         player[player_num].x = (long) s1 << 20;
1182                         player[player_num].y = (long) s2 << 20;
1183                         player[player_num].x_add = player[player_num].y_add = 0;
1184                         player[player_num].direction = 0;
1185                         player[player_num].jump_ready = 1;
1186                         player[player_num].in_water = 0;
1187                         player[player_num].anim = 0;
1188                         player[player_num].frame = 0;
1189                         player[player_num].frame_tick = 0;
1190                         player[player_num].image = player_anims[player[player_num].anim].frame[player[player_num].frame].image;
1191                         break;
1192                 }
1193         }
1194
1195 }
1196
1197
1198 void add_object(int type, int x, int y, int x_add, int y_add, int anim, int frame)
1199 {
1200         int c1;
1201
1202         for (c1 = 0; c1 < NUM_OBJECTS; c1++) {
1203                 if (objects[c1].used == 0) {
1204                         objects[c1].used = 1;
1205                         objects[c1].type = type;
1206                         objects[c1].x = (long) x << 16;
1207                         objects[c1].y = (long) y << 16;
1208                         objects[c1].x_add = x_add;
1209                         objects[c1].y_add = y_add;
1210                         objects[c1].x_acc = 0;
1211                         objects[c1].y_acc = 0;
1212                         objects[c1].anim = anim;
1213                         objects[c1].frame = frame;
1214                         objects[c1].ticks = object_anims[anim].frame[frame].ticks;
1215                         objects[c1].image = object_anims[anim].frame[frame].image;
1216                         break;
1217                 }
1218         }
1219
1220 }
1221
1222
1223 void update_objects(void)
1224 {
1225         int c1;
1226         int s1 = 0;
1227
1228         for (c1 = 0; c1 < NUM_OBJECTS; c1++) {
1229                 if (objects[c1].used == 1) {
1230                         switch (objects[c1].type) {
1231                         case OBJ_SPRING:
1232                                 objects[c1].ticks--;
1233                                 if (objects[c1].ticks <= 0) {
1234                                         objects[c1].frame++;
1235                                         if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames) {
1236                                                 objects[c1].frame--;
1237                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1238                                         } else {
1239                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1240                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1241                                         }
1242                                 }
1243                                 if (objects[c1].used == 1)
1244                                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1245                                 break;
1246                         case OBJ_SPLASH:
1247                                 objects[c1].ticks--;
1248                                 if (objects[c1].ticks <= 0) {
1249                                         objects[c1].frame++;
1250                                         if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames)
1251                                                 objects[c1].used = 0;
1252                                         else {
1253                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1254                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1255                                         }
1256                                 }
1257                                 if (objects[c1].used == 1)
1258                                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1259                                 break;
1260                         case OBJ_SMOKE:
1261                                 objects[c1].x += objects[c1].x_add;
1262                                 objects[c1].y += objects[c1].y_add;
1263                                 objects[c1].ticks--;
1264                                 if (objects[c1].ticks <= 0) {
1265                                         objects[c1].frame++;
1266                                         if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames)
1267                                                 objects[c1].used = 0;
1268                                         else {
1269                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1270                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1271                                         }
1272                                 }
1273                                 if (objects[c1].used == 1)
1274                                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1275                                 break;
1276                         case OBJ_YEL_BUTFLY:
1277                         case OBJ_PINK_BUTFLY:
1278                                 objects[c1].x_acc += rnd(128) - 64;
1279                                 if (objects[c1].x_acc < -1024)
1280                                         objects[c1].x_acc = -1024;
1281                                 if (objects[c1].x_acc > 1024)
1282                                         objects[c1].x_acc = 1024;
1283                                 objects[c1].x_add += objects[c1].x_acc;
1284                                 if (objects[c1].x_add < -32768)
1285                                         objects[c1].x_add = -32768;
1286                                 if (objects[c1].x_add > 32768)
1287                                         objects[c1].x_add = 32768;
1288                                 objects[c1].x += objects[c1].x_add;
1289                                 if ((objects[c1].x >> 16) < 16) {
1290                                         objects[c1].x = 16 << 16;
1291                                         objects[c1].x_add = -objects[c1].x_add >> 2;
1292                                         objects[c1].x_acc = 0;
1293                                 } else if ((objects[c1].x >> 16) > 350) {
1294                                         objects[c1].x = 350 << 16;
1295                                         objects[c1].x_add = -objects[c1].x_add >> 2;
1296                                         objects[c1].x_acc = 0;
1297                                 }
1298                                 if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 0) {
1299                                         if (objects[c1].x_add < 0) {
1300                                                 objects[c1].x = (((objects[c1].x >> 16) + 16) & 0xfff0) << 16;
1301                                         } else {
1302                                                 objects[c1].x = ((((objects[c1].x >> 16) - 16) & 0xfff0) + 15) << 16;
1303                                         }
1304                                         objects[c1].x_add = -objects[c1].x_add >> 2;
1305                                         objects[c1].x_acc = 0;
1306                                 }
1307                                 objects[c1].y_acc += rnd(64) - 32;
1308                                 if (objects[c1].y_acc < -1024)
1309                                         objects[c1].y_acc = -1024;
1310                                 if (objects[c1].y_acc > 1024)
1311                                         objects[c1].y_acc = 1024;
1312                                 objects[c1].y_add += objects[c1].y_acc;
1313                                 if (objects[c1].y_add < -32768)
1314                                         objects[c1].y_add = -32768;
1315                                 if (objects[c1].y_add > 32768)
1316                                         objects[c1].y_add = 32768;
1317                                 objects[c1].y += objects[c1].y_add;
1318                                 if ((objects[c1].y >> 16) < 0) {
1319                                         objects[c1].y = 0;
1320                                         objects[c1].y_add = -objects[c1].y_add >> 2;
1321                                         objects[c1].y_acc = 0;
1322                                 } else if ((objects[c1].y >> 16) > 255) {
1323                                         objects[c1].y = 255 << 16;
1324                                         objects[c1].y_add = -objects[c1].y_add >> 2;
1325                                         objects[c1].y_acc = 0;
1326                                 }
1327                                 if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 0) {
1328                                         if (objects[c1].y_add < 0) {
1329                                                 objects[c1].y = (((objects[c1].y >> 16) + 16) & 0xfff0) << 16;
1330                                         } else {
1331                                                 objects[c1].y = ((((objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1332                                         }
1333                                         objects[c1].y_add = -objects[c1].y_add >> 2;
1334                                         objects[c1].y_acc = 0;
1335                                 }
1336                                 if (objects[c1].type == OBJ_YEL_BUTFLY) {
1337                                         if (objects[c1].x_add < 0 && objects[c1].anim != OBJ_ANIM_YEL_BUTFLY_LEFT) {
1338                                                 objects[c1].anim = OBJ_ANIM_YEL_BUTFLY_LEFT;
1339                                                 objects[c1].frame = 0;
1340                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1341                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1342                                         } else if (objects[c1].x_add > 0 && objects[c1].anim != OBJ_ANIM_YEL_BUTFLY_RIGHT) {
1343                                                 objects[c1].anim = OBJ_ANIM_YEL_BUTFLY_RIGHT;
1344                                                 objects[c1].frame = 0;
1345                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1346                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1347                                         }
1348                                 } else {
1349                                         if (objects[c1].x_add < 0 && objects[c1].anim != OBJ_ANIM_PINK_BUTFLY_LEFT) {
1350                                                 objects[c1].anim = OBJ_ANIM_PINK_BUTFLY_LEFT;
1351                                                 objects[c1].frame = 0;
1352                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1353                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1354                                         } else if (objects[c1].x_add > 0 && objects[c1].anim != OBJ_ANIM_PINK_BUTFLY_RIGHT) {
1355                                                 objects[c1].anim = OBJ_ANIM_PINK_BUTFLY_RIGHT;
1356                                                 objects[c1].frame = 0;
1357                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1358                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1359                                         }
1360                                 }
1361                                 objects[c1].ticks--;
1362                                 if (objects[c1].ticks <= 0) {
1363                                         objects[c1].frame++;
1364                                         if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames)
1365                                                 objects[c1].frame = object_anims[objects[c1].anim].restart_frame;
1366                                         else {
1367                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1368                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1369                                         }
1370                                 }
1371                                 if (objects[c1].used == 1)
1372                                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1373                                 break;
1374                         case OBJ_FUR:
1375                                 if (rnd(100) < 30)
1376                                         add_object(OBJ_FLESH_TRACE, objects[c1].x >> 16, objects[c1].y >> 16, 0, 0, OBJ_ANIM_FLESH_TRACE, 0);
1377                                 if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 0) {
1378                                         objects[c1].y_add += 3072;
1379                                         if (objects[c1].y_add > 196608L)
1380                                                 objects[c1].y_add = 196608L;
1381                                 } else if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 2) {
1382                                         if (objects[c1].x_add < 0) {
1383                                                 if (objects[c1].x_add < -65536L)
1384                                                         objects[c1].x_add = -65536L;
1385                                                 objects[c1].x_add += 1024;
1386                                                 if (objects[c1].x_add > 0)
1387                                                         objects[c1].x_add = 0;
1388                                         } else {
1389                                                 if (objects[c1].x_add > 65536L)
1390                                                         objects[c1].x_add = 65536L;
1391                                                 objects[c1].x_add -= 1024;
1392                                                 if (objects[c1].x_add < 0)
1393                                                         objects[c1].x_add = 0;
1394                                         }
1395                                         objects[c1].y_add += 1024;
1396                                         if (objects[c1].y_add < -65536L)
1397                                                 objects[c1].y_add = -65536L;
1398                                         if (objects[c1].y_add > 65536L)
1399                                                 objects[c1].y_add = 65536L;
1400                                 }
1401                                 objects[c1].x += objects[c1].x_add;
1402                                 if ((objects[c1].y >> 16) > 0 && (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 1 || ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 3)) {
1403                                         if (objects[c1].x_add < 0) {
1404                                                 objects[c1].x = (((objects[c1].x >> 16) + 16) & 0xfff0) << 16;
1405                                                 objects[c1].x_add = -objects[c1].x_add >> 2;
1406                                         } else {
1407                                                 objects[c1].x = ((((objects[c1].x >> 16) - 16) & 0xfff0) + 15) << 16;
1408                                                 objects[c1].x_add = -objects[c1].x_add >> 2;
1409                                         }
1410                                 }
1411                                 objects[c1].y += objects[c1].y_add;
1412                                 if ((objects[c1].x >> 16) < -5 || (objects[c1].x >> 16) > 405 || (objects[c1].y >> 16) > 260)
1413                                         objects[c1].used = 0;
1414                                 if ((objects[c1].y >> 16) > 0 && (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 0)) {
1415                                         if (objects[c1].y_add < 0) {
1416                                                 if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 2) {
1417                                                         objects[c1].y = (((objects[c1].y >> 16) + 16) & 0xfff0) << 16;
1418                                                         objects[c1].x_add >>= 2;
1419                                                         objects[c1].y_add = -objects[c1].y_add >> 2;
1420                                                 }
1421                                         } else {
1422                                                 if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 1) {
1423                                                         if (objects[c1].y_add > 131072L) {
1424                                                                 objects[c1].y = ((((objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1425                                                                 objects[c1].x_add >>= 2;
1426                                                                 objects[c1].y_add = -objects[c1].y_add >> 2;
1427                                                         } else
1428                                                                 objects[c1].used = 0;
1429                                                 } else if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 3) {
1430                                                         objects[c1].y = ((((objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1431                                                         if (objects[c1].y_add > 131072L)
1432                                                                 objects[c1].y_add = -objects[c1].y_add >> 2;
1433                                                         else
1434                                                                 objects[c1].y_add = 0;
1435                                                 }
1436                                         }
1437                                 }
1438                                 if (objects[c1].x_add < 0 && objects[c1].x_add > -16384)
1439                                         objects[c1].x_add = -16384;
1440                                 if (objects[c1].x_add > 0 && objects[c1].x_add < 16384)
1441                                         objects[c1].x_add = 16384;
1442                                 if (objects[c1].used == 1) {
1443                                         s1 = (int)(atan2(objects[c1].y_add, objects[c1].x_add) * 4 / M_PI);
1444                                         if (s1 < 0)
1445                                                 s1 += 8;
1446                                         if (s1 < 0)
1447                                                 s1 = 0;
1448                                         if (s1 > 7)
1449                                                 s1 = 7;
1450                                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame + s1, object_gobs);
1451                                 }
1452                                 break;
1453                         case OBJ_FLESH:
1454                                 if (rnd(100) < 30) {
1455                                         if (objects[c1].frame == 76)
1456                                                 add_object(OBJ_FLESH_TRACE, objects[c1].x >> 16, objects[c1].y >> 16, 0, 0, OBJ_ANIM_FLESH_TRACE, 1);
1457                                         else if (objects[c1].frame == 77)
1458                                                 add_object(OBJ_FLESH_TRACE, objects[c1].x >> 16, objects[c1].y >> 16, 0, 0, OBJ_ANIM_FLESH_TRACE, 2);
1459                                         else if (objects[c1].frame == 78)
1460                                                 add_object(OBJ_FLESH_TRACE, objects[c1].x >> 16, objects[c1].y >> 16, 0, 0, OBJ_ANIM_FLESH_TRACE, 3);
1461                                 }
1462                                 if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 0) {
1463                                         objects[c1].y_add += 3072;
1464                                         if (objects[c1].y_add > 196608L)
1465                                                 objects[c1].y_add = 196608L;
1466                                 } else if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 2) {
1467                                         if (objects[c1].x_add < 0) {
1468                                                 if (objects[c1].x_add < -65536L)
1469                                                         objects[c1].x_add = -65536L;
1470                                                 objects[c1].x_add += 1024;
1471                                                 if (objects[c1].x_add > 0)
1472                                                         objects[c1].x_add = 0;
1473                                         } else {
1474                                                 if (objects[c1].x_add > 65536L)
1475                                                         objects[c1].x_add = 65536L;
1476                                                 objects[c1].x_add -= 1024;
1477                                                 if (objects[c1].x_add < 0)
1478                                                         objects[c1].x_add = 0;
1479                                         }
1480                                         objects[c1].y_add += 1024;
1481                                         if (objects[c1].y_add < -65536L)
1482                                                 objects[c1].y_add = -65536L;
1483                                         if (objects[c1].y_add > 65536L)
1484                                                 objects[c1].y_add = 65536L;
1485                                 }
1486                                 objects[c1].x += objects[c1].x_add;
1487                                 if ((objects[c1].y >> 16) > 0 && (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 1 || ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 3)) {
1488                                         if (objects[c1].x_add < 0) {
1489                                                 objects[c1].x = (((objects[c1].x >> 16) + 16) & 0xfff0) << 16;
1490                                                 objects[c1].x_add = -objects[c1].x_add >> 2;
1491                                         } else {
1492                                                 objects[c1].x = ((((objects[c1].x >> 16) - 16) & 0xfff0) + 15) << 16;
1493                                                 objects[c1].x_add = -objects[c1].x_add >> 2;
1494                                         }
1495                                 }
1496                                 objects[c1].y += objects[c1].y_add;
1497                                 if ((objects[c1].x >> 16) < -5 || (objects[c1].x >> 16) > 405 || (objects[c1].y >> 16) > 260)
1498                                         objects[c1].used = 0;
1499                                 if ((objects[c1].y >> 16) > 0 && (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 0)) {
1500                                         if (objects[c1].y_add < 0) {
1501                                                 if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] != 2) {
1502                                                         objects[c1].y = (((objects[c1].y >> 16) + 16) & 0xfff0) << 16;
1503                                                         objects[c1].x_add >>= 2;
1504                                                         objects[c1].y_add = -objects[c1].y_add >> 2;
1505                                                 }
1506                                         } else {
1507                                                 if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 1) {
1508                                                         if (objects[c1].y_add > 131072L) {
1509                                                                 objects[c1].y = ((((objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1510                                                                 objects[c1].x_add >>= 2;
1511                                                                 objects[c1].y_add = -objects[c1].y_add >> 2;
1512                                                         } else {
1513                                                                 if (rnd(100) < 10) {
1514                                                                         s1 = rnd(4) - 2;
1515                                                                         add_leftovers(0, objects[c1].x >> 16, (objects[c1].y >> 16) + s1, objects[c1].frame, object_gobs);
1516                                                                         add_leftovers(1, objects[c1].x >> 16, (objects[c1].y >> 16) + s1, objects[c1].frame, object_gobs);
1517                                                                 }
1518                                                                 objects[c1].used = 0;
1519                                                         }
1520                                                 } else if (ban_map[objects[c1].y >> 20][objects[c1].x >> 20] == 3) {
1521                                                         objects[c1].y = ((((objects[c1].y >> 16) - 16) & 0xfff0) + 15) << 16;
1522                                                         if (objects[c1].y_add > 131072L)
1523                                                                 objects[c1].y_add = -objects[c1].y_add >> 2;
1524                                                         else
1525                                                                 objects[c1].y_add = 0;
1526                                                 }
1527                                         }
1528                                 }
1529                                 if (objects[c1].x_add < 0 && objects[c1].x_add > -16384)
1530                                         objects[c1].x_add = -16384;
1531                                 if (objects[c1].x_add > 0 && objects[c1].x_add < 16384)
1532                                         objects[c1].x_add = 16384;
1533                                 if (objects[c1].used == 1)
1534                                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame, object_gobs);
1535                                 break;
1536                         case OBJ_FLESH_TRACE:
1537                                 objects[c1].ticks--;
1538                                 if (objects[c1].ticks <= 0) {
1539                                         objects[c1].frame++;
1540                                         if (objects[c1].frame >= object_anims[objects[c1].anim].num_frames)
1541                                                 objects[c1].used = 0;
1542                                         else {
1543                                                 objects[c1].ticks = object_anims[objects[c1].anim].frame[objects[c1].frame].ticks;
1544                                                 objects[c1].image = object_anims[objects[c1].anim].frame[objects[c1].frame].image;
1545                                         }
1546                                 }
1547                                 if (objects[c1].used == 1)
1548                                         add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs);
1549                                 break;
1550                         }
1551                 }
1552         }
1553
1554 }
1555
1556
1557 int add_pob(int page, int x, int y, int image, char *pob_data)
1558 {
1559
1560         if (main_info.page_info[page].num_pobs >= NUM_POBS)
1561                 return 1;
1562
1563         main_info.page_info[page].pobs[main_info.page_info[page].num_pobs].x = x;
1564         main_info.page_info[page].pobs[main_info.page_info[page].num_pobs].y = y;
1565         main_info.page_info[page].pobs[main_info.page_info[page].num_pobs].image = image;
1566         main_info.page_info[page].pobs[main_info.page_info[page].num_pobs].pob_data = pob_data;
1567         main_info.page_info[page].num_pobs++;
1568
1569         return 0;
1570
1571 }
1572
1573
1574 void draw_flies(int page)
1575 {
1576         int c2;
1577
1578         for (c2 = 0; c2 < NUM_FLIES; c2++) {
1579                 flies[c2].back[main_info.draw_page] = get_pixel(main_info.draw_page, flies[c2].x, flies[c2].y);
1580                 flies[c2].back_defined[main_info.draw_page] = 1;
1581                 if (mask_pic[(flies[c2].y * JNB_WIDTH) + flies[c2].x] == 0)
1582                         set_pixel(main_info.draw_page, flies[c2].x, flies[c2].y, 0);
1583         }
1584 }
1585
1586 void draw_pobs(int page)
1587 {
1588         int c1;
1589         int back_buf_ofs;
1590
1591         back_buf_ofs = 0;
1592
1593         for (c1 = main_info.page_info[page].num_pobs - 1; c1 >= 0; c1--) {
1594                 main_info.page_info[page].pobs[c1].back_buf_ofs = back_buf_ofs;
1595                 get_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), (char *) (main_info.pob_backbuf[page] + back_buf_ofs));
1596                 back_buf_ofs += pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data);
1597                 put_pob(page, main_info.page_info[page].pobs[c1].x, main_info.page_info[page].pobs[c1].y, main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data, 1, mask_pic);
1598         }
1599
1600 }
1601
1602
1603 void redraw_flies_background(int page)
1604 {
1605         int c2;
1606
1607         for (c2 = NUM_FLIES - 1; c2 >= 0; c2--) {
1608                 if (flies[c2].back_defined[page] == 1)
1609                         set_pixel(page, flies[c2].old_x, flies[c2].old_y, flies[c2].back[page]);
1610         }
1611 }
1612
1613
1614 void redraw_pob_backgrounds(int page)
1615 {
1616         int c1;
1617
1618         for (c1 = 0; c1 < main_info.page_info[page].num_pobs; c1++)
1619                 put_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), (char *) (main_info.pob_backbuf[page] + main_info.page_info[page].pobs[c1].back_buf_ofs));
1620
1621 }
1622
1623
1624 int add_leftovers(int page, int x, int y, int image, char *pob_data)
1625 {
1626
1627         if (leftovers.page[page].num_pobs >= NUM_LEFTOVERS)
1628                 return 1;
1629
1630         leftovers.page[page].pobs[leftovers.page[page].num_pobs].x = x;
1631         leftovers.page[page].pobs[leftovers.page[page].num_pobs].y = y;
1632         leftovers.page[page].pobs[leftovers.page[page].num_pobs].image = image;
1633         leftovers.page[page].pobs[leftovers.page[page].num_pobs].pob_data = pob_data;
1634         leftovers.page[page].num_pobs++;
1635
1636         return 0;
1637
1638 }
1639
1640
1641 void draw_leftovers(int page)
1642 {
1643         int c1;
1644
1645         for (c1 = leftovers.page[page].num_pobs - 1; c1 >= 0; c1--)
1646                 put_pob(page, leftovers.page[page].pobs[c1].x, leftovers.page[page].pobs[c1].y, leftovers.page[page].pobs[c1].image, leftovers.page[page].pobs[c1].pob_data, 1, mask_pic);
1647
1648         leftovers.page[page].num_pobs = 0;
1649
1650 }
1651
1652
1653 int init_level(int level, char *pal)
1654 {
1655         FILE *handle;
1656         int c1, c2;
1657         int s1, s2;
1658
1659         if ((handle = dat_open("level.pcx", datfile_name, "rb")) == 0) {
1660                 strcpy(main_info.error_str, "Error loading 'level.pcx', aborting...\n");
1661                 return 1;
1662         }
1663         if (read_pcx(handle, background_pic, 102400L, pal) != 0) {
1664                 strcpy(main_info.error_str, "Error loading 'level.pcx', aborting...\n");
1665                 return 1;
1666         }
1667         fclose(handle);
1668         if ((handle = dat_open("mask.pcx", datfile_name, "rb")) == 0) {
1669                 strcpy(main_info.error_str, "Error loading 'mask.pcx', aborting...\n");
1670                 return 1;
1671         }
1672         if (read_pcx(handle, mask_pic, 102400L, 0) != 0) {
1673                 strcpy(main_info.error_str, "Error loading 'mask.pcx', aborting...\n");
1674                 return 1;
1675         }
1676         fclose(handle);
1677
1678         for (c1 = 0; c1 < 4; c1++) {
1679                 if (player[c1].enabled == 1) {
1680                         player[c1].bumps = 0;
1681                         player[c1].bumped[0] = 0;
1682                         player[c1].bumped[1] = 0;
1683                         player[c1].bumped[2] = 0;
1684                         player[c1].bumped[3] = 0;
1685                         position_player(c1);
1686                 }
1687         }
1688
1689         for (c1 = 0; c1 < NUM_OBJECTS; c1++)
1690                 objects[c1].used = 0;
1691
1692         for (c1 = 0; c1 < 16; c1++) {
1693                 for (c2 = 0; c2 < 22; c2++) {
1694                         if (ban_map[c1][c2] == BAN_SPRING)
1695                                 add_object(OBJ_SPRING, c2 << 4, c1 << 4, 0, 0, OBJ_ANIM_SPRING, 5);
1696                 }
1697         }
1698
1699         while (1) {
1700                 s1 = rnd(22);
1701                 s2 = rnd(16);
1702                 if (ban_map[s2][s1] == BAN_VOID) {
1703                         add_object(OBJ_YEL_BUTFLY, (s1 << 4) + 8, (s2 << 4) + 8, (rnd(65535) - 32768) * 2, (rnd(65535) - 32768) * 2, 0, 0);
1704                         break;
1705                 }
1706         }
1707         while (1) {
1708                 s1 = rnd(22);
1709                 s2 = rnd(16);
1710                 if (ban_map[s2][s1] == BAN_VOID) {
1711                         add_object(OBJ_YEL_BUTFLY, (s1 << 4) + 8, (s2 << 4) + 8, (rnd(65535) - 32768) * 2, (rnd(65535) - 32768) * 2, 0, 0);
1712                         break;
1713                 }
1714         }
1715         while (1) {
1716                 s1 = rnd(22);
1717                 s2 = rnd(16);
1718                 if (ban_map[s2][s1] == BAN_VOID) {
1719                         add_object(OBJ_PINK_BUTFLY, (s1 << 4) + 8, (s2 << 4) + 8, (rnd(65535) - 32768) * 2, (rnd(65535) - 32768) * 2, 0, 0);
1720                         break;
1721                 }
1722         }
1723         while (1) {
1724                 s1 = rnd(22);
1725                 s2 = rnd(16);
1726                 if (ban_map[s2][s1] == BAN_VOID) {
1727                         add_object(OBJ_PINK_BUTFLY, (s1 << 4) + 8, (s2 << 4) + 8, (rnd(65535) - 32768) * 2, (rnd(65535) - 32768) * 2, 0, 0);
1728                         break;
1729                 }
1730         }
1731
1732         return 0;
1733
1734 }
1735
1736
1737 void deinit_level(void)
1738 {
1739         dj_set_nosound(1);
1740         dj_stop_mod();
1741 }
1742
1743
1744 int init_program(int argc, char *argv[], char *pal)
1745 {
1746         FILE *handle = (FILE *) NULL;
1747         int c1 = 0, c2 = 0;
1748         char load_flag = 0;
1749         char force2, force3;
1750         sfx_data fly;
1751         int player_anim_data[] = {
1752                 1, 0, 0, 0x7fff, 0, 0, 0, 0, 0, 0,
1753                 4, 0, 0, 4, 1, 4, 2, 4, 3, 4,
1754                 1, 0, 4, 0x7fff, 0, 0, 0, 0, 0, 0,
1755                 4, 2, 5, 8, 6, 10, 7, 3, 6, 3,
1756                 1, 0, 6, 0x7fff, 0, 0, 0, 0, 0, 0,
1757                 2, 1, 5, 8, 4, 0x7fff, 0, 0, 0, 0,
1758                 1, 0, 8, 5, 0, 0, 0, 0, 0, 0
1759         };
1760
1761 #ifdef DOS
1762         if (__djgpp_nearptr_enable() == 0)
1763                 return 1;
1764 #endif
1765
1766         srand(time(NULL));
1767
1768         if (hook_keyb_handler() != 0)
1769                 return 1;
1770
1771         memset(&main_info, 0, sizeof(main_info));
1772
1773         strcpy(datfile_name, "data/jumpbump.dat");
1774
1775         force2 = force3 = 0;
1776
1777         if (argc > 1) {
1778                 for (c1 = 1; c1 < argc; c1++) {
1779                         if (stricmp(argv[c1], "-nosound") == 0)
1780                                 main_info.no_sound = 1;
1781                         else if (stricmp(argv[c1], "-nogore") == 0)
1782                                 main_info.no_gore = 1;
1783                         else if (stricmp(argv[c1], "-nojoy") == 0)
1784                                 main_info.joy_enabled = 0;
1785                         else if (stricmp(argv[c1], "-fireworks") == 0)
1786                                 main_info.fireworks = 1;
1787 #ifdef USE_SDL
1788                         else if (stricmp(argv[c1], "-fullscreen") == 0)
1789                                 fs_toggle();
1790 #endif
1791                         else if (stricmp(argv[c1], "-dat") == 0) {
1792                                 if (c1 < (argc - 1)) {
1793                                         if ((handle = fopen(argv[c1 + 1], "rb")) != NULL) {
1794                                                 fclose(handle);
1795                                                 strcpy(datfile_name, argv[c1 + 1]);
1796                                         }
1797                                 }
1798                         } else if (stricmp(argv[c1], "-mouse") == 0) {
1799                                 if (c1 < (argc - 1)) {
1800                                         if (stricmp(argv[c1 + 1], "2") == 0)
1801                                                 force2 = 1;
1802                                         if (stricmp(argv[c1 + 1], "3") == 0)
1803                                                 force3 = 1;
1804                                 }
1805                         }
1806                 }
1807         }
1808
1809         for (c1 = 0; c1 < 7; c1++) {
1810                 player_anims[c1].num_frames = player_anim_data[c1 * 10];
1811                 player_anims[c1].restart_frame = player_anim_data[c1 * 10 + 1];
1812                 for (c2 = 0; c2 < 4; c2++) {
1813                         player_anims[c1].frame[c2].image = player_anim_data[c1 * 10 + c2 * 2 + 2];
1814                         player_anims[c1].frame[c2].ticks = player_anim_data[c1 * 10 + c2 * 2 + 3];
1815                 }
1816         }
1817
1818         if ((background_pic = malloc(102400)) == NULL)
1819                 return 1;
1820         if ((mask_pic = malloc(102400)) == NULL)
1821                 return 1;
1822         memset(mask_pic, 0, 102400);
1823
1824         main_info.pob_backbuf[0] = malloc(65535);
1825         main_info.pob_backbuf[1] = malloc(65535);
1826         if (main_info.pob_backbuf[0] == 0 || main_info.pob_backbuf[1] == 0)
1827                 return 1;
1828
1829         if ((handle = dat_open("rabbit.gob", datfile_name, "rb")) == 0) {
1830                 strcpy(main_info.error_str, "Error loading 'rabbit.gob', aborting...\n");
1831                 return 1;
1832         }
1833         if ((rabbit_gobs = malloc(dat_filelen("rabbit.gob", datfile_name))) == 0) {
1834                 strcpy(main_info.error_str, "Not enough memory, aborting...\n");
1835                 fclose(handle);
1836                 return 1;
1837         }
1838         fread(rabbit_gobs, 1, dat_filelen("rabbit.gob", datfile_name), handle);
1839         fclose(handle);
1840
1841         if ((handle = dat_open("objects.gob", datfile_name, "rb")) == 0) {
1842                 strcpy(main_info.error_str, "Error loading 'objects.gob', aborting...\n");
1843                 return 1;
1844         }
1845         if ((object_gobs = malloc(dat_filelen("objects.gob", datfile_name))) == 0) {
1846                 strcpy(main_info.error_str, "Not enough memory, aborting...\n");
1847                 fclose(handle);
1848                 return 1;
1849         }
1850         fread(object_gobs, 1, dat_filelen("objects.gob", datfile_name), handle);
1851         fclose(handle);
1852
1853         if ((handle = dat_open("font.gob", datfile_name, "rb")) == 0) {
1854                 strcpy(main_info.error_str, "Error loading 'font.gob', aborting...\n");
1855                 return 1;
1856         }
1857         if ((font_gobs = malloc(dat_filelen("font.gob", datfile_name))) == 0) {
1858                 strcpy(main_info.error_str, "Not enough memory, aborting...\n");
1859                 fclose(handle);
1860                 return 1;
1861         }
1862         fread(font_gobs, 1, dat_filelen("font.gob", datfile_name), handle);
1863         fclose(handle);
1864
1865         if ((handle = dat_open("numbers.gob", datfile_name, "rb")) == 0) {
1866                 strcpy(main_info.error_str, "Error loading 'numbers.gob', aborting...\n");
1867                 return 1;
1868         }
1869         if ((number_gobs = malloc(dat_filelen("numbers.gob", datfile_name))) == 0) {
1870                 strcpy(main_info.error_str, "Not enough memory, aborting...\n");
1871                 fclose(handle);
1872                 return 1;
1873         }
1874         fread(number_gobs, 1, dat_filelen("numbers.gob", datfile_name), handle);
1875         fclose(handle);
1876
1877         if (read_level() != 0) {
1878                 strcpy(main_info.error_str, "Error loading 'levelmap.txt', aborting...\n");
1879                 fclose(handle);
1880                 return 1;
1881         }
1882
1883         dj_init();
1884         if (main_info.no_sound == 0) {
1885                 dj_autodetect_sd();
1886                 dj_set_mixing_freq(20000);
1887                 dj_set_stereo(0);
1888                 dj_set_auto_mix(0);
1889                 dj_set_dma_time(8);
1890                 dj_set_num_sfx_channels(5);
1891                 dj_set_sfx_volume(64);
1892                 dj_set_nosound(1);
1893                 dj_start();
1894
1895                 if ((handle = dat_open("jump.mod", datfile_name, "rb")) == 0) {
1896                         strcpy(main_info.error_str, "Error loading 'jump.mod', aborting...\n");
1897                         return 1;
1898                 }
1899                 if (dj_load_mod(handle, 0, MOD_MENU) != 0) {
1900                         strcpy(main_info.error_str, "Error loading 'jump.mod', aborting...\n");
1901                         return 1;
1902                 }
1903                 fclose(handle);
1904
1905                 if ((handle = dat_open("bump.mod", datfile_name, "rb")) == 0) {
1906                         strcpy(main_info.error_str, "Error loading 'bump.mod', aborting...\n");
1907                         return 1;
1908                 }
1909                 if (dj_load_mod(handle, 0, MOD_GAME) != 0) {
1910                         strcpy(main_info.error_str, "Error loading 'bump.mod', aborting...\n");
1911                         return 1;
1912                 }
1913                 fclose(handle);
1914
1915                 if ((handle = dat_open("scores.mod", datfile_name, "rb")) == 0) {
1916                         strcpy(main_info.error_str, "Error loading 'scores.mod', aborting...\n");
1917                         return 1;
1918                 }
1919                 if (dj_load_mod(handle, 0, MOD_SCORES) != 0) {
1920                         strcpy(main_info.error_str, "Error loading 'scores.mod', aborting...\n");
1921                         return 1;
1922                 }
1923                 fclose(handle);
1924
1925                 if ((handle = dat_open("jump.smp", datfile_name, "rb")) == 0) {
1926                         strcpy(main_info.error_str, "Error loading 'jump.smp', aborting...\n");
1927                         return 1;
1928                 }
1929                 if (dj_load_sfx(handle, 0, dat_filelen("jump.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_JUMP) != 0) {
1930                         strcpy(main_info.error_str, "Error loading 'jump.smp', aborting...\n");
1931                         return 1;
1932                 }
1933                 fclose(handle);
1934
1935                 if ((handle = dat_open("death.smp", datfile_name, "rb")) == 0) {
1936                         strcpy(main_info.error_str, "Error loading 'death.smp', aborting...\n");
1937                         return 1;
1938                 }
1939                 if (dj_load_sfx(handle, 0, dat_filelen("death.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_DEATH) != 0) {
1940                         strcpy(main_info.error_str, "Error loading 'death.smp', aborting...\n");
1941                         return 1;
1942                 }
1943                 fclose(handle);
1944
1945                 if ((handle = dat_open("spring.smp", datfile_name, "rb")) == 0) {
1946                         strcpy(main_info.error_str, "Error loading 'spring.smp', aborting...\n");
1947                         return 1;
1948                 }
1949                 if (dj_load_sfx(handle, 0, dat_filelen("spring.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_SPRING) != 0) {
1950                         strcpy(main_info.error_str, "Error loading 'spring.smp', aborting...\n");
1951                         return 1;
1952                 }
1953                 fclose(handle);
1954
1955                 if ((handle = dat_open("splash.smp", datfile_name, "rb")) == 0) {
1956                         strcpy(main_info.error_str, "Error loading 'splash.smp', aborting...\n");
1957                         return 1;
1958                 }
1959                 if (dj_load_sfx(handle, 0, dat_filelen("splash.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_SPLASH) != 0) {
1960                         strcpy(main_info.error_str, "Error loading 'splash.smp', aborting...\n");
1961                         return 1;
1962                 }
1963                 fclose(handle);
1964
1965                 if ((handle = dat_open("fly.smp", datfile_name, "rb")) == 0) {
1966                         strcpy(main_info.error_str, "Error loading 'fly.smp', aborting...\n");
1967                         return 1;
1968                 }
1969                 if (dj_load_sfx(handle, 0, dat_filelen("fly.smp", datfile_name), DJ_SFX_TYPE_SMP, SFX_FLY) != 0) {
1970                         strcpy(main_info.error_str, "Error loading 'fly.smp', aborting...\n");
1971                         return 1;
1972                 }
1973                 fclose(handle);
1974
1975                 dj_get_sfx_settings(SFX_FLY, &fly);
1976                 fly.priority = 10;
1977                 fly.default_freq = SFX_FLY_FREQ;
1978                 fly.loop = 1;
1979                 fly.loop_start = 0;
1980                 fly.loop_length = fly.length;
1981                 dj_set_sfx_settings(SFX_FLY, &fly);
1982         }
1983
1984         if ((handle = dat_open("menu.pcx", datfile_name, "rb")) == 0) {
1985                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
1986                 return 1;
1987         }
1988         if (read_pcx(handle, background_pic, 102400L, pal) != 0) {
1989                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
1990                 return 1;
1991         }
1992         fclose(handle);
1993
1994         setpalette(0, 256, pal);
1995
1996         init_inputs();
1997
1998         if (main_info.joy_enabled == 1 && main_info.fireworks == 0) {
1999                 load_flag = 0;
2000                 put_text(0, 200, 40, "JOYSTICK CALIBRATION", 2);
2001                 put_text(0, 200, 100, "Move the joystick to the", 2);
2002                 put_text(0, 200, 115, "UPPER LEFT", 2);
2003                 put_text(0, 200, 130, "and press button A", 2);
2004                 put_text(0, 200, 200, "Or press ESC to use", 2);
2005                 put_text(0, 200, 215, "previous settings", 2);
2006                 if (calib_joy(0) != 0)
2007                         load_flag = 1;
2008                 else {
2009                         register_background(NULL);
2010
2011                         main_info.view_page = 1;
2012                         flippage(1);
2013
2014                         wait_vrt(0);
2015
2016                         put_text(1, 200, 40, "JOYSTICK CALIBRATION", 2);
2017                         put_text(1, 200, 100, "Move the joystick to the", 2);
2018                         put_text(1, 200, 115, "LOWER RIGHT", 2);
2019                         put_text(1, 200, 130, "and press button A", 2);
2020                         put_text(1, 200, 200, "Or press ESC to use", 2);
2021                         put_text(1, 200, 215, "previous settings", 2);
2022                         if (calib_joy(1) != 0)
2023                                 load_flag = 1;
2024                         else {
2025                                 register_background(NULL);
2026                                 flippage(0);
2027
2028                                 wait_vrt(0);
2029
2030                                 put_text(0, 200, 40, "JOYSTICK CALIBRATION", 2);
2031                                 put_text(0, 200, 100, "Move the joystick to the", 2);
2032                                 put_text(0, 200, 115, "CENTER", 2);
2033                                 put_text(0, 200, 130, "and press button A", 2);
2034                                 put_text(0, 200, 200, "Or press ESC to use", 2);
2035                                 put_text(0, 200, 215, "previous settings", 2);
2036                                 if (calib_joy(2) != 0)
2037                                         load_flag = 1;
2038                                 else {
2039                                         if (joy.calib_data.x1 == joy.calib_data.x2)
2040                                                 joy.calib_data.x1 -= 10;
2041                                         if (joy.calib_data.x3 == joy.calib_data.x2)
2042                                                 joy.calib_data.x3 += 10;
2043                                         if (joy.calib_data.y1 == joy.calib_data.y2)
2044                                                 joy.calib_data.y1 -= 10;
2045                                         if (joy.calib_data.y3 == joy.calib_data.y2)
2046                                                 joy.calib_data.y3 += 10;
2047                                         write_calib_data();
2048                                 }
2049                         }
2050                 }
2051                 if (load_flag == 1) {
2052                         if ((handle = dat_open("calib.dat", datfile_name, "rb")) == 0) {
2053                                 strcpy(main_info.error_str, "Error loading 'calib.dat', aborting...\n");
2054                                 return 1;
2055                         }
2056                         joy.calib_data.x1 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2057                         joy.calib_data.x2 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2058                         joy.calib_data.x3 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2059                         joy.calib_data.y1 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2060                         joy.calib_data.y2 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2061                         joy.calib_data.y3 = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2062                         fclose(handle);
2063                 }
2064         }
2065
2066         return 0;
2067
2068 }
2069
2070
2071 void deinit_program(void)
2072 {
2073 #ifdef DOS
2074         __dpmi_regs regs;
2075 #endif
2076
2077         dj_stop();
2078         dj_free_mod(MOD_MENU);
2079         dj_free_mod(MOD_GAME);
2080         dj_free_sfx(SFX_DEATH);
2081         dj_free_sfx(SFX_SPRING);
2082         dj_free_sfx(SFX_SPLASH);
2083         dj_deinit();
2084
2085         if (rabbit_gobs != 0)
2086                 free(rabbit_gobs);
2087         if (object_gobs != 0)
2088                 free(object_gobs);
2089         if (number_gobs != 0)
2090                 free(number_gobs);
2091
2092         if (main_info.pob_backbuf[0] != 0)
2093                 free(main_info.pob_backbuf[0]);
2094         if (main_info.pob_backbuf[1] != 0)
2095                 free(main_info.pob_backbuf[1]);
2096
2097         if (background_pic != 0)
2098                 free(background_pic);
2099         if (mask_pic != 0)
2100                 free(mask_pic);
2101
2102         remove_keyb_handler();
2103
2104 #ifdef DOS
2105         regs.x.ax = 0x3;
2106         __dpmi_int(0x10, &regs);
2107 #endif
2108
2109         if (main_info.error_str[0] != 0) {
2110                 printf(main_info.error_str);
2111                 exit(1);
2112         } else
2113                 exit(0);
2114
2115 }
2116
2117
2118 unsigned short rnd(unsigned short max)
2119 {
2120         return (rand() % max);
2121 }
2122
2123
2124 int read_level(void)
2125 {
2126         FILE *handle;
2127         int c1, c2;
2128         int chr;
2129
2130         if ((handle = dat_open("levelmap.txt", datfile_name, "rb")) == 0) {
2131                 strcpy(main_info.error_str, "Error loading 'levelmap.txt', aborting...\n");
2132                 return 1;
2133         }
2134
2135         for (c1 = 0; c1 < 16; c1++) {
2136                 for (c2 = 0; c2 < 22; c2++) {
2137                         while (1) {
2138                                 chr = fgetc(handle);
2139                                 if (chr == EOF) {
2140                                         fclose(handle);
2141                                         return 1;
2142                                 }
2143                                 if (chr >= '0' && chr <= '4')
2144                                         break;
2145                         }
2146                         ban_map[c1][c2] = chr - '0';
2147                 }
2148         }
2149
2150         for (c2 = 0; c2 < 22; c2++)
2151                 ban_map[16][c2] = BAN_SOLID;
2152
2153         fclose(handle);
2154         return 0;
2155
2156 }
2157
2158
2159 FILE *dat_open(char *file_name, char *dat_name, char *mode)
2160 {
2161         FILE *handle;
2162         int num;
2163         int c1;
2164         char name[21];
2165         int ofs;
2166
2167         handle = fopen(dat_name, mode);
2168         if (!handle)
2169                 return 0;
2170
2171         memset(name, 0, sizeof(name));
2172
2173         num = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2174         
2175         for (c1 = 0; c1 < num; c1++) {
2176                 if (!fread(name, 1, 12, handle)) {
2177                         fclose(handle);
2178                         return 0;
2179                 }
2180                 if (strnicmp(name, file_name, strlen(file_name)) == 0) {
2181                         ofs = fgetc(handle);
2182                         ofs += (fgetc(handle) << 8);
2183                         ofs += (fgetc(handle) << 16);
2184                         ofs += (fgetc(handle) << 24);
2185                         fseek(handle, ofs, SEEK_SET);
2186                         return handle;
2187                 }
2188                 fseek(handle, 8, SEEK_CUR);
2189         }
2190
2191         fclose(handle);
2192
2193         return 0;
2194 }
2195
2196
2197 int dat_filelen(char *file_name, char *dat_name)
2198 {
2199         FILE *handle;
2200         int num;
2201         int c1;
2202         char name[21];
2203         int len;
2204
2205         handle = fopen(dat_name, "rb");
2206         if (!handle)
2207                 return 0;
2208
2209         memset(name, 0, sizeof(name));
2210         
2211         num = fgetc(handle) + (fgetc(handle) << 8) + (fgetc(handle) << 16) + (fgetc(handle) << 24);
2212
2213         for (c1 = 0; c1 < num; c1++) {
2214                 if (!fread(name, 1, 12, handle)) {
2215                         fclose(handle);
2216                         return 0;
2217                 }
2218                 if (strnicmp(name, file_name, strlen(file_name)) == 0) {
2219                         fseek(handle, 4, SEEK_CUR);
2220                         len = fgetc(handle);
2221                         len += (fgetc(handle) << 8);
2222                         len += (fgetc(handle) << 16);
2223                         len += (fgetc(handle) << 24);
2224
2225                         fclose(handle);
2226                         return len;
2227                 }
2228                 fseek(handle, 8, SEEK_CUR);
2229         }
2230
2231         fclose(handle);
2232         return 0;
2233 }
2234
2235
2236 #ifndef _MSC_VER
2237 int filelength(int handle)
2238 {
2239         struct stat buf;
2240
2241         if (fstat(handle, &buf) == -1) {
2242                 perror("filelength");
2243                 exit(EXIT_FAILURE);
2244         }
2245
2246         return buf.st_size;
2247 }
2248 #endif
2249
2250
2251 void write_calib_data(void)
2252 {
2253         FILE *handle;
2254         int c1;
2255         int len, num;
2256         char *mem;
2257         int ofs;
2258
2259         if ((handle = fopen(datfile_name, "rb")) == NULL)
2260                 return;
2261         len = filelength(fileno(handle));
2262         if ((mem = malloc(len)) == NULL)
2263                 return;
2264         fread(mem, 1, len, handle);
2265         fclose(handle);
2266
2267         ofs = 4;
2268         num = *(int *) (&mem[0]);
2269         for (c1 = 0; c1 < num; c1++) {
2270                 if (strnicmp(&mem[ofs], "calib.dat", strlen("calib.dat")) == 0) {
2271                         ofs = *(int *) (&mem[ofs + 12]);
2272                         break;
2273                 }
2274                 ofs += 20;
2275         }
2276
2277         mem[ofs] = joy.calib_data.x1 & 0xff;
2278         mem[ofs + 1] = (joy.calib_data.x1 >> 8) & 0xff;
2279         mem[ofs + 2] = (joy.calib_data.x1 >> 16) & 0xff;
2280         mem[ofs + 3] = (joy.calib_data.x1 >> 24) & 0xff;
2281         mem[ofs + 4] = joy.calib_data.x2 & 0xff;
2282         mem[ofs + 5] = (joy.calib_data.x2 >> 8) & 0xff;
2283         mem[ofs + 6] = (joy.calib_data.x2 >> 16) & 0xff;
2284         mem[ofs + 7] = (joy.calib_data.x2 >> 24) & 0xff;
2285         mem[ofs + 8] = joy.calib_data.x3 & 0xff;
2286         mem[ofs + 9] = (joy.calib_data.x3 >> 8) & 0xff;
2287         mem[ofs + 10] = (joy.calib_data.x3 >> 16) & 0xff;
2288         mem[ofs + 11] = (joy.calib_data.x3 >> 24) & 0xff;
2289         mem[ofs + 12] = joy.calib_data.y1 & 0xff;
2290         mem[ofs + 13] = (joy.calib_data.y1 >> 8) & 0xff;
2291         mem[ofs + 14] = (joy.calib_data.y1 >> 16) & 0xff;
2292         mem[ofs + 15] = (joy.calib_data.y1 >> 24) & 0xff;
2293         mem[ofs + 16] = joy.calib_data.y2 & 0xff;
2294         mem[ofs + 17] = (joy.calib_data.y2 >> 8) & 0xff;
2295         mem[ofs + 18] = (joy.calib_data.y2 >> 16) & 0xff;
2296         mem[ofs + 19] = (joy.calib_data.y2 >> 24) & 0xff;
2297         mem[ofs + 20] = joy.calib_data.y3 & 0xff;
2298         mem[ofs + 21] = (joy.calib_data.y3 >> 8) & 0xff;
2299         mem[ofs + 22] = (joy.calib_data.y3 >> 16) & 0xff;
2300         mem[ofs + 23] = (joy.calib_data.y3 >> 24) & 0xff;
2301
2302         if ((handle = fopen(datfile_name, "wb")) == NULL)
2303                 return;
2304         fwrite(mem, 1, len, handle);
2305         fclose(handle);
2306
2307 }