rnd-20020914-1-src
[rocksndiamonds.git] / src / game.c
index f844675e4f6b562133f4a71efa1c4a13ca19fb77..a5620a017b0852734cf7f4998af10fabf0c098a9 100644 (file)
@@ -1,7 +1,7 @@
 /***********************************************************
 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
 *----------------------------------------------------------*
-* (c) 1995-2001 Artsoft Entertainment                      *
+* (c) 1995-2002 Artsoft Entertainment                      *
 *               Holger Schemel                             *
 *               Detmolder Strasse 189                      *
 *               33604 Bielefeld                            *
@@ -140,6 +140,7 @@ static struct
   { ".burning",                SND_ACTION_BURNING,     TRUE },
   { ".growing",                SND_ACTION_UNKNOWN,     TRUE },
   { ".attacking",      SND_ACTION_UNKNOWN,     TRUE },
+  { ".activated",      SND_ACTION_UNKNOWN,     TRUE },
 
   /* other (non-loop) sound actions are optional */
   { ".stepping",       SND_ACTION_MOVING,      FALSE }, /* discrete moving */
@@ -152,7 +153,7 @@ static struct
   { NULL,              0,                      0 },
 };
 static int element_action_sound[NUM_LEVEL_ELEMENTS][NUM_SND_ACTIONS];
-static boolean is_loop_sound[NUM_SOUND_EFFECTS];
+static boolean is_loop_sound[NUM_SOUND_FILES];
 
 #define IS_LOOP_SOUND(x)       (is_loop_sound[x])
 
