rnd-19981024-1
authorHolger Schemel <info@artsoft.org>
Fri, 23 Oct 1998 23:36:24 +0000 (01:36 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:31:21 +0000 (10:31 +0200)
src/events.c
src/game.c
src/game.h
src/init.c
src/joystick.c
src/main.c
src/main.h
src/network.c
src/screens.c
src/screens.h

index a38a6ef0f96c40825db0d04fb710114ce5685c00..dc398df7fe5870ab51767fb52292154ff615a649 100644 (file)
@@ -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->action |= key_action;
+       else
+         stored_player[pnr].action |= key_action;
+      }
+      else
+      {
+       if (network_playing)
+         local_player->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;
@@ -706,6 +775,8 @@ void HandleKey(KeySym key, int key_status)
 
          break;
 
+
+#if 0
        case XK_y:
          /*
          {
@@ -724,6 +795,8 @@ void HandleKey(KeySym key, int key_status)
          printf("direct_draw_on == %d\n", setup.direct_draw_on);
 
          break;
+#endif
+
 
        case XK_z:
          {
@@ -861,10 +934,17 @@ void HandleJoystick()
        return;
       }
 
+      /*
       if (tape.pausing || AllPlayersGone)
-       joy = 0;
+      {
+       int i;
+
+       for (i=0; i<MAX_PLAYERS; i++)
+         stored_player[i].action = 0;
+      }
+      */
 
-      HandleGameActions((byte)joy);
+      HandleGameActions();
       break;
 
     default:
index 23fcc2d4f6819093b0a003964f7ec4fe4a517e7e..4693132bb6cce29def0d0bf882895ae82c1aa4cf 100644 (file)
@@ -25,7 +25,7 @@
 
 void GetPlayerConfig()
 {
-  int old_joystick_nr = setup.joy_input[0].joystick_nr;
+  int old_joystick_nr = setup.input[0].joystick_nr;
 
   if (sound_status==SOUND_OFF)
     local_player->setup &= ~SETUP_SOUND;
@@ -47,14 +47,14 @@ void GetPlayerConfig()
   setup.joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
 #endif
 
-  setup.joy_input[0].joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
+  setup.input[0].joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
 
   setup.quick_doors = SETUP_QUICK_DOORS_ON(local_player->setup);
   setup.scroll_delay_on = SETUP_SCROLL_DELAY_ON(local_player->setup);
   setup.soft_scrolling_on = SETUP_SOFT_SCROLL_ON(local_player->setup);
 
 #ifndef MSDOS
-  if (setup.joy_input[0].joystick_nr != old_joystick_nr)
+  if (setup.input[0].joystick_nr != old_joystick_nr)
   {
     if (joystick_device)
       close(joystick_device);
@@ -82,6 +82,8 @@ void InitGame()
     player->present = FALSE;
     player->active = FALSE;
 
+    player->action = 0;
+
     /*
     player->local = FALSE;
     */
@@ -199,7 +201,7 @@ void InitGame()
        */
 
        player->present = TRUE;
-       if (player->connected)
+       if (!network_playing || player->connected)
        {
          player->active = TRUE;
 
@@ -2881,7 +2883,7 @@ void PlayerActions(struct PlayerInfo *player, byte player_action)
   stored_player_action[player->index_nr] = 0;
   num_stored_actions++;
 
-  if (!player->active || player->gone)
+  if (!player->active || player->gone || tape.pausing)
     return;
 
   if (player_action)
@@ -2948,7 +2950,7 @@ void PlayerActions(struct PlayerInfo *player, byte player_action)
   }
 }
 
-void GameActions(byte player_action)
+void GameActions()
 {
   static long action_delay = 0;
   long action_delay_value;
@@ -2999,13 +3001,11 @@ void GameActions(byte player_action)
   recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
 
   if (network_playing)
-    SendToServer_MovePlayer(player_action);
+    SendToServer_MovePlayer(local_player->action);
 
   for(i=0; i<MAX_PLAYERS; i++)
   {
-    int actual_player_action =
-      (network_playing ? network_player_action[i] : player_action);
-
+    int actual_player_action = stored_player[i].action;
 
     /* TEST TEST TEST */
 
@@ -3014,8 +3014,10 @@ void GameActions(byte player_action)
       actual_player_action = 0;
     */
 
+    /*
     if (!options.network && i != TestPlayer)
       actual_player_action = 0;
+    */
 
     /* TEST TEST TEST */
 
@@ -3026,7 +3028,10 @@ void GameActions(byte player_action)
     PlayerActions(&stored_player[i], actual_player_action);
     ScrollFigure(&stored_player[i], SCROLL_GO_ON);
 
-    network_player_action[i] = 0;
+    /*
+    stored_player[i].action = 0;
+    */
+
   }
 
   network_player_action_received = FALSE;
@@ -3366,6 +3371,13 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
 
     if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy)))
     {
+
+
+      printf("prevent player %d from leaving visible screen\n",
+            player->index_nr);
+
+
+
       /* actual player has left the screen -- scroll in that direction */
       if (jx != old_jx)                /* player has moved horizontally */
        scroll_x += (jx - old_jx);
@@ -3376,9 +3388,19 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
     {
       if (jx != old_jx)                /* player has moved horizontally */
       {
+       /*
        if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
            jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
-         scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
+         scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
+       */
+
+       if ((player->MovDir == MV_LEFT && scroll_x > jx-MIDPOSX+offset) ||
+           (player->MovDir == MV_RIGHT && scroll_x < jx-MIDPOSX-offset))
+         scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
+
+       /* don't scroll over playfield boundaries */
+       if (scroll_x < -1 || scroll_x > lev_fieldx - SCR_FIELDX + 2)
+         scroll_x = (scroll_x < -1 ? -1 : lev_fieldx - SCR_FIELDX + 2);
 
        /* don't scroll more than one field at a time */
        scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
@@ -3390,9 +3412,19 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
       }
       else                     /* player has moved vertically */
       {
+       /*
        if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
            jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
-         scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
+         scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
+       */
+
+       if ((player->MovDir == MV_UP && scroll_y > jy-MIDPOSY+offset) ||
+           (player->MovDir == MV_DOWN && scroll_y < jy-MIDPOSY-offset))
+         scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
+
+       /* don't scroll over playfield boundaries */
+       if (scroll_y < -1 || scroll_y > lev_fieldy - SCR_FIELDY + 2)
+         scroll_y = (scroll_y < -1 ? -1 : lev_fieldy - SCR_FIELDY + 2);
 
        /* don't scroll more than one field at a time */
        scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
@@ -3424,11 +3456,23 @@ boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
     {
       if (!options.network && !AllPlayersInVisibleScreen())
       {
+
+
+       printf("oops! not all players visible if we scroll now\n");
+
+
+
        scroll_x = old_scroll_x;
        scroll_y = old_scroll_y;
       }
       else
       {
+
+
+       printf("ok, scrolling screen...\n");
+
+
+
        ScrollScreen(player, SCROLL_INIT);
        ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
       }
index c8684fe77fa7137ebbc18efaf50a33b44ddfef44..9db0ef6b316edfaa0c58aec551287a9b956e0a03 100644 (file)
@@ -74,7 +74,7 @@ void AusgangstuerBlinken(int, int);
 void EdelsteinFunkeln(int, int);
 void MauerWaechst(int, int);
 void MauerAbleger(int, int);
-void GameActions(byte);
+void GameActions(void);
 void ScrollLevel(int, int);
 
 boolean MoveFigureOneStep(struct PlayerInfo *, int, int, int, int);
index 4a5578e643e3bcc02f2ccc87c6f3b04df1f4d576..c3798d5abd4ac316fd9aba0f23a3d948636572f0 100644 (file)
@@ -108,16 +108,16 @@ void InitLevelAndPlayerInfo()
   setup.quick_doors = FALSE;
   for (i=0; i<MAX_PLAYERS; i++)
   {
-    setup.joy_input[i].use_joystick = FALSE;
-    setup.joy_input[i].joystick_nr = i;
-    setup.joy_input[i].button_snap = JOY_BUTTON_1;
-    setup.joy_input[i].button_bomb = JOY_BUTTON_2;
-    setup.key_input[i].left = DEFAULT_KEY_LEFT;
-    setup.key_input[i].right = DEFAULT_KEY_RIGHT;
-    setup.key_input[i].up = DEFAULT_KEY_UP;
-    setup.key_input[i].down = DEFAULT_KEY_DOWN;
-    setup.key_input[i].snap = DEFAULT_KEY_SNAP;
-    setup.key_input[i].bomb = DEFAULT_KEY_BOMB;
+    setup.input[i].use_joystick = FALSE;
+    setup.input[i].joystick_nr = 0;
+    setup.input[i].joy.snap  = (i == 0 ? JOY_BUTTON_1 : 0);
+    setup.input[i].joy.bomb  = (i == 0 ? JOY_BUTTON_2 : 0);
+    setup.input[i].key.left  = (i == 0 ? DEFAULT_KEY_LEFT  : KEY_UNDEFINDED);
+    setup.input[i].key.right = (i == 0 ? DEFAULT_KEY_RIGHT : KEY_UNDEFINDED);
+    setup.input[i].key.up    = (i == 0 ? DEFAULT_KEY_UP    : KEY_UNDEFINDED);
+    setup.input[i].key.down  = (i == 0 ? DEFAULT_KEY_DOWN  : KEY_UNDEFINDED);
+    setup.input[i].key.snap  = (i == 0 ? DEFAULT_KEY_SNAP  : KEY_UNDEFINDED);
+    setup.input[i].key.bomb  = (i == 0 ? DEFAULT_KEY_BOMB  : KEY_UNDEFINDED);
   }
 
   /* choose default local player */
@@ -242,7 +242,7 @@ void InitSoundServer()
 
 void InitJoystick()
 {
-  int joystick_nr = setup.joy_input[0].joystick_nr;
+  int joystick_nr = setup.input[0].joystick_nr;
 
   if (global_joystick_status == JOYSTICK_OFF)
     return;
index e9e520bd3245f11d691a38168763f081de4dfab4..27a190fc6b14fb48464cc62c64c417000f36d304 100644 (file)
@@ -74,7 +74,7 @@ int Joystick()
   } joy_ctrl;
 #endif
 
-  int joystick_nr = setup.joy_input[0].joystick_nr;
+  int joystick_nr = setup.input[0].joystick_nr;
   int js_x,js_y, js_b1,js_b2;
   int left, right, up, down;
   int result=0;
index 5d8aa5c05093cfe7ea41e2444affade81901bf26..4a713ecfdd0fd4102a6e20acd18dae519c932e7f 100644 (file)
@@ -94,7 +94,6 @@ int           AllPlayersGone;
 int            FrameCounter, TimeFrames, TimeLeft;
 int            MampferNr, SiebAktiv;
 
-byte           network_player_action[MAX_PLAYERS];
 boolean                network_player_action_received = FALSE;
 int            TestPlayer = 0;
 
index 0d427559c812d71a0b821b87c7d2bdeb2dfd5324..16ff5403894d2771b5e3dc7726a0f5e7c3a4c47f 100644 (file)
@@ -229,10 +229,8 @@ struct SetupKeyboardInfo
 
 struct SetupJoystickInfo
 {
-  boolean use_joystick;
-  int joystick_nr;
-  int button_snap;
-  int button_bomb;
+  int snap;
+  int bomb;
 };
 
 struct SetupInfo
@@ -248,8 +246,13 @@ struct SetupInfo
   boolean fading_on;
   boolean autorecord_on;
   boolean quick_doors;
-  struct SetupKeyboardInfo key_input[MAX_PLAYERS];
-  struct SetupJoystickInfo joy_input[MAX_PLAYERS];
+  struct
+  {
+    boolean use_joystick;
+    int joystick_nr;
+    struct SetupJoystickInfo joy;
+    struct SetupKeyboardInfo key;
+  } input[MAX_PLAYERS];
 };
 
 struct PlayerInfo
@@ -261,6 +264,8 @@ struct PlayerInfo
 
   int index_nr, client_nr, element_nr;
 
+  byte action;
+
   char login_name[MAX_NAMELEN];
   char alias_name[MAX_NAMELEN];
   int handicap;
@@ -414,7 +419,6 @@ extern int          AllPlayersGone;
 extern int             FrameCounter, TimeFrames, TimeLeft;
 extern int             MampferNr, SiebAktiv;
 
-extern byte            network_player_action[];
 extern boolean         network_player_action_received;
 extern int             TestPlayer;
 
@@ -1008,12 +1012,15 @@ extern int              num_bg_loops;
                                 (s)==SND_TWILIGHT)
 
 /* default input keys */
+#define KEY_UNDEFINDED         0
 #define DEFAULT_KEY_LEFT       XK_Left
 #define DEFAULT_KEY_RIGHT      XK_Right
 #define DEFAULT_KEY_UP         XK_Up
 #define DEFAULT_KEY_DOWN       XK_Down
 #define DEFAULT_KEY_SNAP       XK_Shift_L
 #define DEFAULT_KEY_BOMB       XK_Shift_R
+#define DEFAULT_KEY_OKAY       XK_Return
+#define DEFAULT_KEY_CANCEL     XK_Escape
 
 /* directions for moving */
 #define MV_NO_MOVING           0
index 092de4d0a3d55819e61c87d3a3e0601b2be4f4d9..a58c6621eb1b1a3e43975a9c1577101f9a6f5e4c 100644 (file)
@@ -568,7 +568,7 @@ static void Handle_OP_MOVE_FIGURE(unsigned int len)
 
   /* copy valid player actions */
   for (i=0; i<MAX_PLAYERS; i++)
-    network_player_action[i] =
+    stored_player[i].action =
       (i < len - 6 && stored_player[i].active ? buf[6 + i] : 0);
 
   network_player_action_received = TRUE;
index 3a9dda073371ed874ba9ce78d515170baf422921..ed3ca8f9d0d03d2e970436305245fd230f88ab46 100644 (file)
@@ -1157,34 +1157,29 @@ static void drawPlayerSetupInputInfo(int player_nr)
 {
   int i;
   static struct SetupKeyboardInfo custom_key;
-  static KeySym *key[] =
+  static struct
   {
-    &custom_key.left,
-    &custom_key.right,
-    &custom_key.up,
-    &custom_key.down,
-    &custom_key.snap,
-    &custom_key.bomb
-  };
-  static char *joy_text[] =
+    KeySym *keysym;
+    char *text;
+  } custom[] =
   {
-    "Joystick Left",
-    "Joystick Right",
-    "Joystick Up",
-    "Joystick Down",
-    "Button 1",
-    "Button 2",
+    { &custom_key.left,  "Joystick Left"  },
+    { &custom_key.right, "Joystick Right" },
+    { &custom_key.up,    "Joystick Up"    },
+    { &custom_key.down,  "Joystick Down"  },
+    { &custom_key.snap,  "Button 1"       },
+    { &custom_key.bomb,  "Button 2"       }
   };
 
-  custom_key = setup.key_input[player_nr];
+  custom_key = setup.input[player_nr].key;
 
   DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
   DrawGraphic(8, 2, GFX_SPIELER1 + player_nr);
 
-  if (setup.joy_input[player_nr].use_joystick)
+  if (setup.input[player_nr].use_joystick)
   {
     DrawText(SX+8*32, SY+3*32,
-            (setup.joy_input[player_nr].joystick_nr == 0 ?
+            (setup.input[player_nr].joystick_nr == 0 ?
              "Joystick1" : "Joystick2"),
             FS_BIG, FC_YELLOW);
     DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
@@ -1214,9 +1209,9 @@ static void drawPlayerSetupInputInfo(int player_nr)
     DrawText(SX + 3*32, SY + ypos*32,
             "              ", FS_BIG, FC_YELLOW);
     DrawText(SX + 3*32, SY + ypos*32,
-            (setup.joy_input[player_nr].use_joystick ?
-             joy_text[i] :
-             getKeySymName(*key[i])),
+            (setup.input[player_nr].use_joystick ?
+             custom[i].text :
+             getKeySymName(*custom[i].keysym)),
             FS_BIG, FC_YELLOW);
   }
 }
@@ -1313,25 +1308,25 @@ void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button)
        int one_joystick_nr       = (dx >= 0 ? 0 : 1);
        int the_other_joystick_nr = (dx >= 0 ? 1 : 0);
 
-       if (setup.joy_input[player_nr].use_joystick)
+       if (setup.input[player_nr].use_joystick)
        {
-         if (setup.joy_input[player_nr].joystick_nr == one_joystick_nr)
-           setup.joy_input[player_nr].joystick_nr = the_other_joystick_nr;
+         if (setup.input[player_nr].joystick_nr == one_joystick_nr)
+           setup.input[player_nr].joystick_nr = the_other_joystick_nr;
          else
-           setup.joy_input[player_nr].use_joystick = FALSE;
+           setup.input[player_nr].use_joystick = FALSE;
        }
        else
        {
-         setup.joy_input[player_nr].use_joystick = TRUE;
-         setup.joy_input[player_nr].joystick_nr = one_joystick_nr;
+         setup.input[player_nr].use_joystick = TRUE;
+         setup.input[player_nr].joystick_nr = one_joystick_nr;
        }
 
        drawPlayerSetupInputInfo(player_nr);
       }
       else if (y == 5)
       {
-       if (setup.joy_input[player_nr].use_joystick)
-         CalibrateJoystick(setup.joy_input[player_nr].joystick_nr);
+       if (setup.input[player_nr].use_joystick)
+         CalibrateJoystick(setup.input[player_nr].joystick_nr);
        else
          CustomizeKeyboard(player_nr);
 
@@ -1374,7 +1369,7 @@ void CustomizeKeyboard(int player_nr)
   };
 
   /* read existing key bindings from player setup */
