rnd-20010120-5-src
[rocksndiamonds.git] / src / game.c
index fd89096ab4dd6259aa320061a3f290e44bca3533..a3dd01dfb41705ef8c2d743d0cb433a26c57c6f5 100644 (file)
@@ -1,14 +1,14 @@
 /***********************************************************
-*  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
+* Rocks'n'Diamonds -- McDuffin Strikes Back!               *
 *----------------------------------------------------------*
-*  (c) 1995-98 Artsoft Entertainment                       *
-*              Holger Schemel                              *
-*              Oststrasse 11a                              *
-*              33604 Bielefeld                             *
-*              phone: ++49 +521 290471                     *
-*              email: aeglos@valinor.owl.de                *
+* (c) 1995-2001 Artsoft Entertainment                      *
+*               Holger Schemel                             *
+*               Detmolder Strasse 189                      *
+*               33604 Bielefeld                            *
+*               Germany                                    *
+*               e-mail: info@artsoft.org                   *
 *----------------------------------------------------------*
-*  game.c                                                  *
+* game.c                                                   *
 ***********************************************************/
 
 #include "libgame/libgame.h"
@@ -671,10 +671,33 @@ void InitGame()
     }
   }
 
+  game.version = (tape.playing ? tape.game_version : level.game_version);
   game.emulation = (emulate_bd ? EMU_BOULDERDASH :
                    emulate_sb ? EMU_SOKOBAN :
                    emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
 
+  /* dynamically adjust element properties according to game engine version */
+  {
+    static int ep_slippery[] =
+    {
+      EL_BETON,
+      EL_MAUERWERK,
+      EL_MAUER_LEBT,
+      EL_MAUER_X,
+      EL_MAUER_Y,
+      EL_MAUER_XY
+    };
+    static int ep_slippery_num = sizeof(ep_slippery)/sizeof(int);
+
+    for (i=0; i<ep_slippery_num; i++)
+    {
+      if (game.version >= GAME_VERSION_2_0)
+       Elementeigenschaften1[ep_slippery[i]] |= EP_BIT_SLIPPERY;
+      else
+       Elementeigenschaften1[ep_slippery[i]] &= ~EP_BIT_SLIPPERY;
+    }
+  }
+
   if (BorderElement == EL_LEERRAUM)
   {
     SBX_Left = 0;
@@ -761,8 +784,8 @@ void InitGame()
 
   OpenDoor(DOOR_OPEN_ALL);
 
-  if (setup.sound_music)
-    PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
+  if (setup.sound_music && num_bg_loops)
+    PlayMusic(level_nr % num_bg_loops);
 
   KeyboardAutoRepeatOff();
 
@@ -960,7 +983,9 @@ void GameWon()
       StopSound(SND_SIRR);
   }
 
+#if 0
   FadeSounds();
+#endif
 
   /* Hero disappears */
   DrawLevelField(ExitX, ExitY);
@@ -981,11 +1006,13 @@ void GameWon()
   {
     leveldir_current->handicap_level++;
     SaveLevelSetup_SeriesInfo();
-
-    if (level_nr < leveldir_current->last_level)
-      raise_level = TRUE;
   }
 
+  if (level_editor_test_game)
+    local_player->score = -1;  /* no highscore when playing from editor */
+  else if (level_nr < leveldir_current->last_level)
+    raise_level = TRUE;                /* advance to next level */
+
   if ((hi_pos = NewHiScore()) >= 0) 
   {
     game_status = HALLOFFAME;
@@ -1170,17 +1197,16 @@ void RemoveMovingField(int x, int y)
   }
 
   if (Feld[x][y] == EL_BLOCKED &&
-      (Store[oldx][oldy] == EL_MORAST_LEER ||
-       Store[oldx][oldy] == EL_MAGIC_WALL_EMPTY ||
-       Store[oldx][oldy] == EL_MAGIC_WALL_BD_EMPTY ||
-       Store[oldx][oldy] == EL_AMOEBE_NASS))
-  {
-    Feld[oldx][oldy] = Store[oldx][oldy];
-    Store[oldx][oldy] = Store2[oldx][oldy] = 0;
-  }
+      (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
+       Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
+       Feld[oldx][oldy] == EL_MAGIC_WALL_BD_EMPTYING ||
+       Feld[oldx][oldy] == EL_AMOEBA_DRIPPING))
+    Feld[oldx][oldy] = get_next_element(Feld[oldx][oldy]);
   else
     Feld[oldx][oldy] = EL_LEERRAUM;
 
