players.c
changeset 2682 94ca0b4dc53f
parent 2639 8a7342eb3a78
child 2684 8aba54c245cc
--- a/players.c	Sat Nov 19 22:39:16 2005 +0000
+++ b/players.c	Mon Nov 21 14:28:31 2005 +0000
@@ -528,12 +528,13 @@
 
 	// when there's a lot of computers in game, the probability that a new one starts is lower
 	if (n < (uint)_opt.diff.max_no_competitors)
-		if (n < (!_network_server ? RandomRange(_opt.diff.max_no_competitors + 2) : InteractiveRandomRange(_opt.diff.max_no_competitors + 2)) )
-		DoStartupNewPlayer(true);
+		if (n < (_network_server ? InteractiveRandomRange(_opt.diff.max_no_competitors + 2) : RandomRange(_opt.diff.max_no_competitors + 2)) )
+			/* Send a command to all clients to start  up a new AI. Works fine for Multiplayer and Singleplayer */
+			DoCommandP(0, 1, 0, NULL, CMD_PLAYER_CTRL);
 
 	// The next AI starts like the difficulty setting said, with +2 month max
 	_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + 1;
-	_next_competitor_start += (!_network_server) ? RandomRange(60 * DAY_TICKS) : InteractiveRandomRange(60 * DAY_TICKS);
+	_next_competitor_start += _network_server ? InteractiveRandomRange(60 * DAY_TICKS) : RandomRange(60 * DAY_TICKS);
 }
 
 void InitializePlayers(void)
@@ -556,9 +557,7 @@
 	_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
 	if (p->name_1 != 0) GenerateCompanyName(p);
 
-	/* XXX -- For now, multiplayer AIs still aren't working, WIP! */
-	//if (_ai.enabled && (!_networking || _network_server) && _game_mode != GM_MENU && !--_next_competitor_start)
-	if (_ai.enabled && !_networking && _game_mode != GM_MENU && !--_next_competitor_start)
+	if (AI_AllowNewAI() && _game_mode != GM_MENU && !--_next_competitor_start)
 		MaybeStartNewPlayer();
 }