summaryrefslogtreecommitdiff
path: root/src/news_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-08-10 20:06:39 +0000
committerfrosch <frosch@openttd.org>2009-08-10 20:06:39 +0000
commit52f9b8ffbd5fe9222da34e968d69876982b9a810 (patch)
treeac1f89eacfa91e22cdd80d1c7d39ba898bd0944f /src/news_gui.cpp
parent238b0e43bbaa997acb7e53f1de118a963bb330fa (diff)
downloadopenttd-52f9b8ffbd5fe9222da34e968d69876982b9a810.tar.xz
(svn r17147) -Fix [FS#3048]: Keep vehicle news and viewports following vehicles, when autoreplacing/renewing them.
Diffstat (limited to 'src/news_gui.cpp')
-rw-r--r--src/news_gui.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index d3c9577e5..db1b4eef6 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -673,6 +673,29 @@ void RemoveOldNewsItems()
}
}
+/**
+ * Report a change in vehicle IDs (due to autoreplace) to affected vehicle news.
+ * @note Viewports of currently displayed news is changed via #ChangeVehicleViewports
+ * @param from_index the old vehicle ID
+ * @param to_index the new vehicle ID
+ */
+void ChangeVehicleNews(VehicleID from_index, VehicleID to_index)
+{
+ for (NewsItem *ni = _oldest_news; ni != NULL; ni = ni->next) {
+ if (ni->reftype1 == NR_VEHICLE && ni->ref1 == from_index) ni->ref1 = to_index;
+ if (ni->reftype2 == NR_VEHICLE && ni->ref2 == from_index) ni->ref2 = to_index;
+
+ /* Oh noes :(
+ * Autoreplace is breaking the whole news-reference concept here, as we want to keep the news,
+ * but do not know which DParams to change.
+ *
+ * Currently only NS_ADVICE news have vehicle IDs in their DParams.
+ * And all NS_ADVICE news have the ID in param 0.
+ */
+ if (ni->subtype == NS_ADVICE && ni->params[0] == from_index) ni->params[0] = to_index;
+ }
+}
+
void NewsLoop()
{
/* no news item yet */