+  Store[oldx][oldy] = Store2[oldx][oldy] = 0;
+
   Feld[newx][newy] = EL_LEERRAUM;
   MovPos[oldx][oldy] = MovDir[oldx][oldy] = MovDelay[oldx][oldy] = 0;
   MovPos[newx][newy] = MovDir[newx][newy] = MovDelay[newx][newy] = 0;
@@ -2428,8 +2454,8 @@ void StartMoving(int x, int y)
       if (IS_FREE(x, y+1))
       {
        InitMovingField(x, y, MV_DOWN);
-       Feld[x][y] = EL_FELSBROCKEN;
-       Store[x][y] = EL_MORAST_LEER;
+       Feld[x][y] = EL_QUICKSAND_EMPTYING;
+       Store[x][y] = EL_FELSBROCKEN;
       }
       else if (Feld[x][y+1] == EL_MORAST_LEER)
       {
@@ -2445,21 +2471,24 @@ void StartMoving(int x, int y)
 
        Feld[x][y] = EL_MORAST_LEER;
        Feld[x][y+1] = EL_MORAST_VOLL;
+       Store[x][y+1] = Store[x][y];
+       Store[x][y] = 0;
       }
     }
     else if ((element == EL_FELSBROCKEN || element == EL_BD_ROCK) &&
             Feld[x][y+1] == EL_MORAST_LEER)
     {
       InitMovingField(x, y, MV_DOWN);
-      Store[x][y] = EL_MORAST_VOLL;
+      Feld[x][y] = EL_QUICKSAND_FILLING;
+      Store[x][y] = element;
     }
     else if (element == EL_MAGIC_WALL_FULL)
     {
       if (IS_FREE(x, y+1))
       {
        InitMovingField(x, y, MV_DOWN);
-       Feld[x][y] = EL_CHANGED(Store2[x][y]);
-       Store[x][y] = EL_MAGIC_WALL_EMPTY;
+       Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
+       Store[x][y] = EL_CHANGED(Store[x][y]);
       }
       else if (Feld[x][y+1] == EL_MAGIC_WALL_EMPTY)
       {
@@ -2475,8 +2504,8 @@ void StartMoving(int x, int y)
 
        Feld[x][y] = EL_MAGIC_WALL_EMPTY;
        Feld[x][y+1] = EL_MAGIC_WALL_FULL;
-       Store2[x][y+1] = EL_CHANGED(Store2[x][y]);
-       Store2[x][y] = 0;
+       Store[x][y+1] = EL_CHANGED(Store[x][y]);
+       Store[x][y] = 0;
       }
     }
     else if (element == EL_MAGIC_WALL_BD_FULL)
@@ -2484,8 +2513,8 @@ void StartMoving(int x, int y)
       if (IS_FREE(x, y+1))
       {
        InitMovingField(x, y, MV_DOWN);
-       Feld[x][y] = EL_CHANGED2(Store2[x][y]);
-       Store[x][y] = EL_MAGIC_WALL_BD_EMPTY;
+       Feld[x][y] = EL_MAGIC_WALL_BD_EMPTYING;
+       Store[x][y] = EL_CHANGED2(Store[x][y]);
       }
       else if (Feld[x][y+1] == EL_MAGIC_WALL_BD_EMPTY)
       {
@@ -2501,8 +2530,8 @@ void StartMoving(int x, int y)
 
        Feld[x][y] = EL_MAGIC_WALL_BD_EMPTY;
        Feld[x][y+1] = EL_MAGIC_WALL_BD_FULL;
-       Store2[x][y+1] = EL_CHANGED2(Store2[x][y]);
-       Store2[x][y] = 0;
+       Store[x][y+1] = EL_CHANGED2(Store[x][y]);
+       Store[x][y] = 0;
       }
     }
     else if (CAN_CHANGE(element) &&
@@ -2510,10 +2539,10 @@ void StartMoving(int x, int y)
              Feld[x][y+1] == EL_MAGIC_WALL_BD_EMPTY))
     {
       InitMovingField(x, y, MV_DOWN);
-      Store[x][y] =
-       (Feld[x][y+1] == EL_MAGIC_WALL_EMPTY ? EL_MAGIC_WALL_FULL :
-        EL_MAGIC_WALL_BD_FULL);
-      Store2[x][y+1] = element;
+      Feld[x][y] =
+       (Feld[x][y+1] == EL_MAGIC_WALL_EMPTY ? EL_MAGIC_WALL_FILLING :
+        EL_MAGIC_WALL_BD_FILLING);
+      Store[x][y] = element;
     }
     else if (CAN_SMASH(element) && Feld[x][y+1] == EL_SALZSAEURE)
     {
@@ -2535,12 +2564,21 @@ void StartMoving(int x, int y)
       Feld[x][y] = EL_AMOEBING;
       Store[x][y] = EL_AMOEBE_NASS;
     }
