Index: client/civclient.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v retrieving revision 1.121 diff -u -r1.121 civclient.c --- client/civclient.c 2002/03/17 10:48:50 1.121 +++ client/civclient.c 2002/03/17 14:50:40 @@ -234,7 +234,7 @@ break; case PACKET_SELECT_NATION: - handle_select_nation((struct packet_generic_values *)packet); + handle_select_nation((struct packet_nations_used *)packet); break; case PACKET_PLAYER_INFO: @@ -387,6 +387,10 @@ case PACKET_CONN_PING: send_packet_generic_empty(&aconnection, PACKET_CONN_PONG); + break; + + case PACKET_SELECT_NATION_OK: + handle_select_nation(NULL); break; case PACKET_ATTRIBUTE_CHUNK: Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.229 diff -u -r1.229 packhand.c --- client/packhand.c 2002/03/17 09:40:04 1.229 +++ client/packhand.c 2002/03/17 14:50:42 @@ -1630,23 +1630,24 @@ /************************************************************************** ... **************************************************************************/ -void handle_select_nation(struct packet_generic_values *packet) +void handle_select_nation(struct packet_nations_used *packet) { - if(get_client_state()==CLIENT_SELECT_RACE_STATE) { - if(packet->value2 == 0xffff) { + if (get_client_state() == CLIENT_SELECT_RACE_STATE) { + if (!packet) { set_client_state(CLIENT_WAITING_FOR_GAME_START_STATE); popdown_races_dialog(); + } else { + races_toggles_set_sensitive(packet); } - else - races_toggles_set_sensitive( packet->value1, packet->value2); - } - else if(get_client_state()==CLIENT_PRE_GAME_STATE) { + } else if (get_client_state() == CLIENT_PRE_GAME_STATE) { set_client_state(CLIENT_SELECT_RACE_STATE); popup_races_dialog(); - races_toggles_set_sensitive( packet->value1, packet->value2); + assert(packet); + races_toggles_set_sensitive(packet); + } else { + freelog(LOG_ERROR, + "got a select nation packet in an incompatible state"); } - else - freelog(LOG_ERROR, "got a select nation packet in an incompatible state"); } /************************************************************************** Index: client/packhand.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.h,v retrieving revision 1.24 diff -u -r1.24 packhand.h --- client/packhand.h 2002/02/07 10:24:14 1.24 +++ client/packhand.h 2002/03/17 14:50:42 @@ -22,7 +22,7 @@ void handle_conn_info(struct packet_conn_info *pinfo); void handle_game_info(struct packet_game_info *pinfo); void handle_map_info(struct packet_map_info *pinfo); -void handle_select_nation(struct packet_generic_values *packet); +void handle_select_nation(struct packet_nations_used *packet); void handle_unit_info(struct packet_unit_info *packet); void handle_chat_msg(struct packet_generic_message *packet); Index: client/gui-gtk/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v retrieving revision 1.90 diff -u -r1.90 dialogs.c --- client/gui-gtk/dialogs.c 2002/03/17 10:48:53 1.90 +++ client/gui-gtk/dialogs.c 2002/03/17 14:50:44 @@ -2091,38 +2091,31 @@ /************************************************************************** ... **************************************************************************/ -void races_toggles_set_sensitive(int bits1, int bits2) +void races_toggles_set_sensitive(struct packet_nations_used *packet) { - int i, mybits; + int i; - mybits=bits1; - - for(i=0; i>=1; + for (i = 0; i < game.playable_nation_count; i++) { + gtk_widget_set_sensitive(races_toggles[g_list_index + (sorted_races_list, + GINT_TO_POINTER(i))], TRUE); } + + freelog(LOG_DEBUG, "%d nations used:", packet->num_nations_used); + for (i = 0; i < packet->num_nations_used; i++) { + int nation = packet->nations_used[i]; + + freelog(LOG_DEBUG, " [%d]: %d = %s", i, nation, + get_nation_name(nation)); - mybits=bits2; + gtk_widget_set_sensitive(races_toggles[g_list_index + (sorted_races_list, + GINT_TO_POINTER(nation))], + FALSE); - for(i=32; i>=1; } } Index: client/gui-gtk-2.0/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.c,v retrieving revision 1.4 diff -u -r1.4 dialogs.c --- client/gui-gtk-2.0/dialogs.c 2002/03/17 10:48:55 1.4 +++ client/gui-gtk-2.0/dialogs.c 2002/03/17 14:50:45 @@ -2071,38 +2071,31 @@ /************************************************************************** ... **************************************************************************/ -void races_toggles_set_sensitive(int bits1, int bits2) +void races_toggles_set_sensitive(struct packet_nations_used *packet) { - int i, mybits; + int i; - mybits=bits1; - - for(i=0; i>=1; + for (i = 0; i < game.playable_nation_count; i++) { + gtk_widget_set_sensitive(races_toggles[g_list_index + (sorted_races_list, + GINT_TO_POINTER(i))], TRUE); } + + freelog(LOG_DEBUG, "%d nations used:", packet->num_nations_used); + for (i = 0; i < packet->num_nations_used; i++) { + int nation = packet->nations_used[i]; + + freelog(LOG_DEBUG, " [%d]: %d = %s", i, nation, + get_nation_name(nation)); - mybits=bits2; + gtk_widget_set_sensitive(races_toggles[g_list_index + (sorted_races_list, + GINT_TO_POINTER(nation))], + FALSE); - for(i=32; i>=1; } } Index: client/gui-mui/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/dialogs.c,v retrieving revision 1.39 diff -u -r1.39 dialogs.c --- client/gui-mui/dialogs.c 2002/03/17 10:48:58 1.39 +++ client/gui-mui/dialogs.c 2002/03/17 14:50:46 @@ -1825,35 +1825,9 @@ /**************************************************************** ... *****************************************************************/ -void races_toggles_set_sensitive(int bits1, int bits2) +void races_toggles_set_sensitive(struct packet_nations_used *packet) { -// remove me -#ifdef DISABLED - int i, selected, mybits; - - mybits=bits1; - - for(i=0; i>=1; - } - - mybits=bits2; - - for(i=32; i>=1; - } - - if((selected=races_buttons_get_current())==-1) - return; -#endif + /* not implemented */ } /**************************************************************** Index: client/gui-win32/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/dialogs.c,v retrieving revision 1.15 diff -u -r1.15 dialogs.c --- client/gui-win32/dialogs.c 2002/03/17 10:49:01 1.15 +++ client/gui-win32/dialogs.c 2002/03/17 14:50:47 @@ -802,41 +802,27 @@ /************************************************************************** **************************************************************************/ -void -races_toggles_set_sensitive(int bits1, int bits2) +void races_toggles_set_sensitive(struct packet_nations_used *packet) { - int i,mybits; - - mybits=bits1; - for(i=0; i>=1; + int i; + + for (i = 0; i < game.playable_nation_count; i++) { + EnableWindow(GetDlgItem(races_dlg, ID_RACESDLG_NATION_BASE + i), TRUE); } + + freelog(LOG_DEBUG, "%d nations used:", packet->num_nations_used); + for (i = 0; i < packet->num_nations_used; i++) { + int nation = packet->nations_used[i]; - mybits=bits2; + freelog(LOG_DEBUG, " [%d]: %d", i, nation); - for(i=32; i>=1; } - } /**************************************************************** Index: client/gui-xaw/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v retrieving revision 1.64 diff -u -r1.64 dialogs.c --- client/gui-xaw/dialogs.c 2002/03/17 10:49:03 1.64 +++ client/gui-xaw/dialogs.c 2002/03/17 14:50:49 @@ -62,6 +62,7 @@ static Widget races_form, races_toggles_form, races_label; static Widget *races_toggles=NULL; static int *races_toggles_to_nations=NULL; +static int *nation_to_race_toggle = NULL; static Widget races_leader_form, races_leader; static Widget races_leader_pick_popupmenu, races_leader_pick_menubutton; static Widget races_sex_toggles[2], races_sex_form, races_sex_label; @@ -178,7 +179,21 @@ XtSetSensitive(toplevel, TRUE); } +/**************************************************************** + ... +*****************************************************************/ +static void select_random_race(void) +{ + /* try to find a free nation */ + while (1) { + int race_toggle_index = myrand(game.playable_nation_count); + if (XtIsSensitive(races_toggles[race_toggle_index])) { + x_simulate_button_click(races_toggles[race_toggle_index]); + break; + } + } +} /**************************************************************** ... @@ -2079,6 +2094,15 @@ races_toggles_to_nations[i] = i; } qsort(races_toggles_to_nations, i, sizeof(int), races_indirect_compare); + + /* Build nation_to_race_toggle */ + free(nation_to_race_toggle); + nation_to_race_toggle = + fc_calloc(game.playable_nation_count, sizeof(int)); + for (i = 0; i < game.playable_nation_count; i++) { + nation_to_race_toggle[races_toggles_to_nations[i]] = i; + } + for(i=0; i> ((race<32)?race:race-32) )&1 ); - XtSetSensitive(races_toggles[i], sens); + for (i = 0; i < game.playable_nation_count; i++) { + XtSetSensitive(races_toggles[nation_to_race_toggle[i]], TRUE); } - if((selected=races_buttons_get_current())==-1) - return; - race = races_toggles_to_nations[selected]; + freelog(LOG_DEBUG, "%d nations used:", packet->num_nations_used); + for (i = 0; i < packet->num_nations_used; i++) { + int nation = packet->nations_used[i], selected_nation = -1; + + if (races_buttons_get_current() != -1) { + selected_nation = + races_toggles_to_nations[races_buttons_get_current()]; + } - if( (bits1 & (1<32 && (bits2 & (1<<(race-32))) ) ) - XawToggleUnsetCurrent(races_toggles[0]); + freelog(LOG_DEBUG, " [%d]: %d = %s", i, nation, + get_nation_name(nation)); + + if (nation == selected_nation) { + XawToggleUnsetCurrent(races_toggles[0]); + XtSetSensitive(races_toggles[nation_to_race_toggle[nation]], FALSE); + select_random_race(); + } else { + XtSetSensitive(races_toggles[nation_to_race_toggle[nation]], FALSE); + } + } } /************************************************************************** Index: client/include/dialogs_g.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/include/dialogs_g.h,v retrieving revision 1.9 diff -u -r1.9 dialogs_g.h --- client/include/dialogs_g.h 2002/03/17 10:49:05 1.9 +++ client/include/dialogs_g.h 2002/03/17 14:50:49 @@ -18,6 +18,7 @@ struct tile; struct unit; struct city; +struct packet_nations_used; void popup_notify_goto_dialog(char *headline, char *lines, int x, int y); void popup_notify_dialog(char *caption, char *headline, char *lines); @@ -27,7 +28,7 @@ void popup_unit_select_dialog(struct tile *ptile); -void races_toggles_set_sensitive(int bits1, int bits2); +void races_toggles_set_sensitive(struct packet_nations_used *packet); void popup_revolution_dialog(void); void popup_government_dialog(void); Index: common/capstr.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v retrieving revision 1.96 diff -u -r1.96 capstr.c --- common/capstr.c 2002/03/08 15:38:19 1.96 +++ common/capstr.c 2002/03/17 14:50:49 @@ -73,7 +73,7 @@ #define CAPABILITY "+1.11.6 conn_info pop_cost +turn +attributes"\ " new_bonus_tech fund_added +processing_packets angrycitizen +tile_trade"\ " init_techs short_worklists tech_cost_style +short_city_tile_trade"\ -" +trade_size" +" +trade_size +new_nation_selection" /* "+1.11.6" is protocol for 1.11.6 beta release. @@ -117,6 +117,9 @@ "trade_size" transfer game.notradesize and game.fulltradesize to the client. + + "new_nation_selection" transfer array of used nations instead of + bit mask */ void init_our_capability(void) Index: common/packets.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v retrieving revision 1.200 diff -u -r1.200 packets.c --- common/packets.c 2002/03/17 10:49:06 1.200 +++ common/packets.c 2002/03/17 14:50:52 @@ -376,6 +376,7 @@ case PACKET_PROCESSING_STARTED: case PACKET_PROCESSING_FINISHED: case PACKET_START_TURN: + case PACKET_SELECT_NATION_OK: return receive_packet_generic_empty(pc); case PACKET_NEW_YEAR: @@ -385,7 +386,7 @@ return receive_packet_tile_info(pc); case PACKET_SELECT_NATION: - return receive_packet_generic_values(pc); + return receive_packet_nations_used(pc); case PACKET_REMOVE_UNIT: case PACKET_REMOVE_CITY: @@ -4303,6 +4304,55 @@ freelog(LOG_ERROR, "invalid type in receive_packet_goto_route()"); return NULL; } +} + +/************************************************************************** +... +**************************************************************************/ +int send_packet_nations_used(struct connection *pc, + const struct packet_nations_used *packet) +{ + unsigned char buffer[MAX_LEN_PACKET], *cptr; + int i; + + cptr = put_uint8(buffer + 2, PACKET_SELECT_NATION); + + for (i = 0; i < packet->num_nations_used; i++) { + assert((packet->nations_used[i] & 0xffff) == packet->nations_used[i]); + cptr = put_uint16(cptr, packet->nations_used[i]); + } + put_uint16(buffer, cptr - buffer); + return send_packet_data(pc, buffer, cptr - buffer); +} + +/************************************************************************** +... +**************************************************************************/ +struct packet_nations_used *receive_packet_nations_used(struct connection + *pc) +{ + struct pack_iter iter; + struct packet_nations_used *packet = + fc_malloc(sizeof(struct packet_nations_used)); + + pack_iter_init(&iter, pc); + + packet->num_nations_used = 0; + + for (;;) { + assert((pack_iter_remaining(&iter) % 2) == 0); + + if (pack_iter_remaining(&iter) == 0) { + break; + } + + iget_uint16(&iter, &packet->nations_used[packet->num_nations_used]); + packet->num_nations_used++; + } + pack_iter_end(&iter, pc); + remove_packet_from_buffer(pc->buffer); + + return packet; } /************************************************************************** Index: common/packets.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v retrieving revision 1.111 diff -u -r1.111 packets.h --- common/packets.h 2002/03/17 10:49:06 1.111 +++ common/packets.h 2002/03/17 14:50:53 @@ -125,6 +125,7 @@ PACKET_PROCESSING_STARTED, PACKET_PROCESSING_FINISHED, PACKET_START_TURN, + PACKET_SELECT_NATION_OK, PACKET_LAST /* leave this last */ }; @@ -884,6 +885,14 @@ unsigned char data[ATTRIBUTE_CHUNK_SIZE]; }; +/********************************************************* +... +*********************************************************/ +struct packet_nations_used { + int num_nations_used; + Nation_Type_id nations_used[MAX_NUM_PLAYERS]; +}; + /* These two are non-static for meta.c; others are now static --dwp */ unsigned char *put_uint16(unsigned char *buffer, int val); unsigned char *put_string(unsigned char *buffer, const char *mystring); @@ -1105,6 +1114,11 @@ int send_packet_generic_empty(struct connection *pc, enum packet_type type); struct packet_generic_empty * receive_packet_generic_empty(struct connection *pc); + +int send_packet_nations_used(struct connection *pc, + const struct packet_nations_used *packet); +struct packet_nations_used *receive_packet_nations_used(struct connection + *pc); #include "packets_lsend.h" /* lsend_packet_* functions */ Index: common/packets_lsend.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets_lsend.c,v retrieving revision 1.9 diff -u -r1.9 packets_lsend.c --- common/packets_lsend.c 2002/03/05 15:47:27 1.9 +++ common/packets_lsend.c 2002/03/17 14:50:53 @@ -363,3 +363,11 @@ conn_list_iterate_end; } +void lsend_packet_nations_used(struct conn_list *dest, + const struct packet_nations_used *packet) +{ + conn_list_iterate(*dest, pconn) + send_packet_nations_used(pconn, packet); + conn_list_iterate_end; +} + Index: common/packets_lsend.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets_lsend.h,v retrieving revision 1.8 diff -u -r1.8 packets_lsend.h --- common/packets_lsend.h 2002/03/05 15:47:27 1.8 +++ common/packets_lsend.h 2002/03/17 14:50:53 @@ -104,3 +104,5 @@ void lsend_packet_attribute_chunk(struct conn_list *dest, struct packet_attribute_chunk *packet); void lsend_packet_generic_empty(struct conn_list *dest, enum packet_type type); +void lsend_packet_nations_used(struct conn_list *dest, + const struct packet_nations_used *packet); Index: server/srv_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v retrieving revision 1.74 diff -u -r1.74 srv_main.c --- server/srv_main.c 2002/03/13 09:56:26 1.74 +++ server/srv_main.c 2002/03/17 14:50:54 @@ -910,7 +910,6 @@ struct packet_alloc_nation *packet) { int nation_used_count; - struct packet_generic_values select_nation; if (server_state != SELECT_RACES_STATE) { freelog(LOG_ERROR, _("Trying to alloc nation outside " @@ -955,9 +954,8 @@ get_nation_name(packet->nation_no), packet->name); /* inform player his choice was ok */ - select_nation.value2=0xffff; - lsend_packet_generic_values(&pplayer->connections, PACKET_SELECT_NATION, - &select_nation); + lsend_packet_generic_empty(&pplayer->connections, + PACKET_SELECT_NATION_OK); pplayer->nation=packet->nation_no; sz_strlcpy(pplayer->name, packet->name); @@ -992,28 +990,23 @@ } /************************************************************************** -Send request to select nation, mask1, mask2 contains those that were -already selected and are not available + Sends the currently collected selected nations to the given player. **************************************************************************/ static void send_select_nation(struct player *pplayer) { - struct packet_generic_values select_nation; - - select_nation.value1=0; /* assume int is 32 bit, safe */ - select_nation.value2=0; + struct packet_nations_used packet; - /* set bits in mask corresponding to nations already selected by others */ + packet.num_nations_used = 0; + players_iterate(other_player) { - if (other_player->nation != MAX_NUM_NATIONS) { - if (other_player->nation < 32) - select_nation.value1 |= 1 << other_player->nation; - else - select_nation.value2 |= 1 << (other_player->nation - 32); + if (other_player->nation == MAX_NUM_NATIONS) { + continue; } + packet.nations_used[packet.num_nations_used] = other_player->nation; + packet.num_nations_used++; } players_iterate_end; - lsend_packet_generic_values(&pplayer->connections, PACKET_SELECT_NATION, - &select_nation); + lsend_packet_nations_used(&pplayer->connections, &packet); } /**************************************************************************