moved setting preferred network player from game start to setup menu
authorHolger Schemel <info@artsoft.org>
Tue, 5 Jun 2018 22:32:37 +0000 (00:32 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 18 Jun 2018 17:47:31 +0000 (19:47 +0200)
When running the game in network game mode (via setup menu option or
command line option), do not ask for the preferred network player on
each start of the game, but use the player that can be configured in
the setup menu now.

src/files.c
src/init.c
src/libgame/misc.c
src/libgame/misc.h
src/libgame/setup.c
src/libgame/setup.h
src/libgame/system.h
src/screens.c

index 2ce77889155c842b8dbcd886781dc0fddf761503..ad84fbc2fee262839f52b25420b1e3af90b7497a 100644 (file)
@@ -8302,19 +8302,20 @@ void SaveScore(int nr)
 #define SETUP_TOKEN_VOLUME_SIMPLE              38
 #define SETUP_TOKEN_VOLUME_LOOPS               39
 #define SETUP_TOKEN_VOLUME_MUSIC               40
-#define SETUP_TOKEN_TOUCH_CONTROL_TYPE         41
-#define SETUP_TOKEN_TOUCH_MOVE_DISTANCE                42
-#define SETUP_TOKEN_TOUCH_DROP_DISTANCE                43
-#define SETUP_TOKEN_TOUCH_TRANSPARENCY         44
-#define SETUP_TOKEN_TOUCH_DRAW_OUTLINED                45
-#define SETUP_TOKEN_TOUCH_DRAW_PRESSED         46
-#define SETUP_TOKEN_TOUCH_GRID_XSIZE_0         47
-#define SETUP_TOKEN_TOUCH_GRID_YSIZE_0         48
-#define SETUP_TOKEN_TOUCH_GRID_XSIZE_1         49
-#define SETUP_TOKEN_TOUCH_GRID_YSIZE_1         50
-#define SETUP_TOKEN_NETWORK_MODE               51
-
-#define NUM_GLOBAL_SETUP_TOKENS                        52
+#define SETUP_TOKEN_NETWORK_MODE               41
+#define SETUP_TOKEN_NETWORK_PLAYER_NR          42
+#define SETUP_TOKEN_TOUCH_CONTROL_TYPE         43
+#define SETUP_TOKEN_TOUCH_MOVE_DISTANCE                44
+#define SETUP_TOKEN_TOUCH_DROP_DISTANCE                45
+#define SETUP_TOKEN_TOUCH_TRANSPARENCY         46
+#define SETUP_TOKEN_TOUCH_DRAW_OUTLINED                47
+#define SETUP_TOKEN_TOUCH_DRAW_PRESSED         48
+#define SETUP_TOKEN_TOUCH_GRID_XSIZE_0         49
+#define SETUP_TOKEN_TOUCH_GRID_YSIZE_0         50
+#define SETUP_TOKEN_TOUCH_GRID_XSIZE_1         51
+#define SETUP_TOKEN_TOUCH_GRID_YSIZE_1         52
+
+#define NUM_GLOBAL_SETUP_TOKENS                        53
 
 /* auto setup */
 #define SETUP_TOKEN_AUTO_EDITOR_ZOOM_TILESIZE  0
@@ -8512,6 +8513,8 @@ static struct TokenInfo global_setup_tokens[] =
   { TYPE_INTEGER,&si.volume_simple,           "volume_simple"          },
   { TYPE_INTEGER,&si.volume_loops,            "volume_loops"           },
   { TYPE_INTEGER,&si.volume_music,            "volume_music"           },
+  { TYPE_SWITCH, &si.network_mode,            "network_mode"           },
+  { TYPE_PLAYER, &si.network_player_nr,       "network_player"         },
   { TYPE_STRING, &si.touch.control_type,      "touch.control_type"     },
   { TYPE_INTEGER,&si.touch.move_distance,     "touch.move_distance"    },
   { TYPE_INTEGER,&si.touch.drop_distance,     "touch.drop_distance"    },
@@ -8522,7 +8525,6 @@ static struct TokenInfo global_setup_tokens[] =
   { TYPE_INTEGER,&si.touch.grid_ysize[0],     "touch.virtual_buttons.0.ysize" },
   { TYPE_INTEGER,&si.touch.grid_xsize[1],     "touch.virtual_buttons.1.xsize" },
   { TYPE_INTEGER,&si.touch.grid_ysize[1],     "touch.virtual_buttons.1.ysize" },
-  { TYPE_SWITCH, &si.network_mode,            "network_mode"           },
 };
 
 static struct TokenInfo auto_setup_tokens[] =
