? a.c ? diff Index: client/civclient.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v retrieving revision 1.107 diff -u -r1.107 civclient.c --- client/civclient.c 2002/02/02 10:01:29 1.107 +++ client/civclient.c 2002/02/03 14:54:07 @@ -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.209 diff -u -r1.209 packhand.c --- client/packhand.c 2002/02/02 09:21:31 1.209 +++ client/packhand.c 2002/02/03 14:54:08 @@ -1620,23 +1620,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.22 diff -u -r1.22 packhand.h --- client/packhand.h 2001/12/09 16:02:11 1.22 +++ client/packhand.h 2002/02/03 14:54:08 @@ -22,7 +22,7 @@ void handle_conn_info(struct packet_conn_info *packet); void handle_game_info(struct packet_game_info *packet); 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.80 diff -u -r1.80 dialogs.c --- client/gui-gtk/dialogs.c 2001/12/21 16:26:38 1.80 +++ client/gui-gtk/dialogs.c 2002/02/03 14:54:10 @@ -2094,38 +2094,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.36 diff -u -r1.36 dialogs.c --- client/gui-mui/dialogs.c 2002/01/09 18:44:47 1.36 +++ client/gui-mui/dialogs.c 2002/02/03 14:54:12 @@ -1827,35 +1827,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.9 diff -u -r1.9 dialogs.c --- client/gui-win32/dialogs.c 2001/12/21 16:26:39 1.9 +++ client/gui-win32/dialogs.c 2002/02/03 14:54:13 @@ -798,41 +798,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.59 diff -u -r1.59 dialogs.c --- client/gui-xaw/dialogs.c 2001/12/21 16:26:40 1.59 +++ client/gui-xaw/dialogs.c 2002/02/03 14:54:14 @@ -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; + } + } +} /**************************************************************** ... @@ -2078,6 +2093,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/gui-xaw/spaceshipdlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/spaceshipdlg.c,v retrieving revision 1.15 diff -u -r1.15 spaceshipdlg.c --- client/gui-xaw/spaceshipdlg.c 2002/02/02 14:07:36 1.15 +++ client/gui-xaw/spaceshipdlg.c 2002/02/03 14:54:15 @@ -56,6 +56,7 @@ #include "mapview.h" #include "repodlgs.h" #include "tilespec.h" +#include "climisc.h" #include "spaceshipdlg.h" Index: client/include/dialogs_g.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/include/dialogs_g.h,v retrieving revision 1.7 diff -u -r1.7 dialogs_g.h --- client/include/dialogs_g.h 2000/04/16 14:35:42 1.7 +++ client/include/dialogs_g.h 2002/02/03 14:54:15 @@ -16,6 +16,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); @@ -25,7 +26,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.92 diff -u -r1.92 capstr.c --- common/capstr.c 2002/02/02 08:57:37 1.92 +++ common/capstr.c 2002/02/03 14:54:15 @@ -72,7 +72,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" +" short_worklists tech_cost_style short_city_tile_trade +new_nation_selection" /* "+1.11.6" is protocol for 1.11.6 beta release. @@ -113,6 +113,9 @@ "short_city_tile_trade" sends the tile trade in the short_city packet. + + "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.171 diff -u -r1.171 packets.c --- common/packets.c 2002/02/02 08:57:37 1.171 +++ common/packets.c 2002/02/03 14:54:18 @@ -367,6 +367,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: @@ -376,7 +377,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: @@ -4189,6 +4190,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.101 diff -u -r1.101 packets.h --- common/packets.h 2002/02/02 08:57:38 1.101 +++ common/packets.h 2002/02/03 14:54:18 @@ -125,6 +125,7 @@ PACKET_PROCESSING_STARTED, PACKET_PROCESSING_FINISHED, PACKET_START_TURN, + PACKET_SELECT_NATION_OK, PACKET_LAST /* leave this last */ }; @@ -882,6 +883,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); @@ -1103,6 +1112,11 @@ int send_packet_generic_empty(struct connection *pc, int 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.8 diff -u -r1.8 packets_lsend.c --- common/packets_lsend.c 2002/02/01 13:28:33 1.8 +++ common/packets_lsend.c 2002/02/03 14:54:18 @@ -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.7 diff -u -r1.7 packets_lsend.h --- common/packets_lsend.h 2002/02/01 13:28:34 1.7 +++ common/packets_lsend.h 2002/02/03 14:54:18 @@ -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, int 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.55 diff -u -r1.55 srv_main.c --- server/srv_main.c 2002/01/23 08:58:29 1.55 +++ server/srv_main.c 2002/02/03 14:54:20 @@ -912,7 +912,6 @@ struct packet_alloc_nation *packet) { int i, 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); @@ -989,28 +987,24 @@ } /************************************************************************** -Send request to select nation, mask1, mask2 contains those that were -already selected and are not available + Sends the collected selected nations to the given player. **************************************************************************/ static void send_select_nation(struct player *pplayer) { int i; - struct packet_generic_values select_nation; - - select_nation.value1=0; /* assume int is 32 bit, safe */ - select_nation.value2=0; - - /* set bits in mask corresponding to nations already selected by others */ - for( i=0; iconnections, PACKET_SELECT_NATION, - &select_nation); + lsend_packet_nations_used(&pplayer->connections, &packet); } /**************************************************************************