1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
26 void GetPlayerConfig()
28 int old_joystick_nr = joystick_nr;
30 if (sound_status==SOUND_OFF)
31 local_player->setup &= ~SETUP_SOUND;
32 if (!sound_loops_allowed)
34 local_player->setup &= ~SETUP_SOUND_LOOPS;
35 local_player->setup &= ~SETUP_SOUND_MUSIC;
38 sound_on = sound_simple_on = SETUP_SOUND_ON(local_player->setup);
39 sound_loops_on = SETUP_SOUND_LOOPS_ON(local_player->setup);
40 sound_music_on = SETUP_SOUND_MUSIC_ON(local_player->setup);
41 toons_on = SETUP_TOONS_ON(local_player->setup);
42 direct_draw_on = SETUP_DIRECT_DRAW_ON(local_player->setup);
43 fading_on = SETUP_FADING_ON(local_player->setup);
44 autorecord_on = SETUP_AUTO_RECORD_ON(local_player->setup);
45 joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
46 quick_doors = SETUP_QUICK_DOORS_ON(local_player->setup);
47 scroll_delay_on = SETUP_SCROLL_DELAY_ON(local_player->setup);
48 soft_scrolling_on = SETUP_SOFT_SCROLL_ON(local_player->setup);
51 if (joystick_nr != old_joystick_nr)
54 close(joystick_device);
63 BOOL emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
64 BOOL emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
66 /* don't play tapes over network */
67 network_playing = (network && !tape.playing);
69 for(i=0; i<MAX_PLAYERS; i++)
71 struct PlayerInfo *player = &stored_player[i];
74 player->element_nr = EL_SPIELER1 + i;
76 player->present = FALSE;
77 player->active = FALSE;
80 player->local = FALSE;
84 player->gems_still_needed = level.edelsteine;
85 player->sokobanfields_still_needed = 0;
86 player->lights_still_needed = 0;
87 player->friends_still_needed = 0;
90 player->key[j] = FALSE;
93 player->dynabomb_count = 0;
94 player->dynabomb_size = 0;
95 player->dynabombs_left = 0;
96 player->dynabomb_xl = FALSE;
98 player->MovDir = MV_NO_MOVING;
100 player->Pushing = FALSE;
104 player->actual_frame_counter = 0;
106 player->frame_reset_delay = 0;
108 player->push_delay = 0;
109 player->push_delay_value = 5;
111 player->move_delay = 0;
112 player->last_move_dir = MV_NO_MOVING;
114 player->snapped = FALSE;
116 player->gone = FALSE;
118 player->last_jx = player->last_jy = 0;
119 player->jx = player->jy = 0;
121 DigField(player, 0,0,0,0,DF_NO_PUSH);
122 SnapField(player, 0,0);
128 stored_player[i].active = TRUE;
133 player->LevelSolved = FALSE;
134 player->GameOver = FALSE;
138 local_player->active = TRUE;
139 local_player->local = TRUE;
142 network_player_action_received = FALSE;
144 /* initial null action */
146 SendToServer_MovePlayer(MV_NO_MOVING);
153 TimeLeft = level.time;
155 ScreenMovDir = MV_NO_MOVING;
159 AllPlayersGone = SiebAktiv = FALSE;
161 for(i=0;i<MAX_NUM_AMOEBA;i++)
162 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
164 for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
166 Feld[x][y] = Ur[x][y];
167 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
168 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = 0;
173 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
175 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
181 Feld[x][y] = EL_SPIELER1;
188 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_SPIELER1];
189 int jx = player->jx, jy = player->jy;
192 player->active = TRUE;
195 player->present = TRUE;
196 if (player->connected)
198 player->active = TRUE;
200 printf("Player %d activated.\n", player->element_nr);
201 printf("[Local player is %d and currently %s.]\n",
202 local_player->element_nr,
203 local_player->active ? "active" : "not active");
206 /* remove potentially duplicate players */
207 if (StorePlayer[jx][jy] == Feld[x][y])
208 StorePlayer[jx][jy] = 0;
210 StorePlayer[x][y] = Feld[x][y];
211 Feld[x][y] = EL_LEERRAUM;
212 player->jx = player->last_jx = x;
213 player->jy = player->last_jy = y;
218 if (x<lev_fieldx-1 && Feld[x+1][y]==EL_SALZSAEURE)
219 Feld[x][y] = EL_BADEWANNE1;
220 else if (x>0 && Feld[x-1][y]==EL_SALZSAEURE)
221 Feld[x][y] = EL_BADEWANNE2;
222 else if (y>0 && Feld[x][y-1]==EL_BADEWANNE1)
223 Feld[x][y] = EL_BADEWANNE3;
224 else if (y>0 && Feld[x][y-1]==EL_SALZSAEURE)
225 Feld[x][y] = EL_BADEWANNE4;
226 else if (y>0 && Feld[x][y-1]==EL_BADEWANNE2)
227 Feld[x][y] = EL_BADEWANNE5;
266 Feld[x][y] = EL_AMOEBING;
267 Store[x][y] = EL_AMOEBE_NASS;
274 local_player->lights_still_needed++;
276 case EL_SOKOBAN_FELD_LEER:
277 local_player->sokobanfields_still_needed++;
281 local_player->friends_still_needed++;
285 MovDir[x][y] = 1<<RND(4);
292 /* check if any connected player was not found in playfield */
293 for(i=0; i<MAX_PLAYERS; i++)
295 struct PlayerInfo *player = &stored_player[i];
297 if (player->connected && !player->present)
302 for(j=0; j<MAX_PLAYERS; j++)
304 struct PlayerInfo *some_player = &stored_player[j];
305 int jx = some_player->jx, jy = some_player->jy;
307 /* assign first free player found that is present in the playfield */
308 if (some_player->present && !some_player->connected)
310 player->present = TRUE;
311 player->active = TRUE;
312 some_player->present = FALSE;
314 StorePlayer[jx][jy] = player->element_nr;
315 player->jx = player->last_jx = jx;
316 player->jy = player->last_jy = jy;
324 for(i=0; i<MAX_PLAYERS; i++)
326 struct PlayerInfo *player = &stored_player[i];
328 printf("Player %d: present == %d, connected == %d, active == %d.\n",
333 if (local_player == player)
334 printf("Player %d is local player.\n", i+1);
338 game_emulation = (emulate_bd ? EMU_BOULDERDASH :
339 emulate_sb ? EMU_SOKOBAN : EMU_NONE);
341 scroll_x = scroll_y = -1;
342 if (local_player->jx >= MIDPOSX-1)
343 scroll_x = (local_player->jx <= lev_fieldx-MIDPOSX ?
344 local_player->jx - MIDPOSX :
345 lev_fieldx - SCR_FIELDX + 1);
346 if (local_player->jy >= MIDPOSY-1)
347 scroll_y = (local_player->jy <= lev_fieldy-MIDPOSY ?
348 local_player->jy - MIDPOSY :
349 lev_fieldy - SCR_FIELDY + 1);
351 CloseDoor(DOOR_CLOSE_1);
357 XCopyArea(display,pix[PIX_DOOR],pix[PIX_DB_DOOR],gc,
358 DOOR_GFX_PAGEX5,DOOR_GFX_PAGEY1, DXSIZE,DYSIZE,
359 DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY1);
360 DrawTextExt(pix[PIX_DB_DOOR],gc,
361 DOOR_GFX_PAGEX1+XX_LEVEL,DOOR_GFX_PAGEY1+YY_LEVEL,
362 int2str(level_nr,2),FS_SMALL,FC_YELLOW);
363 DrawTextExt(pix[PIX_DB_DOOR],gc,
364 DOOR_GFX_PAGEX1+XX_EMERALDS,DOOR_GFX_PAGEY1+YY_EMERALDS,
365 int2str(local_player->gems_still_needed,3),FS_SMALL,FC_YELLOW);
366 DrawTextExt(pix[PIX_DB_DOOR],gc,
367 DOOR_GFX_PAGEX1+XX_DYNAMITE,DOOR_GFX_PAGEY1+YY_DYNAMITE,
368 int2str(local_player->dynamite,3),FS_SMALL,FC_YELLOW);
369 DrawTextExt(pix[PIX_DB_DOOR],gc,
370 DOOR_GFX_PAGEX1+XX_SCORE,DOOR_GFX_PAGEY1+YY_SCORE,
371 int2str(local_player->score,5),FS_SMALL,FC_YELLOW);
372 DrawTextExt(pix[PIX_DB_DOOR],gc,
373 DOOR_GFX_PAGEX1+XX_TIME,DOOR_GFX_PAGEY1+YY_TIME,
374 int2str(TimeLeft,3),FS_SMALL,FC_YELLOW);
376 DrawGameButton(BUTTON_GAME_STOP);
377 DrawGameButton(BUTTON_GAME_PAUSE);
378 DrawGameButton(BUTTON_GAME_PLAY);
379 DrawSoundDisplay(BUTTON_SOUND_MUSIC | (BUTTON_ON * sound_music_on));
380 DrawSoundDisplay(BUTTON_SOUND_LOOPS | (BUTTON_ON * sound_loops_on));
381 DrawSoundDisplay(BUTTON_SOUND_SIMPLE | (BUTTON_ON * sound_simple_on));
382 XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc,
383 DX+GAME_CONTROL_XPOS,DY+GAME_CONTROL_YPOS,
384 GAME_CONTROL_XSIZE,2*GAME_CONTROL_YSIZE,
385 DOOR_GFX_PAGEX1+GAME_CONTROL_XPOS,
386 DOOR_GFX_PAGEY1+GAME_CONTROL_YPOS);
388 OpenDoor(DOOR_OPEN_1);
391 PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
393 XAutoRepeatOff(display);
397 printf("Spieler %d %saktiv.\n",
398 i+1, (stored_player[i].active ? "" : "nicht "));
402 void InitMovDir(int x, int y)
404 int i, element = Feld[x][y];
405 static int xy[4][2] =
412 static int direction[2][4] =
414 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
415 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP }
424 Feld[x][y] = EL_KAEFER;
425 MovDir[x][y] = direction[0][element-EL_KAEFER_R];
431 Feld[x][y] = EL_FLIEGER;
432 MovDir[x][y] = direction[0][element-EL_FLIEGER_R];
438 Feld[x][y] = EL_BUTTERFLY;
439 MovDir[x][y] = direction[0][element-EL_BUTTERFLY_R];
445 Feld[x][y] = EL_FIREFLY;
446 MovDir[x][y] = direction[0][element-EL_FIREFLY_R];
452 Feld[x][y] = EL_PACMAN;
453 MovDir[x][y] = direction[0][element-EL_PACMAN_R];
456 MovDir[x][y] = 1<<RND(4);
457 if (element != EL_KAEFER &&
458 element != EL_FLIEGER &&
459 element != EL_BUTTERFLY &&
460 element != EL_FIREFLY)
470 if (!IN_LEV_FIELD(x1,y1) || !IS_FREE(x1,y1))
472 if (element==EL_KAEFER || element==EL_BUTTERFLY)
474 MovDir[x][y] = direction[0][i];
477 else if (element==EL_FLIEGER || element==EL_FIREFLY)
479 MovDir[x][y] = direction[1][i];
488 void InitAmoebaNr(int x, int y)
491 int group_nr = AmoebeNachbarNr(x,y);
495 for(i=1;i<MAX_NUM_AMOEBA;i++)
505 AmoebaNr[x][y] = group_nr;
506 AmoebaCnt[group_nr]++;
507 AmoebaCnt2[group_nr]++;
513 int bumplevel = FALSE;
515 local_player->LevelSolved = FALSE;
520 PlaySoundExt(SND_SIRR, PSND_MAX_VOLUME, PSND_MAX_RIGHT, PSND_LOOP);
525 PlaySoundStereo(SND_SIRR, PSND_MAX_RIGHT);
526 if (TimeLeft && !(TimeLeft % 10))
527 RaiseScore(level.score[SC_ZEITBONUS]);
528 if (TimeLeft > 100 && !(TimeLeft % 10))
532 DrawText(DX_TIME, DY_TIME, int2str(TimeLeft,3), FS_SMALL, FC_YELLOW);
543 /* Hero disappears */
544 DrawLevelField(ExitX, ExitY);
550 CloseDoor(DOOR_CLOSE_1);
555 SaveLevelTape(tape.level_nr); /* Ask to save tape */
558 if (level_nr == local_player->handicap &&
559 level_nr < leveldir[leveldir_nr].levels-1)
561 local_player->handicap++;
563 SavePlayerInfo(PLAYER_LEVEL);
566 if ((hi_pos=NewHiScore()) >= 0)
568 game_status = HALLOFFAME;
569 DrawHallOfFame(hi_pos);
570 if (bumplevel && TAPE_IS_EMPTY(tape))
575 game_status = MAINMENU;
576 if (bumplevel && TAPE_IS_EMPTY(tape))
591 if (!strcmp(local_player->alias_name,EMPTY_ALIAS) ||
592 local_player->score < highscore[MAX_SCORE_ENTRIES-1].Score)
595 for(k=0;k<MAX_SCORE_ENTRIES;k++)
597 if (local_player->score > highscore[k].Score)
599 /* Spieler kommt in Highscore-Liste */
601 if (k<MAX_SCORE_ENTRIES-1)
603 int m = MAX_SCORE_ENTRIES-1;
606 for(l=k;l<MAX_SCORE_ENTRIES;l++)
607 if (!strcmp(local_player->alias_name,highscore[l].Name))
609 if (m==k) /* Spieler überschreibt seine alte Position */
615 strcpy(highscore[l].Name,highscore[l-1].Name);
616 highscore[l].Score = highscore[l-1].Score;
623 sprintf(highscore[k].Name,local_player->alias_name);
624 highscore[k].Score = local_player->score;
630 else if (!strcmp(local_player->alias_name,highscore[k].Name))
631 break; /* Spieler schon mit besserer Punktzahl in der Liste */
642 void InitMovingField(int x, int y, int direction)
644 int newx = x + (direction==MV_LEFT ? -1 : direction==MV_RIGHT ? +1 : 0);
645 int newy = y + (direction==MV_UP ? -1 : direction==MV_DOWN ? +1 : 0);
647 MovDir[x][y] = direction;
648 MovDir[newx][newy] = direction;
649 if (Feld[newx][newy] == EL_LEERRAUM)
650 Feld[newx][newy] = EL_BLOCKED;
653 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
655 int direction = MovDir[x][y];
656 int newx = x + (direction==MV_LEFT ? -1 : direction==MV_RIGHT ? +1 : 0);
657 int newy = y + (direction==MV_UP ? -1 : direction==MV_DOWN ? +1 : 0);
663 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
665 int oldx = x, oldy = y;
666 int direction = MovDir[x][y];
668 if (direction==MV_LEFT)
670 else if (direction==MV_RIGHT)
672 else if (direction==MV_UP)
674 else if (direction==MV_DOWN)
677 *comes_from_x = oldx;
678 *comes_from_y = oldy;
681 int MovingOrBlocked2Element(int x, int y)
683 int element = Feld[x][y];
685 if (element==EL_BLOCKED)
689 Blocked2Moving(x,y,&oldx,&oldy);
690 return(Feld[oldx][oldy]);
696 static void RemoveField(int x, int y)
698 Feld[x][y] = EL_LEERRAUM;
704 void RemoveMovingField(int x, int y)
706 int oldx = x,oldy = y, newx = x,newy = y;
708 if (Feld[x][y] != EL_BLOCKED && !IS_MOVING(x,y))
713 Moving2Blocked(x,y,&newx,&newy);
714 if (Feld[newx][newy] != EL_BLOCKED)
717 else if (Feld[x][y]==EL_BLOCKED)
719 Blocked2Moving(x,y,&oldx,&oldy);
720 if (!IS_MOVING(oldx,oldy))
724 if (Feld[x][y]==EL_BLOCKED &&
725 (Store[oldx][oldy]==EL_MORAST_LEER ||
726 Store[oldx][oldy]==EL_SIEB_LEER ||
727 Store[oldx][oldy]==EL_SIEB2_LEER ||
728 Store[oldx][oldy]==EL_AMOEBE_NASS))
730 Feld[oldx][oldy] = Store[oldx][oldy];
731 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
734 Feld[oldx][oldy] = EL_LEERRAUM;
736 Feld[newx][newy] = EL_LEERRAUM;
737 MovPos[oldx][oldy] = MovDir[oldx][oldy] = MovDelay[oldx][oldy] = 0;
738 MovPos[newx][newy] = MovDir[newx][newy] = MovDelay[newx][newy] = 0;
740 DrawLevelField(oldx,oldy);
741 DrawLevelField(newx,newy);
744 void DrawDynamite(int x, int y)
746 int sx = SCREENX(x), sy = SCREENY(y);
747 int graphic = el2gfx(Feld[x][y]);
750 if (!IN_SCR_FIELD(sx,sy) || IS_PLAYER(x,y))
754 DrawGraphic(sx,sy, el2gfx(Store[x][y]));
756 if (Feld[x][y]==EL_DYNAMIT)
758 if ((phase = (96-MovDelay[x][y])/12) > 6)
763 if ((phase = ((96-MovDelay[x][y])/6) % 8) > 3)
768 DrawGraphicThruMask(sx,sy, graphic + phase);
770 DrawGraphic(sx,sy, graphic + phase);
773 void CheckDynamite(int x, int y)
775 if (MovDelay[x][y]) /* neues Dynamit / in Wartezustand */
780 if (!(MovDelay[x][y] % 12))
781 PlaySoundLevel(x,y,SND_ZISCH);
783 if (Feld[x][y]==EL_DYNAMIT && !(MovDelay[x][y] % 12))
785 else if (Feld[x][y]==EL_DYNABOMB && !(MovDelay[x][y] % 6))
792 StopSound(SND_ZISCH);
796 void Explode(int ex, int ey, int phase, int mode)
799 int num_phase = 9, delay = 2;
800 int last_phase = num_phase*delay;
801 int half_phase = (num_phase/2)*delay;
803 if (phase==0) /* Feld 'Store' initialisieren */
805 int center_element = Feld[ex][ey];
807 if (IS_MOVING(ex,ey) || IS_BLOCKED(ex,ey))
809 center_element = MovingOrBlocked2Element(ex,ey);
810 RemoveMovingField(ex,ey);
813 for(y=ey-1;y<ey+2;y++) for(x=ex-1;x<ex+2;x++)
815 int element = Feld[x][y];
817 if (IS_MOVING(x,y) || IS_BLOCKED(x,y))
819 element = MovingOrBlocked2Element(x,y);
820 RemoveMovingField(x,y);
823 if (!IN_LEV_FIELD(x,y) || IS_MASSIV(element) || element==EL_BURNING)
826 if ((mode!=EX_NORMAL || center_element==EL_AMOEBA2DIAM) &&
830 if (element==EL_EXPLODING)
831 element = Store2[x][y];
833 if (IS_PLAYER(ex,ey))
835 switch(StorePlayer[ex][ey])
838 Store[x][y] = EL_EDELSTEIN_ROT;
841 Store[x][y] = EL_EDELSTEIN;
844 Store[x][y] = EL_EDELSTEIN_LILA;
848 Store[x][y] = EL_EDELSTEIN_GELB;
852 else if (center_element==EL_MAULWURF)
853 Store[x][y] = EL_EDELSTEIN_ROT;
854 else if (center_element==EL_PINGUIN)
855 Store[x][y] = EL_EDELSTEIN_LILA;
856 else if (center_element==EL_KAEFER)
857 Store[x][y] = ((x==ex && y==ey) ? EL_DIAMANT : EL_EDELSTEIN);
858 else if (center_element==EL_BUTTERFLY)
859 Store[x][y] = EL_EDELSTEIN_BD;
860 else if (center_element==EL_MAMPFER)
861 Store[x][y] = level.mampfer_inhalt[MampferNr][x-ex+1][y-ey+1];
862 else if (center_element==EL_AMOEBA2DIAM)
863 Store[x][y] = level.amoebe_inhalt;
864 else if (element==EL_ERZ_EDEL)
865 Store[x][y] = EL_EDELSTEIN;
866 else if (element==EL_ERZ_DIAM)
867 Store[x][y] = EL_DIAMANT;
868 else if (element==EL_ERZ_EDEL_BD)
869 Store[x][y] = EL_EDELSTEIN_BD;
870 else if (element==EL_ERZ_EDEL_GELB)
871 Store[x][y] = EL_EDELSTEIN_GELB;
872 else if (element==EL_ERZ_EDEL_ROT)
873 Store[x][y] = EL_EDELSTEIN_ROT;
874 else if (element==EL_ERZ_EDEL_LILA)
875 Store[x][y] = EL_EDELSTEIN_LILA;
876 else if (!IS_PFORTE(Store[x][y]))
877 Store[x][y] = EL_LEERRAUM;
879 if (x!=ex || y!=ey || center_element==EL_AMOEBA2DIAM || mode==EX_BORDER)
880 Store2[x][y] = element;
882 if (AmoebaNr[x][y] &&
883 (element==EL_AMOEBE_VOLL ||
884 element==EL_AMOEBE_BD ||
885 element==EL_AMOEBING))
887 AmoebaCnt[AmoebaNr[x][y]]--;
888 AmoebaCnt2[AmoebaNr[x][y]]--;
891 Feld[x][y] = EL_EXPLODING;
892 MovDir[x][y] = MovPos[x][y] = 0;
898 if (center_element==EL_MAMPFER)
899 MampferNr = (MampferNr+1) % 4;
910 Frame[x][y] = (phase<last_phase ? phase+1 : 0);
912 if (phase==half_phase)
914 int element = Store2[x][y];
917 KillHero(PLAYERINFO(x,y));
918 else if (IS_EXPLOSIVE(element))
920 Feld[x][y] = Store2[x][y];
924 else if (element==EL_AMOEBA2DIAM)
925 AmoebeUmwandeln(x,y);
928 if (phase==last_phase)
932 element = Feld[x][y] = Store[x][y];
933 Store[x][y] = Store2[x][y] = 0;
934 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
935 if (CAN_MOVE(element) || COULD_MOVE(element))
939 else if (!(phase%delay) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
942 ErdreichAnbroeckeln(SCREENX(x),SCREENY(y));
944 DrawGraphic(SCREENX(x),SCREENY(y),GFX_EXPLOSION+(phase/delay-1));
948 void DynaExplode(int ex, int ey)
951 struct PlayerInfo *player = &stored_player[Store2[ex][ey] - EL_SPIELER1];
952 static int xy[4][2] =
960 Store2[ex][ey] = 0; /* delete player information */
962 Explode(ex,ey,0,EX_CENTER);
966 for(j=1; j<=player->dynabomb_size; j++)
968 int x = ex+j*xy[i%4][0];
969 int y = ey+j*xy[i%4][1];
972 if (!IN_LEV_FIELD(x,y) || IS_MASSIV(Feld[x][y]))
975 element = Feld[x][y];
976 Explode(x,y,0,EX_BORDER);
978 if (element != EL_LEERRAUM &&
979 element != EL_ERDREICH &&
980 element != EL_EXPLODING &&
981 !player->dynabomb_xl)
986 player->dynabombs_left++;
989 void Bang(int x, int y)
991 int element = Feld[x][y];
993 PlaySoundLevel(x,y,SND_ROAAAR);
1005 RaiseScoreElement(element);
1006 Explode(x,y,0,EX_NORMAL);
1009 case EL_DYNABOMB_NR:
1010 case EL_DYNABOMB_SZ:
1011 case EL_DYNABOMB_XL:
1016 Explode(x,y,0,EX_CENTER);
1019 Explode(x,y,0,EX_NORMAL);
1024 void Blurb(int x, int y)
1026 int element = Feld[x][y];
1028 if (element!=EL_BLURB_LEFT && element!=EL_BLURB_RIGHT) /* Anfang */
1030 PlaySoundLevel(x,y,SND_BLURB);
1031 if (IN_LEV_FIELD(x-1,y) && IS_FREE(x-1,y) &&
1032 (!IN_LEV_FIELD(x-1,y-1) ||
1033 !CAN_FALL(MovingOrBlocked2Element(x-1,y-1))))
1035 Feld[x-1][y] = EL_BLURB_LEFT;
1037 if (IN_LEV_FIELD(x+1,y) && IS_FREE(x+1,y) &&
1038 (!IN_LEV_FIELD(x+1,y-1) ||
1039 !CAN_FALL(MovingOrBlocked2Element(x+1,y-1))))
1041 Feld[x+1][y] = EL_BLURB_RIGHT;
1046 int graphic = (element==EL_BLURB_LEFT ? GFX_BLURB_LEFT : GFX_BLURB_RIGHT);
1048 if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */
1051 if (MovDelay[x][y]) /* neue Phase / in Wartezustand */
1054 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
1055 DrawGraphic(SCREENX(x),SCREENY(y),graphic+4-MovDelay[x][y]/2);
1057 if (!MovDelay[x][y])
1059 Feld[x][y] = EL_LEERRAUM;
1060 DrawLevelField(x,y);
1066 void Impact(int x, int y)
1068 BOOL lastline = (y==lev_fieldy-1);
1069 BOOL object_hit = FALSE;
1070 int element = Feld[x][y];
1073 /* Element darunter berührt? */
1076 if (Feld[x][y+1] == EL_PLAYER_IS_LEAVING)
1079 object_hit = (!IS_FREE(x,y+1) && (!IS_MOVING(x,y+1) ||
1080 MovDir[x][y+1]!=MV_DOWN ||
1081 MovPos[x][y+1]<=TILEY/2));
1083 smashed = MovingOrBlocked2Element(x,y+1);
1086 /* Auftreffendes Element fällt in Salzsäure */
1087 if (!lastline && smashed==EL_SALZSAEURE)
1093 /* Auftreffendes Element ist Bombe */
1094 if (element==EL_BOMBE && (lastline || object_hit))
1100 /* Auftreffendes Element ist Säuretropfen */
1101 if (element==EL_TROPFEN && (lastline || object_hit))
1103 if (object_hit && IS_PLAYER(x,y+1))
1104 KillHero(PLAYERINFO(x,y+1));
1105 else if (object_hit && (smashed==EL_MAULWURF || smashed==EL_PINGUIN))
1109 Feld[x][y] = EL_AMOEBING;
1110 Store[x][y] = EL_AMOEBE_NASS;
1115 /* Welches Element kriegt was auf die Rübe? */
1116 if (!lastline && object_hit)
1118 if (CAN_CHANGE(element) &&
1119 (smashed==EL_SIEB_LEER || smashed==EL_SIEB2_LEER) && !SiebAktiv)
1120 SiebAktiv = level.dauer_sieb * FRAMES_PER_SECOND;
1122 if (IS_PLAYER(x,y+1))
1124 KillHero(PLAYERINFO(x,y+1));
1127 else if (smashed==EL_MAULWURF || smashed==EL_PINGUIN)
1132 else if (element==EL_EDELSTEIN_BD)
1134 if (IS_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
1140 else if (element==EL_FELSBROCKEN)
1142 if (IS_ENEMY(smashed) || smashed==EL_BOMBE || smashed==EL_SONDE ||
1143 smashed==EL_SCHWEIN || smashed==EL_DRACHE)
1148 else if (!IS_MOVING(x,y+1))
1150 if (smashed==EL_BIRNE_AUS || smashed==EL_BIRNE_EIN)
1155 else if (smashed==EL_KOKOSNUSS)
1157 Feld[x][y+1] = EL_CRACKINGNUT;
1158 PlaySoundLevel(x,y,SND_KNACK);
1159 RaiseScoreElement(EL_KOKOSNUSS);
1162 else if (smashed==EL_DIAMANT)
1164 Feld[x][y+1] = EL_LEERRAUM;
1165 PlaySoundLevel(x,y,SND_QUIRK);
1172 /* Geräusch beim Durchqueren des Siebes */
1173 if (!lastline && (Feld[x][y+1]==EL_SIEB_LEER || Feld[x][y+1]==EL_SIEB2_LEER))
1175 PlaySoundLevel(x,y,SND_QUIRK);
1179 /* Geräusch beim Auftreffen */
1180 if (lastline || object_hit)
1187 case EL_EDELSTEIN_BD:
1188 case EL_EDELSTEIN_GELB:
1189 case EL_EDELSTEIN_ROT:
1190 case EL_EDELSTEIN_LILA:
1197 case EL_FELSBROCKEN:
1201 case EL_SCHLUESSEL1:
1202 case EL_SCHLUESSEL2:
1203 case EL_SCHLUESSEL3:
1204 case EL_SCHLUESSEL4:
1217 PlaySoundLevel(x,y,sound);
1221 void TurnRound(int x, int y)
1233 { 0,0 }, { 0,0 }, { 0,0 },
1238 int left,right,back;
1242 { MV_DOWN, MV_UP, MV_RIGHT },
1243 { MV_UP, MV_DOWN, MV_LEFT },
1245 { MV_LEFT, MV_RIGHT, MV_DOWN },
1246 { 0,0,0 }, { 0,0,0 }, { 0,0,0 },
1247 { MV_RIGHT, MV_LEFT, MV_UP }
1250 int element = Feld[x][y];
1251 int old_move_dir = MovDir[x][y];
1252 int left_dir = turn[old_move_dir].left;
1253 int right_dir = turn[old_move_dir].right;
1254 int back_dir = turn[old_move_dir].back;
1256 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
1257 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
1258 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
1259 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
1261 int left_x = x+left_dx, left_y = y+left_dy;
1262 int right_x = x+right_dx, right_y = y+right_dy;
1263 int move_x = x+move_dx, move_y = y+move_dy;
1265 if (element==EL_KAEFER || element==EL_BUTTERFLY)
1267 TestIfBadThingHitsOtherBadThing(x,y);
1269 if (IN_LEV_FIELD(right_x,right_y) &&
1270 IS_FREE_OR_PLAYER(right_x,right_y))
1271 MovDir[x][y] = right_dir;
1272 else if (!IN_LEV_FIELD(move_x,move_y) ||
1273 !IS_FREE_OR_PLAYER(move_x,move_y))
1274 MovDir[x][y] = left_dir;
1276 if (element==EL_KAEFER && MovDir[x][y] != old_move_dir)
1278 else if (element==EL_BUTTERFLY) /* && MovDir[x][y]==left_dir) */
1281 else if (element==EL_FLIEGER || element==EL_FIREFLY)
1283 TestIfBadThingHitsOtherBadThing(x,y);
1285 if (IN_LEV_FIELD(left_x,left_y) &&
1286 IS_FREE_OR_PLAYER(left_x,left_y))
1287 MovDir[x][y] = left_dir;
1288 else if (!IN_LEV_FIELD(move_x,move_y) ||
1289 !IS_FREE_OR_PLAYER(move_x,move_y))
1290 MovDir[x][y] = right_dir;
1292 if (element==EL_FLIEGER && MovDir[x][y] != old_move_dir)
1294 else if (element==EL_FIREFLY) /* && MovDir[x][y]==right_dir) */
1297 else if (element==EL_MAMPFER)
1299 BOOL can_turn_left = FALSE, can_turn_right = FALSE;
1301 if (IN_LEV_FIELD(left_x,left_y) &&
1302 (IS_FREE_OR_PLAYER(left_x,left_y) ||
1303 Feld[left_x][left_y] == EL_DIAMANT))
1304 can_turn_left = TRUE;
1305 if (IN_LEV_FIELD(right_x,right_y) &&
1306 (IS_FREE_OR_PLAYER(right_x,right_y) ||
1307 Feld[right_x][right_y] == EL_DIAMANT))
1308 can_turn_right = TRUE;
1310 if (can_turn_left && can_turn_right)
1311 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
1312 else if (can_turn_left)
1313 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
1314 else if (can_turn_right)
1315 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
1317 MovDir[x][y] = back_dir;
1319 MovDelay[x][y] = 16+16*RND(3);
1321 else if (element==EL_MAMPFER2)
1323 BOOL can_turn_left = FALSE, can_turn_right = FALSE;
1325 if (IN_LEV_FIELD(left_x,left_y) &&
1326 (IS_FREE_OR_PLAYER(left_x,left_y) ||
1327 IS_MAMPF2(Feld[left_x][left_y])))
1328 can_turn_left = TRUE;
1329 if (IN_LEV_FIELD(right_x,right_y) &&
1330 (IS_FREE_OR_PLAYER(right_x,right_y) ||
1331 IS_MAMPF2(Feld[right_x][right_y])))
1332 can_turn_right = TRUE;
1334 if (can_turn_left && can_turn_right)
1335 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
1336 else if (can_turn_left)
1337 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
1338 else if (can_turn_right)
1339 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
1341 MovDir[x][y] = back_dir;
1343 MovDelay[x][y] = 16+16*RND(3);
1345 else if (element==EL_PACMAN)
1347 BOOL can_turn_left = FALSE, can_turn_right = FALSE;
1349 if (IN_LEV_FIELD(left_x,left_y) &&
1350 (IS_FREE_OR_PLAYER(left_x,left_y) ||
1351 IS_AMOEBOID(Feld[left_x][left_y])))
1352 can_turn_left = TRUE;
1353 if (IN_LEV_FIELD(right_x,right_y) &&
1354 (IS_FREE_OR_PLAYER(right_x,right_y) ||
1355 IS_AMOEBOID(Feld[right_x][right_y])))
1356 can_turn_right = TRUE;
1358 if (can_turn_left && can_turn_right)
1359 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
1360 else if (can_turn_left)
1361 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
1362 else if (can_turn_right)
1363 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
1365 MovDir[x][y] = back_dir;
1367 MovDelay[x][y] = 6+RND(40);
1369 else if (element==EL_SCHWEIN)
1371 BOOL can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
1372 BOOL should_turn_left = FALSE, should_turn_right = FALSE;
1373 BOOL should_move_on = FALSE;
1375 int rnd = RND(rnd_value);
1377 if (IN_LEV_FIELD(left_x,left_y) &&
1378 (IS_FREE(left_x,left_y) || IS_GEM(Feld[left_x][left_y])))
1379 can_turn_left = TRUE;
1380 if (IN_LEV_FIELD(right_x,right_y) &&
1381 (IS_FREE(right_x,right_y) || IS_GEM(Feld[right_x][right_y])))
1382 can_turn_right = TRUE;
1383 if (IN_LEV_FIELD(move_x,move_y) &&
1384 (IS_FREE(move_x,move_y) || IS_GEM(Feld[move_x][move_y])))
1387 if (can_turn_left &&
1389 (IN_LEV_FIELD(x+back_dx+left_dx,y+back_dy+left_dy) &&
1390 !IS_FREE(x+back_dx+left_dx,y+back_dy+left_dy))))
1391 should_turn_left = TRUE;
1392 if (can_turn_right &&
1394 (IN_LEV_FIELD(x+back_dx+right_dx,y+back_dy+right_dy) &&
1395 !IS_FREE(x+back_dx+right_dx,y+back_dy+right_dy))))
1396 should_turn_right = TRUE;
1398 (!can_turn_left || !can_turn_right ||
1399 (IN_LEV_FIELD(x+move_dx+left_dx,y+move_dy+left_dy) &&
1400 !IS_FREE(x+move_dx+left_dx,y+move_dy+left_dy)) ||
1401 (IN_LEV_FIELD(x+move_dx+right_dx,y+move_dy+right_dy) &&
1402 !IS_FREE(x+move_dx+right_dx,y+move_dy+right_dy))))
1403 should_move_on = TRUE;
1405 if (should_turn_left || should_turn_right || should_move_on)
1407 if (should_turn_left && should_turn_right && should_move_on)
1408 MovDir[x][y] = (rnd < rnd_value/3 ? left_dir :
1409 rnd < 2*rnd_value/3 ? right_dir :
1411 else if (should_turn_left && should_turn_right)
1412 MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir);
1413 else if (should_turn_left && should_move_on)
1414 MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : old_move_dir);
1415 else if (should_turn_right && should_move_on)
1416 MovDir[x][y] = (rnd < rnd_value/2 ? right_dir : old_move_dir);
1417 else if (should_turn_left)
1418 MovDir[x][y] = left_dir;
1419 else if (should_turn_right)
1420 MovDir[x][y] = right_dir;
1421 else if (should_move_on)
1422 MovDir[x][y] = old_move_dir;
1424 else if (can_move_on && rnd > rnd_value/8)
1425 MovDir[x][y] = old_move_dir;
1426 else if (can_turn_left && can_turn_right)
1427 MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir);
1428 else if (can_turn_left && rnd > rnd_value/8)
1429 MovDir[x][y] = left_dir;
1430 else if (can_turn_right && rnd > rnd_value/8)
1431 MovDir[x][y] = right_dir;
1433 MovDir[x][y] = back_dir;
1435 if (!IS_FREE(x+move_xy[MovDir[x][y]].x,y+move_xy[MovDir[x][y]].y) &&
1436 !IS_GEM(Feld[x+move_xy[MovDir[x][y]].x][y+move_xy[MovDir[x][y]].y]))
1437 MovDir[x][y] = old_move_dir;
1441 else if (element==EL_DRACHE)
1443 BOOL can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
1445 int rnd = RND(rnd_value);
1447 if (IN_LEV_FIELD(left_x,left_y) && IS_FREE(left_x,left_y))
1448 can_turn_left = TRUE;
1449 if (IN_LEV_FIELD(right_x,right_y) && IS_FREE(right_x,right_y))
1450 can_turn_right = TRUE;
1451 if (IN_LEV_FIELD(move_x,move_y) && IS_FREE(move_x,move_y))
1454 if (can_move_on && rnd > rnd_value/8)
1455 MovDir[x][y] = old_move_dir;
1456 else if (can_turn_left && can_turn_right)
1457 MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir);
1458 else if (can_turn_left && rnd > rnd_value/8)
1459 MovDir[x][y] = left_dir;
1460 else if (can_turn_right && rnd > rnd_value/8)
1461 MovDir[x][y] = right_dir;
1463 MovDir[x][y] = back_dir;
1465 if (!IS_FREE(x+move_xy[MovDir[x][y]].x,y+move_xy[MovDir[x][y]].y))
1466 MovDir[x][y] = old_move_dir;
1470 else if (element==EL_ROBOT || element==EL_SONDE ||
1471 element==EL_MAULWURF || element==EL_PINGUIN)
1473 int attr_x = -1, attr_y = -1;
1484 for(i=0; i<MAX_PLAYERS; i++)
1486 struct PlayerInfo *player = &stored_player[i];
1487 int jx = player->jx, jy = player->jy;
1489 if (!player->active || player->gone)
1492 if (attr_x == -1 || ABS(jx-x)+ABS(jy-y) < ABS(attr_x-x)+ABS(attr_y-y))
1500 if (element==EL_ROBOT && ZX>=0 && ZY>=0)
1506 if (element==EL_MAULWURF || element==EL_PINGUIN)
1509 static int xy[4][2] =
1519 int ex = x + xy[i%4][0];
1520 int ey = y + xy[i%4][1];
1522 if (IN_LEV_FIELD(ex,ey) && Feld[ex][ey] == EL_AUSGANG_AUF)
1531 MovDir[x][y] = MV_NO_MOVING;
1533 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
1535 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
1537 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
1539 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
1541 if (element==EL_ROBOT)
1545 if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN)))
1546 MovDir[x][y] &= (RND(2) ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN));
1547 Moving2Blocked(x,y,&newx,&newy);
1549 if (IN_LEV_FIELD(newx,newy) && IS_FREE_OR_PLAYER(newx,newy))
1550 MovDelay[x][y] = 8+8*!RND(3);
1552 MovDelay[x][y] = 16;
1560 if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN)))
1562 BOOL first_horiz = RND(2);
1563 int new_move_dir = MovDir[x][y];
1566 new_move_dir & (first_horiz ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN));
1567 Moving2Blocked(x,y,&newx,&newy);
1569 if (IN_LEV_FIELD(newx,newy) &&
1570 (IS_FREE(newx,newy) ||
1571 Feld[newx][newy] == EL_SALZSAEURE ||
1572 ((element == EL_MAULWURF || element==EL_PINGUIN) &&
1573 (Feld[newx][newy] == EL_AUSGANG_AUF ||
1574 IS_MAMPF3(Feld[newx][newy])))))
1578 new_move_dir & (!first_horiz ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN));
1579 Moving2Blocked(x,y,&newx,&newy);
1581 if (IN_LEV_FIELD(newx,newy) &&
1582 (IS_FREE(newx,newy) ||
1583 Feld[newx][newy] == EL_SALZSAEURE ||
1584 ((element == EL_MAULWURF || element==EL_PINGUIN) &&
1585 (Feld[newx][newy] == EL_AUSGANG_AUF ||
1586 IS_MAMPF3(Feld[newx][newy])))))
1589 MovDir[x][y] = old_move_dir;
1596 static BOOL JustBeingPushed(int x, int y)
1600 for(i=0; i<MAX_PLAYERS; i++)
1602 struct PlayerInfo *player = &stored_player[i];
1604 if (player->active && !player->gone &&
1605 player->Pushing && player->MovPos)
1607 int next_jx = player->jx + (player->jx - player->last_jx);
1608 int next_jy = player->jy + (player->jy - player->last_jy);
1610 if (x == next_jx && y == next_jy)
1618 void StartMoving(int x, int y)
1620 int element = Feld[x][y];
1625 if (CAN_FALL(element) && y<lev_fieldy-1)
1627 if ((x>0 && IS_PLAYER(x-1,y)) || (x<lev_fieldx-1 && IS_PLAYER(x+1,y)))
1628 if (JustBeingPushed(x,y))
1631 if (element==EL_MORAST_VOLL)
1635 InitMovingField(x,y,MV_DOWN);
1636 Feld[x][y] = EL_FELSBROCKEN;
1637 Store[x][y] = EL_MORAST_LEER;
1639 else if (Feld[x][y+1]==EL_MORAST_LEER)
1641 if (!MovDelay[x][y])
1642 MovDelay[x][y] = TILEY + 1;
1651 Feld[x][y] = EL_MORAST_LEER;
1652 Feld[x][y+1] = EL_MORAST_VOLL;
1655 else if (element==EL_FELSBROCKEN && Feld[x][y+1]==EL_MORAST_LEER)
1657 InitMovingField(x,y,MV_DOWN);
1658 Store[x][y] = EL_MORAST_VOLL;
1660 else if (element==EL_SIEB_VOLL)
1664 InitMovingField(x,y,MV_DOWN);
1665 Feld[x][y] = EL_CHANGED(Store2[x][y]);
1666 Store[x][y] = EL_SIEB_LEER;
1668 else if (Feld[x][y+1]==EL_SIEB_LEER)
1670 if (!MovDelay[x][y])
1671 MovDelay[x][y] = TILEY/4 + 1;
1680 Feld[x][y] = EL_SIEB_LEER;
1681 Feld[x][y+1] = EL_SIEB_VOLL;
1682 Store2[x][y+1] = EL_CHANGED(Store2[x][y]);
1686 else if (element==EL_SIEB2_VOLL)
1690 InitMovingField(x,y,MV_DOWN);
1691 Feld[x][y] = EL_CHANGED2(Store2[x][y]);
1692 Store[x][y] = EL_SIEB2_LEER;
1694 else if (Feld[x][y+1]==EL_SIEB2_LEER)
1696 if (!MovDelay[x][y])
1697 MovDelay[x][y] = TILEY/4 + 1;
1706 Feld[x][y] = EL_SIEB2_LEER;
1707 Feld[x][y+1] = EL_SIEB2_VOLL;
1708 Store2[x][y+1] = EL_CHANGED2(Store2[x][y]);
1712 else if (SiebAktiv && CAN_CHANGE(element) &&
1713 (Feld[x][y+1]==EL_SIEB_LEER || Feld[x][y+1]==EL_SIEB2_LEER))
1715 InitMovingField(x,y,MV_DOWN);
1717 (Feld[x][y+1]==EL_SIEB_LEER ? EL_SIEB_VOLL : EL_SIEB2_VOLL);
1718 Store2[x][y+1] = element;
1720 else if (CAN_SMASH(element) && Feld[x][y+1]==EL_SALZSAEURE)
1723 InitMovingField(x,y,MV_DOWN);
1724 Store[x][y] = EL_SALZSAEURE;
1726 else if (CAN_SMASH(element) && Feld[x][y+1]==EL_BLOCKED && JustHit[x][y])
1730 else if (IS_FREE(x,y+1))
1732 InitMovingField(x,y,MV_DOWN);
1734 else if (element==EL_TROPFEN)
1736 Feld[x][y] = EL_AMOEBING;
1737 Store[x][y] = EL_AMOEBE_NASS;
1739 else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1])
1741 BOOL left = (x>0 && IS_FREE(x-1,y) &&
1742 (IS_FREE(x-1,y+1) || Feld[x-1][y+1]==EL_SALZSAEURE));
1743 BOOL right = (x<lev_fieldx-1 && IS_FREE(x+1,y) &&
1744 (IS_FREE(x+1,y+1) || Feld[x+1][y+1]==EL_SALZSAEURE));
1748 if (left && right && game_emulation != EMU_BOULDERDASH)
1749 left = !(right = RND(2));
1751 InitMovingField(x,y,left ? MV_LEFT : MV_RIGHT);
1755 else if (CAN_MOVE(element))
1759 if (element == EL_SONDE && JustBeingPushed(x,y))
1762 if (!MovDelay[x][y]) /* neuer Schritt / noch nicht gewartet */
1764 /* Alle Figuren, die nach jeden Schritt die Richtung wechseln können.
1765 * (MAMPFER, MAMPFER2 und PACMAN laufen bis zur nächsten Wand.)
1768 if (element!=EL_MAMPFER && element!=EL_MAMPFER2 && element!=EL_PACMAN)
1771 if (MovDelay[x][y] && (element == EL_KAEFER || element == EL_FLIEGER))
1772 DrawLevelField(x,y);
1776 if (MovDelay[x][y]) /* neuer Schritt / in Wartezustand */
1780 if (element==EL_ROBOT || element==EL_MAMPFER || element==EL_MAMPFER2)
1782 int phase = MovDelay[x][y] % 8;
1787 if (IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
1788 DrawGraphic(SCREENX(x),SCREENY(y), el2gfx(element)+phase);
1790 if ((element==EL_MAMPFER || element==EL_MAMPFER2)
1791 && MovDelay[x][y]%4==3)
1792 PlaySoundLevel(x,y,SND_NJAM);
1794 else if (element==EL_DRACHE)
1797 int dir = MovDir[x][y];
1798 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
1799 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
1800 int graphic = (dir == MV_LEFT ? GFX_FLAMMEN_LEFT :
1801 dir == MV_RIGHT ? GFX_FLAMMEN_RIGHT :
1802 dir == MV_UP ? GFX_FLAMMEN_UP :
1803 dir == MV_DOWN ? GFX_FLAMMEN_DOWN : GFX_LEERRAUM);
1804 int phase = FrameCounter % 2;
1808 int xx = x + i*dx, yy = y + i*dy;
1809 int sx = SCREENX(xx), sy = SCREENY(yy);
1811 if (!IN_LEV_FIELD(xx,yy) ||
1812 IS_SOLID(Feld[xx][yy]) || Feld[xx][yy]==EL_EXPLODING)
1817 int flamed = MovingOrBlocked2Element(xx,yy);
1819 if (IS_ENEMY(flamed) || IS_EXPLOSIVE(flamed))
1822 RemoveMovingField(xx,yy);
1824 Feld[xx][yy] = EL_BURNING;
1825 if (IN_SCR_FIELD(sx,sy))
1826 DrawGraphic(sx,sy, graphic + phase*3 + i-1);
1830 if (Feld[xx][yy] == EL_BURNING)
1831 Feld[xx][yy] = EL_LEERRAUM;
1832 DrawLevelField(xx,yy);
1841 if (element==EL_KAEFER || element==EL_BUTTERFLY)
1843 PlaySoundLevel(x,y,SND_KLAPPER);
1845 else if (element==EL_FLIEGER || element==EL_FIREFLY)
1847 PlaySoundLevel(x,y,SND_ROEHR);
1850 /* neuer Schritt / Wartezustand beendet */
1852 Moving2Blocked(x,y,&newx,&newy); /* wohin soll's gehen? */
1854 if (IS_ENEMY(element) && IS_PLAYER(newx,newy))
1856 /* Spieler erwischt */
1858 KillHero(PLAYERINFO(newx,newy));
1861 else if ((element == EL_MAULWURF || element == EL_PINGUIN ||
1862 element==EL_ROBOT || element==EL_SONDE) &&
1863 IN_LEV_FIELD(newx,newy) &&
1864 MovDir[x][y]==MV_DOWN && Feld[newx][newy]==EL_SALZSAEURE)
1867 Store[x][y] = EL_SALZSAEURE;
1869 else if ((element == EL_MAULWURF || element == EL_PINGUIN) &&
1870 IN_LEV_FIELD(newx,newy))
1872 if (Feld[newx][newy] == EL_AUSGANG_AUF)
1874 Feld[x][y] = EL_LEERRAUM;
1875 DrawLevelField(x,y);
1877 PlaySoundLevel(newx,newy,SND_BUING);
1878 if (IN_SCR_FIELD(SCREENX(newx),SCREENY(newy)))
1879 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy),el2gfx(element));
1881 local_player->friends_still_needed--;
1882 if (!local_player->friends_still_needed &&
1883 !local_player->GameOver && AllPlayersGone)
1884 local_player->LevelSolved = local_player->GameOver = TRUE;
1888 else if (IS_MAMPF3(Feld[newx][newy]))
1890 if (DigField(local_player, newx,newy, 0,0, DF_DIG) == MF_MOVING)
1891 DrawLevelField(newx,newy);
1893 MovDir[x][y] = MV_NO_MOVING;
1895 else if (!IS_FREE(newx,newy))
1898 DrawPlayerField(x,y);
1900 DrawLevelField(x,y);
1904 else if (element == EL_SCHWEIN && IN_LEV_FIELD(newx,newy))
1906 if (IS_GEM(Feld[newx][newy]))
1908 if (IS_MOVING(newx,newy))
1909 RemoveMovingField(newx,newy);
1912 Feld[newx][newy] = EL_LEERRAUM;
1913 DrawLevelField(newx,newy);
1916 else if (!IS_FREE(newx,newy))
1919 DrawPlayerField(x,y);
1921 DrawLevelField(x,y);
1925 else if (element==EL_DRACHE && IN_LEV_FIELD(newx,newy))
1927 if (!IS_FREE(newx,newy))
1930 DrawPlayerField(x,y);
1932 DrawLevelField(x,y);
1937 BOOL wanna_flame = !RND(10);
1938 int dx = newx - x, dy = newy - y;
1939 int newx1 = newx+1*dx, newy1 = newy+1*dy;
1940 int newx2 = newx+2*dx, newy2 = newy+2*dy;
1941 int element1 = (IN_LEV_FIELD(newx1,newy1) ?
1942 MovingOrBlocked2Element(newx1,newy1) : EL_BETON);
1943 int element2 = (IN_LEV_FIELD(newx2,newy2) ?
1944 MovingOrBlocked2Element(newx2,newy2) : EL_BETON);
1946 if ((wanna_flame || IS_ENEMY(element1) || IS_ENEMY(element2)) &&
1947 element1 != EL_DRACHE && element2 != EL_DRACHE &&
1948 element1 != EL_BURNING && element2 != EL_BURNING)
1951 DrawPlayerField(x,y);
1953 DrawLevelField(x,y);
1955 MovDelay[x][y] = 50;
1956 Feld[newx][newy] = EL_BURNING;
1957 if (IN_LEV_FIELD(newx1,newy1) && Feld[newx1][newy1] == EL_LEERRAUM)
1958 Feld[newx1][newy1] = EL_BURNING;
1959 if (IN_LEV_FIELD(newx2,newy2) && Feld[newx2][newy2] == EL_LEERRAUM)
1960 Feld[newx2][newy2] = EL_BURNING;
1965 else if (element==EL_MAMPFER && IN_LEV_FIELD(newx,newy) &&
1966 Feld[newx][newy]==EL_DIAMANT)
1968 if (IS_MOVING(newx,newy))
1969 RemoveMovingField(newx,newy);
1972 Feld[newx][newy] = EL_LEERRAUM;
1973 DrawLevelField(newx,newy);
1976 else if (element==EL_MAMPFER2 && IN_LEV_FIELD(newx,newy) &&
1977 IS_MAMPF2(Feld[newx][newy]))
1979 if (AmoebaNr[newx][newy])
1981 AmoebaCnt2[AmoebaNr[newx][newy]]--;
1982 if (Feld[newx][newy]==EL_AMOEBE_VOLL || Feld[newx][newy]==EL_AMOEBE_BD)
1983 AmoebaCnt[AmoebaNr[newx][newy]]--;
1986 if (IS_MOVING(newx,newy))
1987 RemoveMovingField(newx,newy);
1990 Feld[newx][newy] = EL_LEERRAUM;
1991 DrawLevelField(newx,newy);
1994 else if (element==EL_PACMAN && IN_LEV_FIELD(newx,newy) &&
1995 IS_AMOEBOID(Feld[newx][newy]))
1997 if (AmoebaNr[newx][newy])
1999 AmoebaCnt2[AmoebaNr[newx][newy]]--;
2000 if (Feld[newx][newy]==EL_AMOEBE_VOLL || Feld[newx][newy]==EL_AMOEBE_BD)
2001 AmoebaCnt[AmoebaNr[newx][newy]]--;
2004 Feld[newx][newy] = EL_LEERRAUM;
2005 DrawLevelField(newx,newy);
2007 else if (!IN_LEV_FIELD(newx,newy) || !IS_FREE(newx,newy))
2008 { /* gegen Wand gelaufen */
2011 if (element == EL_KAEFER || element == EL_FLIEGER)
2012 DrawLevelField(x,y);
2013 else if (element == EL_BUTTERFLY || element == EL_FIREFLY)
2014 DrawGraphicAnimation(x,y, el2gfx(element), 2, 4, ANIM_NORMAL);
2015 else if (element==EL_SONDE)
2016 DrawGraphicAnimation(x,y, GFX_SONDE_START, 8, 2, ANIM_NORMAL);
2021 if (element==EL_ROBOT && IN_SCR_FIELD(x,y))
2022 PlaySoundLevel(x,y,SND_SCHLURF);
2024 InitMovingField(x,y,MovDir[x][y]);
2028 ContinueMoving(x,y);
2031 void ContinueMoving(int x, int y)
2033 int element = Feld[x][y];
2034 int direction = MovDir[x][y];
2035 int dx = (direction==MV_LEFT ? -1 : direction==MV_RIGHT ? +1 : 0);
2036 int dy = (direction==MV_UP ? -1 : direction==MV_DOWN ? +1 : 0);
2037 int horiz_move = (dx!=0);
2038 int newx = x + dx, newy = y + dy;
2039 int step = (horiz_move ? dx : dy) * TILEX/8;
2041 if (CAN_FALL(element) && horiz_move)
2043 else if (element==EL_TROPFEN)
2045 else if (Store[x][y]==EL_MORAST_VOLL || Store[x][y]==EL_MORAST_LEER)
2048 MovPos[x][y] += step;
2050 if (ABS(MovPos[x][y])>=TILEX) /* Zielfeld erreicht */
2052 Feld[x][y] = EL_LEERRAUM;
2053 Feld[newx][newy] = element;
2055 if (Store[x][y]==EL_MORAST_VOLL)
2058 Feld[newx][newy] = EL_MORAST_VOLL;
2059 element = EL_MORAST_VOLL;
2061 else if (Store[x][y]==EL_MORAST_LEER)
2064 Feld[x][y] = EL_MORAST_LEER;
2066 else if (Store[x][y]==EL_SIEB_VOLL)
2069 element = Feld[newx][newy] = (SiebAktiv ? EL_SIEB_VOLL : EL_SIEB_TOT);
2071 else if (Store[x][y]==EL_SIEB_LEER)
2073 Store[x][y] = Store2[x][y] = 0;
2074 Feld[x][y] = (SiebAktiv ? EL_SIEB_LEER : EL_SIEB_TOT);
2076 else if (Store[x][y]==EL_SIEB2_VOLL)
2079 element = Feld[newx][newy] = (SiebAktiv ? EL_SIEB2_VOLL : EL_SIEB2_TOT);
2081 else if (Store[x][y]==EL_SIEB2_LEER)
2083 Store[x][y] = Store2[x][y] = 0;
2084 Feld[x][y] = (SiebAktiv ? EL_SIEB2_LEER : EL_SIEB2_TOT);
2086 else if (Store[x][y]==EL_SALZSAEURE)
2089 Feld[newx][newy] = EL_SALZSAEURE;
2090 element = EL_SALZSAEURE;
2092 else if (Store[x][y]==EL_AMOEBE_NASS)
2095 Feld[x][y] = EL_AMOEBE_NASS;
2098 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
2099 MovDelay[newx][newy] = 0;
2101 if (!CAN_MOVE(element))
2102 MovDir[newx][newy] = 0;
2104 DrawLevelField(x,y);
2105 DrawLevelField(newx,newy);
2107 Stop[newx][newy] = TRUE;
2108 JustHit[x][newy] = 3;
2110 if (DONT_TOUCH(element)) /* Käfer oder Flieger */
2112 TestIfBadThingHitsHero(newx,newy);
2113 TestIfBadThingHitsFriend(newx,newy);
2114 TestIfBadThingHitsOtherBadThing(newx,newy);
2116 else if (element == EL_PINGUIN)
2117 TestIfFriendHitsBadThing(newx,newy);
2119 if (CAN_SMASH(element) && direction==MV_DOWN &&
2120 (newy==lev_fieldy-1 || !IS_FREE(x,newy+1)))
2123 else /* noch in Bewegung */
2124 DrawLevelField(x,y);
2127 int AmoebeNachbarNr(int ax, int ay)
2130 int element = Feld[ax][ay];
2132 static int xy[4][2] =
2142 int x = ax+xy[i%4][0];
2143 int y = ay+xy[i%4][1];
2145 if (!IN_LEV_FIELD(x,y))
2148 if (Feld[x][y]==element && AmoebaNr[x][y]>0)
2149 group_nr = AmoebaNr[x][y];
2155 void AmoebenVereinigen(int ax, int ay)
2158 int new_group_nr = AmoebaNr[ax][ay];
2159 static int xy[4][2] =
2175 if (!IN_LEV_FIELD(x,y))
2178 if ((Feld[x][y]==EL_AMOEBE_VOLL ||
2179 Feld[x][y]==EL_AMOEBE_BD ||
2180 Feld[x][y]==EL_AMOEBE_TOT) &&
2181 AmoebaNr[x][y] != new_group_nr)
2183 int old_group_nr = AmoebaNr[x][y];
2185 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
2186 AmoebaCnt[old_group_nr] = 0;
2187 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
2188 AmoebaCnt2[old_group_nr] = 0;
2190 for(yy=0;yy<lev_fieldy;yy++) for(xx=0;xx<lev_fieldx;xx++)
2191 if (AmoebaNr[xx][yy]==old_group_nr)
2192 AmoebaNr[xx][yy] = new_group_nr;
2197 void AmoebeUmwandeln(int ax, int ay)
2200 int group_nr = AmoebaNr[ax][ay];
2201 static int xy[4][2] =
2209 if (Feld[ax][ay]==EL_AMOEBE_TOT)
2211 for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
2213 if (Feld[x][y]==EL_AMOEBE_TOT && AmoebaNr[x][y]==group_nr)
2216 Feld[x][y] = EL_AMOEBA2DIAM;
2228 if (!IN_LEV_FIELD(x,y))
2231 if (Feld[x][y]==EL_AMOEBA2DIAM)
2237 void AmoebeUmwandeln2(int ax, int ay, int new_element)
2240 int group_nr = AmoebaNr[ax][ay];
2243 for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
2245 if (AmoebaNr[x][y]==group_nr &&
2246 (Feld[x][y]==EL_AMOEBE_TOT ||
2247 Feld[x][y]==EL_AMOEBE_BD ||
2248 Feld[x][y]==EL_AMOEBING))
2251 Feld[x][y] = new_element;
2252 DrawLevelField(x,y);
2258 PlaySoundLevel(ax,ay,new_element==EL_FELSBROCKEN ? SND_KLOPF : SND_PLING);
2261 void AmoebeWaechst(int x, int y)
2263 static long sound_delay = 0;
2264 static int sound_delay_value = 0;
2266 if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */
2270 if (DelayReached(&sound_delay, sound_delay_value))
2272 PlaySoundLevel(x,y,SND_AMOEBE);
2273 sound_delay_value = 30;
2277 if (MovDelay[x][y]) /* neue Phase / in Wartezustand */
2280 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
2281 DrawGraphic(SCREENX(x),SCREENY(y),GFX_AMOEBING+3-MovDelay[x][y]/2);
2283 if (!MovDelay[x][y])
2285 Feld[x][y] = Store[x][y];
2287 DrawLevelField(x,y);
2292 void AmoebeAbleger(int ax, int ay)
2295 int element = Feld[ax][ay];
2296 int newax = ax, neway = ay;
2297 static int xy[4][2] =
2305 if (!level.tempo_amoebe)
2307 Feld[ax][ay] = EL_AMOEBE_TOT;
2308 DrawLevelField(ax,ay);
2312 if (!MovDelay[ax][ay]) /* neue Amoebe / noch nicht gewartet */
2313 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25/(1+level.tempo_amoebe));
2315 if (MovDelay[ax][ay]) /* neue Amoebe / in Wartezustand */
2318 if (MovDelay[ax][ay])
2322 if (element==EL_AMOEBE_NASS) /* tropfende Amöbe */
2325 int x = ax+xy[start][0];
2326 int y = ay+xy[start][1];
2328 if (!IN_LEV_FIELD(x,y))
2332 Feld[x][y]==EL_ERDREICH || Feld[x][y]==EL_MORAST_LEER)
2338 if (newax==ax && neway==ay)
2341 else /* normale oder "gefüllte" Amöbe */
2344 BOOL waiting_for_player = FALSE;
2348 int j = (start+i)%4;
2349 int x = ax+xy[j][0];
2350 int y = ay+xy[j][1];
2352 if (!IN_LEV_FIELD(x,y))
2356 Feld[x][y]==EL_ERDREICH || Feld[x][y]==EL_MORAST_LEER)
2362 else if (IS_PLAYER(x,y))
2363 waiting_for_player = TRUE;
2366 if (newax==ax && neway==ay)
2368 if (i==4 && !waiting_for_player)
2370 Feld[ax][ay] = EL_AMOEBE_TOT;
2371 DrawLevelField(ax,ay);
2372 AmoebaCnt[AmoebaNr[ax][ay]]--;
2374 if (AmoebaCnt[AmoebaNr[ax][ay]]<=0) /* Amöbe vollständig tot */
2376 if (element==EL_AMOEBE_VOLL)
2377 AmoebeUmwandeln(ax,ay);
2378 else if (element==EL_AMOEBE_BD)
2379 AmoebeUmwandeln2(ax,ay,level.amoebe_inhalt);
2384 else if (element==EL_AMOEBE_VOLL || element==EL_AMOEBE_BD)
2386 int new_group_nr = AmoebaNr[ax][ay];
2388 AmoebaNr[newax][neway] = new_group_nr;
2389 AmoebaCnt[new_group_nr]++;
2390 AmoebaCnt2[new_group_nr]++;
2391 AmoebenVereinigen(newax,neway);
2393 if (AmoebaCnt2[new_group_nr] >= 200 && element==EL_AMOEBE_BD)
2395 AmoebeUmwandeln2(newax,neway,EL_FELSBROCKEN);
2401 if (element!=EL_AMOEBE_NASS || neway<ay || !IS_FREE(newax,neway) ||
2402 (neway==lev_fieldy-1 && newax!=ax))
2404 Feld[newax][neway] = EL_AMOEBING;
2405 Store[newax][neway] = element;
2408 Feld[newax][neway] = EL_TROPFEN;
2411 InitMovingField(ax,ay,MV_DOWN);
2412 Feld[ax][ay] = EL_TROPFEN;
2413 Store[ax][ay] = EL_AMOEBE_NASS;
2414 ContinueMoving(ax,ay);
2418 DrawLevelField(newax,neway);
2421 void Life(int ax, int ay)
2424 static int life[4] = { 2,3,3,3 }; /* "Life"-Parameter */
2426 int element = Feld[ax][ay];
2431 if (!MovDelay[ax][ay]) /* neue Phase / noch nicht gewartet */
2432 MovDelay[ax][ay] = life_time;
2434 if (MovDelay[ax][ay]) /* neue Phase / in Wartezustand */
2437 if (MovDelay[ax][ay])
2441 for(y1=-1;y1<2;y1++) for(x1=-1;x1<2;x1++)
2443 int xx = ax+x1, yy = ay+y1;
2446 if (!IN_LEV_FIELD(xx,yy))
2449 for(y2=-1;y2<2;y2++) for(x2=-1;x2<2;x2++)
2451 int x = xx+x2, y = yy+y2;
2453 if (!IN_LEV_FIELD(x,y) || (x==xx && y==yy))
2456 if (((Feld[x][y]==element || (element==EL_LIFE && IS_PLAYER(x,y))) &&
2458 (IS_FREE(x,y) && Stop[x][y]))
2462 if (xx==ax && yy==ay) /* mittleres Feld mit Amoebe */
2464 if (nachbarn<life[0] || nachbarn>life[1])
2466 Feld[xx][yy] = EL_LEERRAUM;
2468 DrawLevelField(xx,yy);
2469 Stop[xx][yy] = TRUE;
2472 else if (IS_FREE(xx,yy) || Feld[xx][yy]==EL_ERDREICH)
2473 { /* Randfeld ohne Amoebe */
2474 if (nachbarn>=life[2] && nachbarn<=life[3])
2476 Feld[xx][yy] = element;
2477 MovDelay[xx][yy] = (element==EL_LIFE ? 0 : life_time-1);
2479 DrawLevelField(xx,yy);
2480 Stop[xx][yy] = TRUE;
2486 void Ablenk(int x, int y)
2488 if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */
2489 MovDelay[x][y] = level.dauer_ablenk * FRAMES_PER_SECOND;
2491 if (MovDelay[x][y]) /* neue Phase / in Wartezustand */
2496 if (IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
2497 DrawGraphic(SCREENX(x),SCREENY(y),GFX_ABLENK+MovDelay[x][y]%4);
2498 if (!(MovDelay[x][y]%4))
2499 PlaySoundLevel(x,y,SND_MIEP);
2504 Feld[x][y] = EL_ABLENK_AUS;
2505 DrawLevelField(x,y);
2510 void Birne(int x, int y)
2512 if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */
2513 MovDelay[x][y] = 800;
2515 if (MovDelay[x][y]) /* neue Phase / in Wartezustand */
2520 if (!(MovDelay[x][y]%5))
2522 if (!(MovDelay[x][y]%10))
2523 Feld[x][y]=EL_ABLENK_EIN;
2525 Feld[x][y]=EL_ABLENK_AUS;
2526 DrawLevelField(x,y);
2527 Feld[x][y]=EL_ABLENK_EIN;
2533 Feld[x][y]=EL_ABLENK_AUS;
2534 DrawLevelField(x,y);
2539 void Blubber(int x, int y)
2541 if (y > 0 && IS_MOVING(x,y-1) && MovDir[x][y-1] == MV_DOWN)
2542 DrawLevelField(x,y-1);
2544 DrawGraphicAnimation(x,y, GFX_GEBLUBBER, 4, 10, ANIM_NORMAL);
2547 void NussKnacken(int x, int y)
2549 if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */
2552 if (MovDelay[x][y]) /* neue Phase / in Wartezustand */
2555 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
2556 DrawGraphic(SCREENX(x),SCREENY(y),GFX_CRACKINGNUT+3-MovDelay[x][y]/2);
2558 if (!MovDelay[x][y])
2560 Feld[x][y] = EL_EDELSTEIN;
2561 DrawLevelField(x,y);
2566 void SiebAktivieren(int x, int y, int typ)
2568 if (!(SiebAktiv % 4) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
2569 DrawGraphic(SCREENX(x),SCREENY(y),
2570 (typ==1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL)+3-(SiebAktiv%16)/4);
2573 void AusgangstuerPruefen(int x, int y)
2575 if (!local_player->gems_still_needed &&
2576 !local_player->sokobanfields_still_needed &&
2577 !local_player->lights_still_needed)
2579 Feld[x][y] = EL_AUSGANG_ACT;
2581 PlaySoundLevel(x < LEVELX(BX1) ? LEVELX(BX1) :
2582 (x > LEVELX(BX2) ? LEVELX(BX2) : x),
2583 y < LEVELY(BY1) ? LEVELY(BY1) :
2584 (y > LEVELY(BY2) ? LEVELY(BY2) : y),
2589 void AusgangstuerOeffnen(int x, int y)
2593 if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */
2594 MovDelay[x][y] = 5*delay;
2596 if (MovDelay[x][y]) /* neue Phase / in Wartezustand */
2601 tuer = MovDelay[x][y]/delay;
2602 if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
2603 DrawGraphic(SCREENX(x),SCREENY(y),GFX_AUSGANG_AUF-tuer);
2605 if (!MovDelay[x][y])
2607 Feld[x][y] = EL_AUSGANG_AUF;
2608 DrawLevelField(x,y);
2613 void AusgangstuerBlinken(int x, int y)
2615 DrawGraphicAnimation(x,y, GFX_AUSGANG_AUF, 4, 4, ANIM_OSCILLATE);
2618 void EdelsteinFunkeln(int x, int y)
2620 if (!IN_SCR_FIELD(SCREENX(x),SCREENY(y)) || IS_MOVING(x,y))
2623 if (Feld[x][y] == EL_EDELSTEIN_BD)
2624 DrawGraphicAnimation(x,y, GFX_EDELSTEIN_BD, 4, 4, ANIM_REVERSE);
2627 if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */
2628 MovDelay[x][y] = 11 * !SimpleRND(500);
2630 if (MovDelay[x][y]) /* neue Phase / in Wartezustand */
2634 if (direct_draw_on && MovDelay[x][y])
2635 SetDrawtoField(DRAW_BUFFERED);
2637 DrawGraphic(SCREENX(x),SCREENY(y), el2gfx(Feld[x][y]));
2641 int phase = (MovDelay[x][y]-1)/2;
2646 DrawGraphicThruMask(SCREENX(x),SCREENY(y), GFX_FUNKELN_WEISS + phase);
2652 dest_x = FX + SCREENX(x)*TILEX;
2653 dest_y = FY + SCREENY(y)*TILEY;
2655 XCopyArea(display,drawto_field,window,gc,
2656 dest_x,dest_y, TILEX,TILEY, dest_x,dest_y);
2657 SetDrawtoField(DRAW_DIRECT);
2664 void MauerWaechst(int x, int y)
2668 if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */
2669 MovDelay[x][y] = 3*delay;
2671 if (MovDelay[x][y]) /* neue Phase / in Wartezustand */
2676 phase = 2-MovDelay[x][y]/delay;
2677 if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
2678 DrawGraphic(SCREENX(x),SCREENY(y),
2679 (MovDir[x][y] == MV_LEFT ? GFX_MAUER_LEFT :
2680 MovDir[x][y] == MV_RIGHT ? GFX_MAUER_RIGHT :
2681 MovDir[x][y] == MV_UP ? GFX_MAUER_UP :
2682 GFX_MAUER_DOWN ) + phase);
2684 if (!MovDelay[x][y])
2686 if (MovDir[x][y] == MV_LEFT)
2688 if (IN_LEV_FIELD(x-1,y) && IS_MAUER(Feld[x-1][y]))
2689 DrawLevelField(x-1,y);
2691 else if (MovDir[x][y] == MV_RIGHT)
2693 if (IN_LEV_FIELD(x+1,y) && IS_MAUER(Feld[x+1][y]))
2694 DrawLevelField(x+1,y);
2696 else if (MovDir[x][y] == MV_UP)
2698 if (IN_LEV_FIELD(x,y-1) && IS_MAUER(Feld[x][y-1]))
2699 DrawLevelField(x,y-1);
2703 if (IN_LEV_FIELD(x,y+1) && IS_MAUER(Feld[x][y+1]))
2704 DrawLevelField(x,y+1);
2707 Feld[x][y] = Store[x][y];
2709 MovDir[x][y] = MV_NO_MOVING;
2710 DrawLevelField(x,y);
2715 void MauerAbleger(int ax, int ay)
2717 int element = Feld[ax][ay];
2718 BOOL oben_frei = FALSE, unten_frei = FALSE;
2719 BOOL links_frei = FALSE, rechts_frei = FALSE;
2720 BOOL oben_massiv = FALSE, unten_massiv = FALSE;
2721 BOOL links_massiv = FALSE, rechts_massiv = FALSE;
2723 if (!MovDelay[ax][ay]) /* neue Mauer / noch nicht gewartet */
2724 MovDelay[ax][ay] = 6;
2726 if (MovDelay[ax][ay]) /* neue Mauer / in Wartezustand */
2729 if (MovDelay[ax][ay])
2733 if (IN_LEV_FIELD(ax,ay-1) && IS_FREE(ax,ay-1))
2735 if (IN_LEV_FIELD(ax,ay+1) && IS_FREE(ax,ay+1))
2737 if (IN_LEV_FIELD(ax-1,ay) && IS_FREE(ax-1,ay))
2739 if (IN_LEV_FIELD(ax+1,ay) && IS_FREE(ax+1,ay))
2742 if (element == EL_MAUER_Y || element == EL_MAUER_XY)
2746 Feld[ax][ay-1] = EL_MAUERND;
2747 Store[ax][ay-1] = element;
2748 MovDir[ax][ay-1] = MV_UP;
2749 if (IN_SCR_FIELD(SCREENX(ax),SCREENY(ay-1)))
2750 DrawGraphic(SCREENX(ax),SCREENY(ay-1),GFX_MAUER_UP);
2754 Feld[ax][ay+1] = EL_MAUERND;
2755 Store[ax][ay+1] = element;
2756 MovDir[ax][ay+1] = MV_DOWN;
2757 if (IN_SCR_FIELD(SCREENX(ax),SCREENY(ay+1)))
2758 DrawGraphic(SCREENX(ax),SCREENY(ay+1),GFX_MAUER_DOWN);
2762 if (element == EL_MAUER_X || element == EL_MAUER_XY ||
2763 element == EL_MAUER_LEBT)
2767 Feld[ax-1][ay] = EL_MAUERND;
2768 Store[ax-1][ay] = element;
2769 MovDir[ax-1][ay] = MV_LEFT;
2770 if (IN_SCR_FIELD(SCREENX(ax-1),SCREENY(ay)))
2771 DrawGraphic(SCREENX(ax-1),SCREENY(ay),GFX_MAUER_LEFT);
2775 Feld[ax+1][ay] = EL_MAUERND;
2776 Store[ax+1][ay] = element;
2777 MovDir[ax+1][ay] = MV_RIGHT;
2778 if (IN_SCR_FIELD(SCREENX(ax+1),SCREENY(ay)))
2779 DrawGraphic(SCREENX(ax+1),SCREENY(ay),GFX_MAUER_RIGHT);
2783 if (element == EL_MAUER_LEBT && (links_frei || rechts_frei))
2784 DrawLevelField(ax,ay);
2786 if (!IN_LEV_FIELD(ax,ay-1) || IS_MAUER(Feld[ax][ay-1]))
2788 if (!IN_LEV_FIELD(ax,ay+1) || IS_MAUER(Feld[ax][ay+1]))
2789 unten_massiv = TRUE;
2790 if (!IN_LEV_FIELD(ax-1,ay) || IS_MAUER(Feld[ax-1][ay]))
2791 links_massiv = TRUE;
2792 if (!IN_LEV_FIELD(ax+1,ay) || IS_MAUER(Feld[ax+1][ay]))
2793 rechts_massiv = TRUE;
2795 if (((oben_massiv && unten_massiv) ||
2796 element == EL_MAUER_X || element == EL_MAUER_LEBT) &&
2797 ((links_massiv && rechts_massiv) ||
2798 element == EL_MAUER_Y))
2799 Feld[ax][ay] = EL_MAUERWERK;
2802 void CheckForDragon(int x, int y)
2805 BOOL dragon_found = FALSE;
2806 static int xy[4][2] =
2818 int xx = x + j*xy[i][0], yy = y + j*xy[i][1];
2820 if (IN_LEV_FIELD(xx,yy) &&
2821 (Feld[xx][yy] == EL_BURNING || Feld[xx][yy] == EL_DRACHE))
2823 if (Feld[xx][yy] == EL_DRACHE)
2824 dragon_found = TRUE;
2837 int xx = x + j*xy[i][0], yy = y + j*xy[i][1];
2839 if (IN_LEV_FIELD(xx,yy) && Feld[xx][yy] == EL_BURNING)
2841 Feld[xx][yy] = EL_LEERRAUM;
2842 DrawLevelField(xx,yy);
2851 void PlayerActions(struct PlayerInfo *player, byte player_action)
2853 static byte stored_player_action[MAX_PLAYERS];
2854 static int num_stored_actions = 0;
2855 BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
2856 int jx = player->jx, jy = player->jy;
2857 int left = player_action & JOY_LEFT;
2858 int right = player_action & JOY_RIGHT;
2859 int up = player_action & JOY_UP;
2860 int down = player_action & JOY_DOWN;
2861 int button1 = player_action & JOY_BUTTON_1;
2862 int button2 = player_action & JOY_BUTTON_2;
2863 int dx = (left ? -1 : right ? 1 : 0);
2864 int dy = (up ? -1 : down ? 1 : 0);
2866 stored_player_action[player->index_nr] = 0;
2867 num_stored_actions++;
2869 if (!player->active || player->gone)
2874 player->frame_reset_delay = 0;
2877 snapped = SnapField(player, dx,dy);
2881 bombed = PlaceBomb(player);
2882 moved = MoveFigure(player, dx,dy);
2885 if (tape.recording && (moved || snapped || bombed))
2887 if (bombed && !moved)
2888 player_action &= JOY_BUTTON;
2890 stored_player_action[player->index_nr] = player_action;
2892 /* this allows cycled sequences of PlayerActions() */
2893 if (num_stored_actions >= MAX_PLAYERS)
2895 TapeRecordAction(stored_player_action);
2896 num_stored_actions = 0;
2899 else if (tape.playing && snapped)
2900 SnapField(player, 0,0); /* stop snapping */
2904 DigField(player, 0,0, 0,0, DF_NO_PUSH);
2905 SnapField(player, 0,0);
2906 if (++player->frame_reset_delay > MoveSpeed)
2910 if (tape.playing && !tape.pausing && !player_action &&
2911 tape.counter < tape.length)
2914 tape.pos[tape.counter].action[player->index_nr] & (JOY_LEFT|JOY_RIGHT);
2916 if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
2918 int dx = (next_joy == JOY_LEFT ? -1 : +1);
2920 if (IN_LEV_FIELD(jx+dx,jy) && IS_PUSHABLE(Feld[jx+dx][jy]))
2922 int el = Feld[jx+dx][jy];
2923 int push_delay = (IS_SB_ELEMENT(el) || el==EL_SONDE ? 2 : 10);
2925 if (tape.delay_played + push_delay >= tape.pos[tape.counter].delay)
2927 player->MovDir = next_joy;
2928 player->Frame = FrameCounter % 4;
2929 player->Pushing = TRUE;
2936 void GameActions(byte player_action)
2938 static long action_delay = 0;
2939 long action_delay_value;
2940 int sieb_x = 0, sieb_y = 0;
2941 int i, x,y, element;
2942 int *recorded_player_action;
2944 if (game_status != PLAYING)
2948 action_delay_value =
2949 (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GameFrameDelay);
2951 action_delay_value =
2952 (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY);
2955 /* main game synchronization point */
2956 WaitUntilDelayReached(&action_delay, action_delay_value);
2958 if (network_playing && !network_player_action_received)
2962 printf("DEBUG: try to get network player actions in time\n");
2966 /* last chance to get network player actions without main loop delay */
2969 if (game_status != PLAYING)
2972 if (!network_player_action_received)
2976 printf("DEBUG: failed to get network player actions in time\n");
2984 if (tape.pausing || (tape.playing && !TapePlayDelay()))
2986 else if (tape.recording)
2991 recorded_player_action = TapePlayAction();
2993 recorded_player_action = NULL;
2995 if (network_playing)
2996 SendToServer_MovePlayer(player_action);
2998 for(i=0; i<MAX_PLAYERS; i++)
3001 int actual_player_action =
3002 (network ? network_player_action[i] : player_action);
3005 int actual_player_action =
3006 (network_playing ? network_player_action[i] : player_action);
3009 int actual_player_action = network_player_action[i];
3013 int actual_player_action = player_action;
3016 /* TEST TEST TEST */
3019 if (i != TestPlayer && !stored_player[i].MovPos)
3020 actual_player_action = 0;
3023 if (!network && i != TestPlayer)
3024 actual_player_action = 0;
3026 /* TEST TEST TEST */
3028 if (recorded_player_action)
3029 actual_player_action = recorded_player_action[i];
3031 PlayerActions(&stored_player[i], actual_player_action);
3032 ScrollFigure(&stored_player[i], SCROLL_GO_ON);
3034 network_player_action[i] = 0;
3037 network_player_action_received = FALSE;
3039 ScrollScreen(NULL, SCROLL_GO_ON);
3042 if (tape.pausing || (tape.playing && !TapePlayDelay()))
3044 else if (tape.recording)
3053 printf("FrameCounter == %d, RND(100) == %d\n", FrameCounter, RND(100));
3057 for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
3060 if (JustHit[x][y]>0)
3064 if (IS_BLOCKED(x,y))
3068 Blocked2Moving(x,y,&oldx,&oldy);
3069 if (!IS_MOVING(oldx,oldy))
3071 printf("GameActions(): (BLOCKED=>MOVING) context corrupted!\n");
3072 printf("GameActions(): BLOCKED: x = %d, y = %d\n",x,y);
3073 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n",oldx,oldy);
3074 printf("GameActions(): This should never happen!\n");
3080 for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
3082 element = Feld[x][y];
3084 if (IS_INACTIVE(element))
3087 if (!IS_MOVING(x,y) && (CAN_FALL(element) || CAN_MOVE(element)))
3091 if (IS_GEM(element))
3092 EdelsteinFunkeln(x,y);
3094 else if (IS_MOVING(x,y))
3095 ContinueMoving(x,y);
3096 else if (element==EL_DYNAMIT || element==EL_DYNABOMB)
3098 else if (element==EL_EXPLODING)
3099 Explode(x,y,Frame[x][y],EX_NORMAL);
3100 else if (element==EL_AMOEBING)
3102 else if (IS_AMOEBALIVE(element))
3104 else if (element==EL_LIFE || element==EL_LIFE_ASYNC)
3106 else if (element==EL_ABLENK_EIN)
3108 else if (element==EL_SALZSAEURE)
3110 else if (element==EL_BLURB_LEFT || element==EL_BLURB_RIGHT)
3112 else if (element==EL_CRACKINGNUT)
3114 else if (element==EL_AUSGANG_ZU)
3115 AusgangstuerPruefen(x,y);
3116 else if (element==EL_AUSGANG_ACT)
3117 AusgangstuerOeffnen(x,y);
3118 else if (element==EL_AUSGANG_AUF)
3119 AusgangstuerBlinken(x,y);
3120 else if (element==EL_MAUERND)
3122 else if (element==EL_MAUER_LEBT ||
3123 element==EL_MAUER_X ||
3124 element==EL_MAUER_Y ||
3125 element==EL_MAUER_XY)
3127 else if (element==EL_BURNING)
3128 CheckForDragon(x,y);
3133 int jx = local_player->jx, jy = local_player->jy;
3135 if (element==EL_SIEB_LEER || element==EL_SIEB_VOLL ||
3136 Store[x][y]==EL_SIEB_LEER)
3138 SiebAktivieren(x, y, 1);
3141 else if (element==EL_SIEB2_LEER || element==EL_SIEB2_VOLL ||
3142 Store[x][y]==EL_SIEB2_LEER)
3144 SiebAktivieren(x, y, 2);
3148 /* play the element sound at the position nearest to the player */
3149 if (sieb && ABS(x-jx)+ABS(y-jy) < ABS(sieb_x-jx)+ABS(sieb_y-jy))
3160 PlaySoundLevel(sieb_x,sieb_y,SND_MIEP);
3164 for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
3166 element = Feld[x][y];
3167 if (element==EL_SIEB_LEER || element==EL_SIEB_VOLL)
3169 Feld[x][y] = EL_SIEB_TOT;
3170 DrawLevelField(x,y);
3172 else if (element==EL_SIEB2_LEER || element==EL_SIEB2_VOLL)
3174 Feld[x][y] = EL_SIEB2_TOT;
3175 DrawLevelField(x,y);
3181 if (TimeLeft>0 && TimeFrames>=(1000/GameFrameDelay) && !tape.pausing)
3186 if (tape.recording || tape.playing)
3187 DrawVideoDisplay(VIDEO_STATE_TIME_ON,level.time-TimeLeft);
3190 PlaySoundStereo(SND_GONG,PSND_MAX_RIGHT);
3192 DrawText(DX_TIME,DY_TIME,int2str(TimeLeft,3),FS_SMALL,FC_YELLOW);
3195 for(i=0; i<MAX_PLAYERS; i++)
3196 KillHero(&stored_player[i]);
3202 static BOOL AllPlayersInSight(struct PlayerInfo *player, int x, int y)
3204 int min_x = x, min_y = y, max_x = x, max_y = y;
3207 for(i=0; i<MAX_PLAYERS; i++)
3209 int jx = stored_player[i].jx, jy = stored_player[i].jy;
3211 if (!stored_player[i].active || stored_player[i].gone ||
3212 &stored_player[i] == player)
3215 min_x = MIN(min_x, jx);
3216 min_y = MIN(min_y, jy);
3217 max_x = MAX(max_x, jx);
3218 max_y = MAX(max_y, jy);
3221 return(max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
3224 static BOOL AllPlayersInVisibleScreen()
3228 for(i=0; i<MAX_PLAYERS; i++)
3230 int jx = stored_player[i].jx, jy = stored_player[i].jy;
3232 if (!stored_player[i].active || stored_player[i].gone)
3235 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
3242 void ScrollLevel(int dx, int dy)
3244 int softscroll_offset = (soft_scrolling_on ? TILEX : 0);
3248 ScreenGfxPos = local_player->GfxPos;
3251 XCopyArea(display,drawto_field,drawto_field,gc,
3252 FX + TILEX*(dx==-1) - softscroll_offset,
3253 FY + TILEY*(dy==-1) - softscroll_offset,
3254 SXSIZE - TILEX*(dx!=0) + 2*softscroll_offset,
3255 SYSIZE - TILEY*(dy!=0) + 2*softscroll_offset,
3256 FX + TILEX*(dx==1) - softscroll_offset,
3257 FY + TILEY*(dy==1) - softscroll_offset);
3261 x = (dx==1 ? BX1 : BX2);
3262 for(y=BY1; y<=BY2; y++)
3263 DrawScreenField(x,y);
3267 y = (dy==1 ? BY1 : BY2);
3268 for(x=BX1; x<=BX2; x++)
3269 DrawScreenField(x,y);
3272 redraw_mask |= REDRAW_FIELD;
3275 BOOL MoveFigureOneStep(struct PlayerInfo *player,
3276 int dx, int dy, int real_dx, int real_dy)
3278 int jx = player->jx, jy = player->jy;
3279 int new_jx = jx+dx, new_jy = jy+dy;
3283 if (player->gone || (!dx && !dy))
3284 return(MF_NO_ACTION);
3286 player->MovDir = (dx < 0 ? MV_LEFT :
3289 dy > 0 ? MV_DOWN : MV_NO_MOVING);
3291 if (!IN_LEV_FIELD(new_jx,new_jy))
3292 return(MF_NO_ACTION);
3294 if (!network && !AllPlayersInSight(player, new_jx,new_jy))
3295 return(MF_NO_ACTION);
3297 element = MovingOrBlocked2Element(new_jx,new_jy);
3299 if (DONT_GO_TO(element))
3301 if (element==EL_SALZSAEURE && dx==0 && dy==1)
3304 Feld[jx][jy] = EL_SPIELFIGUR;
3305 InitMovingField(jx,jy,MV_DOWN);
3306 Store[jx][jy] = EL_SALZSAEURE;
3307 ContinueMoving(jx,jy);
3316 can_move = DigField(player, new_jx,new_jy, real_dx,real_dy, DF_DIG);
3317 if (can_move != MF_MOVING)
3320 StorePlayer[jx][jy] = 0;
3321 player->last_jx = jx;
3322 player->last_jy = jy;
3323 jx = player->jx = new_jx;
3324 jy = player->jy = new_jy;
3325 StorePlayer[jx][jy] = player->element_nr;
3327 player->MovPos = (dx > 0 || dy > 0 ? -1 : 1) * 7*TILEX/8;
3329 ScrollFigure(player, SCROLL_INIT);
3334 BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy)
3336 int jx = player->jx, jy = player->jy;
3337 int old_jx = jx, old_jy = jy;
3338 int moved = MF_NO_ACTION;
3340 if (player->gone || (!dx && !dy))
3343 if (!FrameReached(&player->move_delay,MoveSpeed) && !tape.playing)
3346 if (player->last_move_dir & (MV_LEFT | MV_RIGHT))
3348 if (!(moved |= MoveFigureOneStep(player, 0,dy, dx,dy)))
3349 moved |= MoveFigureOneStep(player, dx,0, dx,dy);
3353 if (!(moved |= MoveFigureOneStep(player, dx,0, dx,dy)))
3354 moved |= MoveFigureOneStep(player, 0,dy, dx,dy);
3363 if (moved & MF_MOVING && player == local_player)
3366 if (moved & MF_MOVING && !ScreenMovPos &&
3367 (player == local_player || !network))
3369 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
3370 int offset = (scroll_delay_on ? 3 : 0);
3373 if (player == local_player)
3375 printf("MOVING LOCAL PLAYER && SCROLLING\n");
3379 if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy)))
3381 /* actual player has left the screen -- scroll in that direction */
3382 if (jx != old_jx) /* player has moved horizontally */
3383 scroll_x += (jx - old_jx);
3384 else /* player has moved vertically */
3385 scroll_y += (jy - old_jy);
3389 if (jx != old_jx) /* player has moved horizontally */
3391 if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
3392 jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
3393 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
3395 /* don't scroll more than one field at a time */
3396 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
3398 /* don't scroll against the player's moving direction */
3399 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
3400 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
3401 scroll_x = old_scroll_x;
3403 else /* player has moved vertically */
3405 if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
3406 jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
3407 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
3409 /* don't scroll more than one field at a time */
3410 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
3412 /* don't scroll against the player's moving direction */
3413 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
3414 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
3415 scroll_y = old_scroll_y;
3420 if (player == local_player)
3422 if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
3423 jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
3424 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
3425 if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
3426 jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
3427 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
3429 /* don't scroll more than one field at a time */
3430 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
3431 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
3435 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
3437 if (!network && !AllPlayersInVisibleScreen())
3439 scroll_x = old_scroll_x;
3440 scroll_y = old_scroll_y;
3444 ScrollScreen(player, SCROLL_INIT);
3445 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
3450 if (!(moved & MF_MOVING) && !player->Pushing)
3453 player->Frame = (player->Frame + 1) % 4;
3455 if (moved & MF_MOVING)
3457 if (old_jx != jx && old_jy == jy)
3458 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
3459 else if (old_jx == jx && old_jy != jy)
3460 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
3462 DrawLevelField(jx,jy); /* für "ErdreichAnbroeckeln()" */
3464 player->last_move_dir = player->MovDir;
3467 player->last_move_dir = MV_NO_MOVING;
3469 TestIfHeroHitsBadThing(jx,jy);
3477 void ScrollFigure(struct PlayerInfo *player, int mode)
3479 int jx = player->jx, jy = player->jy;
3480 int last_jx = player->last_jx, last_jy = player->last_jy;
3482 if (!player->active || player->gone || !player->MovPos)
3485 if (mode == SCROLL_INIT)
3487 player->actual_frame_counter = FrameCounter;
3488 player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize);
3490 if (Feld[last_jx][last_jy] == EL_LEERRAUM)
3491 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
3496 else if (!FrameReached(&player->actual_frame_counter,1))
3499 player->MovPos += (player->MovPos > 0 ? -1 : 1) * TILEX/8;
3500 player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize);
3502 if (Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
3503 Feld[last_jx][last_jy] = EL_LEERRAUM;
3507 if (!player->MovPos)
3509 player->last_jx = jx;
3510 player->last_jy = jy;
3512 if (Feld[jx][jy] == EL_AUSGANG_AUF)
3516 if (!local_player->friends_still_needed)
3517 player->LevelSolved = player->GameOver = TRUE;
3522 void ScrollScreen(struct PlayerInfo *player, int mode)
3524 static long screen_frame_counter = 0;
3526 if (mode == SCROLL_INIT)
3528 screen_frame_counter = FrameCounter;
3529 ScreenMovDir = player->MovDir;
3530 ScreenMovPos = player->MovPos;
3531 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
3534 else if (!FrameReached(&screen_frame_counter,1))
3539 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * TILEX/8;
3540 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
3541 redraw_mask |= REDRAW_FIELD;
3544 ScreenMovDir = MV_NO_MOVING;
3547 void TestIfGoodThingHitsBadThing(int goodx, int goody)
3549 int i, killx = goodx, killy = goody;
3550 static int xy[4][2] =
3557 static int harmless[4] =
3569 x = goodx + xy[i][0];
3570 y = goody + xy[i][1];
3571 if (!IN_LEV_FIELD(x,y))
3574 element = Feld[x][y];
3576 if (DONT_TOUCH(element))
3578 if (MovDir[x][y] == harmless[i])
3587 if (killx != goodx || killy != goody)
3589 if (IS_PLAYER(goodx,goody))
3590 KillHero(PLAYERINFO(goodx,goody));
3596 void TestIfBadThingHitsGoodThing(int badx, int bady)
3598 int i, killx = badx, killy = bady;
3599 static int xy[4][2] =
3606 static int harmless[4] =
3618 x = badx + xy[i][0];
3619 y = bady + xy[i][1];
3620 if (!IN_LEV_FIELD(x,y))
3623 element = Feld[x][y];
3631 else if (element == EL_PINGUIN)
3633 if (MovDir[x][y] == harmless[i] && IS_MOVING(x,y))
3642 if (killx != badx || killy != bady)
3644 if (IS_PLAYER(killx,killy))
3645 KillHero(PLAYERINFO(killx,killy));
3651 void TestIfHeroHitsBadThing(int x, int y)
3653 TestIfGoodThingHitsBadThing(x,y);
3656 void TestIfBadThingHitsHero(int x, int y)
3659 TestIfGoodThingHitsBadThing(JX,JY);
3662 TestIfBadThingHitsGoodThing(x,y);
3665 void TestIfFriendHitsBadThing(int x, int y)
3667 TestIfGoodThingHitsBadThing(x,y);
3670 void TestIfBadThingHitsFriend(int x, int y)
3672 TestIfBadThingHitsGoodThing(x,y);
3675 void TestIfBadThingHitsOtherBadThing(int badx, int bady)
3677 int i, killx = badx, killy = bady;
3678 static int xy[4][2] =
3692 if (!IN_LEV_FIELD(x,y))
3695 element = Feld[x][y];
3696 if (IS_AMOEBOID(element) || element == EL_LIFE ||
3697 element == EL_AMOEBING || element == EL_TROPFEN)
3705 if (killx != badx || killy != bady)
3709 void KillHero(struct PlayerInfo *player)
3711 int jx = player->jx, jy = player->jy;
3716 if (IS_PFORTE(Feld[jx][jy]))
3717 Feld[jx][jy] = EL_LEERRAUM;
3723 void BuryHero(struct PlayerInfo *player)
3725 int jx = player->jx, jy = player->jy;
3730 PlaySoundLevel(jx,jy, SND_AUTSCH);
3731 PlaySoundLevel(jx,jy, SND_LACHEN);
3733 player->GameOver = TRUE;
3737 void RemoveHero(struct PlayerInfo *player)
3739 int jx = player->jx, jy = player->jy;
3740 int i, found = FALSE;
3742 player->gone = TRUE;
3743 StorePlayer[jx][jy] = 0;
3745 for(i=0; i<MAX_PLAYERS; i++)
3746 if (stored_player[i].active && !stored_player[i].gone)
3750 AllPlayersGone = TRUE;
3756 int DigField(struct PlayerInfo *player,
3757 int x, int y, int real_dx, int real_dy, int mode)
3759 int jx = player->jx, jy = player->jy;
3760 int dx = x - jx, dy = y - jy;
3763 if (!player->MovPos)
3764 player->Pushing = FALSE;
3766 if (mode == DF_NO_PUSH)
3768 player->push_delay = 0;
3769 return(MF_NO_ACTION);
3772 if (IS_MOVING(x,y) || IS_PLAYER(x,y))
3773 return(MF_NO_ACTION);
3775 element = Feld[x][y];
3783 Feld[x][y] = EL_LEERRAUM;
3787 case EL_EDELSTEIN_BD:
3788 case EL_EDELSTEIN_GELB:
3789 case EL_EDELSTEIN_ROT:
3790 case EL_EDELSTEIN_LILA:
3793 local_player->gems_still_needed -= (element == EL_DIAMANT ? 3 : 1);
3794 if (local_player->gems_still_needed < 0)
3795 local_player->gems_still_needed = 0;
3796 RaiseScoreElement(element);
3797 DrawText(DX_EMERALDS, DY_EMERALDS,
3798 int2str(local_player->gems_still_needed, 3),
3799 FS_SMALL, FC_YELLOW);
3800 PlaySoundLevel(x, y, SND_PONG);
3803 case EL_DYNAMIT_AUS:
3806 RaiseScoreElement(EL_DYNAMIT);
3807 DrawText(DX_DYNAMITE, DY_DYNAMITE,
3808 int2str(local_player->dynamite, 3),
3809 FS_SMALL, FC_YELLOW);
3810 PlaySoundLevel(x,y,SND_PONG);
3813 case EL_DYNABOMB_NR:
3815 player->dynabomb_count++;
3816 player->dynabombs_left++;
3817 RaiseScoreElement(EL_DYNAMIT);
3818 PlaySoundLevel(x,y,SND_PONG);
3821 case EL_DYNABOMB_SZ:
3823 player->dynabomb_size++;
3824 RaiseScoreElement(EL_DYNAMIT);
3825 PlaySoundLevel(x,y,SND_PONG);
3828 case EL_DYNABOMB_XL:
3830 player->dynabomb_xl = TRUE;
3831 RaiseScoreElement(EL_DYNAMIT);
3832 PlaySoundLevel(x,y,SND_PONG);
3835 case EL_SCHLUESSEL1:
3836 case EL_SCHLUESSEL2:
3837 case EL_SCHLUESSEL3:
3838 case EL_SCHLUESSEL4:
3840 int key_nr = element-EL_SCHLUESSEL1;
3843 player->key[key_nr] = TRUE;
3844 RaiseScoreElement(EL_SCHLUESSEL);
3845 DrawMiniGraphicExt(drawto,gc,
3846 DX_KEYS+key_nr*MINI_TILEX,DY_KEYS,
3847 GFX_SCHLUESSEL1+key_nr);
3848 DrawMiniGraphicExt(window,gc,
3849 DX_KEYS+key_nr*MINI_TILEX,DY_KEYS,
3850 GFX_SCHLUESSEL1+key_nr);
3851 PlaySoundLevel(x,y,SND_PONG);
3856 Feld[x][y] = EL_ABLENK_EIN;
3859 DrawLevelField(x,y);
3863 case EL_FELSBROCKEN:
3867 if (dy || mode==DF_SNAP)
3868 return(MF_NO_ACTION);
3870 player->Pushing = TRUE;
3872 if (!IN_LEV_FIELD(x+dx,y+dy) || !IS_FREE(x+dx,y+dy))
3873 return(MF_NO_ACTION);
3877 if (IN_LEV_FIELD(jx,jy+real_dy) && !IS_SOLID(Feld[jx][jy+real_dy]))
3878 return(MF_NO_ACTION);
3881 if (player->push_delay == 0)
3882 player->push_delay = FrameCounter;
3883 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
3885 return(MF_NO_ACTION);
3888 Feld[x+dx][y+dy] = element;
3890 player->push_delay_value = 2+RND(8);
3892 DrawLevelField(x+dx,y+dy);
3893 if (element==EL_FELSBROCKEN)
3894 PlaySoundLevel(x+dx,y+dy,SND_PUSCH);
3895 else if (element==EL_KOKOSNUSS)
3896 PlaySoundLevel(x+dx,y+dy,SND_KNURK);
3898 PlaySoundLevel(x+dx,y+dy,SND_KLOPF);
3905 if (!player->key[element-EL_PFORTE1])
3906 return(MF_NO_ACTION);
3913 if (!player->key[element-EL_PFORTE1X])
3914 return(MF_NO_ACTION);
3918 case EL_AUSGANG_ACT:
3919 /* Tür ist (noch) nicht offen! */
3920 return(MF_NO_ACTION);
3923 case EL_AUSGANG_AUF:
3925 return(MF_NO_ACTION);
3927 PlaySoundLevel(x,y,SND_BUING);
3930 player->gone = TRUE;
3931 PlaySoundLevel(x,y,SND_BUING);
3933 if (!local_player->friends_still_needed)
3934 player->LevelSolved = player->GameOver = TRUE;
3940 Feld[x][y] = EL_BIRNE_EIN;
3941 local_player->lights_still_needed--;
3942 DrawLevelField(x,y);
3943 PlaySoundLevel(x,y,SND_DENG);
3948 Feld[x][y] = EL_ZEIT_LEER;
3950 DrawText(DX_TIME,DY_TIME,int2str(TimeLeft,3),FS_SMALL,FC_YELLOW);
3951 DrawLevelField(x,y);
3952 PlaySoundStereo(SND_GONG,PSND_MAX_RIGHT);
3956 case EL_SOKOBAN_FELD_LEER:
3959 case EL_SOKOBAN_FELD_VOLL:
3960 case EL_SOKOBAN_OBJEKT:
3963 return(MF_NO_ACTION);
3965 player->Pushing = TRUE;
3967 if (!IN_LEV_FIELD(x+dx,y+dy)
3968 || (!IS_FREE(x+dx,y+dy)
3969 && (Feld[x+dx][y+dy] != EL_SOKOBAN_FELD_LEER
3970 || !IS_SB_ELEMENT(element))))
3971 return(MF_NO_ACTION);
3975 if (IN_LEV_FIELD(jx,jy+real_dy) && !IS_SOLID(Feld[jx][jy+real_dy]))
3976 return(MF_NO_ACTION);
3978 else if (dy && real_dx)
3980 if (IN_LEV_FIELD(jx+real_dx,jy) && !IS_SOLID(Feld[jx+real_dx][jy]))
3981 return(MF_NO_ACTION);
3984 if (player->push_delay == 0)
3985 player->push_delay = FrameCounter;
3986 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
3988 return(MF_NO_ACTION);
3990 if (IS_SB_ELEMENT(element))
3992 if (element == EL_SOKOBAN_FELD_VOLL)
3994 Feld[x][y] = EL_SOKOBAN_FELD_LEER;
3995 local_player->sokobanfields_still_needed++;
4000 if (Feld[x+dx][y+dy] == EL_SOKOBAN_FELD_LEER)
4002 Feld[x+dx][y+dy] = EL_SOKOBAN_FELD_VOLL;
4003 local_player->sokobanfields_still_needed--;
4004 if (element == EL_SOKOBAN_OBJEKT)
4005 PlaySoundLevel(x,y,SND_DENG);
4008 Feld[x+dx][y+dy] = EL_SOKOBAN_OBJEKT;
4013 Feld[x+dx][y+dy] = element;
4016 player->push_delay_value = 2;
4018 DrawLevelField(x,y);
4019 DrawLevelField(x+dx,y+dy);
4020 PlaySoundLevel(x+dx,y+dy,SND_PUSCH);
4022 if (IS_SB_ELEMENT(element) &&
4023 local_player->sokobanfields_still_needed == 0 &&
4024 game_emulation == EMU_SOKOBAN)
4026 player->LevelSolved = player->GameOver = TRUE;
4027 PlaySoundLevel(x,y,SND_BUING);
4039 return(MF_NO_ACTION);
4043 player->push_delay = 0;
4048 BOOL SnapField(struct PlayerInfo *player, int dx, int dy)
4050 int jx = player->jx, jy = player->jy;
4051 int x = jx + dx, y = jy + dy;
4053 if (player->gone || !IN_LEV_FIELD(x,y))
4061 player->snapped = FALSE;
4065 if (player->snapped)
4068 player->MovDir = (dx < 0 ? MV_LEFT :
4071 dy > 0 ? MV_DOWN : MV_NO_MOVING);
4073 if (!DigField(player, x,y, 0,0, DF_SNAP))
4076 player->snapped = TRUE;
4077 DrawLevelField(x,y);
4083 BOOL PlaceBomb(struct PlayerInfo *player)
4085 int jx = player->jx, jy = player->jy;
4088 if (player->gone || player->MovPos)
4091 element = Feld[jx][jy];
4093 if ((player->dynamite==0 && player->dynabombs_left==0) ||
4094 element==EL_DYNAMIT || element==EL_DYNABOMB || element==EL_EXPLODING)
4097 if (element != EL_LEERRAUM)
4098 Store[jx][jy] = element;
4100 if (player->dynamite)
4102 Feld[jx][jy] = EL_DYNAMIT;
4103 MovDelay[jx][jy] = 96;
4105 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(local_player->dynamite, 3),
4106 FS_SMALL, FC_YELLOW);
4107 if (IN_SCR_FIELD(SCREENX(jx),SCREENY(jy)))
4108 DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNAMIT);
4112 Feld[jx][jy] = EL_DYNABOMB;
4113 Store2[jx][jy] = player->element_nr; /* for DynaExplode() */
4114 MovDelay[jx][jy] = 96;
4115 player->dynabombs_left--;
4116 if (IN_SCR_FIELD(SCREENX(jx),SCREENY(jy)))
4117 DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNABOMB);
4123 void PlaySoundLevel(int x, int y, int sound_nr)
4125 int sx = SCREENX(x), sy = SCREENY(y);
4127 int silence_distance = 8;
4129 if ((!sound_simple_on && !IS_LOOP_SOUND(sound_nr)) ||
4130 (!sound_loops_on && IS_LOOP_SOUND(sound_nr)))
4133 if (!IN_LEV_FIELD(x,y) ||
4134 sx < -silence_distance || sx >= SCR_FIELDX+silence_distance ||
4135 sy < -silence_distance || sy >= SCR_FIELDY+silence_distance)
4138 volume = PSND_MAX_VOLUME;
4140 stereo = (sx-SCR_FIELDX/2)*12;
4142 stereo = PSND_MIDDLE+(2*sx-(SCR_FIELDX-1))*5;
4143 if(stereo > PSND_MAX_RIGHT) stereo = PSND_MAX_RIGHT;
4144 if(stereo < PSND_MAX_LEFT) stereo = PSND_MAX_LEFT;
4147 if (!IN_SCR_FIELD(sx,sy))
4149 int dx = ABS(sx-SCR_FIELDX/2)-SCR_FIELDX/2;
4150 int dy = ABS(sy-SCR_FIELDY/2)-SCR_FIELDY/2;
4152 volume -= volume*(dx > dy ? dx : dy)/silence_distance;
4155 PlaySoundExt(sound_nr, volume, stereo, PSND_NO_LOOP);
4158 void RaiseScore(int value)
4160 local_player->score += value;
4161 DrawText(DX_SCORE, DY_SCORE, int2str(local_player->score, 5),
4162 FS_SMALL, FC_YELLOW);
4165 void RaiseScoreElement(int element)
4170 case EL_EDELSTEIN_BD:
4171 case EL_EDELSTEIN_GELB:
4172 case EL_EDELSTEIN_ROT:
4173 case EL_EDELSTEIN_LILA:
4174 RaiseScore(level.score[SC_EDELSTEIN]);
4177 RaiseScore(level.score[SC_DIAMANT]);
4181 RaiseScore(level.score[SC_KAEFER]);
4185 RaiseScore(level.score[SC_FLIEGER]);
4189 RaiseScore(level.score[SC_MAMPFER]);
4192 RaiseScore(level.score[SC_ROBOT]);
4195 RaiseScore(level.score[SC_PACMAN]);
4198 RaiseScore(level.score[SC_KOKOSNUSS]);
4201 RaiseScore(level.score[SC_DYNAMIT]);
4204 RaiseScore(level.score[SC_SCHLUESSEL]);