Author: jtn
Date: Mon Apr 27 11:35:27 2015
New Revision: 28922

URL: http://svn.gna.org/viewcvs/freeciv?rev=28922&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_6/server/connecthand.c
    branches/S2_6/server/ruleset.c
    branches/S2_6/server/savegame.c
    branches/S2_6/server/savegame2.c
    branches/S2_6/server/settings.c
    branches/S2_6/server/srv_main.c
    branches/S2_6/server/srv_main.h
    branches/S2_6/server/stdinhand.c

Modified: branches/S2_6/server/connecthand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/connecthand.c?rev=28922&r1=28921&r2=28922&view=diff
==============================================================================
--- branches/S2_6/server/connecthand.c  (original)
+++ branches/S2_6/server/connecthand.c  Mon Apr 27 11:35:27 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) {
@@ -764,7 +764,7 @@
 
         /* Actually do the removal. */
         server_remove_player(pplayer);
-        aifill(game.info.aifill);
+        (void) aifill(game.info.aifill);
         reset_all_start_commands(TRUE);
       } else {
         /* Aitoggle the player if no longer connected. */

Modified: branches/S2_6/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/ruleset.c?rev=28922&r1=28921&r2=28922&view=diff
==============================================================================
--- branches/S2_6/server/ruleset.c      (original)
+++ branches/S2_6/server/ruleset.c      Mon Apr 27 11:35:27 2015
@@ -6807,7 +6807,7 @@
 
     /* We may need to adjust the number of AI players
      * if the number of available nations changed. */
-    aifill(game.info.aifill);
+    (void) aifill(game.info.aifill);
   }
 
   return ok;

Modified: branches/S2_6/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame.c?rev=28922&r1=28921&r2=28922&view=diff
==============================================================================
--- branches/S2_6/server/savegame.c     (original)
+++ branches/S2_6/server/savegame.c     Mon Apr 27 11:35:27 2015
@@ -3235,7 +3235,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_6/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=28922&r1=28921&r2=28922&view=diff
==============================================================================
--- branches/S2_6/server/savegame2.c    (original)
+++ branches/S2_6/server/savegame2.c    Mon Apr 27 11:35:27 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_6/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.c?rev=28922&r1=28921&r2=28922&view=diff
==============================================================================
--- branches/S2_6/server/settings.c     (original)
+++ branches/S2_6/server/settings.c     Mon Apr 27 11:35:27 2015
@@ -576,7 +576,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);
+  }
 }
 
 /*************************************************************************
@@ -594,7 +598,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_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=28922&r1=28921&r2=28922&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Mon Apr 27 11:35:27 2015
@@ -2047,16 +2047,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()) {
@@ -2076,7 +2092,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()) {
@@ -2118,6 +2134,8 @@
 
     send_player_info_c(pplayer, NULL);
   }
+
+  return limitreason;
 }
 
 /****************************************************************************
@@ -3008,7 +3026,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_6/server/srv_main.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.h?rev=28922&r1=28921&r2=28922&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.h     (original)
+++ branches/S2_6/server/srv_main.h     Mon Apr 27 11:35:27 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_6/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/stdinhand.c?rev=28922&r1=28921&r2=28922&view=diff
==============================================================================
--- branches/S2_6/server/stdinhand.c    (original)
+++ branches/S2_6/server/stdinhand.c    Mon Apr 27 11:35:27 2015
@@ -886,7 +886,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);
@@ -1038,7 +1038,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(TRUE);
   (void) send_server_info_to_metaserver(META_INFO);
 
@@ -1081,7 +1081,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;
 }
 
@@ -3694,7 +3694,7 @@
   } conn_list_iterate_end;
   conn_list_destroy(global_observers);
 
-  aifill(game.info.aifill);
+  (void) aifill(game.info.aifill);
 
   achievements_iterate(pach) {
     players_iterate(pplayer) {


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

Reply via email to