Codechange: make CompanyMask a BaseBitSet implementation
This commit is contained in:
@@ -378,12 +378,12 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||
for (Town *t : Town::Iterate()) {
|
||||
/* If a company takes over, give the ratings to that company. */
|
||||
if (new_owner != INVALID_OWNER) {
|
||||
if (HasBit(t->have_ratings, old_owner)) {
|
||||
if (HasBit(t->have_ratings, new_owner)) {
|
||||
if (t->have_ratings.Test(old_owner)) {
|
||||
if (t->have_ratings.Test(new_owner)) {
|
||||
/* use max of the two ratings. */
|
||||
t->ratings[new_owner] = std::max(t->ratings[new_owner], t->ratings[old_owner]);
|
||||
} else {
|
||||
SetBit(t->have_ratings, new_owner);
|
||||
t->have_ratings.Set(new_owner);
|
||||
t->ratings[new_owner] = t->ratings[old_owner];
|
||||
}
|
||||
}
|
||||
@@ -391,7 +391,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||
|
||||
/* Reset the ratings for the old owner */
|
||||
t->ratings[old_owner] = RATING_INITIAL;
|
||||
ClrBit(t->have_ratings, old_owner);
|
||||
t->have_ratings.Reset(old_owner);
|
||||
|
||||
/* Transfer exclusive rights */
|
||||
if (t->exclusive_counter > 0 && t->exclusivity == old_owner) {
|
||||
@@ -571,7 +571,7 @@ static void CompanyCheckBankrupt(Company *c)
|
||||
if (c->money - c->current_loan >= -c->GetMaxLoan()) {
|
||||
int previous_months_of_bankruptcy = CeilDiv(c->months_of_bankruptcy, 3);
|
||||
c->months_of_bankruptcy = 0;
|
||||
c->bankrupt_asked = 0;
|
||||
c->bankrupt_asked = CompanyMask{};
|
||||
if (previous_months_of_bankruptcy != 0) CompanyAdminUpdate(c);
|
||||
return;
|
||||
}
|
||||
@@ -610,7 +610,7 @@ static void CompanyCheckBankrupt(Company *c)
|
||||
Money val = CalculateCompanyValue(c, false);
|
||||
|
||||
c->bankrupt_value = val;
|
||||
c->bankrupt_asked = 1 << c->index; // Don't ask the owner
|
||||
c->bankrupt_asked = CompanyMask{}.Set(c->index); // Don't ask the owner
|
||||
c->bankrupt_timeout = 0;
|
||||
|
||||
/* The company assets should always have some value */
|
||||
@@ -2047,10 +2047,10 @@ CommandCost CmdBuyCompany(DoCommandFlag flags, CompanyID target_company, bool ho
|
||||
if (c == nullptr) return CMD_ERROR;
|
||||
|
||||
/* If you do a hostile takeover but the company went bankrupt, buy it via bankruptcy rules. */
|
||||
if (hostile_takeover && HasBit(c->bankrupt_asked, _current_company)) hostile_takeover = false;
|
||||
if (hostile_takeover && c->bankrupt_asked.Test(_current_company)) hostile_takeover = false;
|
||||
|
||||
/* Disable takeovers when not asked */
|
||||
if (!hostile_takeover && !HasBit(c->bankrupt_asked, _current_company)) return CMD_ERROR;
|
||||
if (!hostile_takeover && !c->bankrupt_asked.Test(_current_company)) return CMD_ERROR;
|
||||
|
||||
/* Only allow hostile takeover of AI companies and when in single player */
|
||||
if (hostile_takeover && !c->is_ai) return CMD_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user