From dba62b5b8b05e6492faf2de157605d91e153c5f5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 17 Jan 2023 21:37:57 +0200 Subject: [PATCH 35/35] 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 c18e78313b..48380d5425 100644 --- a/common/research.c +++ b/common/research.c @@ -816,7 +816,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: @@ -849,7 +849,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 @@ -863,6 +863,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) @@ -1316,7 +1320,8 @@ int recalculate_techs_researched(const struct research *presearch) int techs = 1; /* A_NONE known, and not part of below iteration */ advance_iterate(A_FIRST, 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 47e7ee4dfd..8544208857 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -7290,8 +7290,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 bfb79a5853..44177892f6 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_military_unit(punit)) { pplayer->score.units++; diff --git a/server/techtools.c b/server/techtools.c index 6c0425471f..b235b21930 100644 --- a/server/techtools.c +++ b/server/techtools.c @@ -1104,7 +1104,8 @@ void init_tech(struct research *research, bool update) while (tech != A_NONE) { tech = A_NONE; advance_index_iterate(A_FIRST, i) { - 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; @@ -1153,7 +1154,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.0