Author: cazfi
Date: Sat Oct 31 19:37:52 2015
New Revision: 30331

URL: http://svn.gna.org/viewcvs/freeciv?rev=30331&view=rev
Log:
Added server setting 'traitdistribution'.

Requested by Jacob Nevins <jtn>

See patch #5028

Modified:
    branches/S2_6/ai/aitraits.c
    branches/S2_6/common/fc_types.h
    branches/S2_6/common/game.c
    branches/S2_6/common/game.h
    branches/S2_6/common/traits.h
    branches/S2_6/data/alien/nations.ruleset
    branches/S2_6/data/civ1/nations.ruleset
    branches/S2_6/data/civ2/nations.ruleset
    branches/S2_6/data/civ2civ3/nations.ruleset
    branches/S2_6/data/classic/nations.ruleset
    branches/S2_6/data/experimental/game.ruleset
    branches/S2_6/data/experimental/nations.ruleset
    branches/S2_6/data/multiplayer/nations.ruleset
    branches/S2_6/data/stub/nations.ruleset
    branches/S2_6/fc_version
    branches/S2_6/server/ruleset.c
    branches/S2_6/server/settings.c

Modified: branches/S2_6/ai/aitraits.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/aitraits.c?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/ai/aitraits.c (original)
+++ branches/S2_6/ai/aitraits.c Sat Oct 31 19:37:52 2015
@@ -20,6 +20,7 @@
 #include "rand.h"
 
 /* common */
+#include "game.h"
 #include "player.h"
 #include "traits.h"
 
@@ -39,7 +40,14 @@
     int min = pplayer->nation->server.traits[tr].min;
     int max = pplayer->nation->server.traits[tr].max;
 
-    pplayer->ai_common.traits[tr].val = fc_rand(max + 1 - min) + min;
+    switch (game.server.trait_dist) {
+    case TDM_FIXED:
+      pplayer->ai_common.traits[tr].val = 
pplayer->nation->server.traits[tr].fixed;
+      break;
+    case TDM_EVEN:
+      pplayer->ai_common.traits[tr].val = fc_rand(max + 1 - min) + min;
+      break;
+    }
     pplayer->ai_common.traits[tr].mod = 0;
   }
 }

Modified: branches/S2_6/common/fc_types.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/fc_types.h?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/common/fc_types.h     (original)
+++ branches/S2_6/common/fc_types.h     Sat Oct 31 19:37:52 2015
@@ -562,7 +562,12 @@
   BORDERS_DISABLED = 0,
   BORDERS_ENABLED,
   BORDERS_SEE_INSIDE,
-  BORDERS_EXPAND,
+  BORDERS_EXPAND
+};
+
+enum trait_dist_mode {
+  TDM_FIXED = 0,
+  TDM_EVEN
 };
 
 /* Used in the network protocol. */

Modified: branches/S2_6/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.c?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/common/game.c (original)
+++ branches/S2_6/common/game.c Sat Oct 31 19:37:52 2015
@@ -394,6 +394,7 @@
     game.server.mgr_turninterval  = GAME_DEFAULT_MGR_TURNINTERVAL;
     game.server.mgr_worldchance   = GAME_DEFAULT_MGR_WORLDCHANCE;
     game.server.migration         = GAME_DEFAULT_MIGRATION;
+    game.server.trait_dist        = GAME_DEFAULT_TRAIT_DIST_MODE;
     game.server.min_players       = GAME_DEFAULT_MIN_PLAYERS;
     game.server.natural_city_names = GAME_DEFAULT_NATURALCITYNAMES;
     game.server.plrcolormode      = GAME_DEFAULT_PLRCOLORMODE;

Modified: branches/S2_6/common/game.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.h?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/common/game.h (original)
+++ branches/S2_6/common/game.h Sat Oct 31 19:37:52 2015
@@ -154,6 +154,7 @@
       int mgr_turninterval;
       int mgr_worldchance;
       bool migration;
+      enum trait_dist_mode trait_dist;
       int min_players;
       bool natural_city_names;
       int netwait;
@@ -425,7 +426,9 @@
 #define GAME_DEFAULT_DISASTERS       10
 #define GAME_MIN_DISASTERS           0
 #define GAME_MAX_DISASTERS           1000
- 
+
+#define GAME_DEFAULT_TRAIT_DIST_MODE TDM_FIXED
+
 #define GAME_DEFAULT_SAVEPALACE      TRUE
 
 #define GAME_DEFAULT_HOMECAUGHTUNITS TRUE

Modified: branches/S2_6/common/traits.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/traits.h?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/common/traits.h       (original)
+++ branches/S2_6/common/traits.h       Sat Oct 31 19:37:52 2015
@@ -41,6 +41,7 @@
 {
   int min;
   int max;
+  int fixed;
 };
 
 #ifdef __cplusplus