+    /* Store[x][y+1] must be zero, because:
+       (EL_MORAST_VOLL -> EL_FELSBROCKEN): Store[x][y+1] == EL_MORAST_LEER
+    */
+#if 0
 #if OLD_GAME_BEHAVIOUR
     else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1])
 #else
     else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1] &&
             !IS_FALLING(x, y+1) && !JustStopped[x][y+1] &&
             element != EL_DX_SUPABOMB)
+#endif
+#else
+    else if (IS_SLIPPERY(Feld[x][y+1]) &&
+            !IS_FALLING(x, y+1) && !JustStopped[x][y+1] &&
+            element != EL_DX_SUPABOMB)
 #endif
     {
       boolean left  = (x>0 && IS_FREE(x-1, y) &&
@@ -2897,10 +2935,16 @@ void ContinueMoving(int x, int y)
   int newx = x + dx, newy = y + dy;
   int step = (horiz_move ? dx : dy) * TILEX / 8;
 
-  if (element == EL_TROPFEN)
+  if (element == EL_TROPFEN || element == EL_AMOEBA_DRIPPING)
     step /= 2;
-  else if (Store[x][y] == EL_MORAST_VOLL || Store[x][y] == EL_MORAST_LEER)
+  else if (element == EL_QUICKSAND_FILLING ||
+          element == EL_QUICKSAND_EMPTYING)
     step /= 4;
+  else if (element == EL_MAGIC_WALL_FILLING ||
+          element == EL_MAGIC_WALL_BD_FILLING ||
+          element == EL_MAGIC_WALL_EMPTYING ||
+          element == EL_MAGIC_WALL_BD_EMPTYING)
+    step /= 2;
   else if (CAN_FALL(element) && horiz_move &&
           y < lev_fieldy-1 && IS_BELT(Feld[x][y+1]))
     step /= 2;
@@ -2945,54 +2989,55 @@ void ContinueMoving(int x, int y)
       }
     }
 
-    if (Store[x][y] == EL_MORAST_VOLL)
+    if (element == EL_QUICKSAND_FILLING)
     {
-      Store[x][y] = 0;
-      Feld[newx][newy] = EL_MORAST_VOLL;
-      element = EL_MORAST_VOLL;
+      element = Feld[newx][newy] = get_next_element(element);
+      Store[newx][newy] = Store[x][y];
     }
-    else if (Store[x][y] == EL_MORAST_LEER)
+    else if (element == EL_QUICKSAND_EMPTYING)
     {
-      Store[x][y] = 0;
-      Feld[x][y] = EL_MORAST_LEER;
+      Feld[x][y] = get_next_element(element);
+      element = Feld[newx][newy] = Store[x][y];
     }
-    else if (Store[x][y] == EL_MAGIC_WALL_FULL)
+    else if (element == EL_MAGIC_WALL_FILLING)
     {
-      Store[x][y] = 0;
-      element = Feld[newx][newy] =
-       (game.magic_wall_active ? EL_MAGIC_WALL_FULL : EL_MAGIC_WALL_DEAD);
+      element = Feld[newx][newy] = get_next_element(element);
+      if (!game.magic_wall_active)
+       element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
+      Store[newx][newy] = Store[x][y];
     }
-    else if (Store[x][y] == EL_MAGIC_WALL_EMPTY)
+    else if (element == EL_MAGIC_WALL_EMPTYING)
     {
-      Store[x][y] = Store2[x][y] = 0;
-      Feld[x][y] = (game.magic_wall_active ? EL_MAGIC_WALL_EMPTY :
-                   EL_MAGIC_WALL_DEAD);
+      Feld[x][y] = get_next_element(element);
+      if (!game.magic_wall_active)
+       Feld[x][y] = EL_MAGIC_WALL_DEAD;
+      element = Feld[newx][newy] = Store[x][y];
     }
-    else if (Store[x][y] == EL_MAGIC_WALL_BD_FULL)
+    else if (element == EL_MAGIC_WALL_BD_FILLING)
     {
-      Store[x][y] = 0;
-      element = Feld[newx][newy] =
-       (game.magic_wall_active ? EL_MAGIC_WALL_BD_FULL :
-        EL_MAGIC_WALL_BD_DEAD);
+      element = Feld[newx][newy] = get_next_element(element);
+      if (!game.magic_wall_active)
+       element = Feld[newx][newy] = EL_MAGIC_WALL_BD_DEAD;
+      Store[newx][newy] = Store[x][y];
     }