@@ -506,7 +507,7 @@ void DrawGameDoorValues()
 
 void InitGameSound()
 {
-  int sound_effect_properties[NUM_SOUND_EFFECTS];
+  int sound_effect_properties[NUM_SOUND_FILES];
   int i, j;
 
 #if 0
@@ -517,22 +518,21 @@ void InitGameSound()
     for (j=0; j<NUM_LEVEL_ELEMENTS; j++)
       element_action_sound[j][i] = -1;
 
-  for (i=0; i<NUM_SOUND_EFFECTS; i++)
+  for (i=0; i<NUM_SOUND_FILES; i++)
   {
-    int len_effect_text = strlen(sound_effects[i].text);
+    int len_effect_text = strlen(sound_files[i].token);
 
     sound_effect_properties[i] = SND_ACTION_UNKNOWN;
     is_loop_sound[i] = FALSE;
 
     /* determine all loop sounds and identify certain sound classes */
 
-    j = 0;
-    while (sound_action_properties[j].text)
+    for (j=0; sound_action_properties[j].text; j++)
     {
       int len_action_text = strlen(sound_action_properties[j].text);
 
       if (len_action_text < len_effect_text &&
-         strcmp(&sound_effects[i].text[len_effect_text - len_action_text],
+         strcmp(&sound_files[i].token[len_effect_text - len_action_text],
                 sound_action_properties[j].text) == 0)
       {
        sound_effect_properties[i] = sound_action_properties[j].value;
@@ -540,8 +540,6 @@ void InitGameSound()
        if (sound_action_properties[j].is_loop)
          is_loop_sound[i] = TRUE;
       }
-
-      j++;
     }
 
     /* associate elements and some selected sound actions */
@@ -553,9 +551,9 @@ void InitGameSound()
        int len_class_text = strlen(element_info[j].sound_class_name);
 
        if (len_class_text + 1 < len_effect_text &&
-           strncmp(sound_effects[i].text,
+           strncmp(sound_files[i].token,
                    element_info[j].sound_class_name, len_class_text) == 0 &&
-           sound_effects[i].text[len_class_text] == '.')
+           sound_files[i].token[len_class_text] == '.')
        {
          int sound_action_value = sound_effect_properties[i];
 
@@ -599,34 +597,16 @@ void InitGameSound()
 
 static void InitGameEngine()
 {
-  boolean emulate_bd = TRUE;   /* unless non-BOULDERDASH elements found */
-  boolean emulate_sb = TRUE;   /* unless non-SOKOBAN     elements found */
-  boolean emulate_sp = TRUE;   /* unless non-SUPAPLEX    elements found */
-  int i, x, y;
-
-  for(y=0; y<lev_fieldy; y++)
-  {
-    for(x=0; x<lev_fieldx; x++)
-    {
-      if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
-       emulate_bd = FALSE;
-      if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
-       emulate_sb = FALSE;
-      if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
-       emulate_sp = FALSE;
-    }
-  }
+  int i;
 
   game.engine_version = (tape.playing ? tape.engine_version :
                         level.game_version);
-  game.emulation = (emulate_bd ? EMU_BOULDERDASH :
-                   emulate_sb ? EMU_SOKOBAN :
-                   emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
 
 #if 0
     printf("level %d: level version == %06d\n", level_nr, level.game_version);
-    printf("          tape version == %06d [%s]\n",
-          tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"));
+    printf("          tape version == %06d [%s] [file: %06d]\n",
+          tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
+          tape.file_version);
     printf("       => game.engine_version == %06d\n", game.engine_version);
 #endif
 
@@ -681,6 +661,9 @@ static void InitGameEngine()
 
 void InitGame()
 {
+  boolean emulate_bd = TRUE;   /* unless non-BOULDERDASH elements found */
+  boolean emulate_sb = TRUE;   /* unless non-SOKOBAN     elements found */
+  boolean emulate_sp = TRUE;   /* unless non-SUPAPLEX    elements found */
   int i, j, x, y;
 
   InitGameEngine();
@@ -817,8 +800,23 @@ void InitGame()
   }
 
   for(y=0; y<lev_fieldy; y++)
+  {
     for(x=0; x<lev_fieldx; x++)
+    {
+      if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
+       emulate_bd = FALSE;
+      if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
+       emulate_sb = FALSE;
+      if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
+       emulate_sp = FALSE;
+
       InitField(x, y, TRUE);
+    }
+  }
+
+  game.emulation = (emulate_bd ? EMU_BOULDERDASH :
+                   emulate_sb ? EMU_SOKOBAN :
+                   emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
 
   /* correct non-moving belts to start moving left */
   for (i=0; i<4; i++)
@@ -3138,7 +3136,11 @@ void StartMoving(int x, int y)
       else if (element == EL_BUTTERFLY || element == EL_FIREFLY)
        DrawGraphicAnimation(x, y, el2gfx(element), 2, 4, ANIM_NORMAL);
       else if (element == EL_SONDE)
+#if 0
        DrawGraphicAnimation(x, y, GFX_SONDE_START, 8, 2, ANIM_NORMAL);
+#else
+       DrawNewGraphicAnimation(x, y, IMG_SATELLITE_MOVING);
+#endif
       else if (element == EL_SP_ELECTRON)
        DrawGraphicAnimation(x, y, GFX2_SP_ELECTRON, 8, 2, ANIM_NORMAL);
 
@@ -3938,7 +3940,7 @@ void AusgangstuerOeffnen(int x, int y)
 
 void AusgangstuerBlinken(int x, int y)
 {
-  DrawGraphicAnimation(x, y, GFX_AUSGANG_AUF, 4, 4, ANIM_OSCILLATE);
+  DrawGraphicAnimation(x, y, GFX_AUSGANG_AUF, 4, 4, ANIM_PINGPONG);
 }
 
 void OpenSwitchgate(int x, int y)
@@ -4795,14 +4797,18 @@ void GameActions()
     else if (element == EL_SHIELD_PASSIVE)
     {
       DrawGraphicAnimation(x, y, GFX_SHIELD_PASSIVE, 6, 4, ANIM_NORMAL);
+#if 0
       if (!(FrameCounter % 4))
        PlaySoundLevel(x, y, SND_SHIELD_PASSIVE_ACTIVATED);
+#endif
     }
     else if (element == EL_SHIELD_ACTIVE)
     {
       DrawGraphicAnimation(x, y, GFX_SHIELD_ACTIVE, 6, 4, ANIM_NORMAL);
+#if 0
       if (!(FrameCounter % 4))
        PlaySoundLevel(x, y, SND_SHIELD_ACTIVE_ACTIVATED);
+#endif
     }
 
     if (game.magic_wall_active)
@@ -4966,6 +4972,19 @@ void GameActions()
       CloseAllOpenTimegates();
   }
 
+  for (i=0; i<MAX_PLAYERS; i++)
+  {
+    struct PlayerInfo *player = &stored_player[i];
+
+    if (SHIELD_ON(player))
+    {
+      if (player->shield_active_time_left)
+       PlaySoundLevel(player->jx, player->jy, SND_SHIELD_ACTIVE_ACTIVATED);
+      else if (player->shield_passive_time_left)
+       PlaySoundLevel(player->jx, player->jy, SND_SHIELD_PASSIVE_ACTIVATED);
+    }
+  }
+
   if (TimeFrames >= (1000 / GameFrameDelay))
   {
     TimeFrames = 0;
@@ -4973,12 +4992,14 @@ void GameActions()
 
     for (i=0; i<MAX_PLAYERS; i++)
     {
-      if (SHIELD_ON(&stored_player[i]))
+      struct PlayerInfo *player = &stored_player[i];
+
+      if (SHIELD_ON(player))
       {
-       stored_player[i].shield_passive_time_left--;
+       player->shield_passive_time_left--;
 
-       if (stored_player[i].shield_active_time_left > 0)
-         stored_player[i].shield_active_time_left--;
+       if (player->shield_active_time_left > 0)
+         player->shield_active_time_left--;
       }
     }
 
@@ -5199,7 +5220,7 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
     return FALSE;
 #else
   if (!FrameReached(&player->move_delay, player->move_delay_value) &&
-      !(tape.playing && tape.game_version < GAME_VERSION_2_0))
+      !(tape.playing && tape.file_version < FILE_VERSION_2_0))
     return FALSE;
 #endif
 
@@ -6063,7 +6084,7 @@ int DigField(struct PlayerInfo *player,
        return MF_NO_ACTION;
 #else
       if (!FrameReached(&player->push_delay, player->push_delay_value) &&
-         !(tape.playing && tape.game_version < GAME_VERSION_2_0) &&
+         !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
          element != EL_SPRING)
        return MF_NO_ACTION;
 #endif
@@ -6305,7 +6326,7 @@ int DigField(struct PlayerInfo *player,
        return MF_NO_ACTION;
 #else
       if (!FrameReached(&player->push_delay, player->push_delay_value) &&
-         !(tape.playing && tape.game_version < GAME_VERSION_2_0) &&
+         !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
          element != EL_BALLOON)
        return MF_NO_ACTION;
 #endif
@@ -6462,8 +6483,8 @@ boolean PlaceBomb(struct PlayerInfo *player)
 
 void PlaySoundLevel(int x, int y, int nr)
 {
-  static int loop_sound_frame[NUM_SOUND_EFFECTS];
-  static int loop_sound_volume[NUM_SOUND_EFFECTS];
+  static int loop_sound_frame[NUM_SOUND_FILES];
+  static int loop_sound_volume[NUM_SOUND_FILES];
   int sx = SCREENX(x), sy = SCREENY(y);
   int volume, stereo_position;
   int max_distance = 8;