diff options
author | planetmaker <planetmaker@openttd.org> | 2012-10-20 22:05:26 +0000 |
---|---|---|
committer | planetmaker <planetmaker@openttd.org> | 2012-10-20 22:05:26 +0000 |
commit | f2e94237fc6dbca89f06de0befd44c2e9faf3b72 (patch) | |
tree | 44e0bb58670faf89266128d139e965a2ae6f3837 /src | |
parent | b446780f01bdf4b01c43204503d38eb191613741 (diff) | |
download | openttd-f2e94237fc6dbca89f06de0befd44c2e9faf3b72.tar.xz |
(svn r24619) -Change: Check for bankruptcy on a monthly basis (ZxBioHazardZx)
Diffstat (limited to 'src')
-rw-r--r-- | src/company_base.h | 2 | ||||
-rw-r--r-- | src/economy.cpp | 37 | ||||
-rw-r--r-- | src/network/network_admin.cpp | 2 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 5 | ||||
-rw-r--r-- | src/saveload/company_sl.cpp | 2 | ||||
-rw-r--r-- | src/saveload/oldloader_sl.cpp | 2 | ||||
-rw-r--r-- | src/saveload/saveload.cpp | 3 |
7 files changed, 39 insertions, 14 deletions
diff --git a/src/company_base.h b/src/company_base.h index 4cd5a498a..6385d6049 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -78,7 +78,7 @@ struct CompanyProperties { Year inaugurated_year; ///< Year of starting the company. - byte quarters_of_bankruptcy; ///< Number of quarters (a quarter is 3 months) that the company has a negative balance. + byte months_of_bankruptcy; ///< Number of months that the company is unable to pay its debts CompanyMask bankrupt_asked; ///< which companies were asked about buying it? int16 bankrupt_timeout; ///< If bigger than \c 0, amount of time to wait for an answer on an offer to buy this company. Money bankrupt_value; diff --git a/src/economy.cpp b/src/economy.cpp index 2483d7b69..072b10795 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -524,19 +524,29 @@ static void CompanyCheckBankrupt(Company *c) { /* If the company has money again, it does not go bankrupt */ if (c->money - c->current_loan >= -_economy.max_loan) { - c->quarters_of_bankruptcy = 0; + c->months_of_bankruptcy = 0; c->bankrupt_asked = 0; return; } - c->quarters_of_bankruptcy++; + c->months_of_bankruptcy++; - switch (c->quarters_of_bankruptcy) { + switch (c->months_of_bankruptcy) { + /* All the boring cases (months) with a bad balance where no action is taken */ case 0: case 1: + case 2: + case 3: + + case 5: + case 6: + + case 8: + case 9: break; - case 2: { + /* Warn about bancruptcy after 3 months */ + case 4: { CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); cni->FillData(c); SetDParam(0, STR_NEWS_COMPANY_IN_TROUBLE_TITLE); @@ -548,8 +558,9 @@ static void CompanyCheckBankrupt(Company *c) break; } - case 3: { - /* Check if the company has any value.. if not, declare it bankrupt + /* Offer company for sale after 6 months */ + case 7: { + /* Check if the company has any value. If not, declare it bankrupt * right now */ Money val = CalculateCompanyValue(c, false); if (val > 0) { @@ -558,10 +569,13 @@ static void CompanyCheckBankrupt(Company *c) c->bankrupt_timeout = 0; break; } - /* FALL THROUGH to case 4... */ + /* FALL THROUGH to case 10 */ } + + /* Bancrupt company after 6 months (if the company has no value) or latest + * after 9 months (if it still had value after 6 months) */ default: - case 4: + case 10: { if (!_networking && _local_company == c->index) { /* If we are in offline mode, leave the company playing. Eg. there * is no THE-END, otherwise mark the client as spectator to make sure @@ -582,6 +596,7 @@ static void CompanyCheckBankrupt(Company *c) * company and thus we won't be moved. */ if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL); break; + } } } @@ -625,6 +640,11 @@ static void CompaniesGenStatistics() } cur_company.Restore(); + /* Check for bankruptcy each month */ + FOR_ALL_COMPANIES(c) { + CompanyCheckBankrupt(c); + } + /* Only run the economic statics and update company stats every 3rd month (1st of quarter). */ if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return; @@ -637,7 +657,6 @@ static void CompaniesGenStatistics() UpdateCompanyRatingAndValue(c, true); if (c->block_preview != 0) c->block_preview--; - CompanyCheckBankrupt(c); } SetWindowDirty(WC_INCOME_GRAPH, 0); diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 9fe7c4f77..359b2a58b 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -365,7 +365,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Compa p->Send_string(manager_name); p->Send_uint8 (c->colour); p->Send_bool (NetworkCompanyIsPassworded(c->index)); - p->Send_uint8 (c->quarters_of_bankruptcy); + p->Send_uint8 (c->months_of_bankruptcy); for (size_t i = 0; i < lengthof(c->share_owners); i++) { p->Send_uint8(c->share_owners[i]); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index bc27288e2..e29889dd5 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2746,6 +2746,11 @@ bool AfterLoadGame() /* Fix too high inflation rates */ if (_economy.inflation_prices > MAX_INFLATION) _economy.inflation_prices = MAX_INFLATION; if (_economy.inflation_payment > MAX_INFLATION) _economy.inflation_payment = MAX_INFLATION; + + /* We have to convert the quarters of bankruptcy into months of bankruptcy */ + FOR_ALL_COMPANIES(c) { + c->months_of_bankruptcy = 3 * c->months_of_bankruptcy; + } } /* Road stops is 'only' updating some caches */ diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index 34309bf9a..5878f31ea 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -272,7 +272,7 @@ static const SaveLoad _company_desc[] = { SLE_VAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8), - SLE_VAR(CompanyProperties, quarters_of_bankruptcy,SLE_UINT8), + SLE_VAR(CompanyProperties, months_of_bankruptcy, SLE_UINT8), SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_FILE_U8 | SLE_VAR_U16, 0, 103), SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_UINT16, 104, SL_MAX_VERSION), SLE_VAR(CompanyProperties, bankrupt_timeout, SLE_INT16), diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index 479ee206e..a78acfd48 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -926,7 +926,7 @@ static const OldChunks _company_chunk[] = { OCL_SVAR( OC_UINT8, Company, colour ), OCL_SVAR( OC_UINT8, Company, money_fraction ), - OCL_SVAR( OC_UINT8, Company, quarters_of_bankruptcy ), + OCL_SVAR( OC_UINT8, Company, months_of_bankruptcy ), OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Company, bankrupt_asked ), OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Company, bankrupt_value ), OCL_SVAR( OC_UINT16, Company, bankrupt_timeout ), diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index d49d90a5a..625a106ff 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -240,8 +240,9 @@ * 174 23973 1.2.x * 175 24136 * 176 24446 + * 177 24619 */ -extern const uint16 SAVEGAME_VERSION = 176; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 177; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading |