Author: jtn
Date: Mon Apr 27 11:25:33 2015
New Revision: 28919

URL: http://svn.gna.org/viewcvs/freeciv?rev=28919&view=rev
Log:
Give a reason when 'set aifill' cannot create as many players as
requested.

Requested by Andreas Røsdal (andreasr@gna).

See gna bug #23526.

Modified:
    branches/S2_5/server/connecthand.c
    branches/S2_5/server/ruleset.c
    branches/S2_5/server/savegame.c
    branches/S2_5/server/savegame2.c
    branches/S2_5/server/settings.c
    branches/S2_5/server/srv_main.c
    branches/S2_5/server/srv_main.h
    branches/S2_5/server/stdinhand.c

Modified: branches/S2_5/server/connecthand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/connecthand.c?rev=28919&r1=28918&r2=28919&view=diff
==============================================================================
--- branches/S2_5/server/connecthand.c  (original)
+++ branches/S2_5/server/connecthand.c  Mon Apr 27 11:25:33 2015
@@ -605,7 +605,7 @@
         /* Temporarily set player_name() to username. */
         server_player_set_name(pplayer, pconn->username);
       }
-      aifill(game.info.aifill);
+      (void) aifill(game.info.aifill);
     }
 
     if (game.server.auto_ai_toggle && pplayer->ai_controlled) {
@@ -745,7 +745,7 @@
 
         /* Actually do the removal. */
         server_remove_player(pplayer);
-        aifill(game.info.aifill);
+        (void) aifill(game.info.aifill);
         reset_all_start_commands();
       } else {
         /* Aitoggle the player if no longer connected. */

Modified: branches/S2_5/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/ruleset.c?rev=28919&r1=28918&r2=28919&view=diff
==============================================================================
--- branches/S2_5/server/ruleset.c      (original)
+++ branches/S2_5/server/ruleset.c      Mon Apr 27 11:25:33 2015
@@ -6197,7 +6197,7 @@
     /* We may need to adjust the number of AI players
      * if the number of available nations changed. */
     if (act) {
-      aifill(game.info.aifill);
+      (void) aifill(game.info.aifill);
     }
   }
 

Modified: branches/S2_5/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/savegame.c?rev=28919&r1=28918&r2=28919&view=diff
==============================================================================
--- branches/S2_5/server/savegame.c     (original)
+++ branches/S2_5/server/savegame.c     Mon Apr 27 11:25:33 2015
@@ -3542,7 +3542,7 @@
   if (game.scenario.is_scenario) {
     /* Remove all defined players. They are recreated with the skill level
      * defined by the scenario. */
-    aifill(0);
+    (void) aifill(0);
   }
 
   {

Modified: branches/S2_5/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/savegame2.c?rev=28919&r1=28918&r2=28919&view=diff
==============================================================================
--- branches/S2_5/server/savegame2.c    (original)
+++ branches/S2_5/server/savegame2.c    Mon Apr 27 11:25:33 2015
@@ -2371,7 +2371,7 @@
   if (game.scenario.is_scenario) {
     /* Remove all defined players. They are recreated with the skill level
      * defined by the scenario. */
-    aifill(0);
+    (void) aifill(0);
   }
 }
 

Modified: branches/S2_5/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/settings.c?rev=28919&r1=28918&r2=28919&view=diff
==============================================================================
--- branches/S2_5/server/settings.c     (original)
+++ branches/S2_5/server/settings.c     Mon Apr 27 11:25:33 2015
@@ -506,7 +506,11 @@
 *************************************************************************/
 static void aifill_action(const struct setting *pset)
 {
-  aifill(*pset->integer.pvalue);
+  const char *msg = aifill(*pset->integer.pvalue);
+  if (msg) {
+    notify_conn(NULL, NULL, E_SETTING, ftc_server,
+                _("Warning: aifill not met: %s."), msg);
+  }
 }
 
 /*************************************************************************
@@ -524,7 +528,7 @@
     }
   } players_iterate_end;
   count_playable_nations();
-  aifill(game.info.aifill);
+  (void) aifill(game.info.aifill);
 
   /* There might now be too many players for the available nations.
    * Rather than getting rid of some players arbitrarily, we let the

Modified: branches/S2_5/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/srv_main.c?rev=28919&r1=28918&r2=28919&view=diff
==============================================================================
--- branches/S2_5/server/srv_main.c     (original)
+++ branches/S2_5/server/srv_main.c     Mon Apr 27 11:25:33 2015
@@ -1908,16 +1908,32 @@
 
 /****************************************************************************
   Fill or remove players to meet the given aifill.
+  If return is non-NULL, points to a translated string explaining why
+  the total number of players is less than 'amount'.
 ****************************************************************************/
