+static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
+{
+ int jx = player->jx, jy = player->jy;
+ int element = player->element_nr;
+ boolean was_waiting = player->is_waiting;
+
+ if (is_waiting)
+ {
+ int action;
+
+ if (!was_waiting) /* not waiting -> waiting */
+ {
+ player->is_waiting = TRUE;
+
+ player->frame_counter_bored =
+ FrameCounter +
+ game.player_boring_delay_fixed +
+ SimpleRND(game.player_boring_delay_random);
+ player->frame_counter_sleeping =
+ FrameCounter +
+ game.player_sleeping_delay_fixed +
+ SimpleRND(game.player_sleeping_delay_random);
+
+ InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
+ }
+
+ if (game.player_sleeping_delay_fixed != -1 &&
+ game.player_sleeping_delay_random != -1 &&
+ 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 &&
+ FrameCounter >= player->frame_counter_bored)
+ player->is_bored = TRUE;
+
+ action = (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);
+
+ player->is_waiting = FALSE;
+ player->is_bored = FALSE;
+ player->is_sleeping = FALSE;
+
+ player->frame_counter_bored = -1;
+ player->frame_counter_sleeping = -1;
+
+ player->anim_delay_counter = 0;
+ player->post_delay_counter = 0;
+
+ player->special_action_bored = ACTION_DEFAULT;
+ player->special_action_sleeping = ACTION_DEFAULT;
+ }
+}
+