From 2086f77daba836dc6cdb5204060adbca8e7377f3 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 10 Aug 2008 19:00:33 +0000 Subject: [PATCH] (svn r14038) -Fix [FS#2211] (r13731): company limit was not properly enforced for CMD_PLAYER_CTRL. --- src/player_base.h | 6 +++++- src/players.cpp | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/player_base.h b/src/player_base.h index e8c77344d2..6f11e54e35 100644 --- a/src/player_base.h +++ b/src/player_base.h @@ -24,7 +24,11 @@ struct PlayerEconomyEntry { Money company_value; }; -DECLARE_OLD_POOL(Player, Player, 1, MAX_PLAYERS) +/* The third parameter and the number after >> MUST be the same, + * otherwise more (or less) players will be allowed to be + * created than what MAX_PLAYER specifies! + */ +DECLARE_OLD_POOL(Player, Player, 1, MAX_PLAYERS >> 1) struct Player : PoolItem { Player(uint16 name_1 = 0, bool is_ai = false); diff --git a/src/players.cpp b/src/players.cpp index c3bef5c3c8..d8e8ad6855 100644 --- a/src/players.cpp +++ b/src/players.cpp @@ -516,9 +516,9 @@ void ResetPlayerLivery(Player *p) */ Player *DoStartupNewPlayer(bool is_ai) { - Player *p = new Player(STR_SV_UNNAMED, is_ai); + if (!Player::CanAllocateItem()) return NULL; - if (p == NULL) return NULL; + Player *p = new Player(STR_SV_UNNAMED, is_ai); memset(&_players_ai[p->index], 0, sizeof(PlayerAI)); memset(&_players_ainew[p->index], 0, sizeof(PlayerAiNew));