Index: ai/advdomestic.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v retrieving revision 1.81 diff -u -r1.81 advdomestic.c --- ai/advdomestic.c 2002/03/06 03:03:02 1.81 +++ ai/advdomestic.c 2002/03/06 11:14:16 @@ -499,11 +499,10 @@ if (is_wonder(id) && could_build_improvement(pcity, id) && !wonder_obsolete(id)&& is_wonder_useful(id)) { if (id == B_ASMITHS) { - impr_type_iterate(id2) { - if (city_got_building(pcity, id2) && - improvement_upkeep(pcity, id2) == 1) + city_impr_type_iterate(pcity, id2) { + if (improvement_upkeep(pcity, id2) == 1) values[id] += t; - } impr_type_iterate_end; + } city_impr_type_iterate_end; } if (id == B_COLLOSSUS) Index: ai/aicity.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v retrieving revision 1.107 diff -u -r1.107 aicity.c --- ai/aicity.c 2002/03/06 10:05:31 1.107 +++ ai/aicity.c 2002/03/06 11:14:16 @@ -748,9 +748,8 @@ { struct player *pplayer = city_owner(pcity); - impr_type_iterate(i) { - if(city_got_building(pcity, i) - && !is_wonder(i) + city_impr_type_iterate(pcity, i) { + if(!is_wonder(i) && i != B_CITY /* selling city walls is really, really dumb -- Syela */ && (wonder_replacement(pcity, i) || building_unwanted(city_owner(pcity), i))) { do_sell_building(pplayer, pcity, i); @@ -760,7 +759,7 @@ improvement_value(i)/2); return; /* max 1 building each turn */ } - } impr_type_iterate_end; + } city_impr_type_iterate_end; } /************************************************************************** Index: ai/aihand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v retrieving revision 1.67 diff -u -r1.67 aihand.c --- ai/aihand.c 2002/03/06 03:03:03 1.67 +++ ai/aihand.c 2002/03/06 11:14:17 @@ -169,9 +169,9 @@ city_refresh(pcity); trade += pcity->trade_prod * city_tax_bonus(pcity) / 100; freelog(LOG_DEBUG, "%s has %d trade.", pcity->name, pcity->trade_prod); - impr_type_iterate(id) { - if (city_got_building(pcity, id)) expense += improvement_upkeep(pcity,id); - } impr_type_iterate_end; + city_impr_type_iterate(pcity, id) { + expense += improvement_upkeep(pcity,id); + } city_impr_type_iterate_end; city_list_iterate_end; Index: client/climisc.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v retrieving revision 1.88 diff -u -r1.88 climisc.c --- client/climisc.c 2002/03/06 10:05:32 1.88 +++ client/climisc.c 2002/03/06 11:14:17 @@ -125,12 +125,10 @@ and to handle the preservation of "destroyed" effects. */ effect_update=FALSE; - impr_type_iterate(i) { - if (pcity->improvements[i]!=I_NONE) { - effect_update=TRUE; - city_remove_improvement(pcity, i); - } - } impr_type_iterate_end; + city_impr_type_iterate(pcity, i) { + effect_update=TRUE; + city_remove_improvement(pcity, i); + } city_impr_type_iterate_end; if (effect_update) update_all_effects(); @@ -921,12 +919,10 @@ assert(pcity != NULL); - impr_type_iterate(id) { - if (pcity->improvements[id] != 0) { - dest_cids[cids_used] = cid_encode(FALSE, id); - cids_used++; - } - } impr_type_iterate_end; + city_impr_type_iterate(pcity, id) { + dest_cids[cids_used] = cid_encode(FALSE, id); + cids_used++; + } city_impr_type_iterate_end; return cids_used; } Index: client/gui-gtk/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v retrieving revision 1.88 diff -u -r1.88 dialogs.c --- client/gui-gtk/dialogs.c 2002/03/06 03:03:05 1.88 +++ client/gui-gtk/dialogs.c 2002/03/06 11:14:19 @@ -828,13 +828,13 @@ gtk_clist_append(GTK_CLIST(spy_improvements_list), row); improvement_type[j++] = -1; - impr_type_iterate(i) { - if(i != B_PALACE && pcity->improvements[i] && !is_wonder(i)) { + city_impr_type_iterate(pcity, i) { + if(i != B_PALACE && !is_wonder(i)) { row[0] = get_impr_name_ex(pcity, i); gtk_clist_append(GTK_CLIST(spy_improvements_list), row); improvement_type[j++] = i; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; if(j > 1) { row[0] = _("At Spy's Discretion"); Index: client/gui-mui/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v retrieving revision 1.50 diff -u -r1.50 citydlg.c --- client/gui-mui/citydlg.c 2002/03/06 10:05:34 1.50 +++ client/gui-mui/citydlg.c 2002/03/06 11:14:21 @@ -2121,16 +2121,13 @@ { LONG j = 0, refresh = FALSE, imprv; - impr_type_iterate(i) { - if(pdialog->pcity->improvements[i]) - { - DoMethod(pdialog->imprv_listview, MUIM_NList_GetEntry, j++, &imprv); - if(!imprv || imprv - 1 != i) { - refresh = TRUE; - goto out; - } + city_impr_type_iterate(pdialog->pcity, i) { + DoMethod(pdialog->imprv_listview, MUIM_NList_GetEntry, j++, &imprv); + if (!imprv || imprv - 1 != i) { + refresh = TRUE; + goto out; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; out: /* check the case for to much improvements in list */ DoMethod(pdialog->imprv_listview, MUIM_NList_GetEntry, j, &imprv); @@ -2140,12 +2137,10 @@ set(pdialog->imprv_listview, MUIA_NList_Quiet, TRUE); DoMethod(pdialog->imprv_listview, MUIM_NList_Clear); - impr_type_iterate(i) { - if (pdialog->pcity->improvements[i]) - { - DoMethod(pdialog->imprv_listview, MUIM_NList_InsertSingle, i + 1, MUIV_NList_Insert_Bottom); - } - } impr_type_iterate_end; + city_impr_type_iterate(pdialog->pcity, i) { + DoMethod(pdialog->imprv_listview, MUIM_NList_InsertSingle, i + 1, + MUIV_NList_Insert_Bottom); + } city_impr_type_iterate_end; set(pdialog->imprv_listview, MUIA_NList_Quiet, FALSE); } Index: client/gui-mui/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/dialogs.c,v retrieving revision 1.37 diff -u -r1.37 dialogs.c --- client/gui-mui/dialogs.c 2002/03/06 03:03:07 1.37 +++ client/gui-mui/dialogs.c 2002/03/06 11:14:22 @@ -446,13 +446,13 @@ { int any_improvements=FALSE; DoMethod(listview, MUIM_NList_InsertSingle, 100-1,MUIV_NList_Insert_Bottom); - impr_type_iterate(i) { - if(i != B_PALACE && pcity->improvements[i] && !is_wonder(i)) + city_impr_type_iterate(pcity, i) { + if(i != B_PALACE && !is_wonder(i)) { DoMethod(listview, MUIM_NList_InsertSingle, i+100,MUIV_NList_Insert_Bottom); any_improvements = TRUE; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; if (any_improvements) { Index: client/gui-win32/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/dialogs.c,v retrieving revision 1.11 diff -u -r1.11 dialogs.c --- client/gui-win32/dialogs.c 2002/03/06 03:03:09 1.11 +++ client/gui-win32/dialogs.c 2002/03/06 11:14:23 @@ -1395,12 +1395,12 @@ ListBox_AddString(lb,_("City Production")); improvement_type[j++] = -1; - impr_type_iterate(i) { - if(i != B_PALACE && pcity->improvements[i] && !is_wonder(i)) { + city_impr_type_iterate(pcity, i) { + if(i != B_PALACE && !is_wonder(i)) { ListBox_AddString(lb,get_impr_name_ex(pcity,i)); improvement_type[j++] = i; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; if(j > 1) { ListBox_AddString(lb,_("At Spy's Discretion")); Index: client/gui-xaw/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v retrieving revision 1.71 diff -u -r1.71 citydlg.c --- client/gui-xaw/citydlg.c 2002/03/06 10:05:36 1.71 +++ client/gui-xaw/citydlg.c 2002/03/06 11:14:25 @@ -1886,17 +1886,16 @@ { int n = 0, flag = 0; - impr_type_iterate(i) { - if(pdialog->pcity->improvements[i]) { - if(!pdialog->improvlist_names_ptrs[n] || - strcmp(pdialog->improvlist_names_ptrs[n], get_impr_name_ex(pdialog->pcity, i)) != 0) - flag=1; - sz_strlcpy(pdialog->improvlist_names[n], - get_impr_name_ex(pdialog->pcity, i)); - pdialog->improvlist_names_ptrs[n]=pdialog->improvlist_names[n]; - n++; - } - } impr_type_iterate_end; + city_impr_type_iterate(pdialog->pcity, i) { + if (!pdialog->improvlist_names_ptrs[n] || + strcmp(pdialog->improvlist_names_ptrs[n], + get_impr_name_ex(pdialog->pcity, i)) != 0) + flag = 1; + sz_strlcpy(pdialog->improvlist_names[n], + get_impr_name_ex(pdialog->pcity, i)); + pdialog->improvlist_names_ptrs[n] = pdialog->improvlist_names[n]; + n++; + } city_impr_type_iterate_end; if(pdialog->improvlist_names_ptrs[n]!=0) { pdialog->improvlist_names_ptrs[n]=0; @@ -2490,29 +2489,27 @@ if(ret->list_index!=XAW_LIST_NONE) { int n = 0; - impr_type_iterate(i) { - if(pdialog->pcity->improvements[i]) { - if(n==ret->list_index) { - char buf[512]; - - if(is_wonder(i)) - return; - - pdialog->sell_id=i; - my_snprintf(buf, sizeof(buf), _("Sell %s for %d gold?"), - get_impr_name_ex(pdialog->pcity, i), - improvement_value(i)); - - popup_message_dialog(pdialog->shell, "selldialog", buf, - sell_callback_yes, pdialog, 0, - sell_callback_no, pdialog, 0, - NULL); - + city_impr_type_iterate(pdialog->pcity, i) { + if (n == ret->list_index) { + char buf[512]; + + if (is_wonder(i)) { return; } - n++; + + pdialog->sell_id = i; + my_snprintf(buf, sizeof(buf), _("Sell %s for %d gold?"), + get_impr_name_ex(pdialog->pcity, i), + improvement_value(i)); + + popup_message_dialog(pdialog->shell, "selldialog", buf, + sell_callback_yes, pdialog, 0, + sell_callback_no, pdialog, 0, NULL); + + return; } - } impr_type_iterate_end; + n++; + } city_impr_type_iterate_end; } } Index: client/gui-xaw/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v retrieving revision 1.61 diff -u -r1.61 dialogs.c --- client/gui-xaw/dialogs.c 2002/03/06 03:03:10 1.61 +++ client/gui-xaw/dialogs.c 2002/03/06 11:14:26 @@ -835,12 +835,12 @@ improvements_can_sabotage[j] = _("City Production"); improvement_type[j++] = -1; - impr_type_iterate(i) { - if(i != B_PALACE && pcity->improvements[i] && !is_wonder(i)) { + city_impr_type_iterate(pcity, i) { + if(i != B_PALACE && !is_wonder(i)) { improvements_can_sabotage[j] = get_impr_name_ex(pcity, i); improvement_type[j++] = i; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; if(j > 1) { improvements_can_sabotage[j] = _("At Spy's Discretion"); Index: common/city.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.c,v retrieving revision 1.154 diff -u -r1.154 city.c --- common/city.c 2002/03/06 03:03:12 1.154 +++ common/city.c 2002/03/06 11:14:28 @@ -899,10 +899,9 @@ bool asmiths = city_affected_by_wonder(pcity, B_ASMITHS); int cost=0; - impr_type_iterate(i) { - if (city_got_building(pcity, i)) - cost+=improvement_upkeep_asmiths(pcity, i, asmiths); - } impr_type_iterate_end; + city_impr_type_iterate(pcity, i) { + cost+=improvement_upkeep_asmiths(pcity, i, asmiths); + } city_impr_type_iterate_end; return pcity->tax_total-cost; } Index: common/city.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.h,v retrieving revision 1.104 diff -u -r1.104 city.h --- common/city.h 2002/03/04 09:01:17 1.104 +++ common/city.h 2002/03/06 11:14:28 @@ -449,4 +449,17 @@ /* misc */ bool is_city_option_set(struct city *pcity, enum city_options option); + +/* + * Iterates over all improvements which are build in the given city. + */ +#define city_impr_type_iterate(m_pcity, m_i) \ + impr_type_iterate(m_i) { \ + if((m_pcity)->improvements[m_i] == I_NONE) { \ + continue; \ + } + +#define city_impr_type_iterate_end \ + } impr_type_iterate_end; + #endif /* FC__CITY_H */ Index: common/game.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.c,v retrieving revision 1.134 diff -u -r1.134 game.c --- common/game.c 2002/03/06 10:05:38 1.134 +++ common/game.c 2002/03/06 11:14:29 @@ -768,10 +768,10 @@ { players_iterate(plr) { city_list_iterate(plr->cities, pcity) { - impr_type_iterate(i) { - if (city_got_building(pcity, i) && is_wonder(i)) + city_impr_type_iterate(pcity, i) { + if (is_wonder(i)) game.global_wonders[i] = pcity->id; - } impr_type_iterate_end; + } city_impr_type_iterate_end; } city_list_iterate_end; } players_iterate_end; } @@ -1035,22 +1035,20 @@ players_iterate(pplayer) { city_list_iterate(pplayer->cities,pcity) { - impr_type_iterate(i) { - if (pcity->improvements[i]==I_NONE) continue; + city_impr_type_iterate(pcity, i) { if (improvement_obsolete(pplayer,i)) { freelog(LOG_DEBUG,"%s in %s is obsolete", improvement_types[i].name,pcity->name); mark_improvement(pcity,i,I_OBSOLETE); } - } impr_type_iterate_end; + } city_impr_type_iterate_end; } city_list_iterate_end; } players_iterate_end; players_iterate(pplayer) { city_list_iterate(pplayer->cities,pcity) { - impr_type_iterate(i) { - if (pcity->improvements[i]==I_NONE || - pcity->improvements[i]==I_OBSOLETE) continue; + city_impr_type_iterate(pcity, i) { + if (pcity->improvements[i]==I_OBSOLETE) continue; if (improvement_redundant(pplayer, pcity, i, FALSE)) { freelog(LOG_DEBUG,"%s in %s is redundant", improvement_types[i].name,pcity->name); @@ -1060,7 +1058,7 @@ freelog(LOG_DEBUG,"%s in %s is active!", improvement_types[i].name,pcity->name); } - } impr_type_iterate_end; + } city_impr_type_iterate_end; } city_list_iterate_end; } players_iterate_end; } Index: server/citytools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v retrieving revision 1.176 diff -u -r1.176 citytools.c --- server/citytools.c 2002/03/06 03:03:14 1.176 +++ server/citytools.c 2002/03/06 11:14:31 @@ -681,12 +681,11 @@ if (is_land_barbarian(city_owner(pcity))) razechance += 30; - impr_type_iterate(i) { - if (city_got_building(pcity, i) && !is_wonder(i) - && (myrand(100) < razechance)) { + city_impr_type_iterate(pcity, i) { + if (!is_wonder(i) && (myrand(100) < razechance)) { pcity->improvements[i]=I_NONE; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; nullify_prechange_production(pcity); pcity->shield_stock = 0; @@ -780,12 +779,10 @@ /* Remove all global improvement effects that this city confers (but then restore the local improvement list - we need this to restore the global effects for the new city owner) */ - impr_type_iterate(i) { - if (pcity->improvements[i]!=I_NONE) { - city_remove_improvement(pcity,i); - pcity->improvements[i]=I_ACTIVE; - } - } impr_type_iterate_end; + city_impr_type_iterate(pcity, i) { + city_remove_improvement(pcity,i); + pcity->improvements[i]=I_ACTIVE; + } city_impr_type_iterate_end; give_citymap_from_player_to_player(pcity, pgiver, ptaker); map_unfog_pseudo_city_area(ptaker, pcity->x, pcity->y); @@ -863,11 +860,9 @@ raze_city(pcity); /* Restore any global improvement effects that this city confers */ - impr_type_iterate(i) { - if (pcity->improvements[i]!=I_NONE) { - city_add_improvement(pcity,i); - } - } impr_type_iterate_end; + city_impr_type_iterate(pcity, i) { + city_add_improvement(pcity,i); + } city_impr_type_iterate_end; update_all_effects(); /* If the city was building something we haven't invented we @@ -1072,12 +1067,10 @@ and to handle the preservation of "destroyed" effects. */ effect_update=FALSE; - impr_type_iterate(i) { - if (pcity->improvements[i]!=I_NONE) { - effect_update=TRUE; - city_remove_improvement(pcity,i); - } - } impr_type_iterate_end; + city_impr_type_iterate(pcity, i) { + effect_update = TRUE; + city_remove_improvement(pcity,i); + } city_impr_type_iterate_end; if (effect_update) update_all_effects(); Index: server/cityturn.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v retrieving revision 1.183 diff -u -r1.183 cityturn.c --- server/cityturn.c 2002/03/06 03:03:15 1.183 +++ server/cityturn.c 2002/03/06 11:14:31 @@ -112,10 +112,8 @@ struct player *pplayer = city_owner(pcity); bool sold = FALSE; - impr_type_iterate(i) { - if (city_got_building(pcity, i) - && !is_wonder(i) - && improvement_obsolete(pplayer, i)) { + city_impr_type_iterate(pcity, i) { + if (!is_wonder(i) && improvement_obsolete(pplayer, i)) { do_sell_building(pplayer, pcity, i); notify_player_ex(pplayer, pcity->x, pcity->y, E_IMP_SOLD, _("Game: %s is selling %s (obsolete) for %d."), @@ -123,7 +121,7 @@ improvement_value(i)); sold = TRUE; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; if (sold) update_all_effects(); @@ -1089,22 +1087,20 @@ **************************************************************************/ static void pay_for_buildings(struct player *pplayer, struct city *pcity) { - impr_type_iterate(i) { - if (city_got_building(pcity, i)) { - if (!is_wonder(i) - && pplayer->government != game.government_when_anarchy) { - if (pplayer->economic.gold-improvement_upkeep(pcity, i) < 0) { - notify_player_ex(pplayer, pcity->x, pcity->y, E_IMP_AUCTIONED, - _("Game: Can't afford to maintain %s in %s, " - "building sold!"), - improvement_types[i].name, pcity->name); - do_sell_building(pplayer, pcity, i); - city_refresh(pcity); - } else - pplayer->economic.gold -= improvement_upkeep(pcity, i); - } + city_impr_type_iterate(pcity, i) { + if (!is_wonder(i) + && pplayer->government != game.government_when_anarchy) { + if (pplayer->economic.gold - improvement_upkeep(pcity, i) < 0) { + notify_player_ex(pplayer, pcity->x, pcity->y, E_IMP_AUCTIONED, + _("Game: Can't afford to maintain %s in %s, " + "building sold!"), + improvement_types[i].name, pcity->name); + do_sell_building(pplayer, pcity, i); + city_refresh(pcity); + } else + pplayer->economic.gold -= improvement_upkeep(pcity, i); } - } impr_type_iterate_end; + } city_impr_type_iterate_end; } /************************************************************************** Index: server/diplomats.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v retrieving revision 1.25 diff -u -r1.25 diplomats.c --- server/diplomats.c 2002/03/06 03:03:15 1.25 +++ server/diplomats.c 2002/03/06 11:14:32 @@ -893,12 +893,11 @@ /* Examine the city for improvements to sabotage. */ count = 0; - impr_type_iterate(index) { - if (city_got_building (pcity, index) && - (!is_wonder (index)) && (index != B_PALACE)) { + city_impr_type_iterate(pcity, index) { + if (!is_wonder(index) && index != B_PALACE) { count++; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; freelog (LOG_DEBUG, "sabotage: count of improvements: %d", count); @@ -931,9 +930,8 @@ target = -1; which = myrand (count); - impr_type_iterate(index) { - if (city_got_building (pcity, index) && - (!is_wonder (index)) && (index != B_PALACE)) { + city_impr_type_iterate(pcity, index) { + if (!is_wonder (index) && index != B_PALACE) { if (which > 0) { which--; } else { @@ -941,7 +939,7 @@ break; } } - } impr_type_iterate_end; + } city_impr_type_iterate_end; freelog (LOG_DEBUG, "sabotage: random: targeted improvement: %d (%s)", target, get_improvement_name (target)); Index: server/report.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/report.c,v retrieving revision 1.25 diff -u -r1.25 report.c --- server/report.c 2002/03/06 03:03:16 1.25 +++ server/report.c 2002/03/06 11:14:33 @@ -206,11 +206,11 @@ { int result = 0; - impr_type_iterate(i) { - if (is_wonder(i) && city_got_building(pcity, i)) { + city_impr_type_iterate(pcity, i) { + if (is_wonder(i)) { result++; } - } impr_type_iterate_end; + } city_impr_type_iterate_end; return result; }