-  custom_key = setup.key_input[player_nr];
+  custom_key = setup.input[player_nr].key;
 
   ClearWindow();
   DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
@@ -1473,7 +1468,7 @@ void CustomizeKeyboard(int player_nr)
   }
 
   /* write new key bindings back to player setup */
-  setup.key_input[player_nr] = custom_key;
+  setup.input[player_nr].key = custom_key;
 
   StopAnimation();
   DrawSetupInputScreen();
@@ -1678,7 +1673,7 @@ void CalibrateJoystick_OLD()
   char joy_nr[4];
 #endif
 
-  int joystick_nr = setup.joy_input[0].joystick_nr;
+  int joystick_nr = setup.input[0].joystick_nr;
   int new_joystick_xleft, new_joystick_xright, new_joystick_xmiddle;
   int new_joystick_yupper, new_joystick_ylower, new_joystick_ymiddle;
 
@@ -1833,7 +1828,7 @@ void CalibrateJoystick_OLD()
   DrawSetupScreen();
 }
 
-void HandleGameActions(byte player_action)
+void HandleGameActions()
 {
   if (game_status != PLAYING)
     return;
@@ -1844,7 +1839,7 @@ void HandleGameActions(byte player_action)
   if (AllPlayersGone && !TAPE_IS_STOPPED(tape))
     TapeStop();
 
-  GameActions(player_action);
+  GameActions();
 
   BackToFront();
 }
index a521b6c77dcbb706398dea3c8492478b5187811a..cf7ec6968f772b0a0bd419785ad9415ffaf651df 100644 (file)
@@ -47,7 +47,7 @@ void DrawSetupInputScreen(void);
 void HandleSetupInputScreen(int, int, int, int, int);
 void CustomizeKeyboard(int);
 void CalibrateJoystick(int);
-void HandleGameActions(byte);
+void HandleGameActions(void);
 void HandleVideoButtons(int, int, int);
 void HandleSoundButtons(int, int, int);
 void HandleGameButtons(int, int, int);