mirror of https://github.com/OpenTTD/OpenTTD
(svn r20392) -Fix [FS#3993]: Prevent buying bankrupt companies when you'd get too many vehicles.
parent
5cfc029523
commit
422a1ad242
|
@ -584,6 +584,25 @@ void InitializeCompanies()
|
||||||
_cur_company_tick_index = 0;
|
_cur_company_tick_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May company \a cbig buy company \a csmall?
|
||||||
|
* @param cbig Company buying \a csmall.
|
||||||
|
* @param csmall Company getting bought.
|
||||||
|
* @return Return \c true if it is allowed.
|
||||||
|
*/
|
||||||
|
bool MayCompanyTakeOver(CompanyID cbig, CompanyID csmall)
|
||||||
|
{
|
||||||
|
uint big_counts[4], small_counts[4];
|
||||||
|
CountCompanyVehicles(cbig, big_counts);
|
||||||
|
CountCompanyVehicles(csmall, small_counts);
|
||||||
|
|
||||||
|
/* Do the combined vehicle counts stay within the limits? */
|
||||||
|
return big_counts[VEH_TRAIN] + small_counts[VEH_TRAIN] <= _settings_game.vehicle.max_trains &&
|
||||||
|
big_counts[VEH_ROAD] + small_counts[VEH_ROAD] <= _settings_game.vehicle.max_roadveh &&
|
||||||
|
big_counts[VEH_SHIP] + small_counts[VEH_SHIP] <= _settings_game.vehicle.max_ships &&
|
||||||
|
big_counts[VEH_AIRCRAFT] + small_counts[VEH_AIRCRAFT] <= _settings_game.vehicle.max_aircraft;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the bankruptcy take over of a company.
|
* Handle the bankruptcy take over of a company.
|
||||||
* Companies going bankrupt will ask the other companies in order of their
|
* Companies going bankrupt will ask the other companies in order of their
|
||||||
|
@ -623,7 +642,8 @@ static void HandleBankruptcyTakeover(Company *c)
|
||||||
FOR_ALL_COMPANIES(c2) {
|
FOR_ALL_COMPANIES(c2) {
|
||||||
if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves
|
if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves
|
||||||
!HasBit(c->bankrupt_asked, c2->index) &&
|
!HasBit(c->bankrupt_asked, c2->index) &&
|
||||||
best_performance < c2->old_economy[1].performance_history) {
|
best_performance < c2->old_economy[1].performance_history &&
|
||||||
|
MayCompanyTakeOver(c2->index, c->index)) {
|
||||||
best_performance = c2->old_economy[1].performance_history;
|
best_performance = c2->old_economy[1].performance_history;
|
||||||
best = c2;
|
best = c2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "tile_type.h"
|
#include "tile_type.h"
|
||||||
#include "gfx_type.h"
|
#include "gfx_type.h"
|
||||||
|
|
||||||
|
bool MayCompanyTakeOver(CompanyID cbig, CompanyID small);
|
||||||
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner);
|
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner);
|
||||||
void GetNameOfOwner(Owner owner, TileIndex tile);
|
void GetNameOfOwner(Owner owner, TileIndex tile);
|
||||||
void SetLocalCompany(CompanyID new_company);
|
void SetLocalCompany(CompanyID new_company);
|
||||||
|
|
|
@ -1600,6 +1600,9 @@ CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
/* Do not allow companies to take over themselves */
|
/* Do not allow companies to take over themselves */
|
||||||
if (target_company == _current_company) return CMD_ERROR;
|
if (target_company == _current_company) return CMD_ERROR;
|
||||||
|
|
||||||
|
/* Disable taking over when not allowed. */
|
||||||
|
if (!MayCompanyTakeOver(_current_company, target_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