Author: jtn
Date: Mon Jun 20 11:06:55 2016
New Revision: 32925

URL: http://svn.gna.org/viewcvs/freeciv?rev=32925&view=rev
Log:
Send whether init government is nation-specific to the client.

So that nation help is not cluttered up with "Initial government is
Despotism" unnecessarily.

default_government is sent too, but not used currently.

See gna patch #7278.

Modified:
    trunk/ai/default/aihand.c
    trunk/client/helpdata.c
    trunk/client/packhand.c
    trunk/common/game.c
    trunk/common/game.h
    trunk/common/nation.c
    trunk/common/nation.h
    trunk/common/networking/packets.def
    trunk/fc_version
    trunk/server/animals.c
    trunk/server/barbarian.c
    trunk/server/edithand.c
    trunk/server/plrhand.c
    trunk/server/rssanity.c
    trunk/server/ruleset.c
    trunk/server/srv_main.c
    trunk/server/stdinhand.c
    trunk/tools/ruleutil/rulesave.c

Modified: trunk/ai/default/aihand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aihand.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/ai/default/aihand.c   (original)
+++ trunk/ai/default/aihand.c   Mon Jun 20 11:06:55 2016
@@ -716,7 +716,7 @@
     struct nation_type *pnation = nation_of_player(pplayer);
     struct ai_plr *plr_data = def_ai_player_data(pplayer, ait);
 
-    if (government_of_player(pplayer) == pnation->init_government) {
+    if (government_of_player(pplayer) == init_government_of_nation(pnation)) {
       /* Default government is the crappy one we start in (like Despotism).
        * We want something better pretty soon! */
       want += 25 * game.info.turn;

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Mon Jun 20 11:06:55 2016
@@ -5916,18 +5916,30 @@
     .kind = VUT_NATION,
     .value = {.nation = pnation}
   };
+  bool print_break = TRUE;
+#define PRINT_BREAK() do { \
+    if (print_break) { \
+      if (buf[0] != '\0') { \
+        CATLSTR(buf, bufsz, "\n\n"); \
+      } \
+      print_break = FALSE; \
+    } \
+  } while(0)
 
   fc_assert_ret(NULL != buf && 0 < bufsz);
   buf[0] = '\0';
 
   if (pnation->legend[0] != '\0') {
     /* Client side legend is stored already translated */
-    sprintf(buf, "%s\n\n", pnation->legend);
+    cat_snprintf(buf, bufsz, "%s", pnation->legend);
   }
   
-  cat_snprintf(buf, bufsz,
-               _("Initial government is %s.\n"),
-               government_name_translation(pnation->init_government));
+  if (pnation->init_government) {
+    PRINT_BREAK();
+    cat_snprintf(buf, bufsz,
+                 _("Initial government is %s.\n"),
+                 government_name_translation(pnation->init_government));
+  }
   if (pnation->init_techs[0] != A_LAST) {
     const char *tech_names[MAX_NUM_TECH_LIST];
     int i;
@@ -5940,6 +5952,7 @@
         advance_name_translation(advance_by_number(pnation->init_techs[i]));
     }
     astr_build_and_list(&list, tech_names, i);
+    PRINT_BREAK();
     if (game.rgame.global_init_techs[0] != A_LAST) {
       cat_snprintf(buf, bufsz,
                    /* TRANS: %s is an and-separated list of techs */
@@ -6001,6 +6014,7 @@
       for (i = 0; i < n; i++) {
         astr_free(&utype_names[i]);
       }
+      PRINT_BREAK();
       cat_snprintf(buf, bufsz,
                    /* TRANS: %s is an and-separated list of unit types
                     * possibly with counts. Plurality is in total number of
@@ -6024,6 +6038,7 @@
           improvement_by_number(pnation->init_buildings[i]));
     }
     astr_build_and_list(&list, impr_names, i);
+    PRINT_BREAK();
     if (game.rgame.global_init_buildings[0] != B_LAST) {
       cat_snprintf(buf, bufsz,
                    /* TRANS: %s is an and-separated list of improvements */
@@ -6048,4 +6063,5 @@
     }
     CATLSTR(buf, bufsz, user_text);
   }
+#undef PRINT_BREAK
 }

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Mon Jun 20 11:06:55 2016
@@ -2048,6 +2048,8 @@
   VALIDATE(granary_num_inis,   MAX_GRANARY_INIS,       "granary entries");
 #undef VALIDATE
 
