summaryrefslogtreecommitdiff
path: root/src/company_cmd.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-08-06 20:26:01 +0000
committeralberth <alberth@openttd.org>2010-08-06 20:26:01 +0000
commit422a1ad24286594285ec6dc14182dd29a92ea21a (patch)
treeffa575483ded0f88d1b214c97955d112c6947b7b /src/company_cmd.cpp
parent5cfc0295236de7f1d32ca23519f35a3ee883f220 (diff)
downloadopenttd-422a1ad24286594285ec6dc14182dd29a92ea21a.tar.xz
(svn r20392) -Fix [FS#3993]: Prevent buying bankrupt companies when you'd get too many vehicles.
Diffstat (limited to 'src/company_cmd.cpp')
-rw-r--r--src/company_cmd.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 9df78ebe7..1ac0c4eb7 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -585,6 +585,25 @@ void InitializeCompanies()
}
/**
+ * 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.
* Companies going bankrupt will ask the other companies in order of their
* performance rating, so better performing companies get the 'do you want to
@@ -623,7 +642,8 @@ static void HandleBankruptcyTakeover(Company *c)
FOR_ALL_COMPANIES(c2) {
if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves
!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 = c2;
}