summaryrefslogtreecommitdiff
path: root/players.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-01-31 22:16:15 +0000
committerDarkvater <Darkvater@openttd.org>2006-01-31 22:16:15 +0000
commit5502f3bf3d3b16458da1d8bfdd8bb9c960a1f10a (patch)
tree763ef198108c0320af48fbac22bf9c998430da2d /players.c
parentbfe7040cde43d9e23bf3346860f865b922f186f1 (diff)
downloadopenttd-5502f3bf3d3b16458da1d8bfdd8bb9c960a1f10a.tar.xz
(svn r3500) - Workaround the inaccurate count of spectators/companies that can happen in certain border-cases. For now just dynamically get this value when requested so it is always right. To do properly all player/client creation/destruction needs a hook for networking.
Diffstat (limited to 'players.c')
-rw-r--r--players.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/players.c b/players.c
index 5266a0d69..9221a8bc2 100644
--- a/players.c
+++ b/players.c
@@ -180,6 +180,18 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
}
}
+byte ActivePlayerCount(void)
+{
+ const Player *p;
+ byte count = 0;
+
+ FOR_ALL_PLAYERS(p) {
+ if (p->is_active) count++;
+ }
+
+ return count;
+}
+
void InvalidatePlayerWindows(const Player *p)
{
PlayerID pid = p->index;
@@ -857,7 +869,6 @@ int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2)
_local_player = ci->client_playas - 1;
NetworkSend_Command(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME, NULL);
_local_player = player_backup;
- _network_game_info.companies_on++;
}
}
} else if (_network_server) { // Creating player failed, defer client to spectator
@@ -865,7 +876,6 @@ int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2)
* in network_server.c:838, function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */
NetworkClientInfo *ci = &_network_client_info[pid];
ci->client_playas = OWNER_SPECTATOR;
- _network_game_info.spectators_on++;
NetworkUpdateClientInfo(ci->client_index);
}
#else
@@ -904,9 +914,6 @@ int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2)
p->is_active = false;
}
RemoveAllEngineReplacementForPlayer(p);
-#ifdef ENABLE_NETWORK
- _network_game_info.companies_on--;
-#endif /* ENABLE_NETWORK */
} break;