summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2007-04-01 10:55:31 +0000
committercelestar <celestar@openttd.org>2007-04-01 10:55:31 +0000
commit6f49e4c644965595910a16ee9fed978bee8a0b72 (patch)
treef6869b31fc9482df524d86d9c7160d95ee70c94c
parent43dc111833c1fba6b701599a701cb405a9a92e4f (diff)
downloadopenttd-6f49e4c644965595910a16ee9fed978bee8a0b72.tar.xz
(svn r9541) -Codechange: Safeguard the company-buying routines so that the buying player and the bought player need to be two different entities
-rw-r--r--src/economy.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 24eab5466..b3d635a02 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -255,6 +255,8 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
Town *t;
PlayerID old = _current_player;
+ assert(old_player != new_player);
+
{
Player *p;
uint i;
@@ -1774,12 +1776,16 @@ int32 CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
int32 CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
Player *p;
+ PlayerID pid = (PlayerID)p1;
/* Disable takeovers in multiplayer games */
- if (!IsValidPlayer((PlayerID)p1) || _networking) return CMD_ERROR;
+ if (!IsValidPlayer(pid) || _networking) return CMD_ERROR;
+
+ /* Do not allow players to take over themselves */
+ if (pid == _current_player) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_OTHER);
- p = GetPlayer((PlayerID)p1);
+ p = GetPlayer(pid);
if (!p->is_ai) return CMD_ERROR;