diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/packhand.c freeciv-patched/client/packhand.c --- freeciv-cvs/client/packhand.c 2003-07-24 16:57:16.000000000 +0100 +++ freeciv-patched/client/packhand.c 2003-07-24 16:59:04.000000000 +0100 @@ -76,6 +76,16 @@ static int *reports_thaw_requests = NULL; static int reports_thaw_requests_size = 0; +/* Keeps track of whether we are in a turn update or not. This is used by + * the city packet handling routines to decide whether to update improvement + * effects immediately on receiving new improvements, or to defer the update + * until the start of the turn. */ +static enum { + EU_BEFORE_YEAR, + EU_UPDATE_DEFERRED, + EU_WITHIN_YEAR +} effect_update_state = EU_BEFORE_YEAR; + /************************************************************************** Unpackage the unit information into a newly allocated unit structure. **************************************************************************/ @@ -120,6 +130,9 @@ char msg[MAX_LEN_MSG]; char *s_capability = aconnection.capability; + /* Defer all effect updates until the start of the first year */ + effect_update_state = EU_BEFORE_YEAR; + sz_strlcpy(aconnection.capability, packet->capability); close_connection_dialog(); @@ -271,15 +284,33 @@ static void try_update_effects(bool need_update) { if (need_update) { - /* nothing yet... */ + if (effect_update_state == EU_WITHIN_YEAR) { + update_all_effects(); + } else { + effect_update_state = EU_UPDATE_DEFERRED; + } } } /************************************************************************** + If any effect updates were deferred by try_update_effects(), update them +**************************************************************************/ +static void do_deferred_effect_updates(void) +{ + if (effect_update_state == EU_UPDATE_DEFERRED) { + update_all_effects(); + } + effect_update_state = EU_WITHIN_YEAR; +} + +/************************************************************************** ... **************************************************************************/ void handle_game_state(struct packet_generic_integer *packet) { + /* If any effect updates were deferred, update effects now */ + do_deferred_effect_updates(); + if (get_client_state() == CLIENT_SELECT_RACE_STATE && packet->value == CLIENT_GAME_RUNNING_STATE && game.player_ptr->nation == NO_NATION_SELECTED) { @@ -467,6 +498,8 @@ pcity->owner==game.player_idx && popup_new_cities) || packet->diplomat_investigate; + try_update_effects(need_effect_update); + if (city_is_new && !city_has_changed_owner) { agents_city_new(pcity); } else { @@ -474,8 +507,6 @@ } handle_city_packet_common(pcity, city_is_new, popup, packet->diplomat_investigate); - - try_update_effects(need_effect_update); } /************************************************************************** @@ -663,6 +694,8 @@ pcity->city_map[x][y] = C_TILE_EMPTY; } /* Dumb values */ + try_update_effects(need_effect_update); + if (city_is_new && !city_has_changed_owner) { agents_city_new(pcity); } else { @@ -675,8 +708,6 @@ if (update_descriptions && tile_visible_mapcanvas(pcity->x,pcity->y)) { queue_mapview_update(UPDATE_CITY_DESCRIPTIONS); } - - try_update_effects(need_effect_update); } /************************************************************************** @@ -684,6 +715,9 @@ **************************************************************************/ void handle_new_year(struct packet_new_year *ppacket) { + /* If any effect updates were deferred, update effects now */ + do_deferred_effect_updates(); + game.year = ppacket->year; /* * The turn was increased in handle_before_new_year() @@ -722,6 +756,9 @@ **************************************************************************/ void handle_before_new_year(void) { + /* Defer all effect updates until the start of the year */ + effect_update_state = EU_BEFORE_YEAR; + clear_notify_window(); /* * The local idea of the game turn is increased here since the @@ -740,6 +777,9 @@ **************************************************************************/ void handle_start_turn(void) { + /* If any effect updates were deferred, update effects now */ + do_deferred_effect_updates(); + agents_start_turn(); non_ai_unit_focus = FALSE;