Author: cazfi
Date: Thu Apr  9 22:56:51 2015
New Revision: 28748

URL: http://svn.gna.org/viewcvs/freeciv?rev=28748&view=rev
Log:
"/explain phasemode" dynamically tells also the phasemode in force this turn, 
not only
the value stored to be active next turn.

See bug #22454

Modified:
    branches/S2_6/server/settings.c
    branches/S2_6/server/settings.h
    branches/S2_6/server/stdinhand.c
    branches/S2_6/tools/civmanual.c

Modified: branches/S2_6/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.c?rev=28748&r1=28747&r2=28748&view=diff
==============================================================================
--- branches/S2_6/server/settings.c     (original)
+++ branches/S2_6/server/settings.c     Thu Apr  9 22:56:51 2015
@@ -77,6 +77,7 @@
                                          size_t reject_msg_len);
 
 typedef void (*action_callback_func_t) (const struct setting *pset);
+typedef char *(*help_callback_func_t) (void);
 typedef const struct sset_val_name * (*val_name_func_t) (int value);
 
 struct setting {
@@ -97,6 +98,10 @@
    * etc, and should end with a "."
    */
   const char *extra_help;
+
+  /* help function */
+  const help_callback_func_t help_func;
+
   enum sset_type stype;
   enum sset_category scategory;
   enum sset_level slevel;
@@ -528,6 +533,27 @@
 
 #undef NAME_CASE
 
+/*************************************************************************
+  Help callback functions.
+*************************************************************************/
+
+/*************************************************************************
+  Help about phasemode setting
+*************************************************************************/
+static char *phasemode_help(void)
+{
+  static char pmhelp[512];
+
+  /* Translated here */
+  fc_snprintf(pmhelp, sizeof(pmhelp),
+              _("This setting controls whether players may make "
+                "moves at the same time during a turn. Change "
+                "in setting takes effect next turn. Currently, at least "
+                "to the end of this turn, mode is \"%s\"."),
+              phasemode_name(game.info.phase_mode)->pretty);
+
+  return pmhelp;
+}
 
 /*************************************************************************
   Action callback functions.
@@ -1090,7 +1116,7 @@
 #define GEN_BOOL(name, value, sclass, scateg, slevel, to_client,            \
                  short_help, extra_help, func_validate, func_action,        \
                  _default)                                                  \
-  {name, sclass, to_client, short_help, extra_help, SSET_BOOL,              \
+  {name, sclass, to_client, short_help, extra_help, NULL, SSET_BOOL,        \
       scateg, slevel,                                                       \
       {.boolean = {&value, _default, func_validate, bool_name,              \
                    FALSE}}, func_action, FALSE},
@@ -1098,7 +1124,7 @@
 #define GEN_INT(name, value, sclass, scateg, slevel, to_client,         \
                 short_help, extra_help, func_validate, func_action,     \
                 _min, _max, _default)                                   \
-  {name, sclass, to_client, short_help, extra_help, SSET_INT,           \
+  {name, sclass, to_client, short_help, extra_help, NULL, SSET_INT,     \
       scateg, slevel,                                                   \
       {.integer = {(int *) &value, _default, _min, _max, func_validate, \
                    0}},                                                 \
@@ -1107,15 +1133,15 @@
 #define GEN_STRING(name, value, sclass, scateg, slevel, to_client,      \
                    short_help, extra_help, func_validate, func_action,  \
                    _default)                                            \
-  {name, sclass, to_client, short_help, extra_help, SSET_STRING,        \
+  {name, sclass, to_client, short_help, extra_help, NULL, SSET_STRING,  \
       scateg, slevel,                                                   \
       {.string = {value, _default, sizeof(value), func_validate, ""}},  \
       func_action, FALSE},
 
 #define GEN_ENUM(name, value, sclass, scateg, slevel, to_client,            \
-                 short_help, extra_help, func_validate, func_action,        \
-                 func_name, _default)                                       \
-  { name, sclass, to_client, short_help, extra_help, SSET_ENUM,             \
+                 short_help, extra_help, func_help, func_validate,          \
+                 func_action, func_name, _default)                          \
+  { name, sclass, to_client, short_help, extra_help, func_help, SSET_ENUM,  \
       scateg, slevel,                                                       \
       { .enumerator = {  &value, sizeof(value), _default,                   \
                          func_validate,                                     \
@@ -1124,7 +1150,7 @@
 #define GEN_BITWISE(name, value, sclass, scateg, slevel, to_client,         \
                    short_help, extra_help, func_validate, func_action,      \
                    func_name, _default)                                     \
-  { name, sclass, to_client, short_help, extra_help, SSET_BITWISE,          \
+  { name, sclass, to_client, short_help, extra_help, NULL, SSET_BITWISE,    \
     scateg, slevel,                                                         \
      { .bitwise = { (unsigned *) (void *) &value, _default, func_validate,  \
        func_name, 0 }}, func_action, FALSE},
@@ -1149,7 +1175,7 @@
              "- \"Tiles per player\" (PLAYER): Number of (land) tiles per "
              "player (option 'tilesperplayer').\n"
              "- \"Width and height\" (XYSIZE): Map width and height in "
-             "tiles (options 'xsize' and 'ysize')."),
+             "tiles (options 'xsize' and 'ysize')."), NULL,
           mapsize_callback, NULL, mapsize_name, MAP_DEFAULT_MAPSIZE)
 
   GEN_INT("size", map.server.size, SSET_MAP_SIZE,
@@ -1271,7 +1297,7 @@
               "same island for every player or every team.\n"
               "If the requested generator is incompatible with other server "
               "settings, the server may fall back to another generator."),
-           generator_validate, NULL, generator_name, MAP_DEFAULT_GENERATOR)
+           NULL, generator_validate, NULL, generator_name, 
MAP_DEFAULT_GENERATOR)
 
   GEN_ENUM("startpos", map.server.startpos,
            SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
@@ -1306,7 +1332,7 @@
               "create the right number of continents for the choice of this "
               "'startpos' setting and the number of players, so this is "
               "unlikely to occur.)"),
-           NULL, NULL, startpos_name, MAP_DEFAULT_STARTPOS)
+           NULL, NULL, NULL, startpos_name, MAP_DEFAULT_STARTPOS)
 
   GEN_ENUM("teamplacement", map.server.team_placement,
            SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
@@ -1331,7 +1357,7 @@
               "team will be placed horizontally.\n"
               "- \"Vertical placement\" (VERTICAL): players of the same "
               "team will be placed vertically."),
-           NULL, NULL, teamplacement_name, MAP_DEFAULT_TEAM_PLACEMENT)
+           NULL, NULL, NULL, teamplacement_name, MAP_DEFAULT_TEAM_PLACEMENT)
 
   GEN_BOOL("tinyisles", map.server.tinyisles,
            SSET_MAP_GEN, SSET_GEOLOGY, SSET_RARE, SSET_TO_CLIENT,
@@ -1490,7 +1516,7 @@
              "those who have already accepted game to start by toggling 
\"Ready\" "
              "get that autotoggled off in the changed situation. This setting "
              "can be used to make readiness more persistent."),
-           NULL, NULL, persistentready_name, GAME_DEFAULT_PERSISTENTREADY)
+           NULL, NULL, NULL, persistentready_name, 
GAME_DEFAULT_PERSISTENTREADY)
 
   GEN_STRING("nationset", game.server.nationset,
              SSET_PLAYERS, SSET_INTERNAL, SSET_RARE, SSET_TO_CLIENT,
@@ -1896,7 +1922,7 @@
            N_("National borders"),
            N_("If this is not disabled, then any land tiles around a "
               "fortress or city will be owned by that nation."),
-           NULL, NULL, borders_name, GAME_DEFAULT_BORDERS)
+           NULL, NULL, NULL, borders_name, GAME_DEFAULT_BORDERS)
 
   GEN_ENUM("happyborders", game.info.happyborders,
            SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL,
@@ -1904,7 +1930,7 @@
            N_("Units inside borders cause no unhappiness"),
            N_("If this is set, units will not cause unhappiness when "
               "inside your borders, or even allies borders, depending "
-              "on value."), NULL, NULL,
+              "on value."), NULL, NULL, NULL,
            happyborders_name, GAME_DEFAULT_HAPPYBORDERS)
 
   GEN_ENUM("diplomacy", game.info.diplomacy,
@@ -1912,7 +1938,7 @@
            N_("Ability to do diplomacy with other players"),
            N_("This setting controls the ability to do diplomacy with "
               "other players."),
-           NULL, NULL, diplomacy_name, GAME_DEFAULT_DIPLOMACY)
+           NULL, NULL, NULL, diplomacy_name, GAME_DEFAULT_DIPLOMACY)
 
   GEN_ENUM("citynames", game.server.allowed_city_names,
            SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
@@ -1930,7 +1956,7 @@
               "\"Globally unique\", but a player isn't allowed to use a "
               "default city name of another nation unless it is a default "
               "for their nation also."),
-           NULL, NULL, citynames_name, GAME_DEFAULT_ALLOWED_CITY_NAMES)
+           NULL, NULL, NULL, citynames_name, GAME_DEFAULT_ALLOWED_CITY_NAMES)
 
   GEN_ENUM("plrcolormode", game.server.plrcolormode,
            SSET_RULES, SSET_INTERNAL, SSET_RARE, SSET_TO_CLIENT,
@@ -1962,7 +1988,7 @@
               "get a random color from the list in the ruleset.\n"
               "Regardless of this setting, individual player colors can be "
               "changed after the game starts with the 'playercolor' command."),
-           plrcol_validate, plrcol_action, plrcol_name,
+           NULL, plrcol_validate, plrcol_action, plrcol_name,
            GAME_DEFAULT_PLRCOLORMODE)
 
   /* Flexible rules: these can be changed after the game has started.
@@ -1985,7 +2011,7 @@
             * should not be translated. */
            N_("This setting controls how frequently the barbarians appear "
               "in the game. See also the 'onsetbarbs' setting."),
-           NULL, NULL, barbarians_name, GAME_DEFAULT_BARBARIANRATE)
+           NULL, NULL, NULL, barbarians_name, GAME_DEFAULT_BARBARIANRATE)
 
   GEN_INT("onsetbarbs", game.server.onsetbarbarian,
          SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_VITAL, SSET_TO_CLIENT,
@@ -2000,7 +2026,7 @@
            N_("Which method is used in determining how long period of anarchy "
               "lasts when changing government. The actual value is set with "
               "'revolen' setting."),
-           NULL, NULL, revolentype_name, GAME_DEFAULT_REVOLENTYPE)
+           NULL, NULL, NULL, revolentype_name, GAME_DEFAULT_REVOLENTYPE)
 
   GEN_INT("revolen", game.server.revolution_length,
          SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
@@ -2375,7 +2401,7 @@
            N_("This setting controls whether players may make "
               "moves at the same time during a turn. Change "
               "in setting takes effect next turn."),
-           NULL, NULL, phasemode_name, GAME_DEFAULT_PHASE_MODE)
+           phasemode_help, NULL, NULL, phasemode_name, GAME_DEFAULT_PHASE_MODE)
 
   GEN_INT("nettimeout", game.server.tcptimeout,
          SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
@@ -2514,7 +2540,7 @@
            SSET_META, SSET_INTERNAL, SSET_RARE, SSET_SERVER_ONLY,
            N_("Savegame compression algorithm"),
            N_("Compression library to use for savegames."),
-           NULL, NULL, compresstype_name, GAME_DEFAULT_COMPRESS_TYPE)
+           NULL, NULL, NULL, compresstype_name, GAME_DEFAULT_COMPRESS_TYPE)
 
   GEN_STRING("savename", game.server.save_name,
              SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_SERVER_ONLY,
@@ -2553,7 +2579,7 @@
            SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_SERVER_ONLY,
            N_("Scorelog level"),
            N_("Whether scores are logged from all players, AI included, "
-              "or only from human players."), NULL, NULL,
+              "or only from human players."), NULL, NULL, NULL,
            scoreloglevel_name, GAME_DEFAULT_SCORELOGLEVEL)
 
   GEN_STRING("scorefile", game.server.scorefile,
@@ -2644,12 +2670,16 @@
 }
 
 /****************************************************************************
-  Access function for the long (extra) help (not translated yet) of
-  the setting.
-****************************************************************************/
-const char *setting_extra_help(const struct setting *pset)
-{
-  return pset->extra_help;
+  Access function for the long (extra) help of the setting.
+  If 'constant' is TRUE, static, not-yet-translated string is always returned.
+****************************************************************************/
+const char *setting_extra_help(const struct setting *pset, bool constant)
+{
+  if (!constant && pset->help_func != NULL) {
+    return pset->help_func();
+  }
+
+  return _(pset->extra_help);
 }
 
 /****************************************************************************
@@ -4474,7 +4504,7 @@
     sz_strlcpy(setting.name, setting_name(pset));
     /* Send untranslated strings to client */
     sz_strlcpy(setting.short_help, setting_short_help(pset));
-    sz_strlcpy(setting.extra_help, setting_extra_help(pset));
+    sz_strlcpy(setting.extra_help, setting_extra_help(pset, TRUE));
     setting.category = pset->scategory;
 
     send_packet_server_setting_const(pconn, &setting);

Modified: branches/S2_6/server/settings.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.h?rev=28748&r1=28747&r2=28748&view=diff
==============================================================================
--- branches/S2_6/server/settings.h     (original)
+++ branches/S2_6/server/settings.h     Thu Apr  9 22:56:51 2015
@@ -97,7 +97,7 @@
 
 const char *setting_name(const struct setting *pset);
 const char *setting_short_help(const struct setting *pset);
-const char *setting_extra_help(const struct setting *pset);
+const char *setting_extra_help(const struct setting *pset, bool constant);
 enum sset_type setting_type(const struct setting *pset);
 enum sset_level setting_level(const struct setting *pset);
 enum sset_category setting_category(const struct setting *pset);

Modified: branches/S2_6/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/stdinhand.c?rev=28748&r1=28747&r2=28748&view=diff
==============================================================================
--- branches/S2_6/server/stdinhand.c    (original)
+++ branches/S2_6/server/stdinhand.c    Thu Apr  9 22:56:51 2015
@@ -1649,6 +1649,7 @@
 {
   char val_buf[256], def_buf[256];
   struct setting *pset = setting_by_number(id);
+  const char *sethelp;
 
   if (setting_short_help(pset)) {
     cmd_reply(help_cmd, caller, C_COMMENT,
@@ -1661,8 +1662,9 @@
               _("Option: %s"), setting_name(pset));
   }
 
-  if (strlen(setting_extra_help(pset)) > 0) {
-    char *help = fc_strdup(_(setting_extra_help(pset)));
+  sethelp = setting_extra_help(pset, FALSE);
+  if (strlen(sethelp) > 0) {
+    char *help = fc_strdup(sethelp);
 
     fc_break_lines(help, LINE_BREAK);
     cmd_reply(help_cmd, caller, C_COMMENT, _("Description:"));

Modified: branches/S2_6/tools/civmanual.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/civmanual.c?rev=28748&r1=28747&r2=28748&view=diff
==============================================================================
--- branches/S2_6/tools/civmanual.c     (original)
+++ branches/S2_6/tools/civmanual.c     Thu Apr  9 22:56:51 2015
@@ -189,12 +189,14 @@
       fprintf(doc, _("<h1>Freeciv %s server options</h1>\n\n"), 
VERSION_STRING);
       settings_iterate(SSET_ALL, pset) {
         char buf[256];
+        const char *sethelp;
 
         fprintf(doc, SEPARATOR);
         fprintf(doc, "%s%s - %s%s\n\n", SECTION_BEGIN, setting_name(pset),
                 _(setting_short_help(pset)), SECTION_END);
-        if (strlen(setting_extra_help(pset)) > 0) {
-          char *help = fc_strdup(_(setting_extra_help(pset)));
+        sethelp = _(setting_extra_help(pset, TRUE));
+        if (strlen(sethelp) > 0) {
+          char *help = fc_strdup(sethelp);
           size_t help_len = strlen(help) + 1;
 
           fc_break_lines(help, LINE_BREAK);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to