mirror of https://github.com/OpenTTD/OpenTTD
(svn r24619) -Change: Check for bankruptcy on a monthly basis (ZxBioHazardZx)
parent
b446780f01
commit
f2e94237fc
|
@ -78,7 +78,7 @@ struct CompanyProperties {
|
||||||
|
|
||||||
Year inaugurated_year; ///< Year of starting the company.
|
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?
|
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.
|
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;
|
Money bankrupt_value;
|
||||||
|
|
|
@ -524,19 +524,29 @@ static void CompanyCheckBankrupt(Company *c)
|
||||||
{
|
{
|
||||||
/* If the company has money again, it does not go bankrupt */
|
/* If the company has money again, it does not go bankrupt */
|
||||||
if (c->money - c->current_loan >= -_economy.max_loan) {
|
if (c->money - c->current_loan >= -_economy.max_loan) {
|
||||||
c->quarters_of_bankruptcy = 0;
|
c->months_of_bankruptcy = 0;
|
||||||
c->bankrupt_asked = 0;
|
c->bankrupt_asked = 0;
|
||||||
return;
|
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 0:
|
||||||
case 1:
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
case 6:
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
case 9:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: {
|
/* Warn about bancruptcy after 3 months */
|
||||||
|
case 4: {
|
||||||
CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
|
CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
|
||||||
cni->FillData(c);
|
cni->FillData(c);
|
||||||
SetDParam(0, STR_NEWS_COMPANY_IN_TROUBLE_TITLE);
|
SetDParam(0, STR_NEWS_COMPANY_IN_TROUBLE_TITLE);
|
||||||
|
@ -548,8 +558,9 @@ static void CompanyCheckBankrupt(Company *c)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 3: {
|
/* Offer company for sale after 6 months */
|
||||||
/* Check if the company has any value.. if not, declare it bankrupt
|
case 7: {
|
||||||
|
/* Check if the company has any value. If not, declare it bankrupt
|
||||||
* right now */
|
* right now */
|
||||||
Money val = CalculateCompanyValue(c, false);
|
Money val = CalculateCompanyValue(c, false);
|
||||||
if (val > 0) {
|
if (val > 0) {
|
||||||
|
@ -558,10 +569,13 @@ static void CompanyCheckBankrupt(Company *c)
|
||||||
c->bankrupt_timeout = 0;
|
c->bankrupt_timeout = 0;
|
||||||
break;
|
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:
|
default:
|
||||||
case 4:
|
case 10: {
|
||||||
if (!_networking && _local_company == c->index) {
|
if (!_networking && _local_company == c->index) {
|
||||||
/* If we are in offline mode, leave the company playing. Eg. there
|
/* 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
|
* 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. */
|
* company and thus we won't be moved. */
|
||||||
if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL);
|
if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,6 +640,11 @@ static void CompaniesGenStatistics()
|
||||||
}
|
}
|
||||||
cur_company.Restore();
|
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). */
|
/* 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;
|
if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return;
|
||||||
|
|
||||||
|
@ -637,7 +657,6 @@ static void CompaniesGenStatistics()
|
||||||
|
|
||||||
UpdateCompanyRatingAndValue(c, true);
|
UpdateCompanyRatingAndValue(c, true);
|
||||||
if (c->block_preview != 0) c->block_preview--;
|
if (c->block_preview != 0) c->block_preview--;
|
||||||
CompanyCheckBankrupt(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetWindowDirty(WC_INCOME_GRAPH, 0);
|
SetWindowDirty(WC_INCOME_GRAPH, 0);
|
||||||
|
|
|
@ -365,7 +365,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Compa
|
||||||
p->Send_string(manager_name);
|
p->Send_string(manager_name);
|
||||||
p->Send_uint8 (c->colour);
|
p->Send_uint8 (c->colour);
|
||||||
p->Send_bool (NetworkCompanyIsPassworded(c->index));
|
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++) {
|
for (size_t i = 0; i < lengthof(c->share_owners); i++) {
|
||||||
p->Send_uint8(c->share_owners[i]);
|
p->Send_uint8(c->share_owners[i]);
|
||||||
|
|
|
@ -2746,6 +2746,11 @@ bool AfterLoadGame()
|
||||||
/* Fix too high inflation rates */
|
/* Fix too high inflation rates */
|
||||||
if (_economy.inflation_prices > MAX_INFLATION) _economy.inflation_prices = MAX_INFLATION;
|
if (_economy.inflation_prices > MAX_INFLATION) _economy.inflation_prices = MAX_INFLATION;
|
||||||
if (_economy.inflation_payment > MAX_INFLATION) _economy.inflation_payment = 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 */
|
/* Road stops is 'only' updating some caches */
|
||||||
|
|
|
@ -272,7 +272,7 @@ static const SaveLoad _company_desc[] = {
|
||||||
|
|
||||||
SLE_VAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8),
|
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_FILE_U8 | SLE_VAR_U16, 0, 103),
|
||||||
SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_UINT16, 104, SL_MAX_VERSION),
|
SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_UINT16, 104, SL_MAX_VERSION),
|
||||||
SLE_VAR(CompanyProperties, bankrupt_timeout, SLE_INT16),
|
SLE_VAR(CompanyProperties, bankrupt_timeout, SLE_INT16),
|
||||||
|
|
|
@ -926,7 +926,7 @@ static const OldChunks _company_chunk[] = {
|
||||||
|
|
||||||
OCL_SVAR( OC_UINT8, Company, colour ),
|
OCL_SVAR( OC_UINT8, Company, colour ),
|
||||||
OCL_SVAR( OC_UINT8, Company, money_fraction ),
|
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_U8 | OC_VAR_U16, Company, bankrupt_asked ),
|
||||||
OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Company, bankrupt_value ),
|
OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Company, bankrupt_value ),
|
||||||
OCL_SVAR( OC_UINT16, Company, bankrupt_timeout ),
|
OCL_SVAR( OC_UINT16, Company, bankrupt_timeout ),
|
||||||
|
|
|
@ -240,8 +240,9 @@
|
||||||
* 174 23973 1.2.x
|
* 174 23973 1.2.x
|
||||||
* 175 24136
|
* 175 24136
|
||||||
* 176 24446
|
* 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
|
SavegameType _savegame_type; ///< type of savegame we are loading
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue