diff -Nurd -X clean/diff_ignore clean/client/Makefile.am work/client/Makefile.am --- clean/client/Makefile.am Thu Mar 14 17:55:16 2002 +++ work/client/Makefile.am Thu Mar 14 17:15:27 2002 @@ -128,6 +128,8 @@ packhand.h \ options.c \ options.h \ + repodlgs_common.c \ + repodlgs_common.h \ tilespec.c \ tilespec.h diff -Nurd -X clean/diff_ignore clean/client/gui-gtk/repodlgs.c work/client/gui-gtk/repodlgs.c --- clean/client/gui-gtk/repodlgs.c Thu Mar 14 17:55:16 2002 +++ work/client/gui-gtk/repodlgs.c Thu Mar 14 17:36:34 2002 @@ -39,6 +39,7 @@ #include "helpdlg.h" #include "optiondlg.h" +#include "repodlgs_common.h" #include "repodlgs.h" /******************************************************************/ @@ -720,56 +721,37 @@ { if(delay_report_update) return; if(economy_dialog_shell) { - int k, count, tax, cost, total; + int tax, total, i, entries_used; char buf0 [64]; char buf1 [64]; char buf2 [64]; char buf3 [64]; gchar *row [4]; char economy_total[48]; - struct city *pcity; - + struct improvement_entry entries[B_LAST]; + gtk_clist_freeze(GTK_CLIST(economy_list)); gtk_clist_clear(GTK_CLIST(economy_list)); - total = 0; - tax=0; - k = 0; row[0] = buf0; row[1] = buf1; row[2] = buf2; row[3] = buf3; - pcity = city_list_get(&game.player_ptr->cities,0); - if(pcity) { - impr_type_iterate(j) { - if(!is_wonder(j)) { - count = 0; - city_list_iterate(game.player_ptr->cities, pcity) - if (city_got_building(pcity, j)) count++; - city_list_iterate_end; - if (!count) continue; - cost = count * improvement_upkeep(pcity, j); - my_snprintf(buf0, sizeof(buf0), "%-20s", get_improvement_name(j)); - my_snprintf(buf1, sizeof(buf1), "%5d", count); - my_snprintf(buf2, sizeof(buf2), "%5d", improvement_upkeep(pcity, j)); - my_snprintf(buf3, sizeof(buf3), "%6d", cost); + get_economy_report_data(entries, &entries_used, &total, &tax); - gtk_clist_append(GTK_CLIST(economy_list), row); + for (i = 0; i < entries_used; i++) { + struct improvement_entry *p = &entries[i]; - total += cost; - economy_improvement_type[k] = j; - k++; - } - city_list_iterate(game.player_ptr->cities,pcity) { - tax += pcity->tax_total; - if (!pcity->is_building_unit && - pcity->currently_building == B_CAPITAL) { - tax += pcity->shield_surplus; - } - } city_list_iterate_end; - } impr_type_iterate_end; - } + my_snprintf(buf0, sizeof(buf0), "%-20s", get_improvement_name(p->type)); + my_snprintf(buf1, sizeof(buf1), "%5d", p->count); + my_snprintf(buf2, sizeof(buf2), "%5d", p->cost); + my_snprintf(buf3, sizeof(buf3), "%6d", p->total_cost); + + gtk_clist_append(GTK_CLIST(economy_list), row); + + economy_improvement_type[i] = p->type; + } my_snprintf(economy_total, sizeof(economy_total), _("Income:%6d Total Costs: %6d"), tax, total); @@ -777,8 +759,7 @@ gtk_widget_show_all(economy_list); gtk_clist_thaw(GTK_CLIST(economy_list)); - } - + } } /**************************************************************** diff -Nurd -X clean/diff_ignore clean/client/gui-gtk-2.0/repodlgs.c work/client/gui-gtk-2.0/repodlgs.c --- clean/client/gui-gtk-2.0/repodlgs.c Tue Mar 12 00:19:27 2002 +++ work/client/gui-gtk-2.0/repodlgs.c Thu Mar 14 18:33:29 2002 @@ -39,6 +39,7 @@ #include "helpdlg.h" #include "optiondlg.h" +#include "repodlgs_common.h" #include "repodlgs.h" /******************************************************************/ @@ -716,56 +717,37 @@ { if(delay_report_update) return; if(economy_dialog_shell) { - int k, count, tax, cost, total; + int tax, total, i, entries_used; char buf0 [64]; char buf1 [64]; char buf2 [64]; char buf3 [64]; gchar *row [4]; char economy_total[48]; - struct city *pcity; - + struct improvement_entry entries[B_LAST]; + gtk_clist_freeze(GTK_CLIST(economy_list)); gtk_clist_clear(GTK_CLIST(economy_list)); - total = 0; - tax=0; - k = 0; row[0] = buf0; row[1] = buf1; row[2] = buf2; row[3] = buf3; - pcity = city_list_get(&game.player_ptr->cities,0); - if(pcity) { - impr_type_iterate(j) { - if(!is_wonder(j)) { - count = 0; - city_list_iterate(game.player_ptr->cities, pcity) - if (city_got_building(pcity, j)) count++; - city_list_iterate_end; - if (!count) continue; - cost = count * improvement_upkeep(pcity, j); - my_snprintf(buf0, sizeof(buf0), "%-20s", get_improvement_name(j)); - my_snprintf(buf1, sizeof(buf1), "%5d", count); - my_snprintf(buf2, sizeof(buf2), "%5d", improvement_upkeep(pcity, j)); - my_snprintf(buf3, sizeof(buf3), "%6d", cost); + get_economy_report_data(entries, &entries_used, &total, &tax); - gtk_clist_append(GTK_CLIST(economy_list), row); + for (i = 0; i < entries_used; i++) { + struct improvement_entry *p = &entries[i]; - total += cost; - economy_improvement_type[k] = j; - k++; - } - city_list_iterate(game.player_ptr->cities,pcity) { - tax += pcity->tax_total; - if (!pcity->is_building_unit && - pcity->currently_building == B_CAPITAL) { - tax += pcity->shield_surplus; - } - } city_list_iterate_end; - } impr_type_iterate_end; - } + my_snprintf(buf0, sizeof(buf0), "%-20s", get_improvement_name(p->type)); + my_snprintf(buf1, sizeof(buf1), "%5d", p->count); + my_snprintf(buf2, sizeof(buf2), "%5d", p->cost); + my_snprintf(buf3, sizeof(buf3), "%6d", p->total_cost); + + gtk_clist_append(GTK_CLIST(economy_list), row); + + economy_improvement_type[i] = p->type; + } my_snprintf(economy_total, sizeof(economy_total), _("Income:%6d Total Costs: %6d"), tax, total); @@ -773,8 +755,7 @@ gtk_widget_show_all(economy_list); gtk_clist_thaw(GTK_CLIST(economy_list)); - } - + } } /**************************************************************** diff -Nurd -X clean/diff_ignore clean/client/gui-mui/repodlgs.c work/client/gui-mui/repodlgs.c --- clean/client/gui-mui/repodlgs.c Thu Mar 14 17:55:16 2002 +++ work/client/gui-mui/repodlgs.c Thu Mar 14 17:36:52 2002 @@ -41,6 +41,7 @@ #include "helpdlg.h" #include "gui_main.h" #include "repodlgs.h" +#include "repodlgs_common.h" /* Amiga Client stuff */ @@ -439,13 +440,6 @@ ****************************************************************/ -struct trade_imprv_entry -{ - int type; - int count; - struct city *pcity; -}; - static Object *trade_wnd; static Object *trade_title_text; static Object *trade_imprv_listview; @@ -460,9 +454,9 @@ /**************************************************************** Constructor of a new entry in the trade listview *****************************************************************/ -HOOKPROTONHNO(trade_imprv_construct, struct trade_imprv_entry *, struct trade_imprv_entry *entry) +HOOKPROTONHNO(trade_imprv_construct, struct improvement_entry *, struct improvement_entry *entry) { - struct trade_imprv_entry *newentry = (struct trade_imprv_entry *) AllocVec(sizeof(*newentry), 0); + struct improvement_entry *newentry = (struct improvement_entry *) AllocVec(sizeof(*newentry), 0); if (newentry) { *newentry = *entry; @@ -473,7 +467,7 @@ /**************************************************************** Destructor of a entry in the trades listview *****************************************************************/ -HOOKPROTONHNO(trade_imprv_destruct, void, struct trade_imprv_entry *entry) +HOOKPROTONHNO(trade_imprv_destruct, void, struct improvement_entry *entry) { FreeVec(entry); } @@ -481,7 +475,7 @@ /**************************************************************** Display function for the trade listview *****************************************************************/ -HOOKPROTONH(trade_imprv_render, void, char **array, struct trade_imprv_entry *entry) +HOOKPROTONH(trade_imprv_render, void, char **array, struct improvement_entry *entry) { if (entry) { @@ -489,15 +483,11 @@ static char coststr[16]; static char utotal[16]; - struct city *pcity = entry->pcity; - int j = entry->type; - int cost = entry->count * improvement_upkeep(pcity, j); - my_snprintf(count, sizeof(count), "%5d", entry->count); - my_snprintf(coststr, sizeof(coststr), "%5d", improvement_upkeep(pcity, j)); - my_snprintf(utotal, sizeof(utotal), "%6d", cost); + my_snprintf(coststr, sizeof(coststr), "%5d", entry->cost); + my_snprintf(utotal, sizeof(utotal), "%6d", entry->total_cost); - *array++ = get_improvement_name(j); + *array++ = get_improvement_name(entry->type); *array++ = count; *array++ = coststr; *array = utotal; @@ -530,11 +520,11 @@ *****************************************************************/ static void trade_sell(int *data) { - struct trade_imprv_entry *entry; + struct improvement_entry *entry; DoMethod(trade_imprv_listview, MUIM_NList_GetEntry, MUIV_NList_GetEntry_Active, &entry); if (entry) { - int i = entry->type; + Impr_Type_id i = entry->type; int count = 0, gold = 0; char str[128]; @@ -618,8 +608,7 @@ { int tax, total; char *report_title; - struct city *pcity; - struct trade_imprv_entry entry; + struct improvement_entry entries[B_LAST]; if (delay_report_update) return; @@ -635,39 +624,12 @@ set(trade_imprv_listview, MUIA_NList_Quiet, TRUE); DoMethod(trade_imprv_listview, MUIM_NList_Clear); - total = tax = 0; - - if ((pcity = city_list_get(&game.player_ptr->cities, 0))) - { - impr_type_iterate(j) { - if (!is_wonder(j)) - { - int cost, count = 0; - city_list_iterate(game.player_ptr->cities, pcity) - if (city_got_building(pcity, j)) - count++; - city_list_iterate_end; - - if (!count) - continue; - cost = count * improvement_upkeep(pcity, j); - - entry.type = j; - entry.count = count; - entry.pcity = pcity; - - DoMethod(trade_imprv_listview, MUIM_NList_InsertSingle, &entry, MUIV_NList_Insert_Bottom); - - total += cost; - } - } impr_type_iterate_end; + get_economy_report_data(entries, &entries_used, &total, &tax); - city_list_iterate(game.player_ptr->cities, pcity) - tax += pcity->tax_total; - if (!pcity->is_building_unit && pcity->currently_building == B_CAPITAL) - tax += pcity->shield_surplus; - city_list_iterate_end; + for (i = 0; i < entries_used; i++) { + DoMethod(trade_imprv_listview, MUIM_NList_InsertSingle, &entries[i], + MUIV_NList_Insert_Bottom); } set(trade_imprv_listview, MUIA_NList_Quiet, FALSE); diff -Nurd -X clean/diff_ignore clean/client/gui-stub/repodlgs.c work/client/gui-stub/repodlgs.c --- clean/client/gui-stub/repodlgs.c Thu Mar 14 17:55:16 2002 +++ work/client/gui-stub/repodlgs.c Thu Mar 14 17:32:58 2002 @@ -3,7 +3,7 @@ #include #include "repodlgs.h" - +#include "repodlgs_common.h" void report_update_delay_on(void) diff -Nurd -X clean/diff_ignore clean/client/gui-win32/repodlgs.c work/client/gui-win32/repodlgs.c --- clean/client/gui-win32/repodlgs.c Thu Mar 14 17:55:16 2002 +++ work/client/gui-win32/repodlgs.c Thu Mar 14 17:36:38 2002 @@ -315,7 +315,7 @@ { HWND lv; - int j, k, count, tax, cost, total; + int tax, total, i, entries_used; char *report_title; char buf0 [64]; char buf1 [64]; @@ -323,7 +323,8 @@ char buf3 [64]; char *row[4]; char economy_total[48]; - struct city *pcity; + struct improvement_entry entries[B_LAST]; + if(delay_report_update) return; if(!economy_dlg) return; lv=GetDlgItem(economy_dlg,ID_TRADEREP_LIST); @@ -331,42 +332,24 @@ SetWindowText(GetDlgItem(economy_dlg,ID_TRADEREP_TOP), report_title); ListView_DeleteAllItems(lv); - total = 0; - tax=0; - k = 0; row[0] = buf0; row[1] = buf1; row[2] = buf2; row[3] = buf3; - pcity = city_list_get(&game.player_ptr->cities,0); - if(pcity) { - impr_type_iterate(j) { - if(!is_wonder(j)) { - count = 0; - city_list_iterate(game.player_ptr->cities,pcity) - if (city_got_building(pcity, j)) count++; - city_list_iterate_end; - if (!count) continue; - cost = count * improvement_upkeep(pcity, j); - my_snprintf( buf0, sizeof(buf0), "%s", get_improvement_name(j) ); - my_snprintf( buf1, sizeof(buf1), "%5d", count ); - my_snprintf( buf2, sizeof(buf2), "%5d", improvement_upkeep(pcity, j) ); - my_snprintf( buf3, sizeof(buf3), "%6d", cost ); - fcwin_listview_add_row(lv,k,4,row); - - - total+=cost; - economy_improvement_type[k]=j; - k++; - } - city_list_iterate(game.player_ptr->cities,pcity) { - tax+=pcity->tax_total; - if (!pcity->is_building_unit && - pcity->currently_building==B_CAPITAL) - tax+=pcity->shield_surplus; - } city_list_iterate_end; - } impr_type_iterate_end; + get_economy_report_data(entries, &entries_used, &total, &tax); + + for (i = 0; i < entries_used; i++) { + struct improvement_entry *p = &entries[i]; + + my_snprintf(buf0, sizeof(buf0), "%s", get_improvement_name(p->type)); + my_snprintf(buf1, sizeof(buf1), "%5d", p->count); + my_snprintf(buf2, sizeof(buf2), "%5d", p->cost); + my_snprintf(buf3, sizeof(buf3), "%6d", p->total_cost); + + fcwin_listview_add_row(lv, k, 4, row); + + economy_improvement_type[i] = p->type; } my_snprintf(economy_total, sizeof(economy_total), _("Income:%6d Total Costs: %6d"), tax, total); diff -Nurd -X clean/diff_ignore clean/client/gui-xaw/repodlgs.c work/client/gui-xaw/repodlgs.c --- clean/client/gui-xaw/repodlgs.c Thu Mar 14 17:55:16 2002 +++ work/client/gui-xaw/repodlgs.c Thu Mar 14 17:50:54 2002 @@ -51,6 +51,7 @@ #include "optiondlg.h" #include "repodlgs.h" +#include "repodlgs_common.h" /******************************************************************/ @@ -778,56 +779,37 @@ { if(delay_report_update) return; if(economy_dialog_shell) { - int k, count, tax, cost, total; + int i, entries_used, tax, total; Dimension width; static char *economy_list_names_ptrs[B_LAST+1]; static char economy_list_names[B_LAST][200]; char *report_title; char economy_total[48]; - struct city *pcity; + struct improvement_entry entries[B_LAST]; report_title=get_report_title(_("Economy")); xaw_set_label(economy_label, report_title); free(report_title); - total = 0; - tax=0; - k = 0; - pcity = city_list_get(&game.player_ptr->cities,0); - if(pcity) { - impr_type_iterate(j) { - if(!is_wonder(j)) { - count = 0; - city_list_iterate(game.player_ptr->cities,pcity) { - if (city_got_building(pcity, j)) count++; - } city_list_iterate_end; - if (!count) continue; - cost = count * improvement_upkeep(pcity, j); - my_snprintf(economy_list_names[k], sizeof(economy_list_names[k]), - "%-20s%5d%5d%6d", get_improvement_name(j), - count, improvement_upkeep(pcity, j), cost); - total += cost; - economy_list_names_ptrs[k] = economy_list_names[k]; - economy_improvement_type[k] = j; - k++; - } - } impr_type_iterate_end; - city_list_iterate(game.player_ptr->cities,pcity) { - tax += pcity->tax_total; - if (!pcity->is_building_unit && - pcity->currently_building == B_CAPITAL) { - tax += pcity->shield_surplus; - } - } city_list_iterate_end; + get_economy_report_data(entries, &entries_used, &total, &tax); + + for (i = 0; i < entries_used; i++) { + struct improvement_entry *p = &entries[i]; + + my_snprintf(economy_list_names[i], sizeof(economy_list_names[i]), + "%-20s%5d%5d%6d", get_improvement_name(p->type), + p->count, p->cost, p->total_cost); + economy_list_names_ptrs[i] = economy_list_names[i]; + economy_improvement_type[i] = p->type; } - if(k==0) { + if (entries_used == 0) { sz_strlcpy(economy_list_names[0], " "); - economy_list_names_ptrs[0]=economy_list_names[0]; - k=1; + economy_list_names_ptrs[0] = economy_list_names[0]; + entries_used = 1; } - economy_list_names_ptrs[k]=NULL; + economy_list_names_ptrs[entries_used] = NULL; my_snprintf(economy_total, sizeof(economy_total), _("Income:%6d Total Costs: %6d"), tax, total); diff -Nurd -X clean/diff_ignore clean/client/repodlgs_common.c work/client/repodlgs_common.c --- clean/client/repodlgs_common.c Thu Jan 1 01:00:00 1970 +++ work/client/repodlgs_common.c Thu Mar 14 17:24:10 2002 @@ -0,0 +1,51 @@ + +#include "game.h" + +#include "repodlgs_common.h" + + +/**************************************************************** + Fills out the array of struct improvement_entry given by + entries. The array must be able to hold at least B_LAST entries. +*****************************************************************/ +void get_economy_report_data(struct improvement_entry *entries, + int *num_entries_used, int *total_cost, + int *total_income) +{ + *num_entries_used = 0; + *total_cost = 0; + + impr_type_iterate(j) { + if (!is_wonder(j)) { + int count = 0, cost = 0; + city_list_iterate(game.player_ptr->cities, pcity) { + if (city_got_building(pcity, j)) { + count++; + cost += improvement_upkeep(pcity, j); + } + } + city_list_iterate_end; + + if (count == 0) { + continue; + } + + entries[*num_entries_used].type = j; + entries[*num_entries_used].count = count; + entries[*num_entries_used].total_cost = cost; + entries[*num_entries_used].cost = cost / count; + (*num_entries_used)++; + + *total_cost += cost; + } + } impr_type_iterate_end; + + *total_income = 0; + + city_list_iterate(game.player_ptr->cities, pcity) { + *total_income += pcity->tax_total; + if (!pcity->is_building_unit && pcity->currently_building == B_CAPITAL) { + *total_income += pcity->shield_surplus; + } + } city_list_iterate_end; +} diff -Nurd -X clean/diff_ignore clean/client/repodlgs_common.h work/client/repodlgs_common.h --- clean/client/repodlgs_common.h Thu Jan 1 01:00:00 1970 +++ work/client/repodlgs_common.h Thu Mar 14 18:32:02 2002 @@ -0,0 +1,29 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifndef FC__REPODLGS_COMMON_H +#define FC__REPODLGS_COMMON_H + +#include "improvement.h" + +struct improvement_entry +{ + Impr_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); + +#endif /* FC__REPODLGS_COMMON_H */