+  game.default_government =
+    government_by_number(game.info.default_government_id);
   game.government_during_revolution =
     government_by_number(game.info.government_during_revolution_id);
 
@@ -4142,6 +4144,7 @@
     }
   }
 
+  /* init_government may be NULL */
   pnation->init_government = government_by_number(packet->init_government_id);
   for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
     pnation->init_techs[i] = packet->init_techs[i];

Modified: trunk/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/game.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/common/game.c (original)
+++ trunk/common/game.c Mon Jun 20 11:06:55 2016
@@ -305,6 +305,7 @@
   game.info.global_warming   = GAME_DEFAULT_GLOBAL_WARMING;
   game.info.gold             = GAME_DEFAULT_GOLD;
   game.info.revolentype      = GAME_DEFAULT_REVOLENTYPE;
+  game.info.default_government_id = G_LAST;
   game.info.government_during_revolution_id = G_LAST;
   game.info.happyborders     = GAME_DEFAULT_HAPPYBORDERS;
   game.info.heating          = 0;

Modified: trunk/common/game.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/game.h?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/common/game.h (original)
+++ trunk/common/game.h Mon Jun 20 11:06:55 2016
@@ -88,6 +88,7 @@
   struct packet_calendar_info calendar;
   struct packet_timeout_info tinfo;
 
+  struct government *default_government; /* may be overridden by nation */
   struct government *government_during_revolution;
 
   struct conn_list *all_connections;   /* including not yet established */
@@ -256,7 +257,6 @@
       } mutexes;
 
       struct trait_limits default_traits[TRAIT_COUNT];
-      struct government *default_government;
 
       struct {
         char *description_file;

Modified: trunk/common/nation.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/nation.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/common/nation.c       (original)
+++ trunk/common/nation.c       Mon Jun 20 11:06:55 2016
@@ -648,6 +648,21 @@
 }
 
 /****************************************************************************
+  Returns initial government type for this nation.
+  Always returns non-NULL -- nation-specific government or failing that
+  ruleset default government.
+****************************************************************************/
+struct government *init_government_of_nation(const struct nation_type *pnation)
+{
+  NATION_CHECK(pnation, return game.default_government);
+  if (pnation->init_government) {
+    return pnation->init_government;
+  } else {
+    return game.default_government;
+  }
+}
+
+/****************************************************************************
   Returns nation's style.
 ****************************************************************************/
 struct nation_style *style_of_nation(const struct nation_type *pnation)

Modified: trunk/common/nation.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/nation.h?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/common/nation.h       (original)
+++ trunk/common/nation.h       Mon Jun 20 11:06:55 2016
@@ -120,7 +120,7 @@
   /* (Only used in the client for documentation purposes.) */
   int init_techs[MAX_NUM_TECH_LIST];
   int init_buildings[MAX_NUM_BUILDING_LIST];
