Changeset - r25744:540e044a54a1
[Not reviewed]
master
0 4 0
rubidium42 - 3 years ago 2021-06-16 15:54:08
rubidium@openttd.org
Codechange: use the constructor for CompanyNewsItem to fill the data instead of a separate function
4 files changed with 14 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -367,26 +367,25 @@ verify_name:;
 
		}
 

	
 
		GetString(buffer, str, lastof(buffer));
 
		if (Utf8StringLength(buffer) >= MAX_LENGTH_COMPANY_NAME_CHARS) goto bad_town_name;
 

	
 
set_name:;
 
		c->name_1 = str;
 
		c->name_2 = strp;
 

	
 
		MarkWholeScreenDirty();
 

	
 
		if (c->is_ai) {
 
			CompanyNewsInformation *cni = new CompanyNewsInformation();
 
			cni->FillData(c);
 
			CompanyNewsInformation *cni = new CompanyNewsInformation(c);
 
			SetDParam(0, STR_NEWS_COMPANY_LAUNCH_TITLE);
 
			SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION);
 
			SetDParamStr(2, cni->company_name);
 
			SetDParam(3, t->index);
 
			AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate, NR_NONE, UINT32_MAX, cni);
 
		}
 
		return;
 
	}
 
bad_town_name:;
 

	
 
	if (c->president_name_1 == SPECSTR_PRESIDENT_NAME) {
 
		str = SPECSTR_ANDCO_NAME;
 
@@ -746,39 +745,37 @@ void CompaniesYearlyLoop()
 
			if (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);
 
		} else {
 
			if (_settings_client.sound.new_year) SndPlayFx(SND_00_GOOD_YEAR);
 
		}
 
	}
 
}
 

	
 
/**
 
 * Fill the CompanyNewsInformation struct with the required data.
 
 * @param c the current company.
 
 * @param other the other company (use \c nullptr if not relevant).
 
 */
 
void CompanyNewsInformation::FillData(const Company *c, const Company *other)
 
CompanyNewsInformation::CompanyNewsInformation(const Company *c, const Company *other)
 
