From ff6e20e5ff096f00c914642474e457ca2860b6db Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 7 Apr 2021 21:59:31 +0300 Subject: [PATCH 45/45] Rulesave: Save comment about civstyle.granary settings See osdn #41936 Signed-off-by: Marko Lindqvist --- data/ruledit/comments-3.2.txt | 13 +++++++++++++ tools/ruleutil/comments.c | 32 +++++++++++++++++++++++++++++++- tools/ruleutil/comments.h | 5 +++++ tools/ruleutil/rulesave.c | 2 ++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/data/ruledit/comments-3.2.txt b/data/ruledit/comments-3.2.txt index 40cd8b4d86..eeea848ddf 100644 --- a/data/ruledit/comments-3.2.txt +++ b/data/ruledit/comments-3.2.txt @@ -1187,3 +1187,16 @@ clauses = "\ ;\n\ ; */ <-- avoid gettext warnings\n\ " + + +[entrydoc] +; This section has comments documenting individual entries + +granary = "\n\ +; Parameters used to generalize the calculation of city granary size:\n\ +; if city_size <= num_inis:\n\ +; city_granary_size = (granary_food_ini[city_size] * foodbox / 100)\n\ +; if city_size > num_inis;\n\ +; city_granary_size = (granary_food_ini[num_inis] +\n\ +; granary_food_inc * (city_size - num_inis)) * foodbox / 100\ +" diff --git a/tools/ruleutil/comments.c b/tools/ruleutil/comments.c index fb327dc6ae..b554c70a71 100644 --- a/tools/ruleutil/comments.c +++ b/tools/ruleutil/comments.c @@ -23,6 +23,7 @@ #include "comments.h" static struct { + /* Comment sections */ char *file_header; char *buildings; char *tech_classes; @@ -49,6 +50,9 @@ static struct { char *nationgroups; char *nationsets; char *clauses; + + /* Comment entries */ + char *civstyle_granary; } comments_storage; /**********************************************************************//** @@ -120,6 +124,9 @@ bool comments_load(void) comment_file, "typedoc.nationsets"); comment_load(comments_storage.clauses, comment_file, "typedoc.clauses"); + comment_load(comments_storage.civstyle_granary, comment_file, + "entrydoc.granary"); + secfile_check_unused(comment_file); secfile_destroy(comment_file); @@ -135,7 +142,7 @@ void comments_free(void) } /**********************************************************************//** - Generic comment writing function with some error checking. + Generic comment section writing function with some error checking. **************************************************************************/ static void comment_write(struct section_file *sfile, const char *comment, const char *name) @@ -148,6 +155,20 @@ static void comment_write(struct section_file *sfile, const char *comment, secfile_insert_long_comment(sfile, comment); } +/**********************************************************************//** + Generic comment entry writing function with some error checking. +**************************************************************************/ +static void comment_entry_write(struct section_file *sfile, + const char *comment, const char *section) +{ + if (comment == NULL) { + log_error("Comment to section %s missing.", section); + return; + } + + secfile_insert_comment(sfile, comment, "%s", section); +} + /**********************************************************************//** Write file header. **************************************************************************/ @@ -355,3 +376,12 @@ void comment_clauses(struct section_file *sfile) { comment_write(sfile, comments_storage.clauses, "Clauses"); } + +/**********************************************************************//** + Write civstyle granary settings header. +**************************************************************************/ +void comment_civstyle_granary(struct section_file *sfile) +{ + comment_entry_write(sfile, comments_storage.civstyle_granary, + "civstyle"); +} diff --git a/tools/ruleutil/comments.h b/tools/ruleutil/comments.h index a63bddf9d2..48f887ac76 100644 --- a/tools/ruleutil/comments.h +++ b/tools/ruleutil/comments.h @@ -24,6 +24,8 @@ struct section_file; bool comments_load(void); void comments_free(void); + +/* Section comments */ void comment_file_header(struct section_file *sfile); void comment_buildings(struct section_file *sfile); @@ -52,6 +54,9 @@ void comment_nationgroups(struct section_file *sfile); void comment_nations(struct section_file *sfile); void comment_clauses(struct section_file *sfile); +/* Entry comments */ +void comment_civstyle_granary(struct section_file *sfile); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index f89ac392ff..82dca62097 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -1179,6 +1179,8 @@ static bool save_game_ruleset(const char *filename, const char *name) RS_DEFAULT_UPGRADE_VETERAN_LOSS, "civstyle.autoupgrade_veteran_loss", NULL); + comment_civstyle_granary(sfile); + secfile_insert_int_vec(sfile, game.info.granary_food_ini, game.info.granary_num_inis, "civstyle.granary_food_ini"); -- 2.30.2