Index: repodlgs_common.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.c,v retrieving revision 1.6 diff -u -r1.6 repodlgs_common.c --- repodlgs_common.c 4 Apr 2003 15:47:46 -0000 1.6 +++ repodlgs_common.c 2 Jul 2003 19:17:26 -0000 @@ -18,6 +18,7 @@ #include #include "game.h" +#include "government.h" #include "repodlgs_g.h" @@ -72,6 +73,53 @@ *total_income += MAX(0, pcity->shield_surplus); } } city_list_iterate_end; +} + +/****************************************************************** + Returns an array of units with gold_upkeep. Number of units in + the array is added to num_entries_used. +******************************************************************/ +void get_economy_report_units_data(struct unit_entry *entries, + int *num_entries_used, int *total_cost) +{ + int count, cost, partial_cost; + struct unit_type *unittype; + + unit_type_iterate(utype) { + unittype = get_unit_type(utype); + cost = utype_gold_cost(unittype, get_gov_pplayer(game.player_ptr)); + + if (cost == 0) { + continue; + } + + count = 0; + partial_cost = 0; + + city_list_iterate(game.player_ptr->cities, pcity) { + unit_list_iterate(pcity->units_supported, punit) { + + if (punit->type == utype) { + count++; + partial_cost += punit->upkeep_gold; + } + + } unit_list_iterate_end; + } city_list_iterate_end; + + if (count == 0) { + continue; + } + + (*total_cost) += partial_cost; + + entries[*num_entries_used].type = utype; + entries[*num_entries_used].count = count; + entries[*num_entries_used].cost = cost; + entries[*num_entries_used].total_cost = partial_cost; + (*num_entries_used)++; + + } unit_type_iterate_end; } static int frozen_level = 0; Index: repodlgs_common.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.h,v retrieving revision 1.2 diff -u -r1.2 repodlgs_common.h --- repodlgs_common.h 27 Jun 2002 00:59:12 -0000 1.2 +++ repodlgs_common.h 2 Jul 2003 19:17:26 -0000 @@ -15,6 +15,7 @@ #define FC__REPODLGS_COMMON_H #include "improvement.h" +#include "unittype.h" struct improvement_entry { @@ -22,9 +23,23 @@ int count, cost, total_cost; }; +struct unit_entry +{ + Unit_Type_id type; + int count, cost, total_cost; +}; + void get_economy_report_data(struct improvement_entry *entries, int *num_entries_used, int *total_cost, int *total_income); +/* This function returns an array with the gold upkeeped units. + * FIXME: Many clients doesn't yet use this function and show also only the + * buildings in the economy reports + * I think that there should be only one function which returns an array of + * char* arrays like some other common functions but that means updating all + * client simultaneously and I simply can't */ +void get_economy_report_units_data(struct unit_entry *entries, + int *num_entries_used, int *total_cost); void report_dialogs_freeze(void); void report_dialogs_thaw(void); Index: tilespec.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v retrieving revision 1.119 diff -u -r1.119 tilespec.c --- tilespec.c 30 Jun 2003 20:53:24 -0000 1.119 +++ tilespec.c 2 Jul 2003 19:17:26 -0000 @@ -920,6 +920,8 @@ SET_SPRITE(upkeep.food[1], "upkeep.food2"); SET_SPRITE(upkeep.unhappy[0], "upkeep.unhappy"); SET_SPRITE(upkeep.unhappy[1], "upkeep.unhappy2"); + SET_SPRITE(upkeep.gold[0], "upkeep.gold"); + SET_SPRITE(upkeep.gold[1], "upkeep.gold2"); SET_SPRITE(upkeep.shield, "upkeep.shield"); SET_SPRITE(user.attention, "user.attention"); Index: tilespec.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v retrieving revision 1.44 diff -u -r1.44 tilespec.h --- tilespec.h 9 Apr 2003 20:47:43 -0000 1.44 +++ tilespec.h 2 Jul 2003 19:17:27 -0000 @@ -158,6 +158,7 @@ struct Sprite *food[2], *unhappy[2], + *gold[2], *shield; } upkeep; struct { Index: gui-gtk/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v retrieving revision 1.170 diff -u -r1.170 mapview.c --- gui-gtk/mapview.c 14 May 2003 00:58:19 -0000 1.170 +++ gui-gtk/mapview.c 2 Jul 2003 19:17:27 -0000 @@ -947,25 +947,34 @@ gtk_pixcomm_changed(GTK_PIXCOMM(p)); } - /************************************************************************** - FIXME: - For now only two food, one shield and two masks can be drawn per unit, - the proper way to do this is probably something like what Civ II does. - (One food/shield/mask drawn N times, possibly one top of itself. -- SKi + FIXME: For now only two food, two golds, one shield and two masks can be + drawn per unit, the proper way to do this is probably something like + what Civ II does. (One food/shield/mask drawn N times, possibly one top + of itself.) **************************************************************************/ void put_unit_gpixmap_city_overlays(struct unit *punit, GtkPixcomm *p) { int upkeep_food = CLIP(0, punit->upkeep_food, 2); + int upkeep_gold = CLIP(0, punit->upkeep_gold, 2); int unhappy = CLIP(0, punit->unhappiness, 2); /* draw overlay pixmaps */ - if (punit->upkeep > 0) + if (punit->upkeep > 0) { put_overlay_tile_gpixmap(p, 0, NORMAL_TILE_HEIGHT, sprites.upkeep.shield); - if (upkeep_food > 0) - put_overlay_tile_gpixmap(p, 0, NORMAL_TILE_HEIGHT, sprites.upkeep.food[upkeep_food-1]); - if (unhappy > 0) - put_overlay_tile_gpixmap(p, 0, NORMAL_TILE_HEIGHT, sprites.upkeep.unhappy[unhappy-1]); + } + if (upkeep_food > 0) { + put_overlay_tile_gpixmap(p, 0, NORMAL_TILE_HEIGHT, + sprites.upkeep.food[upkeep_food-1]); + } + if (upkeep_gold > 0) { + put_overlay_tile_gpixmap(p, 0, NORMAL_TILE_HEIGHT, + sprites.upkeep.gold[upkeep_gold - 1]); + } + if (unhappy > 0) { + put_overlay_tile_gpixmap(p, 0, NORMAL_TILE_HEIGHT, + sprites.upkeep.unhappy[unhappy-1]); + } } /************************************************************************** Index: gui-gtk/repodlgs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/repodlgs.c,v retrieving revision 1.71 diff -u -r1.71 repodlgs.c --- gui-gtk/repodlgs.c 26 Jun 2003 23:03:12 -0000 1.71 +++ gui-gtk/repodlgs.c 2 Jul 2003 19:17:27 -0000 @@ -33,6 +33,7 @@ #include "civclient.h" #include "clinet.h" #include "repodlgs_common.h" +#include "control.h" #include "cityrep.h" #include "dialogs.h" @@ -67,7 +68,12 @@ static void economy_selloff_callback(GtkWidget * w, gpointer data); static void economy_list_callback(GtkWidget * w, gint row, gint column); static void economy_list_ucallback(GtkWidget * w, gint row, gint column); -static int economy_improvement_type[B_LAST]; + +struct economy_row { + int is_impr; + int type; +}; +static struct economy_row economy_row_type[B_LAST]; static GtkWidget *economy_dialog_shell = NULL; static GtkWidget *economy_label2; @@ -653,14 +659,19 @@ *****************************************************************/ void economy_list_callback(GtkWidget *w, gint row, gint column) { - int i = economy_improvement_type[row]; - bool is_sellable = (i >= 0 && i < game.num_impr_types && !is_wonder(i)); + int i = economy_row_type[row].type; + + if (economy_row_type[row].is_impr == TRUE) { + bool is_sellable = (i >= 0 && i < game.num_impr_types && !is_wonder(i)); - gtk_widget_set_sensitive(sellobsolete_command, is_sellable - && can_client_issue_orders() - && improvement_obsolete(game.player_ptr, i)); - gtk_widget_set_sensitive(sellall_command, is_sellable - && can_client_issue_orders()); + gtk_widget_set_sensitive(sellobsolete_command, is_sellable + && can_client_issue_orders() + && improvement_obsolete(game.player_ptr, i)); + gtk_widget_set_sensitive(sellall_command, is_sellable + && can_client_issue_orders()); + } else { + gtk_widget_set_sensitive(sellall_command, can_client_issue_orders()); + } } /**************************************************************** @@ -685,38 +696,64 @@ *****************************************************************/ void economy_selloff_callback(GtkWidget *w, gpointer data) { - int i,count=0,gold=0; + int count = 0, gold = 0; + struct economy_row row_type; struct packet_city_request packet; char str[64]; - GList *selection; - gint row; + GList *selection; + int row; while ((selection = GTK_CLIST(economy_list)->selection)) { row = GPOINTER_TO_INT(selection->data); - i=economy_improvement_type[row]; + row_type = economy_row_type[row]; + + if (row_type.is_impr == TRUE) { + city_list_iterate(game.player_ptr->cities, pcity) { + if (!pcity->did_sell && city_got_building(pcity, row_type.type) + && (data + || improvement_obsolete(game.player_ptr, row_type.type) + || wonder_replacement(pcity, row_type.type))) { + count++; + gold += improvement_value(row_type.type); + packet.city_id = pcity->id; + packet.build_id = row_type.type; + send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL); + } + } city_list_iterate_end; + + if (count) { + my_snprintf(str, sizeof(str), _("Sold %d %s for %d gold"), + count, get_improvement_name(row_type.type), gold); + } else { + my_snprintf(str, sizeof(str), _("No %s could be sold"), + get_improvement_name(row_type.type)); + } + } else { + city_list_iterate(game.player_ptr->cities, pcity) { + unit_list_iterate(pcity->units_supported, punit) { + /* We don't sell obsolete units when sell obsolete is clicked. + * Indeed, unlike improvements, obsolete units can fight like + * up-to-date ones */ + if (punit->type == row_type.type && data) { + count++; + request_unit_disband(punit); + } + } unit_list_iterate_end; + } city_list_iterate_end; + + if (count > 0) { + my_snprintf(str, sizeof(str), "Disbanded %d %s", count, + unit_name(row_type.type)); + } else { + my_snprintf(str, sizeof(str), "No %s could be disbanded", + unit_name(row_type.type)); + } + } + + gtk_clist_unselect_row(GTK_CLIST(economy_list), row, 0); + popup_notify_dialog(_("Sell-Off:"),_("Results"), str); - city_list_iterate(game.player_ptr->cities, pcity) { - if(!pcity->did_sell && city_got_building(pcity, i) && - (data || - improvement_obsolete(game.player_ptr,i) || - wonder_replacement(pcity, i) )) { - count++; gold+=improvement_value(i); - packet.city_id=pcity->id; - packet.build_id=i; - send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL); - } - } city_list_iterate_end; - - if(count) { - my_snprintf(str, sizeof(str), _("Sold %d %s for %d gold"), - count, get_improvement_name(i), gold); - } else { - my_snprintf(str, sizeof(str), _("No %s could be sold"), - get_improvement_name(i)); - } - gtk_clist_unselect_row(GTK_CLIST(economy_list),row,0); - popup_notify_dialog(_("Sell-Off:"),_("Results"),str); } return; } @@ -726,9 +763,11 @@ *****************************************************************/ void economy_report_dialog_update(void) { - if(is_report_dialogs_frozen()) return; - if(economy_dialog_shell) { - int tax, total, i, entries_used; + if (is_report_dialogs_frozen()) { + return; + } + if (economy_dialog_shell) { + int tax, total, i, entries_used, nbr_impr; char buf0 [64]; char buf1 [64]; char buf2 [64]; @@ -736,6 +775,7 @@ gchar *row [4]; char economy_total[48]; struct improvement_entry entries[B_LAST]; + struct unit_entry entries_units[U_LAST]; gtk_clist_freeze(GTK_CLIST(economy_list)); gtk_clist_clear(GTK_CLIST(economy_list)); @@ -757,7 +797,26 @@ gtk_clist_append(GTK_CLIST(economy_list), row); - economy_improvement_type[i] = p->type; + economy_row_type[i].is_impr = TRUE; + economy_row_type[i].type = p->type; + } + + nbr_impr = entries_used; + entries_used = 0; + get_economy_report_units_data(entries_units, &entries_used, &total); + + for (i = 0; i < entries_used; i++) { + my_snprintf(buf0, sizeof(buf0), "%-20s", + unit_name(entries_units[i].type)); + my_snprintf(buf1, sizeof(buf1), "%5d", entries_units[i].count); + my_snprintf(buf2, sizeof(buf2), "%5d", entries_units[i].cost); + my_snprintf(buf3, sizeof(buf3), "%6d", entries_units[i].total_cost); + + gtk_clist_append(GTK_CLIST(economy_list), row); + + economy_row_type[i + nbr_impr].is_impr = FALSE; + economy_row_type[i + nbr_impr].type = entries_units[i].type; + } my_snprintf(economy_total, sizeof(economy_total), @@ -775,7 +834,7 @@ ****************************************************************/ -#define AU_COL 6 +#define AU_COL 7 /**************************************************************** ... @@ -817,7 +876,7 @@ GtkWidget *close_command, *refresh_command; static const char *titles_[AU_COL] = { N_("Unit Type"), N_("U"), N_("In-Prog"), N_("Active"), - N_("Shield"), N_("Food") }; + N_("Shield"), N_("Food"), N_("Gold") }; static gchar **titles; int i; GtkAccelGroup *accel=gtk_accel_group_new(); @@ -975,7 +1034,7 @@ int active_count; int upkeep_shield; int upkeep_food; - /* int upkeep_gold; FIXME: add gold when gold is implemented --jjm */ + int upkeep_gold; int building_count; }; if(is_report_dialogs_frozen()) return; @@ -1000,6 +1059,7 @@ if (punit->homecity) { unitarray[punit->type].upkeep_shield += punit->upkeep; unitarray[punit->type].upkeep_food += punit->upkeep_food; + unitarray[punit->type].upkeep_gold += punit->upkeep_gold; } } unit_list_iterate_end; @@ -1021,6 +1081,7 @@ my_snprintf(buf[3], sizeof(buf[3]), "%9d", unitarray[i].active_count); my_snprintf(buf[4], sizeof(buf[4]), "%9d", unitarray[i].upkeep_shield); my_snprintf(buf[5], sizeof(buf[5]), "%9d", unitarray[i].upkeep_food); + my_snprintf(buf[6], sizeof(buf[6]), "%9d", unitarray[i].upkeep_gold); gtk_clist_append( GTK_CLIST( activeunits_list ), row ); @@ -1029,17 +1090,19 @@ unittotals.active_count += unitarray[i].active_count; unittotals.upkeep_shield += unitarray[i].upkeep_shield; unittotals.upkeep_food += unitarray[i].upkeep_food; + unittotals.upkeep_gold += unitarray[i].upkeep_gold; unittotals.building_count += unitarray[i].building_count; } } unit_type_iterate_end; /* horrible kluge, but I can't get gtk_label_set_justify() to work --jjm */ my_snprintf(activeunits_total, sizeof(activeunits_total), - _("Totals: %s%9d%s%9d%s%9d%s%9d"), + _("Totals: %s%9d%s%9d%s%9d%s%9d%s%9d"), " ", unittotals.building_count, " ", unittotals.active_count, " ", unittotals.upkeep_shield, - " ", unittotals.upkeep_food); + " ", unittotals.upkeep_food, + " ", unittotals.upkeep_gold); gtk_set_label(activeunits_label2, activeunits_total); gtk_widget_show_all(activeunits_list);