diff --git a/src/economy.cpp b/src/economy.cpp index 96b79601a4..b591d5d9bf 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1490,12 +1490,12 @@ extern int GetAmountOwnedBy(const Company *c, Owner owner); CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { CommandCost cost(EXPENSES_OTHER); - - Company *c = Company::GetIfValid(p1); + CompanyID target_company = (CompanyID)p1; + Company *c = Company::GetIfValid(target_company); /* Check if buying shares is allowed (protection against modified clients) * Cannot buy own shares */ - if (c == NULL || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR; + if (c == NULL || !_settings_game.economy.allow_shares || _current_company == target_company) return CMD_ERROR; /* Protect new companies from hostile takeovers */ if (_cur_year - c->inaugurated_year < 6) return_cmd_error(STR_ERROR_PROTECTED); @@ -1521,7 +1521,7 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, break; } } - SetWindowDirty(WC_COMPANY, p1); + SetWindowDirty(WC_COMPANY, target_company); } return cost; } @@ -1536,11 +1536,12 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, */ CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - Company *c = Company::GetIfValid(p1); + CompanyID target_company = (CompanyID)p1; + Company *c = Company::GetIfValid(target_company); /* Check if selling shares is allowed (protection against modified clients) * Cannot sell own shares */ - if (c == NULL || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR; + if (c == NULL || !_settings_game.economy.allow_shares || _current_company == target_company) return CMD_ERROR; /* Those lines are here for network-protection (clients can be slow) */ if (GetAmountOwnedBy(c, _current_company) == 0) return CommandCost(); @@ -1553,7 +1554,7 @@ CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1 OwnerByte *b = c->share_owners; while (*b != _current_company) b++; // share owners is guaranteed to contain company *b = COMPANY_SPECTATOR; - SetWindowDirty(WC_COMPANY, p1); + SetWindowDirty(WC_COMPANY, target_company); } return CommandCost(EXPENSES_OTHER, cost); } @@ -1571,7 +1572,8 @@ CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1 */ CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - Company *c = Company::GetIfValid(p1); + CompanyID target_company = (CompanyID)p1; + Company *c = Company::GetIfValid(target_company); if (c == NULL) return CMD_ERROR; /* Disable takeovers when not asked */ @@ -1581,7 +1583,7 @@ CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 if (!_networking && _local_company == c->index) return CMD_ERROR; /* Do not allow companies to take over themselves */ - if ((CompanyID)p1 == _current_company) return CMD_ERROR; + if (target_company == _current_company) return CMD_ERROR; /* Get the cost here as the company is deleted in DoAcquireCompany. */ CommandCost cost(EXPENSES_OTHER, c->bankrupt_value);