Modified: branches/S2_6/data/alien/nations.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/alien/nations.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/alien/nations.ruleset    (original)
+++ branches/S2_6/data/alien/nations.ruleset    Sat Oct 31 19:37:52 2015
@@ -31,10 +31,13 @@
 [default_traits]
 ;expansionist_min = 50
 ;expansionist_max = 50
+;expansionist_default = 50
 ;trader_min = 50
 ;trader_max = 50
+;trader_default = 50
 ;aggressive_min = 50
 ;aggressive_max = 50
+;aggressive_default = 50
 
 ; Descriptions of nation sets
 ; These are self-contained subsets of the available nations; one of these

Modified: branches/S2_6/data/civ1/nations.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/civ1/nations.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/civ1/nations.ruleset     (original)
+++ branches/S2_6/data/civ1/nations.ruleset     Sat Oct 31 19:37:52 2015
@@ -34,10 +34,13 @@
 [default_traits]
 ;expansionist_min = 50
 ;expansionist_max = 50
+;expansionist_default = 50
 ;trader_min = 50
 ;trader_max = 50
+;trader_default = 50
 ;aggressive_min = 50
 ;aggressive_max = 50
+;aggressive_default = 50
 
 ; Descriptions of nation sets
 ; These are self-contained subsets of the available nations; one of these

Modified: branches/S2_6/data/civ2/nations.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/civ2/nations.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/civ2/nations.ruleset     (original)
+++ branches/S2_6/data/civ2/nations.ruleset     Sat Oct 31 19:37:52 2015
@@ -36,10 +36,13 @@
 [default_traits]
 ;expansionist_min = 50
 ;expansionist_max = 50
+;expansionist_default = 50
 ;trader_min = 50
 ;trader_max = 50
+;trader_default = 50
 ;aggressive_min = 50
 ;aggressive_max = 50
+;aggressive_default = 50
 
 ; Descriptions of nation sets
 ; These are self-contained subsets of the available nations; one of these

Modified: branches/S2_6/data/civ2civ3/nations.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/civ2civ3/nations.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/civ2civ3/nations.ruleset (original)
+++ branches/S2_6/data/civ2civ3/nations.ruleset Sat Oct 31 19:37:52 2015
@@ -31,10 +31,13 @@
 [default_traits]
 ;expansionist_min = 50
 ;expansionist_max = 50
+;expansionist_default = 50
 ;trader_min = 50
 ;trader_max = 50
+;trader_default = 50
 ;aggressive_min = 50
 ;aggressive_max = 50
+;aggressive_default = 50
 
 ; Please keep [ruledit] section in sync with these includes
 *include "default/nationlist.ruleset"

Modified: branches/S2_6/data/classic/nations.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/classic/nations.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/classic/nations.ruleset  (original)
+++ branches/S2_6/data/classic/nations.ruleset  Sat Oct 31 19:37:52 2015
@@ -31,10 +31,13 @@
 [default_traits]
 ;expansionist_min = 50
 ;expansionist_max = 50
+;expansionist_default = 50
 ;trader_min = 50
 ;trader_max = 50
+;trader_default = 50
 ;aggressive_min = 50
 ;aggressive_max = 50
+;aggressive_default = 50
 
 ; Please keep [ruledit] section in sync with these includes
 *include "default/nationlist.ruleset"

Modified: branches/S2_6/data/experimental/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/experimental/game.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/experimental/game.ruleset        (original)
+++ branches/S2_6/data/experimental/game.ruleset        Sat Oct 31 19:37:52 2015
@@ -718,4 +718,5 @@
       "ec_chat", TRUE, FALSE
       "ec_info", TRUE, FALSE
       "techlossforgiveness", 15, FALSE
-    }
+      "traitdistribution", "EVEN", FALSE
+    }

Modified: branches/S2_6/data/experimental/nations.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/experimental/nations.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/experimental/nations.ruleset     (original)
+++ branches/S2_6/data/experimental/nations.ruleset     Sat Oct 31 19:37:52 2015
@@ -31,10 +31,13 @@
 [default_traits]
 expansionist_min = 35
 expansionist_max = 80
+expansionist_default = 50
 trader_min = 35
 trader_max = 80
+trader_default = 50
 aggressive_min = 35
 aggressive_max = 80
+aggressive_default = 50
 
 ; Please keep [ruledit] section in sync with these includes
 *include "default/nationlist.ruleset"

Modified: branches/S2_6/data/multiplayer/nations.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/multiplayer/nations.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/multiplayer/nations.ruleset      (original)
+++ branches/S2_6/data/multiplayer/nations.ruleset      Sat Oct 31 19:37:52 2015
@@ -31,10 +31,13 @@
 [default_traits]
 ;expansionist_min = 50
 ;expansionist_max = 50
+;expansionist_default = 50
 ;trader_min = 50
 ;trader_max = 50
+;trader_default = 50
 ;aggressive_min = 50
 ;aggressive_max = 50
+;aggressive_default = 50
 
 ; Please keep [ruledit] section in sync with these includes
 *include "default/nationlist.ruleset"

