rnd-20031215-1-src
[rocksndiamonds.git] / src / game.c
index 855e331ab1f5d54b359e3d10b9869dd70048397d..de6aa0c5ce229725a407d0ef4101ef4178ef9515 100644 (file)
@@ -1075,6 +1075,8 @@ void InitGame()
     player->anim_delay_counter = 0;
     player->post_delay_counter = 0;
 
+    player->action_waiting = ACTION_DEFAULT;
+    player->last_action_waiting = ACTION_DEFAULT;
     player->special_action_bored = ACTION_DEFAULT;
     player->special_action_sleeping = ACTION_DEFAULT;
 
@@ -4437,8 +4439,13 @@ void StartMoving(int x, int y)
     {
       if (Feld[newx][newy] == EL_EXIT_OPEN)
       {
+#if 1
+       RemoveField(x, y);
+       DrawLevelField(x, y);
+#else
        Feld[x][y] = EL_EMPTY;
        DrawLevelField(x, y);
+#endif
 
        PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
        if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
@@ -4878,6 +4885,7 @@ void ContinueMoving(int x, int y)
     CheckElementSideChange(newx, newy, Feld[newx][newy],
                           direction, CE_COLLISION_ACTIVE, -1);
 
+#if 0
     if (IN_LEV_FIELD(nextx, nexty))
     {
       static int opposite_directions[] =
@@ -4945,6 +4953,7 @@ void ContinueMoving(int x, int y)
        }
       }
     }
+#endif
   }
 
   TestIfPlayerTouchesCustomElement(newx, newy);
@@ -6172,17 +6181,49 @@ static boolean CheckElementChange(int x, int y, int element, int trigger_event)
   return CheckElementSideChange(x, y, element, CH_SIDE_ANY, trigger_event, -1);
 }
 
