removed duplicate code
[rocksndiamonds.git] / src / game.c
index c6a7ef73146a7cf1bd90b59121cbf0856b802189..ecd5f2649d337721f118c9009c18b731d6fbae0a 100644 (file)
@@ -2325,6 +2325,43 @@ static void UpdateGameControlValues(void)
       stored_player[player_nr].num_white_keys;
   }
 
+  // try to display as many collected keys as possible in the default game panel
+  for (i = STD_NUM_KEYS; i < MAX_NUM_KEYS + 1; i++)    // EMC keys + white key
+  {
+    int nr = GAME_PANEL_KEY_1 + i;
+    int emc_key = get_key_element_from_nr(i);
+    int element = (i < MAX_NUM_KEYS ? emc_key : EL_DC_KEY_WHITE);
+    struct GamePanelControlInfo *gpc = &game_panel_controls[nr];
+    struct TextPosInfo *pos = gpc->pos;
+
+    // check if panel position is undefined for a certain EMC key or white key
+    if (gpc->value != EL_EMPTY && pos->x == -1 && pos->y == -1)
+    {
+      int nr_new = GAME_PANEL_KEY_1 + i % STD_NUM_KEYS;
+
+      // 1st try: display key at the same position as normal or EM keys
+      if (game_panel_controls[nr_new].value == EL_EMPTY)
+      {
+       game_panel_controls[nr_new].value = element;
+      }
+      else
+      {
+       // 2nd try: display key at the next free position in the key panel
+       for (k = 0; k < STD_NUM_KEYS; k++)
+       {
+         nr_new = GAME_PANEL_KEY_1 + k;
+
+         if (game_panel_controls[nr_new].value == EL_EMPTY)
+         {
+           game_panel_controls[nr_new].value = element;
+
+           break;
+         }
+       }
+      }
+    }
+  }
+
   for (i = 0; i < NUM_PANEL_INVENTORY; i++)
   {
     game_panel_controls[GAME_PANEL_INVENTORY_FIRST_1 + i].value =
@@ -2499,8 +2536,7 @@ static void UpdateGameControlValues(void)
        if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
          gpc->gfx_frame = element_info[element].collect_score;
 
-       gpc->frame = getGraphicAnimationFrame(el2panelimg(gpc->value),
-                                             gpc->gfx_frame);
+       gpc->frame = getGraphicAnimationFrame(graphic, gpc->gfx_frame);
 
        if (ANIM_MODE(graphic) == ANIM_RANDOM)
          gfx.anim_random_frame = last_anim_random_frame;
@@ -2589,6 +2625,10 @@ static void DisplayGameControlValues(void)
     if (PANEL_DEACTIVATED(pos))
       continue;
 
+    if (pos->class == get_hash_from_key("extra_panel_items") &&
+       !setup.prefer_extra_panel_items)
+      continue;
+
     gpc->last_value = value;
     gpc->last_frame = frame;
 
@@ -15252,6 +15292,9 @@ void RequestRestartGame(char *message)
   }
   else
   {
+    // needed in case of envelope request to close game panel
+    CloseDoor(DOOR_CLOSE_1);
+
     SetGameStatus(GAME_MODE_MAIN);
 
     DrawMainMenu();