@@ -8733,6 +8735,9 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->volume_loops = 100;              /* percent */
   si->volume_music = 100;              /* percent */
 
+  si->network_mode = FALSE;
+  si->network_player_nr = 0;           /* first player */
+
   si->touch.control_type = getStringCopy(TOUCH_CONTROL_DEFAULT);
   si->touch.move_distance = TOUCH_MOVE_DISTANCE_DEFAULT;       /* percent */
   si->touch.drop_distance = TOUCH_DROP_DISTANCE_DEFAULT;       /* percent */
@@ -8789,8 +8794,6 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
 
   si->touch.grid_initialized           = video.initialized;
 
-  si->network_mode = FALSE;
-
   si->editor.el_boulderdash            = TRUE;
   si->editor.el_emerald_mine           = TRUE;
   si->editor.el_emerald_mine_club      = TRUE;
@@ -9330,6 +9333,7 @@ void SaveSetup()
     if (i == SETUP_TOKEN_PLAYER_NAME + 1 ||
        i == SETUP_TOKEN_GRAPHICS_SET ||
        i == SETUP_TOKEN_VOLUME_SIMPLE ||
+       i == SETUP_TOKEN_NETWORK_MODE ||
        i == SETUP_TOKEN_TOUCH_CONTROL_TYPE ||
        i == SETUP_TOKEN_TOUCH_GRID_XSIZE_0 ||
        i == SETUP_TOKEN_TOUCH_GRID_XSIZE_1)
index 8fb9f80df81798f971ea07192ded0064caba7f09..88ffc38bfca24941a3a051b2381723b2567f1078 100644 (file)
@@ -5607,10 +5607,6 @@ static void InitArtworkDone()
 
 void InitNetworkServer()
 {
-#if defined(NETWORK_AVALIABLE)
-  int nr_wanted;
-#endif
-
   if (setup.network_mode)
     options.network = TRUE;
 
@@ -5618,16 +5614,12 @@ void InitNetworkServer()
     return;
 
 #if defined(NETWORK_AVALIABLE)
-  nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
-
   if (!ConnectToServer(options.server_host, options.server_port))
     Error(ERR_EXIT, "cannot connect to network game server");
 
   SendToServer_PlayerName(setup.player_name);
   SendToServer_ProtocolVersion();
-
-  if (nr_wanted)
-    SendToServer_NrWanted(nr_wanted);
+  SendToServer_NrWanted(setup.network_player_nr + 1);
 #endif
 }
 
index 6577f95127e93d2b049435c5016188a94a3d6195..28cc8bd5af3efdbb66387dbb11e0d14c36afeb06 100644 (file)
@@ -2043,6 +2043,31 @@ int get_switch3_from_string(char *s)
   return result;
 }
 
+int get_player_nr_from_string(char *s)
+{
+  static char *player_text[] =
+  {
+    "player_1",
+    "player_2",
+    "player_3",
+    "player_4",
+
+    NULL
+  };
+
+  char *s_lower = getStringToLower(s);
+  int result = 0;
+  int i;
+
+  for (i = 0; player_text[i] != NULL; i++)
+    if (strEqual(s_lower, player_text[i]))
+      result = i;
+
+  free(s_lower);
+
+  return result;
+}
+
 
 /* ------------------------------------------------------------------------- */
 /* functions for generic lists                                               */
index 078a10f3ba0ba3d9ee38cafbfe27fb0013f7de80..e71a8df2d443732e209b1dac0622dcc5a417d374 100644 (file)
@@ -235,6 +235,7 @@ char getValidConfigValueChar(char);
 int get_integer_from_string(char *);
 boolean get_boolean_from_string(char *);
 int get_switch3_from_string(char *);
