summaryrefslogtreecommitdiff
path: root/src/players.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-07-18 16:26:51 +0000
committerrubidium <rubidium@openttd.org>2008-07-18 16:26:51 +0000
commit891bec7e23a0a077df93b8fd1fe156ef059df8b4 (patch)
tree71817bf7af4429f1e29b23c2bb0148ca8b0bea3c /src/players.cpp
parente48d86fad0a384335fa4c49a4f15032bee54b16e (diff)
downloadopenttd-891bec7e23a0a077df93b8fd1fe156ef059df8b4.tar.xz
(svn r13730) -Fix: make a copy of the names for news messages about the deletion of companies as the removal of a company could lead to wrong names in the news messages.
Diffstat (limited to 'src/players.cpp')
-rw-r--r--src/players.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/players.cpp b/src/players.cpp
index dc161ba5a..14906b98f 100644
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -357,11 +357,13 @@ set_name:;
MarkWholeScreenDirty();
if (!IsHumanPlayer(p->index)) {
+ CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
+ cni->FillData(p);
SetDParam(0, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED);
SetDParam(1, STR_705F_STARTS_CONSTRUCTION_NEAR);
- SetDParam(2, p->index);
+ SetDParamStr(2, cni->company_name);
SetDParam(3, t->index);
- AddNewsItem(STR_02B6, NS_COMPANY_NEW, p->last_build_coordinate, p->index);
+ AddNewsItem(STR_02B6, NS_COMPANY_NEW, p->last_build_coordinate, 0, cni);
}
return;
}
@@ -795,6 +797,32 @@ CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
return CommandCost();
}
+/**
+ * Fill the CompanyNewsInformation struct with the required data.
+ * @param p the current company.
+ * @param other the other company.
+ */
+void CompanyNewsInformation::FillData(const Player *p, const Player *other)
+{
+ SetDParam(0, p->index);
+ GetString(this->company_name, STR_COMPANY_NAME, lastof(this->company_name));
+
+ if (other == NULL) {
+ *this->other_company_name = '\0';
+ } else {
+ SetDParam(0, other->index);
+ GetString(this->other_company_name, STR_COMPANY_NAME, lastof(this->other_company_name));
+ p = other;
+ }
+
+ SetDParam(0, p->index);
+ GetString(this->president_name, STR_7058_PRESIDENT, lastof(this->president_name));
+
+ this->colour = p->player_color;
+ this->face = p->face;
+
+}
+
/** Control the players: add, delete, etc.
* @param tile unused
* @param flags operation to perform
@@ -933,11 +961,14 @@ CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Delete any open window of the company */
DeletePlayerWindows(p->index);
+ CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
+ cni->FillData(p);
+
/* Show the bankrupt news */
SetDParam(0, STR_705C_BANKRUPT);
SetDParam(1, STR_705D_HAS_BEEN_CLOSED_DOWN_BY);
- SetDParam(2, p->index);
- AddNewsItem(STR_02B6, NS_COMPANY_BANKRUPT, 0, p->index);
+ SetDParamStr(2, cni->company_name);
+ AddNewsItem(STR_02B6, NS_COMPANY_BANKRUPT, 0, 0, cni);
/* Remove the company */
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);