Author: jtn
Date: Thu Dec 17 03:34:11 2015
New Revision: 31035

URL: http://svn.gna.org/viewcvs/freeciv?rev=31035&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:
    branches/S2_6/server/srv_main.c

Modified: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=31035&r1=31034&r2=31035&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Thu Dec 17 03:34:11 2015
@@ -2314,19 +2314,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