+int get_player_nr_from_string(char *);
 
 ListNode *newListNode(void);
 void addNodeToList(ListNode **, char *, void *);
index bf02c2276e2a6a2f2227e993705fa64d26ad15f3..1d5a83bfffabcc9c064861e4c20c6ad292026282 100644 (file)
@@ -2629,6 +2629,10 @@ void setSetupInfo(struct TokenInfo *token_info,
       *(char **)setup_value = getStringCopy(token_value);
       break;
 
+    case TYPE_PLAYER:
+      *(int *)setup_value = get_player_nr_from_string(token_value);
+      break;
+
     default:
       break;
   }
@@ -3872,6 +3876,10 @@ char *getSetupValue(int type, void *value)
       strcpy(value_string, *(char **)value);
       break;
 
+    case TYPE_PLAYER:
+      sprintf(value_string, "player_%d", *(int *)value + 1);
+      break;
+
     default:
       value_string[0] = '\0';
       break;
index bfaadc79a92289d2867f07a0eca6418d2a014a54..a9ca6109703a8589eed2d944f186674ea1636c3a 100644 (file)
 #define TYPE_KEY_X11                   (1 << 7)
 #define TYPE_INTEGER                   (1 << 8)
 #define TYPE_STRING                    (1 << 9)
-#define TYPE_ELEMENT                   (1 << 10)
-#define TYPE_GRAPHIC                   (1 << 11)
+#define TYPE_PLAYER                    (1 << 10)
+#define TYPE_ELEMENT                   (1 << 11)
+#define TYPE_GRAPHIC                   (1 << 12)
 
 /* additional values for setup screen */
-#define TYPE_ENTER_SCREEN              (1 << 12)
-#define TYPE_LEAVE_SCREEN              (1 << 13)
-#define TYPE_ENTER_MENU                        (1 << 14)
-#define TYPE_LEAVE_MENU                        (1 << 15)
-#define TYPE_ENTER_LIST                        (1 << 16)
-#define TYPE_LEAVE_LIST                        (1 << 17)
-#define TYPE_EMPTY                     (1 << 18)
-#define TYPE_SKIPPABLE                 (1 << 19)
-#define TYPE_KEYTEXT                   (1 << 20)
-
-#define TYPE_GHOSTED                   (1 << 21)
-#define TYPE_QUERY                     (1 << 22)
+#define TYPE_ENTER_SCREEN              (1 << 13)
+#define TYPE_LEAVE_SCREEN              (1 << 14)
+#define TYPE_ENTER_MENU                        (1 << 15)
+#define TYPE_LEAVE_MENU                        (1 << 16)
+#define TYPE_ENTER_LIST                        (1 << 17)
+#define TYPE_LEAVE_LIST                        (1 << 18)
+#define TYPE_EMPTY                     (1 << 19)
+#define TYPE_SKIPPABLE                 (1 << 20)
+#define TYPE_KEYTEXT                   (1 << 21)
+
+#define TYPE_GHOSTED                   (1 << 22)
+#define TYPE_QUERY                     (1 << 23)
 
 /* additional values for internal purposes */
-#define TYPE_BITFIELD                  (1 << 23)
-#define TYPE_CONTENT                   (1 << 24)
-#define TYPE_ELEMENT_LIST              (1 << 25)
-#define TYPE_CONTENT_LIST              (1 << 26)
+#define TYPE_BITFIELD                  (1 << 24)
+#define TYPE_CONTENT                   (1 << 25)
+#define TYPE_ELEMENT_LIST              (1 << 26)
+#define TYPE_CONTENT_LIST              (1 << 27)
 
 /* derived values for setup file handling */
 #define TYPE_BOOLEAN_STYLE             (TYPE_BOOLEAN | \
@@ -64,6 +65,7 @@
                                         TYPE_KEY_X11           | \
                                         TYPE_INTEGER           | \
                                         TYPE_STRING            | \
+                                        TYPE_PLAYER            | \
                                         TYPE_ELEMENT           | \
                                         TYPE_GRAPHIC)
 
