From 04223caf8e56b6d8b5564b033117b6a2423b53d1 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 18 Jul 2022 20:23:26 +0300 Subject: [PATCH 57/57] Drop checks if a valid unit isn't in game For a very long time, units that are not meant to be in the game, have not been included in the unit array. See osdn #45021 Signed-off-by: Marko Lindqvist --- ai/default/aiparatrooper.c | 4 --- ai/default/aitech.c | 52 ++++++++++++++++++-------------------- ai/default/aiunit.c | 3 +-- ai/default/daisettler.c | 3 +-- client/gui-qt/helpdlg.cpp | 4 +-- client/gui-sdl2/helpdlg.c | 6 ++--- common/unittype.h | 2 +- 7 files changed, 32 insertions(+), 42 deletions(-) diff --git a/ai/default/aiparatrooper.c b/ai/default/aiparatrooper.c index 3dba4edc59..bed07d569e 100644 --- a/ai/default/aiparatrooper.c +++ b/ai/default/aiparatrooper.c @@ -398,10 +398,6 @@ void dai_choose_paratrooper(struct ai_type *ait, continue; } - if (A_NEVER == u_type->_retire.require_advance) { - continue; - } - if (!allow_gold_upkeep && utype_upkeep_cost(u_type, pplayer, O_GOLD) > 0) { continue; } diff --git a/ai/default/aitech.c b/ai/default/aitech.c index cb466dd422..ab6d6fa4ee 100644 --- a/ai/default/aitech.c +++ b/ai/default/aitech.c @@ -417,21 +417,19 @@ struct unit_type *dai_wants_defender_against(struct ai_type *ait, struct advance *itech = A_NEVER; bool impossible_to_get = FALSE; - if (A_NEVER != deftype->_retire.require_advance) { - unit_tech_reqs_iterate(deftype, padv) { - if (research_invention_state(presearch, - advance_number(padv)) != TECH_KNOWN) { - /* See if we want to invent this. */ - int ucost = research_goal_bulbs_required(presearch, - advance_number(padv)); - - if (cost == 0 || ucost < cost) { - cost = ucost; - itech = padv; - } + unit_tech_reqs_iterate(deftype, padv) { + if (research_invention_state(presearch, + advance_number(padv)) != TECH_KNOWN) { + /* See if we want to invent this. */ + int ucost = research_goal_bulbs_required(presearch, + advance_number(padv)); + + if (cost == 0 || ucost < cost) { + cost = ucost; + itech = padv; } - } unit_tech_reqs_iterate_end; - } + } + } unit_tech_reqs_iterate_end; building = utype_needs_improvement(deftype, pcity); if (building != NULL @@ -524,21 +522,19 @@ struct unit_type *dai_wants_role_unit(struct ai_type *ait, struct player *pplaye struct advance *itech = A_NEVER; int cost = 0; - if (A_NEVER != iunit->_retire.require_advance) { - unit_tech_reqs_iterate(iunit, padv) { - if (research_invention_state(presearch, - advance_number(padv)) != TECH_KNOWN) { - /* See if we want to invent this. */ - int ucost = research_goal_bulbs_required(presearch, - advance_number(padv)); - - if (cost == 0 || ucost < cost) { - cost = ucost; - itech = padv; - } + unit_tech_reqs_iterate(iunit, padv) { + if (research_invention_state(presearch, + advance_number(padv)) != TECH_KNOWN) { + /* See if we want to invent this. */ + int ucost = research_goal_bulbs_required(presearch, + advance_number(padv)); + + if (cost == 0 || ucost < cost) { + cost = ucost; + itech = padv; } - } unit_tech_reqs_iterate_end; - } + } + } unit_tech_reqs_iterate_end; building = utype_needs_improvement(iunit, pcity); if (building != NULL diff --git a/ai/default/aiunit.c b/ai/default/aiunit.c index 467223dacb..2a481450b1 100644 --- a/ai/default/aiunit.c +++ b/ai/default/aiunit.c @@ -3142,8 +3142,7 @@ static void update_simple_ai_types(void) unit_type_iterate(punittype) { struct unit_class *pclass = utype_class(punittype); - if (A_NEVER != punittype->_retire.require_advance - && !utype_has_flag(punittype, UTYF_CIVILIAN) + if (!utype_has_flag(punittype, UTYF_CIVILIAN) && !utype_can_do_action(punittype, ACTION_SUICIDE_ATTACK) && !(pclass->adv.land_move == MOVE_NONE && !can_attack_non_native(punittype)) diff --git a/ai/default/daisettler.c b/ai/default/daisettler.c index 94d4fcc8cf..0d03fd1380 100644 --- a/ai/default/daisettler.c +++ b/ai/default/daisettler.c @@ -922,8 +922,7 @@ static struct cityresult *find_best_city_placement(struct ai_type *ait, /* Sea travel not possible yet. Bump tech want for ferries. */ boattype = get_role_unit(L_FERRYBOAT, 0); - if (NULL != boattype - && A_NEVER != boattype->_retire.require_advance) { + if (NULL != boattype) { struct ai_plr *plr_data = def_ai_player_data(pplayer, ait); unit_tech_reqs_iterate(boattype, padv) { diff --git a/client/gui-qt/helpdlg.cpp b/client/gui-qt/helpdlg.cpp index 46f0143dba..0ed9fc8bfc 100644 --- a/client/gui-qt/helpdlg.cpp +++ b/client/gui-qt/helpdlg.cpp @@ -919,7 +919,7 @@ void help_widget::set_topic_unit(const help_item *topic, // Tech requirement tech = utype_primary_tech_req(utype); - if (tech && advance_number(tech) != A_NONE) { + if (advance_number(tech) != A_NONE) { QLabel *tb; tb = new QLabel(this); @@ -943,7 +943,7 @@ void help_widget::set_topic_unit(const help_item *topic, obsolete = utype->obsoleted_by; if (obsolete) { tech = utype_primary_tech_req(obsolete); - if (tech && advance_number(tech) != A_NONE) { + if (advance_number(tech) != A_NONE) { QLabel *tb; tb = new QLabel(this); diff --git a/client/gui-sdl2/helpdlg.c b/client/gui-sdl2/helpdlg.c index bd2e559b9e..76e2a13553 100644 --- a/client/gui-sdl2/helpdlg.c +++ b/client/gui-sdl2/helpdlg.c @@ -854,10 +854,10 @@ void popup_unit_info(Unit_type_id type_id) req = utype_primary_tech_req(punittype); - if (A_NEVER == punittype->_retire.require_advance - || advance_number(req) == A_NONE) { + if (advance_number(req) == A_NONE) { requirement_label2 = create_iconlabel_from_chars(NULL, pwindow->dst, - Q_("?tech:None"), adj_font(12), 0); + Q_("?tech:None"), + adj_font(12), 0); requirement_label2->id = ID_LABEL; } else { Tech_type_id req_id = advance_number(req); diff --git a/common/unittype.h b/common/unittype.h index 89a963c7e7..f2721b44d0 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -854,7 +854,7 @@ const struct unit_type *unit_type_array_last(void); #define unit_tech_reqs_iterate(_utype_, _p) \ do { \ struct advance *_p = (_utype_)->_retire.require_advance; \ - if (advance_number(_p) != A_NONE && _p != A_NEVER) { + if (advance_number(_p) != A_NONE) { #define unit_tech_reqs_iterate_end \ } \ -- 2.35.1