<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40233 >

 This fixes the problem of running out of playable nations because of civil war.

 Inspired by player_count() function, I added new functions
barbarian_count() and normal_player_count(). Former is added just to
make complete set of functions, latter should be used to hide the fact
that in current implementation barbarians are almost like other
players (included to player_count).


 - ML

diff -Nurd -X.diff_ignore freeciv/server/plrhand.c freeciv/server/plrhand.c
--- freeciv/server/plrhand.c	2008-04-08 15:32:21.000000000 +0300
+++ freeciv/server/plrhand.c	2008-05-08 00:26:06.000000000 +0300
@@ -1681,6 +1681,13 @@
             nation_plural_for_player(pplayer));
     return;
   }
+  if (normal_player_count() >= server.playable_nations) {
+    /* No nation for additional player */
+    freelog(LOG_NORMAL,
+            _("Could not throw %s into civil war - no available nations"),
+            nation_plural_for_player(pplayer));
+    return;
+  }
 
   cplayer = split_player(pplayer);
 
@@ -1785,3 +1792,19 @@
 
   send_player_info(pplayer, NULL);
 }
+
+/**************************************************************************
+  Return the number of barbarian players.
+**************************************************************************/
+int barbarian_count(void)
+{
+  return server.nbarbarians;
+}
+
+/**************************************************************************
+  Return the number of non-barbarian players.
+**************************************************************************/
+int normal_player_count(void)
+{
+  return game.info.nplayers - server.nbarbarians;
+}
diff -Nurd -X.diff_ignore freeciv/server/plrhand.h freeciv/server/plrhand.h
--- freeciv/server/plrhand.h	2008-01-22 04:10:30.000000000 +0200
+++ freeciv/server/plrhand.h	2008-05-08 00:24:31.000000000 +0300
@@ -103,4 +103,9 @@
 
 void update_players_after_alliance_breakup(struct player* pplayer,
                                           struct player* pplayer2);
+
+/* Player counts, total player_count() is in common/player.c */
+int barbarian_count(void);
+int normal_player_count(void);
+
 #endif  /* FC__PLRHAND_H */
diff -Nurd -X.diff_ignore freeciv/server/plrhand.c freeciv/server/plrhand.c
--- freeciv/server/plrhand.c	2008-01-31 17:13:30.000000000 +0200
+++ freeciv/server/plrhand.c	2008-05-08 00:28:33.000000000 +0300
@@ -1652,6 +1652,13 @@
             "players"), player_name(pplayer));
     return;
   }
+  if (normal_player_count() >= game.playable_nations) {
+    /* No nation for additional player */
+    freelog(LOG_NORMAL,
+            _("Could not throw %s into civil war - no available nations"),
+            nation_plural_for_player(pplayer));
+    return;
+  }
 
   cplayer = split_player(pplayer);
 
@@ -1755,3 +1762,19 @@
 
   send_player_info(pplayer, NULL);
 }
+
+/**************************************************************************
+  Return the number of barbarian players.
+**************************************************************************/
+int barbarian_count(void)
+{
+  return game.info.nbarbarians;
+}
+
+/**************************************************************************
+  Return the number of non-barbarian players.
+**************************************************************************/
+int normal_player_count(void)
+{
+  return game.info.nplayers - game.info.nbarbarians;
+}
diff -Nurd -X.diff_ignore freeciv/server/plrhand.h freeciv/server/plrhand.h
--- freeciv/server/plrhand.h	2008-01-22 03:47:20.000000000 +0200
+++ freeciv/server/plrhand.h	2008-05-08 00:26:55.000000000 +0300
@@ -102,4 +102,9 @@
 
 void update_players_after_alliance_breakup(struct player* pplayer,
                                           struct player* pplayer2);
+
+/* Player counts, total player_count() is in common/player.c */
+int barbarian_count(void);
+int normal_player_count(void);
+
 #endif  /* FC__PLRHAND_H */
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to