diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-gtk/happiness.c freeciv-patched/client/gui-gtk/happiness.c --- freeciv-cvs/client/gui-gtk/happiness.c 2003-07-10 11:53:39.000000000 +0100 +++ freeciv-patched/client/gui-gtk/happiness.c 2003-07-24 16:59:50.000000000 +0100 @@ -78,8 +78,6 @@ *pdialog); static void happiness_dialog_update_units(struct happiness_dialog *pdialog); -static void happiness_dialog_update_wonders(struct happiness_dialog - *pdialog); /**************************************************************** ... @@ -199,7 +197,6 @@ happiness_dialog_update_luxury(pdialog); happiness_dialog_update_buildings(pdialog); happiness_dialog_update_units(pdialog); - happiness_dialog_update_wonders(pdialog); } /************************************************************************** @@ -275,59 +272,36 @@ } /************************************************************************** -... + Lists the buildings or Wonders that contribute to happiness **************************************************************************/ -static void happiness_dialog_update_buildings(struct happiness_dialog - *pdialog) +static void set_building_label(char *title, int improvs[B_LAST], + int numperline, char *linespacer, + struct city *pcity, GtkWidget *label) { int faces = 0; - char buf[512], *bptr = buf; - int nleft = sizeof(buf); - struct city *pcity = pdialog->pcity; - struct government *g = get_gov_pcity(pcity); + char buf[512], *bptr; + int nleft, i; + + nleft = sizeof(buf); + bptr = buf; - my_snprintf(bptr, nleft, _("Buildings: ")); + my_snprintf(bptr, nleft, title); bptr = end_of_strn(bptr, &nleft); - if (city_got_building(pcity, B_TEMPLE)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_TEMPLE)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_got_building(pcity, B_COURTHOUSE) && g->corruption_level == 0) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_COURTHOUSE)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_got_building(pcity, B_COLOSSEUM)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_COLOSSEUM)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - /* hack for eliminating gtk_set_line_wrap() -mck */ - if (faces > 2) { - /* sizeof("Buildings: ") */ - my_snprintf(bptr, nleft, _("\n ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_got_effect(pcity, B_CATHEDRAL)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_CATHEDRAL)); - bptr = end_of_strn(bptr, &nleft); - if (!city_got_building(pcity, B_CATHEDRAL)) { - my_snprintf(bptr, nleft, _("(")); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, get_improvement_name(B_MICHELANGELO)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(")")); + faces = 0; + for (i = 0;i < game.num_impr_types; i++) if (improvs[i]) { + /* hack for eliminating gtk_set_line_wrap() -mck */ + if (faces && faces % numperline == 0) { + my_snprintf(bptr, nleft, linespacer); bptr = end_of_strn(bptr, &nleft); } + faces++; + if (city_got_building(pcity,i)) { + my_snprintf(bptr, nleft, get_improvement_name(i)); + } else { + my_snprintf(bptr, nleft, _("(%s)"), get_improvement_name(i)); + } + bptr = end_of_strn(bptr, &nleft); my_snprintf(bptr, nleft, _(". ")); bptr = end_of_strn(bptr, &nleft); } @@ -337,7 +311,53 @@ bptr = end_of_strn(bptr, &nleft); } - gtk_set_label(pdialog->hlabels[BUILDINGS], buf); + gtk_set_label(label, buf); +} + +/************************************************************************** + Updates the lists of ordinary buildings and Wonders that affect the + number of happy/content citizens, using ruleset improvement effects +**************************************************************************/ +static void happiness_dialog_update_buildings(struct happiness_dialog + *pdialog) +{ + struct city *pcity = pdialog->pcity; + int i, improvs[B_LAST], forceimprovs[B_LAST]; + Impr_Type_id impr; + + for (i = 0; i < game.num_impr_types; i++) { + improvs[i] = forceimprovs[i] = FALSE; + } + + city_effects_iterate(iter, pcity) { + switch(iter.imeff->type) { + case EFT_MAKE_CONTENT: + case EFT_MAKE_CONTENT_PCT: + case EFT_MAKE_HAPPY: + impr = eff_iterator_get_improvement(&iter); + if (improvement_exists(impr)) { + improvs[impr] = TRUE; + } + break; + case EFT_FORCE_CONTENT: + case EFT_FORCE_CONTENT_PCT: + case EFT_FORCE_HAPPY: + impr = eff_iterator_get_improvement(&iter); + if (improvement_exists(impr)) { + forceimprovs[impr] = TRUE; + } + break; + default: + break; + } + } city_effects_iterate_end; + + set_building_label(_("Buildings: "), improvs, 3, + _("\n "), /* sizeof("Buildings: ") */ + pcity, pdialog->hlabels[BUILDINGS]); + set_building_label(_("Wonders: "), forceimprovs, 2, + _("\n "), /* sizeof("Wonders: ") */ + pcity, pdialog->hlabels[WONDERS]); } /************************************************************************** @@ -384,62 +404,6 @@ /************************************************************************** ... **************************************************************************/ -static void happiness_dialog_update_wonders(struct happiness_dialog - *pdialog) -{ - int faces = 0; - char buf[512], *bptr = buf; - int nleft = sizeof(buf); - struct city *pcity = pdialog->pcity; - - my_snprintf(bptr, nleft, _("Wonders: ")); - bptr = end_of_strn(bptr, &nleft); - - if (city_affected_by_wonder(pcity, B_HANGING)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_HANGING)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_affected_by_wonder(pcity, B_BACH)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_BACH)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - /* hack for eliminating gtk_set_line_wrap() -mck */ - if (faces > 1) { - /* sizeof("Wonders: ") */ - my_snprintf(bptr, nleft, _("\n ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_SHAKESPEARE)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_affected_by_wonder(pcity, B_CURE)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_CURE)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - - if (faces == 0) { - my_snprintf(bptr, nleft, _("None. ")); - } - - gtk_set_label(pdialog->hlabels[WONDERS], buf); -} - -/************************************************************************** -... -**************************************************************************/ GtkWidget *get_top_happiness_display(struct city *pcity) { return create_happiness_dialog(pcity)->shell; diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-gtk-2.0/happiness.c freeciv-patched/client/gui-gtk-2.0/happiness.c --- freeciv-cvs/client/gui-gtk-2.0/happiness.c 2003-07-10 11:53:39.000000000 +0100 +++ freeciv-patched/client/gui-gtk-2.0/happiness.c 2003-07-24 16:59:50.000000000 +0100 @@ -77,8 +77,6 @@ *pdialog); static void happiness_dialog_update_units(struct happiness_dialog *pdialog); -static void happiness_dialog_update_wonders(struct happiness_dialog - *pdialog); /**************************************************************** ... @@ -193,7 +191,6 @@ happiness_dialog_update_luxury(pdialog); happiness_dialog_update_buildings(pdialog); happiness_dialog_update_units(pdialog); - happiness_dialog_update_wonders(pdialog); } /************************************************************************** @@ -269,59 +266,36 @@ } /************************************************************************** -... + Lists the buildings or Wonders that contribute to happiness **************************************************************************/ -static void happiness_dialog_update_buildings(struct happiness_dialog - *pdialog) +static void set_building_label(char *title, int improvs[B_LAST], + int numperline, char *linespacer, + struct city *pcity, GtkWidget *label) { int faces = 0; - char buf[512], *bptr = buf; - int nleft = sizeof(buf); - struct city *pcity = pdialog->pcity; - struct government *g = get_gov_pcity(pcity); + char buf[512], *bptr; + int nleft, i; + + nleft = sizeof(buf); + bptr = buf; - my_snprintf(bptr, nleft, _("Buildings: ")); + my_snprintf(bptr, nleft, title); bptr = end_of_strn(bptr, &nleft); - if (city_got_building(pcity, B_TEMPLE)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_TEMPLE)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_got_building(pcity, B_COURTHOUSE) && g->corruption_level == 0) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_COURTHOUSE)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_got_building(pcity, B_COLOSSEUM)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_COLOSSEUM)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - /* hack for eliminating gtk_set_line_wrap() -mck */ - if (faces > 2) { - /* sizeof("Buildings: ") */ - my_snprintf(bptr, nleft, _("\n ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_got_effect(pcity, B_CATHEDRAL)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_CATHEDRAL)); - bptr = end_of_strn(bptr, &nleft); - if (!city_got_building(pcity, B_CATHEDRAL)) { - my_snprintf(bptr, nleft, _("(")); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, get_improvement_name(B_MICHELANGELO)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(")")); + faces = 0; + for (i = 0;i < game.num_impr_types; i++) if (improvs[i]) { + /* hack for eliminating gtk_set_line_wrap() -mck */ + if (faces && faces % numperline == 0) { + my_snprintf(bptr, nleft, linespacer); bptr = end_of_strn(bptr, &nleft); } + faces++; + if (city_got_building(pcity,i)) { + my_snprintf(bptr, nleft, get_improvement_name(i)); + } else { + my_snprintf(bptr, nleft, _("(%s)"), get_improvement_name(i)); + } + bptr = end_of_strn(bptr, &nleft); my_snprintf(bptr, nleft, _(". ")); bptr = end_of_strn(bptr, &nleft); } @@ -331,7 +305,53 @@ bptr = end_of_strn(bptr, &nleft); } - gtk_label_set_text(GTK_LABEL(pdialog->hlabels[BUILDINGS]), buf); + gtk_set_label(label, buf); +} + +/************************************************************************** + Updates the lists of ordinary buildings and Wonders that affect the + number of happy/content citizens, using ruleset improvement effects +**************************************************************************/ +static void happiness_dialog_update_buildings(struct happiness_dialog + *pdialog) +{ + struct city *pcity = pdialog->pcity; + int i, improvs[B_LAST], forceimprovs[B_LAST]; + Impr_Type_id impr; + + for (i = 0; i < game.num_impr_types; i++) { + improvs[i] = forceimprovs[i] = FALSE; + } + + city_effects_iterate(iter, pcity) { + switch(iter.imeff->type) { + case EFT_MAKE_CONTENT: + case EFT_MAKE_CONTENT_PCT: + case EFT_MAKE_HAPPY: + impr = eff_iterator_get_improvement(&iter); + if (improvement_exists(impr)) { + improvs[impr] = TRUE; + } + break; + case EFT_FORCE_CONTENT: + case EFT_FORCE_CONTENT_PCT: + case EFT_FORCE_HAPPY: + impr = eff_iterator_get_improvement(&iter); + if (improvement_exists(impr)) { + forceimprovs[impr] = TRUE; + } + break; + default: + break; + } + } city_effects_iterate_end; + + set_building_label(_("Buildings: "), improvs, 3, + _("\n "), /* sizeof("Buildings: ") */ + pcity, pdialog->hlabels[BUILDINGS]); + set_building_label(_("Wonders: "), forceimprovs, 2, + _("\n "), /* sizeof("Wonders: ") */ + pcity, pdialog->hlabels[WONDERS]); } /************************************************************************** @@ -378,62 +398,6 @@ /************************************************************************** ... **************************************************************************/ -static void happiness_dialog_update_wonders(struct happiness_dialog - *pdialog) -{ - int faces = 0; - char buf[512], *bptr = buf; - int nleft = sizeof(buf); - struct city *pcity = pdialog->pcity; - - my_snprintf(bptr, nleft, _("Wonders: ")); - bptr = end_of_strn(bptr, &nleft); - - if (city_affected_by_wonder(pcity, B_HANGING)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_HANGING)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_affected_by_wonder(pcity, B_BACH)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_BACH)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - /* hack for eliminating gtk_set_line_wrap() -mck */ - if (faces > 1) { - /* sizeof("Wonders: ") */ - my_snprintf(bptr, nleft, _("\n ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_SHAKESPEARE)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - if (city_affected_by_wonder(pcity, B_CURE)) { - faces++; - my_snprintf(bptr, nleft, get_improvement_name(B_CURE)); - bptr = end_of_strn(bptr, &nleft); - my_snprintf(bptr, nleft, _(". ")); - bptr = end_of_strn(bptr, &nleft); - } - - if (faces == 0) { - my_snprintf(bptr, nleft, _("None. ")); - } - - gtk_label_set_text(GTK_LABEL(pdialog->hlabels[WONDERS]), buf); -} - -/************************************************************************** -... -**************************************************************************/ GtkWidget *get_top_happiness_display(struct city *pcity) { return create_happiness_dialog(pcity)->shell;