Author: jtn
Date: Thu Dec 17 03:33:41 2015
New Revision: 31033

URL: http://svn.gna.org/viewcvs/freeciv?rev=31033&view=rev
Log:
If a player's name corresponds to a leader in more than one nation at
game start, pick a random nation rather than the first one encountered.

Spotted by Marko Lindqvist (cazfi@gna).

See gna bug #24181.

Modified:
    trunk/server/srv_main.c

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=31033&r1=31032&r2=31033&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Thu Dec 17 03:33:41 2015
@@ -2410,19 +2410,29 @@
       continue;
     }
 
-    /* See if the player name matches a known leader name. */
-    allowed_nations_iterate(pnation) {
-      struct nation_leader *pleader;
-      const char *name = player_name(pplayer);
-
-      if (is_nation_playable(pnation)
-          && client_can_pick_nation(pnation)
-          && NULL == pnation->player
-          && (pleader = nation_leader_by_name(pnation, name))) {
-        player_set_nation_full(pplayer, pnation);
-        break;
-      }
-    } allowed_nations_iterate_end;
+    /* See if the player name matches a known leader name.
+     * If more than one nation has this leader name, pick one at random.
+     * No attempt is made to avoid clashes to maximise the number of
+     * nations that can be assigned in this way. */
+    {
+      struct nation_list *candidates = nation_list_new();
+      int n = 0;
+
+      allowed_nations_iterate(pnation) {
+        if (is_nation_playable(pnation)
+            && client_can_pick_nation(pnation)
+            && NULL == pnation->player
+            && (nation_leader_by_name(pnation, player_name(pplayer)))) {
+          nation_list_append(candidates, pnation);
+          n++;
+        }
+      } allowed_nations_iterate_end;
+      if (n > 0) {
+        player_set_nation_full(pplayer,
+                               nation_list_get(candidates, fc_rand(n)));
+      }
+      nation_list_destroy(candidates);
+    }
     if (pplayer->nation != NO_NATION_SELECTED) {
       announce_player(pplayer);
     } else {


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

Reply via email to