-  struct government *init_government;
+  struct government *init_government; /* use game default_government if NULL */
   struct unit_type *init_units[MAX_NUM_UNIT_LIST];
 
   union {
@@ -198,6 +198,8 @@
 const char *nation_adjective_for_player(const struct player *pplayer);
 const char *nation_plural_translation(const struct nation_type *pnation);
 const char *nation_plural_for_player(const struct player *pplayer);
+
+struct government *init_government_of_nation(const struct nation_type 
*pnation);
 
 struct nation_style *style_of_nation(const struct nation_type *pnation);
 

Modified: trunk/common/networking/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/networking/packets.def?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/common/networking/packets.def (original)
+++ trunk/common/networking/packets.def Mon Jun 20 11:06:55 2016
@@ -489,6 +489,7 @@
   GOLD gold;
   GOLD_UPKEEP_STYLE gold_upkeep_style;
   REVOLENTYPE revolentype;
+  GOVERNMENT default_government_id;
   GOVERNMENT government_during_revolution_id;
   UINT8 granary_food_inc;
   UINT8 granary_food_ini[MAX_GRANARY_INIS];

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Mon Jun 20 11:06:55 2016
@@ -56,7 +56,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Jun.20"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Jun.20b"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/animals.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/animals.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/server/animals.c      (original)
+++ trunk/server/animals.c      Mon Jun 20 11:06:55 2016
@@ -120,7 +120,7 @@
   sz_strlcpy(plr->username, _(ANON_USER_NAME));
   plr->unassigned_user = TRUE;
   plr->is_connected = FALSE;
-  plr->government = anination->init_government;
+  plr->government = init_government_of_nation(anination);
   plr->economic.gold = 100;
 
   plr->phase_done = TRUE;

Modified: trunk/server/barbarian.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/barbarian.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/server/barbarian.c    (original)
+++ trunk/server/barbarian.c    Mon Jun 20 11:06:55 2016
@@ -162,7 +162,7 @@
   sz_strlcpy(barbarians->username, _(ANON_USER_NAME));
   barbarians->unassigned_user = TRUE;
   barbarians->is_connected = FALSE;
-  barbarians->government = nation->init_government;
+  barbarians->government = init_government_of_nation(nation);
   fc_assert(barbarians->revolution_finishes < 0);
   barbarians->server.got_first_city = FALSE;
   barbarians->economic.gold = 100;

Modified: trunk/server/edithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/edithand.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/server/edithand.c     (original)
+++ trunk/server/edithand.c     Mon Jun 20 11:06:55 2016
@@ -900,7 +900,7 @@
   sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
   pplayer->unassigned_user = TRUE;
   pplayer->is_connected = FALSE;
-  pplayer->government = pnation->init_government;
+  pplayer->government = init_government_of_nation(pnation);
   pplayer->server.got_first_city = FALSE;
 
   pplayer->economic.gold = 0;

Modified: trunk/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/plrhand.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/server/plrhand.c      (original)
+++ trunk/server/plrhand.c      Mon Jun 20 11:06:55 2016
@@ -2478,7 +2478,7 @@
   sz_strlcpy(cplayer->username, _(ANON_USER_NAME));
   cplayer->unassigned_user = TRUE;
   cplayer->is_connected = FALSE;
-  cplayer->government = nation_of_player(cplayer)->init_government;
+  cplayer->government = init_government_of_nation(nation_of_player(cplayer));
   fc_assert(cplayer->revolution_finishes < 0);
   /* No capital for the splitted player. */
   cplayer->server.got_first_city = FALSE;

Modified: trunk/server/rssanity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rssanity.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/server/rssanity.c     (original)
+++ trunk/server/rssanity.c     Mon Jun 20 11:06:55 2016
@@ -629,7 +629,7 @@
     }
   } advance_iterate_end;
 