{
 
	SetDParam(0, c->index);
 
	GetString(this->company_name, STR_COMPANY_NAME, lastof(this->company_name));
 
	this->company_name = GetString(STR_COMPANY_NAME);
 

	
 
	if (other == nullptr) {
 
		*this->other_company_name = '\0';
 
	} else {
 
	if (other != nullptr) {
 
		SetDParam(0, other->index);
 
		GetString(this->other_company_name, STR_COMPANY_NAME, lastof(this->other_company_name));
 
		this->other_company_name = GetString(STR_COMPANY_NAME);
 
		c = other;
 
	}
 

	
 
	SetDParam(0, c->index);
 
	GetString(this->president_name, STR_PRESIDENT_NAME_MANAGER, lastof(this->president_name));
 
	this->president_name = GetString(STR_PRESIDENT_NAME_MANAGER);
 

	
 
	this->colour = c->colour;
 
	this->face = c->face;
 

	
 
}
 

	
 
/**
 
 * Called whenever company related information changes in order to notify admins.
 
 * @param company The company data changed of.
 
 */
 
void CompanyAdminUpdate(const Company *company)
 
{
 
@@ -879,26 +876,25 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
			if (reason >= CRR_END) return CMD_ERROR;
 

	
 
			/* We can't delete the last existing company in singleplayer mode. */
 
			if (!_networking && Company::GetNumItems() == 1) return CMD_ERROR;
 

	
 
			Company *c = Company::GetIfValid(company_id);
 
			if (c == nullptr) return CMD_ERROR;
 

	
 
			if (!(flags & DC_EXEC)) return CommandCost();
 

	
 
			/* Delete any open window of the company */
 
			CloseCompanyWindows(c->index);
 
			CompanyNewsInformation *cni = new CompanyNewsInformation();
 
			cni->FillData(c);
 
			CompanyNewsInformation *cni = new CompanyNewsInformation(c);
 

	
 
			/* Show the bankrupt news */
 
			SetDParam(0, STR_NEWS_COMPANY_BANKRUPT_TITLE);
 
			SetDParam(1, STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION);
 
			SetDParamStr(2, cni->company_name);
 
			AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, cni);
 

	
 
			/* Remove the company */
 
			ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
 
			if (c->is_ai) AI::Stop(c->index);
 

	
 
			CompanyID c_index = c->index;
src/economy.cpp
Show inline comments
 
@@ -571,26 +571,25 @@ static void CompanyCheckBankrupt(Company
 
		case 2:
 
		case 3:
 

	
 
		case 5:
 
		case 6:
 

	
 
		case 8:
 
		case 9:
 
			break;
 

	
 
		/* Warn about bankruptcy after 3 months */
 
		case 4: {
 
			CompanyNewsInformation *cni = new CompanyNewsInformation();
 
			cni->FillData(c);
 
			CompanyNewsInformation *cni = new CompanyNewsInformation(c);
 
			SetDParam(0, STR_NEWS_COMPANY_IN_TROUBLE_TITLE);
 
			SetDParam(1, STR_NEWS_COMPANY_IN_TROUBLE_DESCRIPTION);
 
			SetDParamStr(2, cni->company_name);
 
			AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, cni);
 
			AI::BroadcastNewEvent(new ScriptEventCompanyInTrouble(c->index));
 
			Game::NewEvent(new ScriptEventCompanyInTrouble(c->index));
 
			break;
 
		}
 

	
 
		/* Offer company for sale after 6 months */
 
		case 7: {
 
			/* Don't consider the loan */
 
@@ -1966,26 +1965,25 @@ void CompaniesMonthlyLoop()
 
	if (_settings_game.economy.inflation) {
 
		AddInflation();
 
		RecomputePrices();
 
	}
 
	CompaniesPayInterest();
 
	HandleEconomyFluctuations();
 
}
 

	
 
static void DoAcquireCompany(Company *c)
 
{
 
	CompanyID ci = c->index;
 

	
 
	CompanyNewsInformation *cni = new CompanyNewsInformation();
 
	cni->FillData(c, Company::Get(_current_company));
 
	CompanyNewsInformation *cni = new CompanyNewsInformation(c, Company::Get(_current_company));
 

	
 
	SetDParam(0, STR_NEWS_COMPANY_MERGER_TITLE);
 
	SetDParam(1, c->bankrupt_value == 0 ? STR_NEWS_MERGER_TAKEOVER_TITLE : STR_NEWS_COMPANY_MERGER_DESCRIPTION);
 
	SetDParamStr(2, cni->company_name);
 
	SetDParamStr(3, cni->other_company_name);
 
	SetDParam(4, c->bankrupt_value);
 
	AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, cni);
 
	AI::BroadcastNewEvent(new ScriptEventCompanyMerger(ci, _current_company));
 
	Game::NewEvent(new ScriptEventCompanyMerger(ci, _current_company));
 

	
 
	ChangeOwnershipOfCompanyItems(ci, _current_company);
 

	
src/news_type.h
Show inline comments
 
@@ -149,23 +149,23 @@ struct NewsItem {
 
struct NewsStringData : NewsAllocatedData {
 
	std::string string; ///< The string to retain.
 
	NewsStringData(const std::string &str) : string(str) {}
 
};
 

	
 
/**
 
 * Data that needs to be stored for company news messages.
 
 * The problem with company news messages are the custom name
 
 * of the companies and the fact that the company data is reset,
 
 * resulting in wrong names and such.
 
 */
 
struct CompanyNewsInformation : NewsAllocatedData {
 
	char company_name[64];       ///< The name of the company
 
	char president_name[64];     ///< The name of the president
 
	char other_company_name[64]; ///< The name of the company taking over this one
 
	std::string company_name;       ///< The name of the company
 
	std::string president_name;     ///< The name of the president
 
	std::string other_company_name; ///< The name of the company taking over this one
 

	
 
	uint32 face; ///< The face of the president
 
	byte colour; ///< The colour related to the company
 

	
 
	void FillData(const struct Company *c, const struct Company *other = nullptr);
 
	CompanyNewsInformation(const struct Company *c, const struct Company *other = nullptr);
 
};
 

	
 
#endif /* NEWS_TYPE_H */
src/town_cmd.cpp
Show inline comments
 
@@ -3222,26 +3222,25 @@ static CommandCost TownActionBuyRights(T
 
	/* Check if it's allowed to buy the rights */
 
	if (!_settings_game.economy.exclusive_rights) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		t->exclusive_counter = 12;
 
		t->exclusivity = _current_company;
 

	
 
		ModifyStationRatingAround(t->xy, _current_company, 130, 17);
 

	
 
		SetWindowClassesDirty(WC_STATION_VIEW);
 

	
 
		/* Spawn news message */
 
		CompanyNewsInformation *cni = new CompanyNewsInformation();
 
		cni->FillData(Company::Get(_current_company));
 
		CompanyNewsInformation *cni = new CompanyNewsInformation(Company::Get(_current_company));
 
		SetDParam(0, STR_NEWS_EXCLUSIVE_RIGHTS_TITLE);
 
		SetDParam(1, STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION);
 
		SetDParam(2, t->index);
 
		SetDParamStr(3, cni->company_name);
 
		AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_GENERAL, NF_COMPANY, NR_TOWN, t->index, NR_NONE, UINT32_MAX, cni);
 
		AI::BroadcastNewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
 
		Game::NewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index));
 
	}
 
	return CommandCost();
 
}
 

	
 
static CommandCost TownActionBribe(Town *t, DoCommandFlag flags)
0 comments (0 inline, 0 general)