-static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
+static void PlayPlayerSound(struct PlayerInfo *player)
 {
   int jx = player->jx, jy = player->jy;
   int element = player->element_nr;
-  boolean was_waiting = player->is_waiting;
+  int last_action = player->last_action_waiting;
+  int action = player->action_waiting;
 
-  if (is_waiting)
+  if (player->is_waiting)
+  {
+    if (action != last_action)
+      PlayLevelSoundElementAction(jx, jy, element, action);
+    else
+      PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
+  }
+  else
   {
-    int action;
+    if (action != last_action)
+      StopSound(element_info[element].sound[last_action]);
+
+    if (last_action == ACTION_SLEEPING)
+      PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
+  }
+}
+
+static void PlayAllPlayersSound()
+{
+  int i;
+
+  for (i = 0; i < MAX_PLAYERS; i++)
+    if (stored_player[i].active)
+      PlayPlayerSound(&stored_player[i]);
+}
+
+static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
+{
+  boolean last_waiting = player->is_waiting;
+  int move_dir = player->MovDir;
+
+  player->last_action_waiting = player->action_waiting;
 
-    if (!was_waiting)          /* not waiting -> waiting */
+  if (is_waiting)
+  {
+    if (!last_waiting)         /* not waiting -> waiting */
     {
       player->is_waiting = TRUE;
 
@@ -6198,30 +6239,93 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
       InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
     }
 
-    if (game.player_sleeping_delay_fixed != -1 &&
-       game.player_sleeping_delay_random != -1 &&
+    if (game.player_sleeping_delay_fixed +
+       game.player_sleeping_delay_random > 0 &&
        player->anim_delay_counter == 0 &&
        player->post_delay_counter == 0 &&
        FrameCounter >= player->frame_counter_sleeping)
       player->is_sleeping = TRUE;
-    else if (game.player_boring_delay_fixed != -1 &&
-            game.player_boring_delay_random != -1 &&
+    else if (game.player_boring_delay_fixed +
+            game.player_boring_delay_random > 0 &&
             FrameCounter >= player->frame_counter_bored)
       player->is_bored = TRUE;
 
-    action = (player->is_sleeping ? ACTION_SLEEPING :
-             player->is_bored ? ACTION_BORING : ACTION_WAITING);
+    player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
+                             player->is_bored ? ACTION_BORING :
+                             ACTION_WAITING);
 
-    if (!was_waiting)
-      PlayLevelSoundElementAction(jx, jy, element, action);
-    else
-      PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
-  }
-  else if (was_waiting)                /* waiting -> not waiting */
-  {
     if (player->is_sleeping)
-      PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
+    {
+      if (player->num_special_action_sleeping > 0)
+      {
+       if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
+       {
+         int last_special_action = player->special_action_sleeping;
+         int num_special_action = player->num_special_action_sleeping;
+         int special_action =
+           (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
+            last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
+            last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
+            last_special_action + 1 : ACTION_SLEEPING);
+         int special_graphic =
+           el_act_dir2img(player->element_nr, special_action, move_dir);
+
+         player->anim_delay_counter =
+           graphic_info[special_graphic].anim_delay_fixed +
+           SimpleRND(graphic_info[special_graphic].anim_delay_random);
+         player->post_delay_counter =
+           graphic_info[special_graphic].post_delay_fixed +
+           SimpleRND(graphic_info[special_graphic].post_delay_random);
+
+         player->special_action_sleeping = special_action;
+       }
+
+       if (player->anim_delay_counter > 0)
+       {
+         player->action_waiting = player->special_action_sleeping;
+         player->anim_delay_counter--;
+       }
+       else if (player->post_delay_counter > 0)
+       {
+         player->post_delay_counter--;
+       }
+      }
+    }
+    else if (player->is_bored)
+    {
+      if (player->num_special_action_bored > 0)
+      {
+       if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
+       {
+         int special_action =
+           ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
+         int special_graphic =
+           el_act_dir2img(player->element_nr, special_action, move_dir);
+
+         player->anim_delay_counter =
+           graphic_info[special_graphic].anim_delay_fixed +
+           SimpleRND(graphic_info[special_graphic].anim_delay_random);
+         player->post_delay_counter =
+           graphic_info[special_graphic].post_delay_fixed +
+           SimpleRND(graphic_info[special_graphic].post_delay_random);
+
+         player->special_action_bored = special_action;
+       }
 
+       if (player->anim_delay_counter > 0)
+       {
+         player->action_waiting = player->special_action_bored;
+         player->anim_delay_counter--;
+       }
+       else if (player->post_delay_counter > 0)
+       {
+         player->post_delay_counter--;
+       }
+      }
+    }
+  }
+  else if (last_waiting)       /* waiting -> not waiting */
+  {
     player->is_waiting = FALSE;
     player->is_bored = FALSE;
     player->is_sleeping = FALSE;
@@ -6232,6 +6336,8 @@ static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
     player->anim_delay_counter = 0;
     player->post_delay_counter = 0;
 
+    player->action_waiting = ACTION_DEFAULT;
+
     player->special_action_bored = ACTION_DEFAULT;
     player->special_action_sleeping = ACTION_DEFAULT;
   }
@@ -6658,6 +6764,7 @@ void GameActions()
       StartMoving(x, y);
 
 #if 1
+      element = Feld[x][y];
       graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
 #if 0
       if (element == EL_MOLE)
@@ -6942,6 +7049,7 @@ void GameActions()
   }
 
   DrawAllPlayers();
+  PlayAllPlayersSound();
 
   if (options.debug)                   /* calculate frames per second */
   {
@@ -8816,13 +8924,10 @@ void InitPlayLevelSound()
 {
   int num_sounds = getSoundListSize();
 
-  if (loop_sound_frame != NULL)
-    free(loop_sound_frame);
-
-  if (loop_sound_volume != NULL)
-    free(loop_sound_volume);
+  checked_free(loop_sound_frame);
+  checked_free(loop_sound_volume);
 
-  loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
+  loop_sound_frame  = checked_calloc(num_sounds * sizeof(int));
   loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
 }
 
@@ -8915,7 +9020,7 @@ static void StopLevelSoundActionIfLoop(int x, int y, int action)
   int sound_effect = element_info[Feld[x][y]].sound[action];
 
   if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
-    StopSoundExt(sound_effect, SND_CTRL_STOP_SOUND);
+    StopSound(sound_effect);
 }
 
 static void PlayLevelMusic()