-  if (game.server.default_government == game.government_during_revolution) {
+  if (game.default_government == game.government_during_revolution) {
     ruleset_error(LOG_ERROR,
                   "The government form %s reserved for revolution handling has 
been set as "
                   "default_government.",

Modified: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Mon Jun 20 11:06:55 2016
@@ -4112,7 +4112,7 @@
     free(vec);
   }
 
-  game.server.default_government = NULL;
+  game.default_government = NULL;
 
   ruleset_load_traits(game.server.default_traits, file, "default_traits", "");
   for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
@@ -4191,7 +4191,9 @@
      * specified once so not vulnerable to typos, and may usefully be set in
      * a specific ruleset to a gov not explicitly known by the nation set. */
     if (sval != NULL) {
-      game.server.default_government = government_by_rule_name(sval);
+      game.default_government = government_by_rule_name(sval);
+      game.info.default_government_id
+        = government_number(game.default_government);
     }
 
     sec = secfile_sections_by_name_prefix(file, NATION_SET_SECTION_PREFIX);
@@ -4636,26 +4638,28 @@
       }
       fc_strlcat(tmp, sec_name, 200);
       fc_strlcat(tmp, ".init_government", 200);
-      pnation->init_government = lookup_government(file, tmp, filename,
-                                                   
game.server.default_government);
-      /* init_government has to be in this specific ruleset, not just
-       * allowed_govs */
-      if (pnation->init_government == NULL) {
-        ok = FALSE;
-        break;
-      }
-      /* ...but if a list of govs has been specified, enforce that this
-       * nation's init_government is on the list. */
-      if (game.server.ruledit.allowed_govs != NULL
-          && 
!is_on_allowed_list(government_rule_name(pnation->init_government),
-                                 game.server.ruledit.allowed_govs,
-                                 game.server.ruledit.ag_count)) {
-        ruleset_error(LOG_ERROR,
-                      "Nation %s: init_government \"%s\" not allowed.",
-                      nation_rule_name(pnation),
-                      government_rule_name(pnation->init_government));
-        ok = FALSE;
-        break;
+      if (secfile_entry_by_path(file, tmp)) {
+        pnation->init_government = lookup_government(file, tmp, filename,
+                                                     NULL);
+        /* If specified, init_government has to be in this specific ruleset,
+         * not just allowed_govs */
+        if (pnation->init_government == NULL) {
+          ok = FALSE;
+          break;
+        }
+        /* ...but if a list of govs has been specified, enforce that this
+         * nation's init_government is on the list. */
+        if (game.server.ruledit.allowed_govs != NULL
+            && 
!is_on_allowed_list(government_rule_name(pnation->init_government),
+                                   game.server.ruledit.allowed_govs,
+                                   game.server.ruledit.ag_count)) {
+          ruleset_error(LOG_ERROR,
+                        "Nation %s: init_government \"%s\" not allowed.",
+                        nation_rule_name(pnation),
+                        government_rule_name(pnation->init_government));
+          ok = FALSE;
+          break;
+        }
       }
 
       /* Read default city names. */
@@ -7323,7 +7327,8 @@
     } nation_group_list_iterate_end;
     packet.ngroups = i;
 
-    packet.init_government_id = government_number(n->init_government);
+    packet.init_government_id = n->init_government
+      ? government_number(n->init_government) : government_count();
     fc_assert(ARRAY_SIZE(packet.init_techs) == ARRAY_SIZE(n->init_techs));
     for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
       packet.init_techs[i] = n->init_techs[i];

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Mon Jun 20 11:06:55 2016
@@ -2781,7 +2781,7 @@
   players_iterate(pplayer) {
     struct nation_type *pnation = nation_of_player(pplayer);
 
-    pplayer->government = pnation->init_government;
+    pplayer->government = init_government_of_nation(pnation);
 
     if (pnation->init_government == game.government_during_revolution) {
       /* If we do not do this, an assertion will trigger. This enables us to

Modified: trunk/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/stdinhand.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/server/stdinhand.c    (original)
+++ trunk/server/stdinhand.c    Mon Jun 20 11:06:55 2016
@@ -901,8 +901,8 @@
   server_player_init(pplayer, TRUE, TRUE);
 
   player_nation_defaults(pplayer, pnation, FALSE);
-  pplayer->government = pnation->init_government;
-  pplayer->target_government = pnation->init_government;
+  pplayer->government = pplayer->target_government =
+    init_government_of_nation(pnation);
   /* Find a color for the new player. */
   assign_player_colors();
 

Modified: trunk/tools/ruleutil/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruleutil/rulesave.c?rev=32925&r1=32924&r2=32925&view=diff
==============================================================================
--- trunk/tools/ruleutil/rulesave.c     (original)
+++ trunk/tools/ruleutil/rulesave.c     Mon Jun 20 11:06:55 2016
@@ -1490,7 +1490,7 @@
   save_building_list(sfile, pnat->init_buildings, path, "init_buildings");
   save_unit_list(sfile, pnat->init_units, path, "init_units");
 
-  if (pnat->init_government != game.server.default_government) {
+  if (pnat->init_government) {
     secfile_insert_str(sfile, government_rule_name(pnat->init_government),
                        "%s.init_government", path);
   }
@@ -1617,8 +1617,8 @@
                            "compatibility.allowed_styles");
   }
 
-  if (game.server.default_government != NULL) {
-    secfile_insert_str(sfile, 
government_rule_name(game.server.default_government),
+  if (game.default_government != NULL) {
+    secfile_insert_str(sfile, government_rule_name(game.default_government),
                        "compatibility.default_government");
   }
 


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

Reply via email to