mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-04 05:15:21 +00:00
(svn r19655) -Codechange: Reduce usage magic p1 parameter.
This commit is contained in:
parent
75d4bc947d
commit
2a5ddd0dae
@ -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 CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
CommandCost cost(EXPENSES_OTHER);
|
CommandCost cost(EXPENSES_OTHER);
|
||||||
|
CompanyID target_company = (CompanyID)p1;
|
||||||
Company *c = Company::GetIfValid(p1);
|
Company *c = Company::GetIfValid(target_company);
|
||||||
|
|
||||||
/* Check if buying shares is allowed (protection against modified clients)
|
/* Check if buying shares is allowed (protection against modified clients)
|
||||||
* Cannot buy own shares */
|
* 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 */
|
/* Protect new companies from hostile takeovers */
|
||||||
if (_cur_year - c->inaugurated_year < 6) return_cmd_error(STR_ERROR_PROTECTED);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetWindowDirty(WC_COMPANY, p1);
|
SetWindowDirty(WC_COMPANY, target_company);
|
||||||
}
|
}
|
||||||
return cost;
|
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)
|
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)
|
/* Check if selling shares is allowed (protection against modified clients)
|
||||||
* Cannot sell own shares */
|
* 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) */
|
/* Those lines are here for network-protection (clients can be slow) */
|
||||||
if (GetAmountOwnedBy(c, _current_company) == 0) return CommandCost();
|
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;
|
OwnerByte *b = c->share_owners;
|
||||||
while (*b != _current_company) b++; // share owners is guaranteed to contain company
|
while (*b != _current_company) b++; // share owners is guaranteed to contain company
|
||||||
*b = COMPANY_SPECTATOR;
|
*b = COMPANY_SPECTATOR;
|
||||||
SetWindowDirty(WC_COMPANY, p1);
|
SetWindowDirty(WC_COMPANY, target_company);
|
||||||
}
|
}
|
||||||
return CommandCost(EXPENSES_OTHER, cost);
|
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)
|
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;
|
if (c == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
/* Disable takeovers when not asked */
|
/* 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;
|
if (!_networking && _local_company == c->index) return CMD_ERROR;
|
||||||
|
|
||||||
/* Do not allow companies to take over themselves */
|
/* 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. */
|
/* Get the cost here as the company is deleted in DoAcquireCompany. */
|
||||||
CommandCost cost(EXPENSES_OTHER, c->bankrupt_value);
|
CommandCost cost(EXPENSES_OTHER, c->bankrupt_value);
|
||||||
|
Loading…
Reference in New Issue
Block a user