-void aifill(int amount)
-{
-  int limit = MIN(amount, game.server.max_players);
+const char *aifill(int amount)
+{
+  char *limitreason = NULL;
+  int limit;
+ 
+  if (game_was_started()) {
+    return NULL;
+  }
+
+  limit = MIN(amount, game.server.max_players);
+  if (limit < amount) {
+    limitreason = _("requested more than 'maxplayers' setting");
+  }
 
   /* Limit to nations provided by ruleset */
-  limit = MIN(limit, server.playable_nations);
-
-  if (game_was_started()) {
-    return;
+  if (limit > server.playable_nations) {
+    limit = server.playable_nations;
+    if (nation_set_count() > 1) {
+      limitreason = _("not enough playable nations in this nationset "
+                      "(see 'nationset' setting)");
+    } else {
+      limitreason = _("not enough playable nations");
+    }
   }
 
   if (limit < player_count()) {
@@ -1937,7 +1953,7 @@
 
     /* 'limit' can be different from 'player_count()' at this point if
      * there are more human or created players than the 'limit'. */
-    return;
+    return limitreason;
   }
 
   while (limit > player_count()) {
@@ -1978,6 +1994,8 @@
 
     send_player_info_c(pplayer, NULL);
   }
+
+  return limitreason;
 }
 
 /****************************************************************************
@@ -2857,7 +2875,7 @@
       (void) read_init_script(NULL, srvarg.script_filename, TRUE, FALSE);
     }
 
-    aifill(game.info.aifill);
+    (void) aifill(game.info.aifill);
     if (!game_was_started()) {
       event_cache_clear();
     }

Modified: branches/S2_5/server/srv_main.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/srv_main.h?rev=28919&r1=28918&r2=28919&view=diff
==============================================================================
--- branches/S2_5/server/srv_main.h     (original)
+++ branches/S2_5/server/srv_main.h     Mon Apr 27 11:25:33 2015
@@ -111,7 +111,7 @@
 int identity_number(void);
 void server_game_init(void);
 void server_game_free(void);
-void aifill(int amount);
+const char *aifill(int amount);
 
 extern struct server_arguments srvarg;
 

Modified: branches/S2_5/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/stdinhand.c?rev=28919&r1=28918&r2=28919&view=diff
==============================================================================
--- branches/S2_5/server/stdinhand.c    (original)
+++ branches/S2_5/server/stdinhand.c    Mon Apr 27 11:25:33 2015
@@ -988,7 +988,7 @@
   }
 
   /* We have a player; now initialise all needed data. */
-  aifill(game.info.aifill);
+  (void) aifill(game.info.aifill);
 
   /* Initialise player. */
   server_player_init(pplayer, TRUE, TRUE);
@@ -1123,7 +1123,7 @@
   CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
   send_player_info_c(pplayer, game.est_connections);
 
-  aifill(game.info.aifill);
+  (void) aifill(game.info.aifill);
   reset_all_start_commands();
   (void) send_server_info_to_metaserver(META_INFO);
 
@@ -1166,7 +1166,7 @@
     cmd_reply(CMD_REMOVE, caller, C_OK,
              _("Removed player %s from the game."), name);
   }
-  aifill(game.info.aifill);
+  (void) aifill(game.info.aifill);
   return TRUE;
 }
 
@@ -3767,7 +3767,7 @@
   } conn_list_iterate_end;
   conn_list_destroy(global_observers);
 
-  aifill(game.info.aifill);
+  (void) aifill(game.info.aifill);
   return TRUE;
 }
 


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

Reply via email to