-    else if (Store[x][y] == EL_MAGIC_WALL_BD_EMPTY)
+    else if (element == EL_MAGIC_WALL_BD_EMPTYING)
     {
-      Store[x][y] = Store2[x][y] = 0;
-      Feld[x][y] = (game.magic_wall_active ? EL_MAGIC_WALL_BD_EMPTY :
-                   EL_MAGIC_WALL_BD_DEAD);
+      Feld[x][y] = get_next_element(element);
+      if (!game.magic_wall_active)
+       Feld[x][y] = EL_MAGIC_WALL_BD_DEAD;
+      element = Feld[newx][newy] = Store[x][y];
     }
-    else if (Store[x][y] == EL_SALZSAEURE)
+    else if (element == EL_AMOEBA_DRIPPING)
     {
-      Store[x][y] = 0;
-      Feld[newx][newy] = EL_SALZSAEURE;
-      element = EL_SALZSAEURE;
+      Feld[x][y] = get_next_element(element);
+      element = Feld[newx][newy] = Store[x][y];
     }
-    else if (Store[x][y] == EL_AMOEBE_NASS)
+    else if (Store[x][y] == EL_SALZSAEURE)
     {
-      Store[x][y] = 0;
-      Feld[x][y] = EL_AMOEBE_NASS;
+      element = Feld[newx][newy] = EL_SALZSAEURE;
     }
 
+    Store[x][y] = 0;
     MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
     MovDelay[newx][newy] = 0;
 
@@ -3390,8 +3435,8 @@ void AmoebeAbleger(int ax, int ay)
   else
   {
     InitMovingField(ax, ay, MV_DOWN);
-    Feld[ax][ay] = EL_TROPFEN;
-    Store[ax][ay] = EL_AMOEBE_NASS;
+    Feld[ax][ay] = EL_AMOEBA_DRIPPING;
+    Store[ax][ay] = EL_TROPFEN;
     ContinueMoving(ax, ay);
     return;
   }
@@ -4440,15 +4485,16 @@ void GameActions()
       boolean sieb = FALSE;
       int jx = local_player->jx, jy = local_player->jy;
 
-      if (element == EL_MAGIC_WALL_EMPTY || element == EL_MAGIC_WALL_FULL ||
-         Store[x][y] == EL_MAGIC_WALL_EMPTY)
+      if (element == EL_MAGIC_WALL_FULL ||
+         element == EL_MAGIC_WALL_EMPTY ||
+         element == EL_MAGIC_WALL_EMPTYING)
       {
        SiebAktivieren(x, y, 1);
        sieb = TRUE;
       }
-      else if (element == EL_MAGIC_WALL_BD_EMPTY ||
-              element == EL_MAGIC_WALL_BD_FULL ||
-              Store[x][y] == EL_MAGIC_WALL_BD_EMPTY)
+      else if (element == EL_MAGIC_WALL_BD_FULL ||
+              element == EL_MAGIC_WALL_BD_EMPTY ||
+              element == EL_MAGIC_WALL_BD_EMPTYING)
       {
        SiebAktivieren(x, y, 2);
        sieb = TRUE;
@@ -4477,7 +4523,8 @@ void GameActions()
        {
          element = Feld[x][y];
 
-         if (element == EL_MAGIC_WALL_EMPTY || element == EL_MAGIC_WALL_FULL)
+         if (element == EL_MAGIC_WALL_EMPTY ||
+             element == EL_MAGIC_WALL_FULL)
          {
            Feld[x][y] = EL_MAGIC_WALL_DEAD;
            DrawLevelField(x, y);
@@ -6082,7 +6129,7 @@ void CreateGameButtons()
 
   for (i=0; i<NUM_GAME_BUTTONS; i++)
   {
-    Bitmap gd_bitmap = pix[PIX_DOOR];
+    Bitmap *gd_bitmap = pix[PIX_DOOR];
     struct GadgetInfo *gi;
     int button_type;
     boolean checked;
@@ -6227,12 +6274,13 @@ static void HandleGameButtons(struct GadgetInfo *gi)
       if (setup.sound_music)
       { 
        setup.sound_music = FALSE;
-       FadeSound(background_loop[level_nr % num_bg_loops]);
+       FadeMusic();
       }
       else if (audio.loops_available)
       { 
        setup.sound = setup.sound_music = TRUE;
-       PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
+       if (num_bg_loops)
+         PlayMusic(level_nr % num_bg_loops);
       }
       break;