Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2005:
[Freeciv-Dev] (PR#14051) /create and aifill == maxplayers
Home

[Freeciv-Dev] (PR#14051) /create and aifill == maxplayers

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14051) /create and aifill == maxplayers
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Sat, 24 Sep 2005 05:53:21 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Here's a patch.
--
mateusz
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.437
diff -u -r1.437 stdinhand.c
--- server/stdinhand.c  20 Sep 2005 12:48:35 -0000      1.437
+++ server/stdinhand.c  24 Sep 2005 12:47:24 -0000
@@ -857,6 +857,7 @@
 {
   struct player *pplayer;
   PlayerNameStatus PNameStatus;
+  bool ai_player_should_be_removed = FALSE;
    
   if (server_state!=PRE_GAME_STATE)
   {
@@ -869,9 +870,22 @@
    * MAX_NUM_PLAYERS is a limit on all players. */
   if (get_num_nonobserver_players() >= game.info.max_players
       || game.info.nplayers >= MAX_NUM_PLAYERS) {
-    cmd_reply(CMD_CREATE, caller, C_FAIL,
-             _("Can't add more players, server is full."));
-    return FALSE;
+    /* Try emptying a slot if there is an ai player
+     * created through the /aifill command */
+    players_iterate(eplayer) {
+      if (eplayer->is_observer || eplayer->is_connected
+         || eplayer->was_created) {
+        continue;
+      }     
+      ai_player_should_be_removed = TRUE;
+      break;
+    } players_iterate_end;
+    
+    if (!ai_player_should_be_removed) {
+      cmd_reply(CMD_CREATE, caller, C_FAIL,
+               _("Can't add more players, server is full."));
+      return FALSE;
+    }
   }
 
   if ((PNameStatus = test_player_name(arg)) == PNameEmpty)
@@ -907,6 +921,17 @@
   if (check) {
     return TRUE;
   }
+  
+  if (ai_player_should_be_removed) {
+    players_iterate(eplayer) {
+      if (eplayer->is_observer || eplayer->is_connected
+         || eplayer->was_created) {
+        continue;
+      }
+      server_remove_player(eplayer);
+      break;
+    } players_iterate_end;
+  }
 
   pplayer = &game.players[game.info.nplayers];
   server_player_init(pplayer, FALSE, TRUE);

[Prev in Thread] Current Thread [Next in Thread]