Author: cazfi
Date: Thu Apr  2 22:14:02 2015
New Revision: 28695

URL: http://svn.gna.org/viewcvs/freeciv?rev=28695&view=rev
Log:
Added server setting setscoreloglevel

Patch by Dumbo <dumbo>

See patch #5727

Modified:
    branches/S2_6/common/game.c
    branches/S2_6/common/game.h
    branches/S2_6/server/report.c
    branches/S2_6/server/settings.c

Modified: branches/S2_6/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.c?rev=28695&r1=28694&r2=28695&view=diff
==============================================================================
--- branches/S2_6/common/game.c (original)
+++ branches/S2_6/common/game.c Thu Apr  2 22:14:02 2015
@@ -412,6 +412,7 @@
     game.server.save_options.save_starts = TRUE;
     game.server.savepalace        = GAME_DEFAULT_SAVEPALACE;
     game.server.scorelog          = GAME_DEFAULT_SCORELOG;
+    game.server.scoreloglevel     = GAME_DEFAULT_SCORELOGLEVEL;
     game.server.scoreturn         = GAME_DEFAULT_SCORETURN;
     game.server.seed              = GAME_DEFAULT_SEED;
     sz_strlcpy(game.server.start_units, GAME_DEFAULT_START_UNITS);

Modified: branches/S2_6/common/game.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.h?rev=28695&r1=28694&r2=28695&view=diff
==============================================================================
--- branches/S2_6/common/game.h (original)
+++ branches/S2_6/common/game.h Thu Apr  2 22:14:02 2015
@@ -60,6 +60,11 @@
   AS_QUITIDLE,
   AS_INTERRUPT,
   AS_TIMER
+};
+
+enum scorelog_level {
+  SL_ALL = 0,
+  SL_HUMANS
 };
 
 struct user_flag
@@ -196,6 +201,7 @@
       char connectmsg[MAX_LEN_MSG];
       char save_name[MAX_LEN_NAME];
       bool scorelog;
+      enum scorelog_level scoreloglevel;
       char scorefile[MAX_LEN_NAME];
       int scoreturn;    /* next make_history_report() */
       int seed;
@@ -471,6 +477,7 @@
 #define GAME_DEFAULT_REVEALMAP       REVEAL_MAP_NONE
 
 #define GAME_DEFAULT_SCORELOG        FALSE
+#define GAME_DEFAULT_SCORELOGLEVEL   SL_ALL
 #define GAME_DEFAULT_SCOREFILE       "freeciv-score.log"
 #define GAME_DEFAULT_SCORETURN       20
 

Modified: branches/S2_6/server/report.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/report.c?rev=28695&r1=28694&r2=28695&view=diff
==============================================================================
--- branches/S2_6/server/report.c       (original)
+++ branches/S2_6/server/report.c       Thu Apr  2 22:14:02 2015
@@ -146,6 +146,7 @@
 static const char *culture_to_text(int value);
 
 #define GOOD_PLAYER(p) ((p)->is_alive && !is_barbarian(p))
+#define AI_PLAYER(p) ((p)->ai_controlled)
 
 /*
  * Describes a row.
@@ -1450,30 +1451,47 @@
   players_iterate(pplayer) {
     struct plrdata_slot *plrdata = score_log->plrdata + player_index(pplayer);
     if (plrdata->name == NULL && GOOD_PLAYER(pplayer)) {
-      fprintf(score_log->fp, "addplayer %d %d %s\n", game.info.turn,
+      switch (game.server.scoreloglevel) {
+      case SL_HUMANS:
+        if (AI_PLAYER(pplayer)) {
+          break;
+        }
+      case SL_ALL:
+        fprintf(score_log->fp, "addplayer %d %d %s\n", game.info.turn,
               player_number(pplayer), player_name(pplayer));
-      plrdata_slot_init(plrdata, player_name(pplayer));
+        plrdata_slot_init(plrdata, player_name(pplayer));
+      }
     }
   } players_iterate_end;
 
   players_iterate(pplayer) {
     struct plrdata_slot *plrdata = score_log->plrdata + player_index(pplayer);
 
-    if (GOOD_PLAYER(pplayer)
-        && strcmp(plrdata->name, player_name(pplayer)) != 0) {
-      log_debug("player names does not match '%s' != '%s'", plrdata->name,
-                player_name(pplayer));
-      fprintf(score_log->fp, "delplayer %d %d\n", game.info.turn - 1,
-              player_number(pplayer));
-      fprintf(score_log->fp, "addplayer %d %d %s\n", game.info.turn,
-              player_number(pplayer), player_name(pplayer));
-      plrdata_slot_replace(plrdata, player_name(pplayer));
+    if (GOOD_PLAYER(pplayer)) {
+      switch (game.server.scoreloglevel) {
+      case SL_HUMANS:
+        if (AI_PLAYER(pplayer) && plrdata->name == NULL) {
+          /* If a human player toggled into AI mode, don't break. */
+          break;
+        }
+      case SL_ALL:
+        if (strcmp(plrdata->name, player_name(pplayer)) != 0) {
+          log_debug("player names does not match '%s' != '%s'", plrdata->name,
+                  player_name(pplayer));
+          fprintf(score_log->fp, "delplayer %d %d\n", game.info.turn - 1,
+                  player_number(pplayer));
+          fprintf(score_log->fp, "addplayer %d %d %s\n", game.info.turn,
+                  player_number(pplayer), player_name(pplayer));
+          plrdata_slot_replace(plrdata, player_name(pplayer));
+        }
+      }
     }
   } players_iterate_end;
 
   for (i = 0; i < ARRAY_SIZE(score_tags); i++) {
     players_iterate(pplayer) {
-      if (!GOOD_PLAYER(pplayer)) {
+      if (!GOOD_PLAYER(pplayer) ||
+         (game.server.scoreloglevel == SL_HUMANS && AI_PLAYER(pplayer))) {
         continue;
       }
 

Modified: branches/S2_6/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.c?rev=28695&r1=28694&r2=28695&view=diff
==============================================================================
--- branches/S2_6/server/settings.c     (original)
+++ branches/S2_6/server/settings.c     Thu Apr  2 22:14:02 2015
@@ -466,6 +466,19 @@
 }
 
 /****************************************************************************
+  Scorelog level names accessor.
+****************************************************************************/
+static const struct sset_val_name *
+scoreloglevel_name(enum scorelog_level sl_level) 
+{
+  switch (sl_level) {
+  NAME_CASE(SL_ALL, "ALL", N_("Scorelog all players, AI included"));
+  NAME_CASE(SL_HUMANS, "HUMANS", N_("Scorelog only human players"));
+  }
+  return NULL;
+}
+
+/****************************************************************************
   Savegame compress type names accessor.
 ****************************************************************************/
 static const struct sset_val_name *
@@ -2511,6 +2524,13 @@
               "the file defined by the option 'scorefile' every turn. "
               "These statistics can be used to create power graphs after "
               "the game."), NULL, scorelog_action, GAME_DEFAULT_SCORELOG)
+
+  GEN_ENUM("scoreloglevel", game.server.scoreloglevel,
+           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,
+           scoreloglevel_name, GAME_DEFAULT_SCORELOGLEVEL)
 
   GEN_STRING("scorefile", game.server.scorefile,
              SSET_META, SSET_INTERNAL, SSET_SITUATIONAL, SSET_SERVER_ONLY,


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

Reply via email to