rnd-20040103-1-src
[rocksndiamonds.git] / src / events.c
index 8cb7c51d81c9876ec600649928b1ebe13651c2c2..366acd1a4fa83215d053491484e12c7006501020 100644 (file)
@@ -377,7 +377,7 @@ void HandleButton(int mx, int my, int button)
   if (HandleGadgets(mx, my, button))
   {
     /* do not handle this button event anymore */
-    mx = my = 0;
+    mx = my = -32;     /* force mouse event to be outside screen tiles */
   }
 
   switch(game_status)
@@ -449,6 +449,100 @@ void HandleButton(int mx, int my, int button)
   }
 }
 
+static boolean is_string_suffix(char *string, char *suffix)
+{
+  int string_len = strlen(string);
+  int suffix_len = strlen(suffix);
+
+  if (suffix_len > string_len)
+    return FALSE;
+
+  return (strcmp(&string[string_len - suffix_len], suffix) == 0);
+}
+
+#define MAX_CHEAT_INPUT_LEN    32
+
+static void HandleKeysCheating(Key key)
+{
+  static char cheat_input[2 * MAX_CHEAT_INPUT_LEN + 1] = "";
+  char letter = getCharFromKey(key);
+  int cheat_input_len = strlen(cheat_input);
+  int i;
+
+  if (letter == 0)
+    return;
+
+  if (cheat_input_len >= 2 * MAX_CHEAT_INPUT_LEN)
+  {
+    for (i = 0; i < MAX_CHEAT_INPUT_LEN + 1; i++)
+      cheat_input[i] = cheat_input[MAX_CHEAT_INPUT_LEN + i];
+
+    cheat_input_len = MAX_CHEAT_INPUT_LEN;
+  }
+
+  cheat_input[cheat_input_len++] = letter;
+  cheat_input[cheat_input_len] = '\0';
+
+#if 0
+  printf("::: '%s' [%d]\n", cheat_input, cheat_input_len);
+#endif
+
+  if (game_status == GAME_MODE_MAIN)
+  {
+    if (is_string_suffix(cheat_input, ":insert-solution-tape") ||
+       is_string_suffix(cheat_input, ":ist"))
+    {
+      InsertSolutionTape();
+    }
+    else if (is_string_suffix(cheat_input, ":reload-graphics") ||
+            is_string_suffix(cheat_input, ":rg"))
+    {
+      ReloadCustomArtwork(1 << ARTWORK_TYPE_GRAPHICS);
+      DrawMainMenu();
+    }
+    else if (is_string_suffix(cheat_input, ":reload-sounds") ||
+            is_string_suffix(cheat_input, ":rs"))
+    {
+      ReloadCustomArtwork(1 << ARTWORK_TYPE_SOUNDS);
+      DrawMainMenu();
+    }
+    else if (is_string_suffix(cheat_input, ":reload-music") ||
+            is_string_suffix(cheat_input, ":rm"))
+    {
+      ReloadCustomArtwork(1 << ARTWORK_TYPE_MUSIC);
+      DrawMainMenu();
+    }
+    else if (is_string_suffix(cheat_input, ":reload-artwork") ||
+            is_string_suffix(cheat_input, ":ra"))
+    {
+      ReloadCustomArtwork(1 << ARTWORK_TYPE_GRAPHICS |
+                         1 << ARTWORK_TYPE_SOUNDS |
+                         1 << ARTWORK_TYPE_MUSIC);
+      DrawMainMenu();
+    }
+    else if (is_string_suffix(cheat_input, ":dump-level") ||
+            is_string_suffix(cheat_input, ":dl"))
+    {
+      DumpLevel(&level);
+    }
+    else if (is_string_suffix(cheat_input, ":dump-tape") ||
+            is_string_suffix(cheat_input, ":dt"))
+    {
+      DumpTape(&tape);
+    }
+  }
+  else if (game_status == GAME_MODE_PLAYING)
+  {
+#ifdef DEBUG
+    if (is_string_suffix(cheat_input, ".q"))
+      for (i = 0; i < MAX_INVENTORY_SIZE; i++)
+       if (local_player->inventory_size < MAX_INVENTORY_SIZE)
+         local_player->inventory_element[local_player->inventory_size++] =
+           EL_DYNAMITE;
+#endif
+  }
+}
+
 void HandleKey(Key key, int key_status)
 {
   int joy = 0;
@@ -466,14 +560,14 @@ void HandleKey(Key key, int key_status)
     { &custom_key.up,    DEFAULT_KEY_UP,    JOY_UP       },
     { &custom_key.down,  DEFAULT_KEY_DOWN,  JOY_DOWN     },
     { &custom_key.snap,  DEFAULT_KEY_SNAP,  JOY_BUTTON_1 },
-    { &custom_key.bomb,  DEFAULT_KEY_BOMB,  JOY_BUTTON_2 }
+    { &custom_key.drop,  DEFAULT_KEY_DROP,  JOY_BUTTON_2 }
   };
 
   if (game_status == GAME_MODE_PLAYING)
   {
     /* only needed for single-step tape recording mode */
     static boolean clear_button_2[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
-    static boolean bomb_placed[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
+    static boolean element_dropped[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
     int pnr;
 
     for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
@@ -511,13 +605,13 @@ void HandleKey(Key key, int key_status)
          if (key_action & KEY_MOTION)
          {
            if (stored_player[pnr].action & KEY_BUTTON_2)
-             bomb_placed[pnr] = TRUE;
+             element_dropped[pnr] = TRUE;
          }
        }
        else if (key_status == KEY_RELEASED &&
                 (key_action & KEY_BUTTON_2))
        {
-         if (!bomb_placed[pnr])
+         if (!element_dropped[pnr])
          {
            TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
 
@@ -525,7 +619,7 @@ void HandleKey(Key key, int key_status)
            clear_button_2[pnr] = TRUE;
          }
 
-         bomb_placed[pnr] = FALSE;
+         element_dropped[pnr] = FALSE;
        }
       }
       else if (tape.recording && tape.pausing && (key_action & KEY_ACTION))
@@ -557,16 +651,35 @@ void HandleKey(Key key, int key_status)
   if (key_status == KEY_RELEASED)
     return;
 
-  if ((key == KSYM_Return || key == setup.shortcut.toggle_pause) &&
-      game_status == GAME_MODE_PLAYING && AllPlayersGone)
+  if (game_status == GAME_MODE_PLAYING && AllPlayersGone &&
+      (key == KSYM_Return || key == setup.shortcut.toggle_pause))
   {
     CloseDoor(DOOR_CLOSE_1);
     game_status = GAME_MODE_MAIN;
     DrawMainMenu();
+
+    return;
+  }
+
+  if (game_status == GAME_MODE_MAIN && key == setup.shortcut.toggle_pause)
+  {
+    if (setup.autorecord)
+      TapeStartRecording();
+
+#if defined(PLATFORM_UNIX)
+    if (options.network)
+      SendToServer_StartPlaying();
+    else
+#endif
+    {
+      game_status = GAME_MODE_PLAYING;
+      StopAnimation();
+      InitGame();
+    }
+
     return;
   }
 
-  /* special key shortcuts */
   if (game_status == GAME_MODE_MAIN || game_status == GAME_MODE_PLAYING)
   {
     if (key == setup.shortcut.save_game)
@@ -575,6 +688,8 @@ void HandleKey(Key key, int key_status)
       TapeQuickLoad();
     else if (key == setup.shortcut.toggle_pause)
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
+
+    HandleKeysCheating(key);
   }
 
   if (HandleGadgetsKeyInput(key))
@@ -633,12 +748,6 @@ void HandleKey(Key key, int key_status)
            HandleInfoScreen(0,0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
          break;
 
-#ifdef DEBUG
-        case KSYM_t:
-         DumpTape(&tape);
-         break;
-#endif
-
        default:
          break;
       }
@@ -716,7 +825,7 @@ void HandleKey(Key key, int key_status)
          }
          break;
 
-       case KSYM_s:
+       case KSYM_S:
          if (!global.fps_slowdown)
          {
            global.fps_slowdown = TRUE;
@@ -782,20 +891,6 @@ void HandleKey(Key key, int key_status)
          printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize);
          break;
 
-       case KSYM_Q:
-       case KSYM_q:
-         {
-           int i;
-
-           for (i = 0; i < MAX_INVENTORY_SIZE; i++)
-             if (local_player->inventory_size < MAX_INVENTORY_SIZE)
-               local_player->inventory_element[local_player->inventory_size++] =
-                 EL_DYNAMITE;
-         }
-
-         break;
-
-
 #if 0
 
        case KSYM_z:
@@ -822,6 +917,7 @@ void HandleKey(Key key, int key_status)
       }
       break;
     }
+
     default:
       if (key == KSYM_Escape)
       {