Modified: branches/S2_6/data/stub/nations.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/stub/nations.ruleset?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/data/stub/nations.ruleset     (original)
+++ branches/S2_6/data/stub/nations.ruleset     Sat Oct 31 19:37:52 2015
@@ -20,10 +20,13 @@
 [default_traits]
 ;expansionist_min = 50
 ;expansionist_max = 50
+;expansionist_default = 50
 ;trader_min       = 50
 ;trader_max       = 50
+;trader_default   = 50
 ;aggressive_min   = 50
 ;aggressive_max   = 50
+;aggressive_default = 50
 
 ; Descriptions of nation sets
 ; These are self-contained subsets of the available nations; one of these

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Sat Oct 31 19:37:52 2015
@@ -54,7 +54,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-2.6-2015.Oct.30"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Oct.31"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/ruleset.c?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/server/ruleset.c      (original)
+++ branches/S2_6/server/ruleset.c      Sat Oct 31 19:37:52 2015
@@ -992,6 +992,10 @@
                                              secname,
                                              field_prefix,
                                              trait_names[tr]);
+    out[tr].fixed = secfile_lookup_int_default(file, -1, "%s.%s%s_default",
+                                               secname,
+                                               field_prefix,
+                                               trait_names[tr]);
   }
 
   fc_assert(tr == trait_end()); /* number of trait_names correct */
@@ -3883,6 +3887,12 @@
     if (game.server.default_traits[tr].max < 0) {
       game.server.default_traits[tr].max = TRAIT_DEFAULT_VALUE;
     }
+    if (game.server.default_traits[tr].fixed < 0) {
+      int diff = game.server.default_traits[tr].max - 
game.server.default_traits[tr].min;
+
+      /* TODO: Should sometimes round the a / 2 = x.5 results up */
+      game.server.default_traits[tr].fixed = diff / 2 + 
game.server.default_traits[tr].min;
+    }
     if (game.server.default_traits[tr].max < 
game.server.default_traits[tr].min) {
       ruleset_error(LOG_ERROR, "Default values for trait %s not sane.",
                     trait_name(tr));
@@ -4188,11 +4198,27 @@
       /* Load nation traits */
       ruleset_load_traits(pnation->server.traits, file, sec_name, "trait_");
       for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
+        bool server_traits_used = TRUE;
+
         if (pnation->server.traits[tr].min < 0) {
           pnation->server.traits[tr].min = game.server.default_traits[tr].min;
+        } else {
+          server_traits_used = FALSE;
         }
         if (pnation->server.traits[tr].max < 0) {
           pnation->server.traits[tr].max = game.server.default_traits[tr].max;
+        } else {
+          server_traits_used = FALSE;
+        }
+        if (pnation->server.traits[tr].fixed < 0) {
+          if (server_traits_used) {
+            pnation->server.traits[tr].fixed = 
game.server.default_traits[tr].fixed;
+          } else {
+            int diff = pnation->server.traits[tr].max - 
pnation->server.traits[tr].min;
+
+            /* TODO: Should sometimes round the a / 2 = x.5 results up */
+            pnation->server.traits[tr].fixed = diff / 2 + 
pnation->server.traits[tr].min;
+          }
         }
         if (pnation->server.traits[tr].max < pnation->server.traits[tr].min) {
           ruleset_error(LOG_ERROR, "%s values for trait %s not sane.",

Modified: branches/S2_6/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.c?rev=30331&r1=30330&r2=30331&view=diff
==============================================================================
--- branches/S2_6/server/settings.c     (original)
+++ branches/S2_6/server/settings.c     Sat Oct 31 19:37:52 2015
@@ -354,6 +354,18 @@
 }
 
 /****************************************************************************
+  Trait distribution setting names accessor.
+****************************************************************************/
+static const struct sset_val_name *trait_dist_name(int trait_dist)
+{
+  switch (trait_dist) {
+  NAME_CASE(TDM_FIXED, "FIXED", N_("Fixed"));
+  NAME_CASE(TDM_EVEN, "EVEN", N_("Even"));
+  }
+  return NULL;
+}
+
+/****************************************************************************
   Player colors configuration setting names accessor.
 ****************************************************************************/
 static const struct sset_val_name *plrcol_name(int plrcol)
@@ -1909,6 +1921,12 @@
           NULL, NULL,
           GAME_MIN_DISASTERS, GAME_MAX_DISASTERS,
           GAME_DEFAULT_DISASTERS)
+
+  GEN_ENUM("traitdistribution", game.server.trait_dist,
+           SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, SSET_TO_CLIENT,
+           N_("AI trait distribution method"),
+           N_("How trait values are given to AI players."),
+           NULL, NULL, NULL, trait_dist_name, GAME_DEFAULT_TRAIT_DIST_MODE)
 
   GEN_INT("razechance", game.server.razechance,
          SSET_RULES, SSET_MILITARY, SSET_RARE, SSET_TO_CLIENT,


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

Reply via email to