From dd16c65620cecb2ba6589ca466bdb5bc3eb73a06 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 14 Nov 2021 01:15:17 +0200 Subject: [PATCH 37/37] Drop 'start' parameter from advance_iterate() - Rename old advance_iterate(), with the 'start' parameter, as advance_iterate_base() - Introduce new advance_iterate() that is a wrapper around advance_iterate_base(A_FIRST) - Turn advance_iterate_all() as wrapper around advance_iterate_base(A_NONE) - Adjust all users of advance_iterate() - all of them wanted iteration from A_FIRST, so now use new advance_iterate() See osdn #43216 Signed-off-by: Marko Lindqvist --- ai/default/aitech.c | 2 +- ai/default/daiactions.c | 2 +- client/gui-gtk-3.22/diplodlg.c | 4 ++-- client/gui-gtk-3.22/editprop.c | 2 +- client/gui-gtk-3.22/menu.c | 2 +- client/gui-gtk-4.0/diplodlg.c | 4 ++-- client/gui-gtk-4.0/editprop.c | 2 +- client/gui-gtk-4.0/menu.c | 2 +- client/gui-qt/diplodlg.cpp | 4 ++-- client/gui-qt/menu.cpp | 2 +- client/gui-qt/plrdlg.cpp | 4 ++-- client/tilespec.c | 2 +- common/actions.c | 2 +- common/research.c | 2 +- common/tech.c | 2 +- common/tech.h | 23 +++++++++++++---------- server/rssanity.c | 2 +- server/ruleset.c | 15 ++++++++------- server/savegame/savegame3.c | 2 +- tools/civmanual.c | 2 +- tools/ruledit/tab_tech.cpp | 6 +++--- 21 files changed, 46 insertions(+), 42 deletions(-) diff --git a/ai/default/aitech.c b/ai/default/aitech.c index 1853ad5d61..1ee41d0bfb 100644 --- a/ai/default/aitech.c +++ b/ai/default/aitech.c @@ -249,7 +249,7 @@ static void dai_tech_effect_values(struct ai_type *ait, struct player *pplayer) } } players_iterate_end; - advance_iterate(A_FIRST, padv) { + advance_iterate(padv) { if (research_invention_state(research_get(pplayer), advance_number(padv)) != TECH_KNOWN) { struct universal source = { .kind = VUT_ADVANCE, .value.advance = padv }; diff --git a/ai/default/daiactions.c b/ai/default/daiactions.c index 2d68b28915..ae014664ae 100644 --- a/ai/default/daiactions.c +++ b/ai/default/daiactions.c @@ -67,7 +67,7 @@ choose_tech_to_steal(const struct player *actor_player, if (actor_research != target_research) { if (can_see_techs_of_target(actor_player, target_player)) { - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { Tech_type_id i = advance_number(padvance); if (research_invention_state(target_research, i) == TECH_KNOWN diff --git a/client/gui-gtk-3.22/diplodlg.c b/client/gui-gtk-3.22/diplodlg.c index be9301fa3b..63890e5e13 100644 --- a/client/gui-gtk-3.22/diplodlg.c +++ b/client/gui-gtk-3.22/diplodlg.c @@ -277,7 +277,7 @@ static void popup_add_menu(GtkMenuShell *parent, gpointer data) advance_item = gtk_menu_item_new_with_mnemonic(_("_Advances")); gtk_menu_shell_append(GTK_MENU_SHELL(parent), advance_item); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { Tech_type_id i = advance_number(padvance); if (research_invention_state(gresearch, i) == TECH_KNOWN @@ -967,7 +967,7 @@ static void diplomacy_dialog_tech_callback(GtkWidget *w, gpointer data) dresearch = research_get(pdest); gresearch = research_get(pgiver); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { Tech_type_id i = advance_number(padvance); if (research_invention_state(gresearch, i) == TECH_KNOWN diff --git a/client/gui-gtk-3.22/editprop.c b/client/gui-gtk-3.22/editprop.c index 36f292e74f..1d33cfa754 100644 --- a/client/gui-gtk-3.22/editprop.c +++ b/client/gui-gtk-3.22/editprop.c @@ -3991,7 +3991,7 @@ static void extviewer_refresh_widgets(struct extviewer *ev, case OPID_PLAYER_INVENTIONS: gtk_list_store_clear(store); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { id = advance_index(padvance); present = BV_ISSET(pv->data.v_bv_inventions, id); name = advance_name_translation(padvance); diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index f74b8c3dc3..1a1fd28cbe 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -2820,7 +2820,7 @@ void real_menus_init(void) } improvement_iterate_end; break; case ASTK_TECH: - advance_iterate(A_FIRST, ptech) { + advance_iterate(ptech) { CREATE_SUB_ITEM(ptech, "end_tech", advance_name_translation(ptech)); } advance_iterate_end; diff --git a/client/gui-gtk-4.0/diplodlg.c b/client/gui-gtk-4.0/diplodlg.c index 3af99d2bb9..f0e9c1e6b8 100644 --- a/client/gui-gtk-4.0/diplodlg.c +++ b/client/gui-gtk-4.0/diplodlg.c @@ -282,7 +282,7 @@ static void popup_add_menu(GtkMenuShell *parent, gpointer data) advance_item = gtk_menu_item_new_with_mnemonic(_("_Advances")); gtk_menu_shell_append(GTK_MENU_SHELL(parent), advance_item); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { Tech_type_id i = advance_number(padvance); if (research_invention_state(gresearch, i) == TECH_KNOWN @@ -979,7 +979,7 @@ static void diplomacy_dialog_tech_callback(GtkWidget *w, gpointer data) dresearch = research_get(pdest); gresearch = research_get(pgiver); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { Tech_type_id i = advance_number(padvance); if (research_invention_state(gresearch, i) == TECH_KNOWN diff --git a/client/gui-gtk-4.0/editprop.c b/client/gui-gtk-4.0/editprop.c index 30616aa344..a1986e6aef 100644 --- a/client/gui-gtk-4.0/editprop.c +++ b/client/gui-gtk-4.0/editprop.c @@ -3992,7 +3992,7 @@ static void extviewer_refresh_widgets(struct extviewer *ev, case OPID_PLAYER_INVENTIONS: gtk_list_store_clear(store); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { id = advance_index(padvance); present = BV_ISSET(pv->data.v_bv_inventions, id); name = advance_name_translation(padvance); diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c index 018b5fcb5f..83414ca68f 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -2838,7 +2838,7 @@ void real_menus_init(void) } improvement_iterate_end; break; case ASTK_TECH: - advance_iterate(A_FIRST, ptech) { + advance_iterate(ptech) { CREATE_SUB_ITEM(ptech, "end_tech", advance_name_translation(ptech)); } advance_iterate_end; diff --git a/client/gui-qt/diplodlg.cpp b/client/gui-qt/diplodlg.cpp index 84f529b144..792d2d0a08 100644 --- a/client/gui-qt/diplodlg.cpp +++ b/client/gui-qt/diplodlg.cpp @@ -340,7 +340,7 @@ void diplo_wdg::show_menu(int player) const struct research *gresearch = research_get(pgiver); const struct research *oresearch = research_get(pother); adv_menu = menu->addMenu(_("Advances")); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { Tech_type_id i = advance_number(padvance); if (research_invention_state(gresearch, i) == TECH_KNOWN @@ -591,7 +591,7 @@ void diplo_wdg::all_advances() dresearch = research_get(pdest); gresearch = research_get(pgiver); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { Tech_type_id i = advance_number(padvance); if (research_invention_state(gresearch, i) == TECH_KNOWN diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 03e6ad0017..6172c46849 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -787,7 +787,7 @@ void go_act_menu::create() } improvement_iterate_end; break; case ASTK_TECH: - advance_iterate(A_FIRST, ptech) { + advance_iterate(ptech) { CREATE_SUB_ITEM(sub_target_menu, act_id, advance_number(ptech), advance_name_translation(ptech)); diff --git a/client/gui-qt/plrdlg.cpp b/client/gui-qt/plrdlg.cpp index 883521d207..c74cf1f0cb 100644 --- a/client/gui-qt/plrdlg.cpp +++ b/client/gui-qt/plrdlg.cpp @@ -591,7 +591,7 @@ void plr_widget::nation_selected(const QItemSelection &sl, .toHtmlEscaped()); techs_unknown = QString(_("Techs unknown by you :")); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { tech_id = advance_number(padvance); if (research_invention_state(my_research, tech_id) == TECH_KNOWN && (research_invention_state(research, tech_id) @@ -636,7 +636,7 @@ void plr_widget::nation_selected(const QItemSelection &sl, } else { tech_str = QString(_("Techs known by %1:")). arg(QString(nation_plural_for_player(pplayer)).toHtmlEscaped()); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { tech_id = advance_number(padvance); if (research_invention_state(research, tech_id) == TECH_KNOWN) { sorted_list_a << research_advance_name_translation(research, tech_id); diff --git a/client/tilespec.c b/client/tilespec.c index e4178a8955..88dbe0ddd0 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -1407,7 +1407,7 @@ bool tilespec_reread(const char *new_tileset_name, improvement_iterate(pimprove) { tileset_setup_impr_type(tileset, pimprove); } improvement_iterate_end; - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { tileset_setup_tech_type(tileset, padvance); } advance_iterate_end; specialist_type_iterate(sp) { diff --git a/common/actions.c b/common/actions.c index c08173f422..81667f5c1a 100644 --- a/common/actions.c +++ b/common/actions.c @@ -5301,7 +5301,7 @@ tech_can_be_stolen(const struct player *actor_player, if (actor_research != target_research) { if (can_see_techs_of_target(actor_player, target_player)) { - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { Tech_type_id i = advance_number(padvance); if (research_invention_state(target_research, i) == TECH_KNOWN diff --git a/common/research.c b/common/research.c index 904a7bed27..fa656f7947 100644 --- a/common/research.c +++ b/common/research.c @@ -1084,7 +1084,7 @@ int player_tech_upkeep(const struct player *pplayer) case TECH_COST_EXPERIMENTAL: case TECH_COST_EXPERIMENTAL_PRESET: case TECH_COST_LINEAR: - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { if (TECH_KNOWN == research_invention_state(presearch, advance_number(padvance))) { tech_upkeep += padvance->cost; diff --git a/common/tech.c b/common/tech.c index 718176d114..1e7b212738 100644 --- a/common/tech.c +++ b/common/tech.c @@ -220,7 +220,7 @@ void techs_precalc_data(void) fc_assert_msg(tech_cost_style_is_valid(game.info.tech_cost_style), "Invalid tech_cost_style %d", game.info.tech_cost_style); - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { int num_reqs = 0; bool min_req = TRUE; diff --git a/common/tech.h b/common/tech.h index 7b6850d8f0..912220922d 100644 --- a/common/tech.h +++ b/common/tech.h @@ -238,22 +238,25 @@ void techs_precalc_data(void); const struct advance *advance_array_last(void); -#define advance_iterate(_start, _p) \ -{ \ - struct advance *_p = advance_by_number(_start); \ - if (NULL != _p) { \ +#define advance_iterate_base(_start, _p) \ +{ \ + struct advance *_p = advance_by_number(_start); \ + if (NULL != _p) { \ for (; _p <= advance_array_last(); _p++) { -#define advance_iterate_end \ - } \ - } \ +#define advance_iterate_base_end \ + } \ + } \ } -#define advance_iterate_all(_p) advance_iterate(A_NONE, _p) -#define advance_iterate_all_end advance_iterate_end +#define advance_iterate(_p) advance_iterate_base(A_FIRST, _p) +#define advance_iterate_end advance_iterate_base_end + +#define advance_iterate_all(_p) advance_iterate_base(A_NONE, _p) +#define advance_iterate_all_end advance_iterate_base_end #define advance_re_active_iterate(_p) \ - advance_iterate(A_FIRST, _p) { \ + advance_iterate(_p) { \ if (_p->require[AR_ONE] != A_NEVER) { #define advance_re_active_iterate_end \ diff --git a/server/rssanity.c b/server/rssanity.c index 8fac594096..8c73094558 100644 --- a/server/rssanity.c +++ b/server/rssanity.c @@ -746,7 +746,7 @@ bool sanity_check_ruleset_data(bool ignore_retired) } /* Advances. */ - advance_iterate(A_FIRST, padvance) { + advance_iterate(padvance) { for (i = AR_ONE; i < AR_SIZE; i++) { const struct advance *preq; diff --git a/server/ruleset.c b/server/ruleset.c index 6e99eb264c..df7a42b662 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -1508,8 +1508,9 @@ static bool load_tech_names(struct section_file *file, game.control.num_tech_types = num_techs + A_FIRST; /* includes A_NONE */ i = 0; - advance_iterate(A_FIRST, a) { - if (!ruleset_load_names(&a->name, NULL, file, section_name(section_list_get(sec, i)))) { + advance_iterate(adv) { + if (!ruleset_load_names(&adv->name, NULL, file, + section_name(section_list_get(sec, i)))) { ok = FALSE; break; } @@ -1550,7 +1551,7 @@ static bool load_ruleset_techs(struct section_file *file, sec = secfile_sections_by_name_prefix(file, ADVANCE_SECTION_PREFIX); i = 0; - advance_iterate(A_FIRST, a) { + advance_iterate(a) { const char *sec_name = section_name(section_list_get(sec, i)); const char *sval; int j, ival; @@ -1658,14 +1659,14 @@ static bool load_ruleset_techs(struct section_file *file, restart: if (ok) { - advance_iterate(A_FIRST, a) { + advance_iterate(a) { if (valid_advance(a) && A_NEVER != a->require[AR_ROOT]) { bool out_of_order = FALSE; /* Now find any tech depending on this technology and update its * root_req. */ - advance_iterate(A_FIRST, b) { + advance_iterate(b) { if (valid_advance(b) && A_NEVER == b->require[AR_ROOT] && (a == b->require[AR_ONE] || a == b->require[AR_TWO])) { @@ -1697,7 +1698,7 @@ restart: Non-removed techs depending on removed techs is too broken to fix by default, so die. */ - advance_iterate(A_FIRST, a) { + advance_iterate(a) { if (valid_advance(a)) { /* We check for recursive tech loops later, * in build_required_techs_helper. */ @@ -7749,7 +7750,7 @@ static void send_ruleset_techs(struct conn_list *dest) lsend_packet_ruleset_tech_flag(dest, &fpacket); } - advance_iterate(A_FIRST, a) { + advance_iterate(a) { packet.id = advance_number(a); packet.removed = !valid_advance(a); if (a->tclass == NULL) { diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 54a93ba4ba..1d874799fb 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -1681,7 +1681,7 @@ static void sg_save_savefile(struct savedata *saving) const char *buf[game.control.num_tech_types]; buf[A_NONE] = "A_NONE"; - advance_iterate(A_FIRST, a) { + advance_iterate(a) { buf[advance_index(a)] = advance_rule_name(a); } advance_iterate_end; secfile_insert_str_vec(saving->file, buf, game.control.num_tech_types, diff --git a/tools/civmanual.c b/tools/civmanual.c index afbc72993c..08eb076e07 100644 --- a/tools/civmanual.c +++ b/tools/civmanual.c @@ -732,7 +732,7 @@ static bool manual_command(struct tag_types *tag_info) fprintf(doc, _("%sFreeciv %s tech help (%s)%s\n\n"), tag_info->title_begin, VERSION_STRING, game.control.name, tag_info->title_end); - advance_iterate(A_FIRST, ptech) { + advance_iterate(ptech) { if (valid_advance(ptech)) { char buf[64000]; diff --git a/tools/ruledit/tab_tech.cpp b/tools/ruledit/tab_tech.cpp index f4ad2d8215..fb0bca6ef7 100644 --- a/tools/ruledit/tab_tech.cpp +++ b/tools/ruledit/tab_tech.cpp @@ -136,7 +136,7 @@ void tab_tech::refresh() { tech_list->clear(); - advance_iterate(A_FIRST, padv) { + advance_iterate(padv) { if (padv->require[AR_ONE] != A_NEVER) { QListWidgetItem *item = new QListWidgetItem(advance_rule_name(padv)); @@ -347,7 +347,7 @@ void tab_tech::name_given() QByteArray name_bytes; QByteArray rname_bytes; - advance_iterate(A_FIRST, padv) { + advance_iterate(padv) { if (padv != selected && padv->require[AR_ONE] != A_NEVER) { rname_bytes = rname->text().toUtf8(); @@ -418,7 +418,7 @@ void tab_tech::add_now() struct advance *new_adv; // Try to reuse freed tech slot - advance_iterate(A_FIRST, padv) { + advance_iterate(padv) { if (padv->require[AR_ONE] == A_NEVER) { if (initialize_new_tech(padv)) { update_tech_info(padv); -- 2.33.0