Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.247 diff -u -r1.247 packhand.c --- client/packhand.c 2002/07/14 13:40:23 1.247 +++ client/packhand.c 2002/07/16 17:42:09 @@ -404,6 +404,7 @@ pcity->turn_last_built=packet->turn_last_built; pcity->turn_changed_target=packet->turn_changed_target; + pcity->turn_founded = packet->turn_founded; pcity->changed_from_id=packet->changed_from_id; pcity->changed_from_is_unit=packet->changed_from_is_unit; pcity->before_change_shields=packet->before_change_shields; @@ -615,7 +616,7 @@ pcity->currently_building = 0; init_worklist(&pcity->worklist); pcity->airlift = FALSE; - pcity->did_buy = 0; + pcity->did_buy = FALSE; pcity->did_sell = FALSE; pcity->was_happy = FALSE; Index: client/gui-gtk/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v retrieving revision 1.140 diff -u -r1.140 citydlg.c --- client/gui-gtk/citydlg.c 2002/06/19 02:18:00 1.140 +++ client/gui-gtk/citydlg.c 2002/07/16 17:42:11 @@ -3524,14 +3524,26 @@ } /************************************************************************ + Helper for switch_city_callback. +*************************************************************************/ +static int city_comp_by_turn_founded(const void *a, const void *b) +{ + struct city *pcity1 = *((struct city **) a); + struct city *pcity2 = *((struct city **) b); + + return pcity1->turn_founded - pcity2->turn_founded; +} + +/************************************************************************ Callback for the prev/next buttons. Switches to the previous/next city. *************************************************************************/ static void switch_city_callback(GtkWidget *w, gpointer data) { struct city_dialog *pdialog = (struct city_dialog *) data; - int i, j, dir, size = city_list_size(&game.player_ptr->cities); + int i, dir, non_open_size, size = city_list_size(&game.player_ptr->cities); struct city *new_pcity = NULL; + struct city **array; assert(city_dialogs_have_been_initialised); assert(size >= 1); @@ -3551,30 +3563,37 @@ dir = 1; } + array = fc_malloc(size * sizeof(struct city *)); + + non_open_size = 0; for (i = 0; i < size; i++) { - if (pdialog->pcity == city_list_get(&game.player_ptr->cities, i)) { - break; + struct city *other_pcity = city_list_get(&game.player_ptr->cities, i); + if (other_pcity == pdialog->pcity || !get_city_dialog(other_pcity)) { + array[non_open_size] = other_pcity; + non_open_size++; } } - assert(i < size); + assert(non_open_size > 0); - for (j = 1; j < size; j++) { - struct city *other_pcity = city_list_get(&game.player_ptr->cities, - (i + dir * j + size) % size); - struct city_dialog *other_pdialog = get_city_dialog(other_pcity); - - assert(other_pdialog != pdialog); - if (!other_pdialog) { - new_pcity = other_pcity; + if (non_open_size == 1) { + free(array); + return; + } + + qsort(array, non_open_size, sizeof(struct city *), + city_comp_by_turn_founded); + + for (i = 0; i < non_open_size; i++) { + if (pdialog->pcity == array[i]) { break; } } - if (!new_pcity) { - /* Every other city has an open city dialog. */ - return; - } + assert(i < non_open_size); + + new_pcity = array[(i + dir + non_open_size) % non_open_size]; + free(array); /* cleanup worklist and happiness dialogs */ if(pdialog->wl_editor->changed){ Index: common/capstr.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v retrieving revision 1.102 diff -u -r1.102 capstr.c --- common/capstr.c 2002/07/14 13:40:24 1.102 +++ common/capstr.c 2002/07/16 17:42:12 @@ -70,12 +70,14 @@ * are not directly related to the capability strings discussed here.) */ -#define CAPABILITY "+1.13.0 conn_info" +#define CAPABILITY "+1.13.0 conn_info turn_founded" /* "+1.13.0" is protocol for 1.13.0 release. "conn_info" is sending the conn_id field. To preserve compatability with old clients trying to connect this should persist across releases. + + "turn_founded" transfers turn_founded of struct city to the client. */ void init_our_capability(void) Index: common/city.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.h,v retrieving revision 1.110 diff -u -r1.110 city.h --- common/city.h 2002/07/15 17:06:22 1.110 +++ common/city.h 2002/07/16 17:42:12 @@ -266,7 +266,7 @@ struct unit_list units_supported; int steal; /* diplomats steal once; for spies, gets harder */ /* turn states */ - int did_buy; + bool did_buy; bool did_sell, is_updated; int turn_last_built; /* The last year in which something was built */ int turn_changed_target; /* Suffer shield loss at most once per turn */ @@ -284,6 +284,8 @@ /* server variable. indicates if the city map is synced with the client. */ bool synced; + + int turn_founded; /* In which turn was the city founded? */ /* info for dipl/spy investigation -- used only in client */ struct unit_list info_units_supported; Index: common/packets.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v retrieving revision 1.208 diff -u -r1.208 packets.c --- common/packets.c 2002/07/14 13:40:25 1.208 +++ common/packets.c 2002/07/16 17:42:15 @@ -2421,6 +2421,10 @@ /* only 8 options allowed before need to extend protocol */ cptr=put_uint8(cptr, req->city_options); + + if (has_capability("turn_founded", pc->capability)) { + cptr = put_uint32(cptr, req->turn_founded); + } for (data = 0; data < NUM_TRADEROUTES; data++) { if(req->trade[data] != 0) { @@ -2507,6 +2511,12 @@ sizeof(packet->improvements)); iget_uint8(&iter, &packet->city_options); + + if (has_capability("turn_founded", pc->capability)) { + iget_uint32(&iter, &packet->turn_founded); + } else { + packet->turn_founded = -1; + } for (data = 0; data < NUM_TRADEROUTES; data++) { if (pack_iter_remaining(&iter) < 3) Index: common/packets.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v retrieving revision 1.117 diff -u -r1.117 packets.h --- common/packets.h 2002/07/14 13:40:25 1.117 +++ common/packets.h 2002/07/16 17:42:15 @@ -365,6 +365,7 @@ bool airlift; bool diplomat_investigate; int city_options; + int turn_founded; }; Index: server/cityhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v retrieving revision 1.114 diff -u -r1.114 cityhand.c --- server/cityhand.c 2002/06/12 07:24:48 1.114 +++ server/cityhand.c 2002/07/16 17:42:16 @@ -230,15 +230,15 @@ assert(pcity && player_owns_city(pplayer, pcity)); - if (pcity->did_buy > 0) { + if (pcity->turn_founded == game.turn) { notify_player_ex(pplayer, pcity->x, pcity->y, E_NOEVENT, - _("Game: You have already bought this turn.")); + _("Game: Cannot buy in city created this turn.")); return; } - if (pcity->did_buy < 0) { + if (pcity->did_buy) { notify_player_ex(pplayer, pcity->x, pcity->y, E_NOEVENT, - _("Game: Cannot buy in city created this turn.")); + _("Game: You have already bought this turn.")); return; } @@ -281,7 +281,7 @@ * fully well add the missing shields there. */ pcity->disbanded_shields += total - pcity->shield_stock; pcity->shield_stock=total; /* AI wants this -- Syela */ - pcity->did_buy=1; /* !PS: no need to set buy flag otherwise */ + pcity->did_buy = TRUE; /* !PS: no need to set buy flag otherwise */ } city_refresh(pcity); @@ -360,7 +360,7 @@ return; if (!preq->is_build_id_unit_id && !can_build_improvement(pcity, preq->build_id)) return; - if (pcity->did_buy && pcity->shield_stock) { /* did_buy > 0 should be same -- Syela */ + if (pcity->did_buy && pcity->shield_stock) { notify_player_ex(pplayer, pcity->x, pcity->y, E_NOEVENT, _("Game: You have bought this turn, can't change.")); return; Index: server/citytools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v retrieving revision 1.183 diff -u -r1.183 citytools.c --- server/citytools.c 2002/07/03 07:59:02 1.183 +++ server/citytools.c 2002/07/16 17:42:17 @@ -604,8 +604,8 @@ if (city_got_building(pcity, B_AQUEDUCT) && pcity->size < game.sewer_size) return TRUE; if (!pcity->is_building_unit) { - if (pcity->currently_building == B_SEWER && pcity->did_buy == 1) return TRUE; - if (pcity->currently_building == B_AQUEDUCT && pcity->did_buy == 1) return TRUE; + if (pcity->currently_building == B_SEWER && pcity->did_buy) return TRUE; + if (pcity->currently_building == B_AQUEDUCT && pcity->did_buy) return TRUE; } /* saves a lot of stupid flipflops -- Syela */ return FALSE; } @@ -1026,7 +1026,8 @@ pcity->trade_prod=0; pcity->original = pplayer->player_no; pcity->is_building_unit = TRUE; - pcity->did_buy=-1; /* code so we get a different message */ + pcity->turn_founded = game.turn; + pcity->did_buy = TRUE; pcity->did_sell = FALSE; pcity->airlift = FALSE; pcity->currently_building=best_role_unit(pcity, L_FIRSTBUILD); @@ -1654,6 +1655,7 @@ packet->turn_last_built=pcity->turn_last_built; packet->turn_changed_target=pcity->turn_changed_target; + packet->turn_founded = pcity->turn_founded; packet->changed_from_id=pcity->changed_from_id; packet->changed_from_is_unit=pcity->changed_from_is_unit; packet->before_change_shields=pcity->before_change_shields; Index: server/cityturn.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v retrieving revision 1.193 diff -u -r1.193 cityturn.c --- server/cityturn.c 2002/07/11 13:42:22 1.193 +++ server/cityturn.c 2002/07/16 17:42:18 @@ -1297,7 +1297,7 @@ pcity->is_updated=TRUE; pcity->did_sell=FALSE; - pcity->did_buy=0; + pcity->did_buy = FALSE; if (city_got_building(pcity, B_AIRPORT)) pcity->airlift=TRUE; else Index: server/savegame.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v retrieving revision 1.83 diff -u -r1.83 savegame.c --- server/savegame.c 2002/07/15 19:31:01 1.83 +++ server/savegame.c 2002/07/16 17:42:20 @@ -769,8 +769,16 @@ secfile_lookup_int_default(file, 0, "player%d.c%d.caravan_shields", plrno, i); - pcity->did_buy=secfile_lookup_int(file, - "player%d.c%d.did_buy", plrno,i); + pcity->turn_founded = + secfile_lookup_int_default(file, -2, "player%d.c%d.turn_founded", + plrno, i); + + j = secfile_lookup_int(file, "player%d.c%d.did_buy", plrno, i); + pcity->did_buy = (i != 0); + if (j == -1 && pcity->turn_founded == -2) { + pcity->turn_founded = game.turn; + } + pcity->did_sell = secfile_lookup_bool_default(file, FALSE, "player%d.c%d.did_sell", plrno,i); @@ -1424,7 +1432,15 @@ secfile_insert_int(file, pcity->anarchy, "player%d.c%d.anarchy", plrno,i); secfile_insert_int(file, pcity->rapture, "player%d.c%d.rapture", plrno,i); secfile_insert_bool(file, pcity->was_happy, "player%d.c%d.was_happy", plrno,i); - secfile_insert_int(file, pcity->did_buy, "player%d.c%d.did_buy", plrno,i); + if (pcity->turn_founded == game.turn) { + j = -1; + } else { + assert(pcity->did_buy == TRUE || pcity->did_buy == FALSE); + j = pcity->did_buy; + } + secfile_insert_int(file, j, "player%d.c%d.did_buy", plrno, i); + secfile_insert_int(file, pcity->turn_founded, + "player%d.c%d.turn_founded", plrno, i); secfile_insert_bool(file, pcity->did_sell, "player%d.c%d.did_sell", plrno,i); secfile_insert_bool(file, pcity->airlift, "player%d.c%d.airlift", plrno,i);