rnd-19981029-1
[rocksndiamonds.git] / src / events.c
index a38a6ef0f96c40825db0d04fb710114ce5685c00..a967230e3bb0f3d39c6bb2bb3341c0918a8e0a58 100644 (file)
@@ -189,7 +189,7 @@ void HandleExposeEvent(XExposeEvent *event)
   int x = event->x, y = event->y;
   int width = event->width, height = event->height;
 
-  if (setup.direct_draw_on && game_status==PLAYING)
+  if (setup.direct_draw && game_status==PLAYING)
   {
     int xx,yy;
     int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY;
@@ -206,7 +206,7 @@ void HandleExposeEvent(XExposeEvent *event)
     SetDrawtoField(DRAW_DIRECT);
   }
 
-  if (setup.soft_scrolling_on && game_status == PLAYING)
+  if (setup.soft_scrolling && game_status == PLAYING)
   {
     int fx = FX, fy = FY;
 
@@ -372,6 +372,68 @@ void HandleButton(int mx, int my, int button)
 void HandleKey(KeySym key, int key_status)
 {
   int joy = 0;
+  static struct SetupKeyboardInfo custom_key;
+  static struct
+  {
+    KeySym *keysym_custom;
+    KeySym keysym_default;
+    byte action;
+  } key_info[] =
+  {
+    { &custom_key.left,  DEFAULT_KEY_LEFT,  JOY_LEFT     },
+    { &custom_key.right, DEFAULT_KEY_RIGHT, JOY_RIGHT    },
+    { &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 }
+  };
+
+  if (game_status == PLAYING)
+  {
+    int pnr;
+
+    for (pnr=0; pnr<MAX_PLAYERS; pnr++)
+    {
+      int i;
+      byte key_action = 0;
+
+      if (setup.input[pnr].use_joystick)
+       continue;
+
+      custom_key = setup.input[pnr].key;
+
+      for (i=0; i<6; i++)
+       if (key == *key_info[i].keysym_custom)
+         key_action |= key_info[i].action;
+
+      if (key_status == KEY_PRESSED)
+      {
+       if (network_playing)
+         local_player->potential_action |= key_action;
+       else
+         stored_player[pnr].action |= key_action;
+      }
+      else
+      {
+       if (network_playing)
+         local_player->potential_action &= ~key_action;
+       else
+         stored_player[pnr].action &= ~key_action;
+      }
+    }
+  }
+  else
+  {
+    int i;
+
+    for (i=0; i<6; i++)
+      if (key == key_info[i].keysym_default)
+       joy |= key_info[i].action;
+  }
+
+
+#if 0
+
 
   /* Map cursor keys to joystick directions */
 
@@ -507,6 +569,10 @@ void HandleKey(KeySym key, int key_status)
       break;
   }
 
+
+#endif
+
+
   if (joy)
   {
     if (key_status == KEY_PRESSED)
@@ -616,6 +682,8 @@ void HandleKey(KeySym key, int key_status)
                 GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay);
          break;
 
+
+#if 0
        case XK_a:
          if (ScrollStepSize == TILEX/8)
            ScrollStepSize = TILEX/4;
@@ -623,6 +691,7 @@ void HandleKey(KeySym key, int key_status)
            ScrollStepSize = TILEX/8;
          printf("ScrollStepSize == %d\n", ScrollStepSize);
          break;
+#endif
 
        case XK_f:
          ScrollStepSize = TILEX/8;
@@ -651,6 +720,10 @@ void HandleKey(KeySym key, int key_status)
          local_player->dynamite = 1000;
          break;
 
+
+
+#if 0
+
        case XK_x:
 
          {
@@ -721,7 +794,7 @@ void HandleKey(KeySym key, int key_status)
          }
          */
 
-         printf("direct_draw_on == %d\n", setup.direct_draw_on);
+         printf("direct_draw == %d\n", setup.direct_draw);
 
          break;
 
@@ -755,6 +828,7 @@ void HandleKey(KeySym key, int key_status)
          }
 
          break;
+#endif
 #endif
 
        default:
@@ -803,9 +877,34 @@ void HandleNoXEvent()
   }
 }
 
+static int HandleJoystickForAllPlayers()
+{
+  int i;
+  int result = 0;
+
+  for (i=0; i<MAX_PLAYERS; i++)
+  {
+    byte joy_action = 0;
+
+    if (!setup.input[i].use_joystick)
+      continue;
+
+    joy_action = Joystick(i);
+
+    result |= joy_action;
+
+    if (network_playing)
+      local_player->potential_action |= joy_action;
+    else
+      stored_player[i].action |= joy_action;
+  }
+
+  return result;
+}
+
 void HandleJoystick()
 {
-  int joystick = Joystick();
+  int joystick = HandleJoystickForAllPlayers();
   int keyboard = key_joystick_mapping;
   int joy      = (joystick | keyboard);
   int left     = joy & JOY_LEFT;
@@ -813,7 +912,7 @@ void HandleJoystick()
   int up       = joy & JOY_UP;
   int down     = joy & JOY_DOWN;
   int button   = joy & JOY_BUTTON;
-  int newbutton        = (JoystickButton() == JOY_BUTTON_NEW_PRESSED);
+  int newbutton        = (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED);
   int dx       = (left ? -1    : right ? 1     : 0);
   int dy       = (up   ? -1    : down  ? 1     : 0);
 
@@ -861,10 +960,7 @@ void HandleJoystick()
        return;
       }
 
-      if (tape.pausing || AllPlayersGone)
-       joy = 0;
-
-      HandleGameActions((byte)joy);
+      HandleGameActions();
       break;
 
     default: