From b262a6ee1f400d1ca772655f5d61b1c0385831ca Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 1 Oct 2023 22:33:57 +0300 Subject: [PATCH 55/55] Split Terrain manual creation to separate source file See osdn #48783 Signed-off-by: Marko Lindqvist --- meson.build | 1 + tools/manual/Makefile.am | 3 +- tools/manual/fc_manual.c | 133 +------------------------- tools/manual/fc_manual.h | 1 + tools/manual/manual_terrain.c | 169 ++++++++++++++++++++++++++++++++++ translations/core/POTFILES.in | 1 + 6 files changed, 178 insertions(+), 130 deletions(-) create mode 100644 tools/manual/manual_terrain.c diff --git a/meson.build b/meson.build index 0aff6222a7..6cc886ba16 100644 --- a/meson.build +++ b/meson.build @@ -4250,6 +4250,7 @@ executable('freeciv-manual', 'tools/manual/fc_manual.c', 'tools/manual/manual_commands.c', 'tools/manual/manual_settings.c', + 'tools/manual/manual_terrain.c', 'client/helpdata.c', link_with: [common_lib, server_lib, tool_lib, ais], include_directories: [tool_inc, diff --git a/tools/manual/Makefile.am b/tools/manual/Makefile.am index 7a7a6f8f67..2358224b7e 100644 --- a/tools/manual/Makefile.am +++ b/tools/manual/Makefile.am @@ -21,7 +21,8 @@ freeciv_manual_SOURCES = \ fc_manual.c \ fc_manual.h \ manual_commands.c \ - manual_settings.c + manual_settings.c \ + manual_terrain.c # This is a bit of a hack. The program links in with the server lib # but also uses some files from the client. diff --git a/tools/manual/fc_manual.c b/tools/manual/fc_manual.c index ebf9650828..c8b7670f6f 100644 --- a/tools/manual/fc_manual.c +++ b/tools/manual/fc_manual.c @@ -39,7 +39,6 @@ #include "fc_cmdhelp.h" #include "fc_interface.h" #include "fc_types.h" /* LINE_BREAK */ -#include "game.h" #include "government.h" #include "improvement.h" #include "map.h" @@ -354,12 +353,12 @@ static bool manual_command(struct tag_types *tag_info) } if (!manual_settings(tag_info) - || !manual_commands(tag_info)) { + || !manual_commands(tag_info) + || !manual_terrain(tag_info)) { return FALSE; } - for (manuals = MANUAL_TERRAIN; manuals < MANUAL_COUNT; manuals++) { - int ri; + for (manuals = MANUAL_BUILDINGS; manuals < MANUAL_COUNT; manuals++) { char mnamebuf[20]; FILE *doc; @@ -372,135 +371,11 @@ static bool manual_command(struct tag_types *tag_info) switch (manuals) { case MANUAL_SETTINGS: case MANUAL_COMMANDS: + case MANUAL_TERRAIN: /* Should be handled in separate functions */ fc_assert(FALSE); break; - case MANUAL_TERRAIN: - /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ - fprintf(doc, _("%sFreeciv %s terrain help (%s)%s\n\n"), tag_info->title_begin, - VERSION_STRING, game.control.name, tag_info->title_end); - fprintf(doc, "", _("Terrain")); - fprintf(doc, "", _("Resources")); - fprintf(doc, "", _("Move cost"), _("Defense bonus")); - fprintf(doc, "", - _("Irrigation"), _("Cultivate"), _("Mining"), _("Plant"), _("Transform"), - /* xgettext:no-c-format */ - _("% of Road bonus"), _("turns")); - ri = 0; - if (game.control.num_road_types > 0) { - fprintf(doc, "", extra_name_translation(pextra)); - } - } extra_type_by_cause_iterate_end; - fprintf(doc, "\n\n"); - terrain_type_iterate(pterrain) { - struct extra_type **r; - struct universal for_terr - = { .kind = VUT_TERRAIN, .value = { .terrain = pterrain }}; - - if (0 == strlen(terrain_rule_name(pterrain))) { - /* Must be a disabled piece of terrain */ - continue; - } - - fprintf(doc, "", - tag_info->image_begin, pterrain->graphic_str, - tag_info->image_end, - terrain_name_translation(pterrain)); - fprintf(doc, "\n", - pterrain->output[O_FOOD], pterrain->output[O_SHIELD], - pterrain->output[O_TRADE]); - - /* TODO: include resource frequency information */ - fprintf(doc, "\n"); - - fprintf(doc, "\n", - pterrain->movement_cost, pterrain->defense_bonus); - - fprintf(doc, "\n", - pterrain->road_output_incr_pct[O_FOOD], - pterrain->road_output_incr_pct[O_SHIELD], - pterrain->road_output_incr_pct[O_TRADE]); - - ri = 0; - if (game.control.num_road_types > 0) { - fprintf(doc, "", terrain_extra_build_time(pterrain, ACTIVITY_GEN_ROAD, - pextra)); - } - } extra_type_by_cause_iterate_end; - fprintf(doc, "\n\n"); - } terrain_type_iterate_end; - - fprintf(doc, "
%sF/P/T%s%s
%s
%s
%s
%s
%s
%s
%s
(%s)
"); - } - extra_type_by_cause_iterate(EC_ROAD, pextra) { - if (++ri < game.control.num_road_types) { - fprintf(doc, "%s
", extra_name_translation(pextra)); - } else { - /* Last one */ - fprintf(doc, "%s
%s%s%s%s%d/%d/%d\n"); - for (r = pterrain->resources; *r; r++) { - fprintf(doc, "" - "\n", - tag_info->image_begin, (*r)->graphic_str, tag_info->image_end, - extra_name_translation(*r), - (*r)->data.resource->output[O_FOOD], - (*r)->data.resource->output[O_SHIELD], - (*r)->data.resource->output[O_TRADE]); - } - fprintf(doc, "
%s%s%s%s%d/%d/%d
%d
+%d%%
\n"); - if (action_id_univs_not_blocking(ACTION_IRRIGATE, - NULL, &for_terr)) { - fprintf(doc, "\n", - pterrain->irrigation_food_incr, pterrain->irrigation_time); - } else { - fprintf(doc, "\n", _("impossible")); - } - if (pterrain->cultivate_result != NULL - && action_id_univs_not_blocking(ACTION_CULTIVATE, - NULL, &for_terr)) { - fprintf(doc, "\n", - terrain_name_translation(pterrain->cultivate_result), - pterrain->cultivate_time); - } else { - fprintf(doc, "\n", _("impossible")); - } - if (action_id_univs_not_blocking(ACTION_MINE, NULL, &for_terr)) { - fprintf(doc, "\n", - pterrain->mining_shield_incr, pterrain->mining_time); - } else { - fprintf(doc, "\n", _("impossible")); - } - if (pterrain->plant_result != NULL - && action_id_univs_not_blocking(ACTION_PLANT, - NULL, &for_terr)) { - fprintf(doc, "\n", - terrain_name_translation(pterrain->plant_result), - pterrain->plant_time); - } else { - fprintf(doc, "\n", _("impossible")); - } - - if (pterrain->transform_result - && action_id_univs_not_blocking(ACTION_TRANSFORM_TERRAIN, - NULL, &for_terr)) { - fprintf(doc, "\n", - terrain_name_translation(pterrain->transform_result), - pterrain->transform_time); - } else { - fprintf(doc, "\n"); - } - fprintf(doc, "\n
+%d F(%d)
%s
%s(%d)
%s
+%d P(%d)
%s
%s(%d)
%s
%s(%d)
-(-)
%d / %d / %d
"); - } - extra_type_by_cause_iterate(EC_ROAD, pextra) { - if (++ri < game.control.num_road_types) { - fprintf(doc, "%d / ", terrain_extra_build_time(pterrain, ACTIVITY_GEN_ROAD, - pextra)); - } else { - fprintf(doc, "%d
\n"); - - break; - case MANUAL_BUILDINGS: case MANUAL_WONDERS: if (manuals == MANUAL_BUILDINGS) { diff --git a/tools/manual/fc_manual.h b/tools/manual/fc_manual.h index 5958a548f8..c1d6dc342d 100644 --- a/tools/manual/fc_manual.h +++ b/tools/manual/fc_manual.h @@ -61,6 +61,7 @@ char *html_special_chars(char *str, size_t *len); /* Individual manual pages */ bool manual_settings(struct tag_types *tag_info); bool manual_commands(struct tag_types *tag_info); +bool manual_terrain(struct tag_types *tag_info); #ifdef __cplusplus } diff --git a/tools/manual/manual_terrain.c b/tools/manual/manual_terrain.c new file mode 100644 index 0000000000..daeeccf78b --- /dev/null +++ b/tools/manual/manual_terrain.c @@ -0,0 +1,169 @@ +/*********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/* utility */ +#include "fcintl.h" + +/* common */ +#include "game.h" + +/* tools/manual */ +#include "fc_manual.h" + +/**********************************************************************//** + Write terrain manual page + + @param tag_info Tag set to use + @return Success +**************************************************************************/ +bool manual_terrain(struct tag_types *tag_info) +{ + FILE *doc; + int ri; + + doc = manual_start(tag_info, MANUAL_TERRAIN); + + if (doc == NULL) { + return FALSE; + } + + /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ + fprintf(doc, _("%sFreeciv %s terrain help (%s)%s\n\n"), tag_info->title_begin, + VERSION_STRING, game.control.name, tag_info->title_end); + fprintf(doc, "", _("Terrain")); + fprintf(doc, "", _("Resources")); + fprintf(doc, "", _("Move cost"), _("Defense bonus")); + fprintf(doc, "", + _("Irrigation"), _("Cultivate"), _("Mining"), _("Plant"), _("Transform"), + /* xgettext:no-c-format */ + _("% of Road bonus"), _("turns")); + ri = 0; + if (game.control.num_road_types > 0) { + fprintf(doc, "", extra_name_translation(pextra)); + } + } extra_type_by_cause_iterate_end; + fprintf(doc, "\n\n"); + terrain_type_iterate(pterrain) { + struct extra_type **r; + struct universal for_terr + = { .kind = VUT_TERRAIN, .value = { .terrain = pterrain }}; + + if (0 == strlen(terrain_rule_name(pterrain))) { + /* Must be a disabled piece of terrain */ + continue; + } + + fprintf(doc, "", + tag_info->image_begin, pterrain->graphic_str, + tag_info->image_end, + terrain_name_translation(pterrain)); + fprintf(doc, "\n", + pterrain->output[O_FOOD], pterrain->output[O_SHIELD], + pterrain->output[O_TRADE]); + + /* TODO: include resource frequency information */ + fprintf(doc, "\n"); + + fprintf(doc, "\n", + pterrain->movement_cost, pterrain->defense_bonus); + + fprintf(doc, "\n", + pterrain->road_output_incr_pct[O_FOOD], + pterrain->road_output_incr_pct[O_SHIELD], + pterrain->road_output_incr_pct[O_TRADE]); + + ri = 0; + if (game.control.num_road_types > 0) { + fprintf(doc, "", terrain_extra_build_time(pterrain, ACTIVITY_GEN_ROAD, + pextra)); + } + } extra_type_by_cause_iterate_end; + fprintf(doc, "\n\n"); + } terrain_type_iterate_end; + + fprintf(doc, "
%sF/P/T%s%s
%s
%s
%s
%s
%s
%s
%s
(%s)
"); + } + extra_type_by_cause_iterate(EC_ROAD, pextra) { + if (++ri < game.control.num_road_types) { + fprintf(doc, "%s
", extra_name_translation(pextra)); + } else { + /* Last one */ + fprintf(doc, "%s
%s%s%s%s%d/%d/%d\n"); + for (r = pterrain->resources; *r; r++) { + fprintf(doc, "" + "\n", + tag_info->image_begin, (*r)->graphic_str, tag_info->image_end, + extra_name_translation(*r), + (*r)->data.resource->output[O_FOOD], + (*r)->data.resource->output[O_SHIELD], + (*r)->data.resource->output[O_TRADE]); + } + fprintf(doc, "
%s%s%s%s%d/%d/%d
%d
+%d%%
\n"); + if (action_id_univs_not_blocking(ACTION_IRRIGATE, + NULL, &for_terr)) { + fprintf(doc, "\n", + pterrain->irrigation_food_incr, pterrain->irrigation_time); + } else { + fprintf(doc, "\n", _("impossible")); + } + if (pterrain->cultivate_result != NULL + && action_id_univs_not_blocking(ACTION_CULTIVATE, + NULL, &for_terr)) { + fprintf(doc, "\n", + terrain_name_translation(pterrain->cultivate_result), + pterrain->cultivate_time); + } else { + fprintf(doc, "\n", _("impossible")); + } + if (action_id_univs_not_blocking(ACTION_MINE, NULL, &for_terr)) { + fprintf(doc, "\n", + pterrain->mining_shield_incr, pterrain->mining_time); + } else { + fprintf(doc, "\n", _("impossible")); + } + if (pterrain->plant_result != NULL + && action_id_univs_not_blocking(ACTION_PLANT, + NULL, &for_terr)) { + fprintf(doc, "\n", + terrain_name_translation(pterrain->plant_result), + pterrain->plant_time); + } else { + fprintf(doc, "\n", _("impossible")); + } + + if (pterrain->transform_result + && action_id_univs_not_blocking(ACTION_TRANSFORM_TERRAIN, + NULL, &for_terr)) { + fprintf(doc, "\n", + terrain_name_translation(pterrain->transform_result), + pterrain->transform_time); + } else { + fprintf(doc, "\n"); + } + fprintf(doc, "\n
+%d F(%d)
%s
%s(%d)
%s
+%d P(%d)
%s
%s(%d)
%s
%s(%d)
-(-)
%d / %d / %d
"); + } + extra_type_by_cause_iterate(EC_ROAD, pextra) { + if (++ri < game.control.num_road_types) { + fprintf(doc, "%d / ", terrain_extra_build_time(pterrain, ACTIVITY_GEN_ROAD, + pextra)); + } else { + fprintf(doc, "%d
\n"); + + manual_finalize(tag_info, doc, _("Terrain")); + + return TRUE; +} diff --git a/translations/core/POTFILES.in b/translations/core/POTFILES.in index 40877f2f0c..4cfcf9ffca 100644 --- a/translations/core/POTFILES.in +++ b/translations/core/POTFILES.in @@ -394,6 +394,7 @@ tools/fcmp/mpgui_qt_worker.cpp tools/manual/fc_manual.c tools/manual/manual_commands.c tools/manual/manual_settings.c +tools/manual/manual_terrain.c tools/ruleutil/rulesave.c server/actiontools.c server/aiiface.c -- 2.40.1