From: Holger Schemel Date: Tue, 5 Jun 2018 22:32:37 +0000 (+0200) Subject: moved setting preferred network player from game start to setup menu X-Git-Tag: 4.1.1.0~121 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c5f483ea6c651aba3f9834ee47ba94e2c1bf9055;p=rocksndiamonds.git moved setting preferred network player from game start to setup menu 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. --- diff --git a/src/files.c b/src/files.c index 2ce77889..ad84fbc2 100644 --- a/src/files.c +++ b/src/files.c @@ -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) diff --git a/src/init.c b/src/init.c index 8fb9f80d..88ffc38b 100644 --- a/src/init.c +++ b/src/init.c @@ -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 } diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 6577f951..28cc8bd5 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -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 */ diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 078a10f3..e71a8df2 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -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 *); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index bf02c227..1d5a83bf 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -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; diff --git a/src/libgame/setup.h b/src/libgame/setup.h index bfaadc79..a9ca6109 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -27,28 +27,29 @@ #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) diff --git a/src/libgame/system.h b/src/libgame/system.h index bc294f22..23bb94d4 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1273,6 +1273,7 @@ struct SetupInfo int volume_music; boolean network_mode; + int network_player_nr; struct SetupAutoSetupInfo auto_setup; struct SetupEditorInfo editor; diff --git a/src/screens.c b/src/screens.c index 1346c218..2b4539f9 100644 --- a/src/screens.c +++ b/src/screens.c @@ -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);