From 88584694c65abfa62677131ab156350bf4b6eaa0 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 17 Jan 2023 21:41:05 +0200 Subject: [PATCH 17/17] Fix errors because of Never reachable techs Reported by dark-ether See osdn #45115 Signed-off-by: Marko Lindqvist --- common/research.c | 11 ++++++++--- server/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 5323e9a838..1444445df9 100644 --- a/common/research.c +++ b/common/research.c @@ -836,7 +836,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: @@ -869,7 +869,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 @@ -883,6 +883,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) @@ -1336,7 +1340,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/savegame3.c b/server/savegame3.c index eb5598474b..69623905aa 100644 --- a/server/savegame3.c +++ b/server/savegame3.c @@ -6807,8 +6807,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 0ee31235f8..6770bd5213 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 eed0e3ebac..58b034ad84 100644 --- a/server/techtools.c +++ b/server/techtools.c @@ -1107,7 +1107,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; @@ -1156,7 +1157,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