From d46652e241bca9278ff5f414e136cb572a75afbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Sat, 9 Apr 2022 18:38:18 +0200 Subject: [PATCH 2/3] =?UTF-8?q?OSDN!41121=20S=C5=82awomir=20Lach=20=20-=20Add=20routines=20to=20load=20counters=20fro?= =?UTF-8?q?m=20ruleset=20Basic=20routines=20to=20load=20counter=20definiti?= =?UTF-8?q?ons=20from=20ruleset=20are=20added=20by=20this=20patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit diff --git a/server/ruleset.c b/server/ruleset.c index 6e994de287..76001fe919 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -1343,7 +1343,7 @@ static bool load_game_names(struct section_file *file, (void) secfile_entry_by_path(file, "datafile.description"); /* unused */ (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */ - + sec = secfile_sections_by_name_prefix(file, ACHIEVEMENT_SECTION_PREFIX); nval = (NULL != sec ? section_list_size(sec) : 0); if (nval > MAX_ACHIEVEMENT_TYPES) { @@ -1422,11 +1422,14 @@ static bool load_game_names(struct section_file *file, section_list_destroy(sec); ok = FALSE; } else { - game.control.num_goods_types = nval; } if (ok) { - city_counters_iterate(pcount) { + int count_idx; + + for (count_idx = 0; count_idx < nval; ++count_idx) { + struct counter *pcount = counter_by_id(count_idx); + const char *sec_name = section_name(section_list_get(sec, counter_index(pcount))); @@ -1436,7 +1439,7 @@ static bool load_game_names(struct section_file *file, ok = FALSE; break; } - } city_counters_iterate_end; + } } section_list_destroy(sec); } @@ -7584,12 +7587,51 @@ static bool load_ruleset_game(struct section_file *file, bool act, if (sec != NULL) { int num = section_list_size(sec); + int curr_; - for (i = 0; i < num; i++) { + for (curr_ = 0; curr_ < num; ++curr_) { - const char *sec_name = section_name(section_list_get(sec, i)); + struct counter *pcount = counter_by_id(curr_); + const char *sec_name = section_name(section_list_get(sec, curr_)); const char *counter_type = secfile_lookup_str_default(file, NULL, "%s.type", sec_name); + const char *counter_target = secfile_lookup_str_default(file, NULL, + "%s.range", sec_name); + + + enum counter_behaviour cb = counter_behaviour_by_name(counter_type, fc_strcasecmp); + if (!counter_behaviour_is_valid(cb)) { + + ruleset_error(LOG_ERROR, "\"%s\" unknown counter type \"%s\".", + filename, counter_type); + ok = FALSE; + break; + } + + enum counter_target tg = counter_target_by_name(counter_target, fc_strcasecmp); + if (!counter_target_is_valid(tg)) { + + ruleset_error(LOG_ERROR, "\"%s\" unknown counter range \"%s\".", + filename, counter_target); + ok = FALSE; + break; + } + + if (!ruleset_load_names(&pcount->name, NULL, file, sec_name)) { + ruleset_error(LOG_ERROR, "\"%s\": Cannot load counter names", + filename); + ok = FALSE; + break; + } + + pcount->type = cb; + pcount->checkpoint = secfile_lookup_int_default(file, 1, + "%s.checkpoint", sec_name); + pcount->target = CTGT_CITY; + pcount->index = curr_; + pcount->def = secfile_lookup_int_default(file, 0, + "%s.def", sec_name); + attach_city_counter(pcount); } } } -- 2.35.1