index bc294f227bb3b8622d0e5ba68366b966d2104361..23bb94d41042398ac7353fcafd954c3946d89f4d 100644 (file)
@@ -1273,6 +1273,7 @@ struct SetupInfo
   int volume_music;
 
   boolean network_mode;
+  int network_player_nr;
 
   struct SetupAutoSetupInfo auto_setup;
   struct SetupEditorInfo editor;
index 1346c21886fef76e0ca866324d03f14b77affd2f..2b4539f990d2aa12547abbadc627ca7e7e9874c0 100644 (file)
@@ -2213,6 +2213,7 @@ static int getMenuTextFont(int type)
              TYPE_YES_NO       |
              TYPE_YES_NO_AUTO  |
              TYPE_STRING       |
+             TYPE_PLAYER       |
              TYPE_ECS_AGA      |
              TYPE_KEYTEXT      |
              TYPE_ENTER_LIST))
@@ -2544,7 +2545,8 @@ void HandleMenuScreen(int mx, int my, int dx, int dy, int button,
 
       if (menu_info[choice].type & menu_navigation_type ||
          menu_info[choice].type & TYPE_BOOLEAN_STYLE ||
-         menu_info[choice].type & TYPE_YES_NO_AUTO)
+         menu_info[choice].type & TYPE_YES_NO_AUTO ||
+         menu_info[choice].type & TYPE_PLAYER)
        button = MB_MENU_CHOICE;
     }
     else if (dy)
@@ -5880,6 +5882,7 @@ static struct TokenInfo setup_info_game[] =
 {
   { TYPE_SWITCH,       &setup.team_mode,       "Team-Mode (Multi-Player):" },
   { TYPE_SWITCH,       &setup.network_mode,    "Network Multi-Player Mode:" },
+  { TYPE_PLAYER,       &setup.network_player_nr,"Preferred Network Player:" },
   { TYPE_YES_NO,       &setup.input_on_focus,  "Only Move Focussed Player:" },
   { TYPE_SWITCH,       &setup.time_limit,      "Time Limit:"           },
   { TYPE_SWITCH,       &setup.handicap,        "Handicap:"             },
@@ -6247,6 +6250,8 @@ static int getSetupValueFont(int type, void *value)
   else if (type & TYPE_YES_NO_AUTO)
     return (*(int *)value == AUTO  ? FONT_OPTION_ON :
            *(int *)value == FALSE ? FONT_OPTION_OFF : FONT_OPTION_ON);
+  else if (type & TYPE_PLAYER)
+    return FONT_VALUE_1;
   else
     return FONT_VALUE_1;
 }
@@ -6302,6 +6307,12 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
   {
     xpos = menu_screen_value_xpos - 1;
   }
+  else if (type & TYPE_PLAYER)
+  {
+    int displayed_player_nr = *(int *)value + 1;
+
+    value_string = getSetupValue(TYPE_INTEGER, (void *)&displayed_player_nr);
+  }
 
   startx = mSX + xpos * 32;
   starty = mSY + ypos * 32;
@@ -6372,6 +6383,15 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
 
   DrawText(startx, starty, value_string, font_nr);
 
+  if (type & TYPE_PLAYER)
+  {
+    int player_nr = *(int *)value;
+    int xoff = getFontWidth(font_nr);
+
+    DrawFixedGraphicThruMaskExt(drawto, startx + xoff, starty,
+                               PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0);
+  }
+
   if (font_draw_xoffset_modified)
     getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old;
 }
@@ -6406,6 +6426,17 @@ static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
     if (key != KSYM_UNDEFINED)
       *(Key *)si->value = key;
   }
+  else if (si->type & TYPE_PLAYER)
+  {
+    int player_nr = *(int *)si->value;
+
+    if (dx)
+      player_nr += dx;
+    else
+      player_nr = Request("Choose player", REQ_PLAYER) - 1;
+
+    *(int *)si->value = MIN(MAX(0, player_nr), MAX_PLAYERS - 1);
+  }
 
   drawSetupValue(screen_pos, setup_info_pos_raw);