From 9b242625453f4993c63d4bdcb91c4b61eb979702 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 4 Mar 2023 07:19:34 +0200 Subject: [PATCH 15/15] Fix errors because of Never reachable techs Reported by dark-ether See osdn #45115 Signed-off-by: Marko Lindqvist --- common/research.c | 11 ++++++++--- server/savegame/savegame3.c | 5 +++-- server/score.c | 5 +++-- server/techtools.c | 5 +++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/common/research.c b/common/research.c index acc27eafde..3ec1a41bba 100644 --- a/common/research.c +++ b/common/research.c @@ -825,7 +825,7 @@ bool research_goal_tech_req(const struct research *presearch, } /************************************************************************//** - Function to determine cost for technology. The equation is determined + Function to determine cost for technology. The equation is determined from game.info.tech_cost_style and game.info.tech_leakage. tech_cost_style: @@ -858,7 +858,7 @@ bool research_goal_tech_req(const struct research *presearch, of normal players (human and AI) which already know the tech. - At the end we multiply by the sciencebox value, as a percentage. The + At the end we multiply by the sciencebox value, as a percentage. The cost can never be less than 1. 'presearch' may be NULL in which case a simplified result is returned @@ -872,6 +872,10 @@ int research_total_bulbs_required(const struct research *presearch, double base_cost, total_cost; double leak = 0.0; + if (valid_advance_by_number(tech) == NULL) { + return 0; + } + if (!loss_value && NULL != presearch && !is_future_tech(tech) @@ -1342,7 +1346,8 @@ int recalculate_techs_researched(const struct research *presearch) int techs = 1; /* A_NONE known, and not part of below iteration */ advance_iterate(t) { - if (research_invention_state(presearch, advance_number(t)) == TECH_KNOWN) { + if (valid_advance(t) != NULL + && research_invention_state(presearch, advance_number(t)) == TECH_KNOWN) { techs++; } } advance_iterate_end; diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 9c5c55eeb9..1a42c82160 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -7431,8 +7431,9 @@ static void sg_save_researches(struct savedata *saving) /* Save technology lists as bytevector. Note that technology order is * saved in savefile.technology.order */ advance_index_iterate(A_NONE, tech_id) { - invs[tech_id] = (research_invention_state(presearch, tech_id) - == TECH_KNOWN ? '1' : '0'); + invs[tech_id] = (valid_advance_by_number(tech_id) != NULL + && research_invention_state(presearch, tech_id) + == TECH_KNOWN ? '1' : '0'); } advance_index_iterate_end; invs[game.control.num_tech_types] = '\0'; secfile_insert_str(saving->file, invs, "research.r%d.done", i); diff --git a/server/score.c b/server/score.c index f405337658..b083ea9a7b 100644 --- a/server/score.c +++ b/server/score.c @@ -310,12 +310,13 @@ void calc_civ_score(struct player *pplayer) presearch = research_get(pplayer); advance_index_iterate(A_FIRST, i) { - if (research_invention_state(presearch, i) == TECH_KNOWN) { + if (valid_advance_by_number(i) != NULL + && research_invention_state(presearch, i) == TECH_KNOWN) { pplayer->score.techs++; } } advance_index_iterate_end; pplayer->score.techs += research_get(pplayer)->future_tech * 5 / 2; - + unit_list_iterate(pplayer->units, punit) { if (!is_special_unit(punit)) { /* TODO: Which units really should count? */ pplayer->score.units++; diff --git a/server/techtools.c b/server/techtools.c index 62d810554e..041cf30294 100644 --- a/server/techtools.c +++ b/server/techtools.c @@ -1127,7 +1127,8 @@ void init_tech(struct research *research, bool update) while (tech != A_NONE) { tech = A_NONE; advance_index_iterate_max(A_FIRST, i, ac) { - if (research_invention_state(research, i) == TECH_PREREQS_KNOWN) { + if (valid_advance_by_number(i) != NULL + && research_invention_state(research, i) == TECH_PREREQS_KNOWN) { /* Found a tech which can be researched. */ tech = i; break; @@ -1176,7 +1177,7 @@ void init_tech(struct research *research, bool update) } /************************************************************************//** - Gives global (read from the game ruleset file) and nation (read from the + Gives global (read from the game.ruleset file) and nation (read from the nation ruleset files) initial techs as specified in the ruleset, and random free technologies thanks to the techlevel setting. ****************************************************************************/ -- 2.39.2