added setup option to enable network multi-player games
authorHolger Schemel <info@artsoft.org>
Fri, 1 Jun 2018 17:03:58 +0000 (19:03 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 18 Jun 2018 17:47:31 +0000 (19:47 +0200)
This is a work-in-progress change: The new setup option to enable
network mode just sets the same flag as using the command-line option
"--network" (without specifying a hostname or a port).

For local network games, and if UDP broadcasting works as it should
to auto-detect a local network server that is already running, this is
already sufficient to play network multi-player games.

What's still missing is a way to explicitly specify a network server
to also be able to play network games with hosts outside of the local
network (or if UDP broadcasting does not work correctly).

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

index ac75c2afc8151a97e03cd7428bb08ab5265c8b59..2ce77889155c842b8dbcd886781dc0fddf761503 100644 (file)
@@ -8312,8 +8312,9 @@ void SaveScore(int nr)
 #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                        51
+#define NUM_GLOBAL_SETUP_TOKENS                        52
 
 /* auto setup */
 #define SETUP_TOKEN_AUTO_EDITOR_ZOOM_TILESIZE  0
@@ -8521,6 +8522,7 @@ 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[] =
@@ -8787,6 +8789,8 @@ 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;
index b32141fbd7320ecbe26ab6769ea1961d4580e248..8fb9f80df81798f971ea07192ded0064caba7f09 100644 (file)
@@ -5611,6 +5611,9 @@ void InitNetworkServer()
   int nr_wanted;
 #endif
 
+  if (setup.network_mode)
+    options.network = TRUE;
+
   if (!options.network)
     return;
 
index 1b2b079b701878004f37a63b9a023ce7457d531a..bc294f227bb3b8622d0e5ba68366b966d2104361 100644 (file)
@@ -1272,6 +1272,8 @@ struct SetupInfo
   int volume_loops;
   int volume_music;
 
+  boolean network_mode;
+
   struct SetupAutoSetupInfo auto_setup;
   struct SetupEditorInfo editor;
   struct SetupEditorCascadeInfo editor_cascade;
index 200f725c27edc2ea348f530f3bdc54908366969c..1346c21886fef76e0ca866324d03f14b77affd2f 100644 (file)
@@ -5879,6 +5879,7 @@ static struct TokenInfo setup_info_main[] =
 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_YES_NO,       &setup.input_on_focus,  "Only Move Focussed Player:" },
   { TYPE_SWITCH,       &setup.time_limit,      "Time Limit:"           },
   { TYPE_SWITCH,       &setup.handicap,        "Handicap:"             },
@@ -6411,6 +6412,11 @@ static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
   // fullscreen state may have changed at this point
   if (si->value == &setup.fullscreen)
     ToggleFullscreenOrChangeWindowScalingIfNeeded();
+
+  if (si->value == &setup.network_mode &&
+      setup.network_mode &&
+      !options.network)
+    Request("Please restart game to enable network games!", REQ_CONFIRM);
 }
 
 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)