(svn r14307) -Fix: when deleting a station, remove news items regarding it
authorsmatz
Sat, 13 Sep 2008 10:19:51 +0000
changeset 10123 f73d96619303
parent 10122 c524226103f1
child 10124 089100e22a6a
(svn r14307) -Fix: when deleting a station, remove news items regarding it
src/aircraft_cmd.cpp
src/news_func.h
src/news_gui.cpp
src/roadveh_cmd.cpp
src/ship_cmd.cpp
src/station.cpp
src/station_cmd.cpp
src/train_cmd.cpp
--- a/src/aircraft_cmd.cpp	Sat Sep 13 10:04:36 2008 +0000
+++ b/src/aircraft_cmd.cpp	Sat Sep 13 10:19:51 2008 +0000
@@ -1402,7 +1402,8 @@
 			STR_A033_CITIZENS_CELEBRATE_FIRST,
 			(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
 			v->index,
-			0);
+			st->index
+		);
 	}
 
 	v->BeginLoading();
--- a/src/news_func.h	Sat Sep 13 10:04:36 2008 +0000
+++ b/src/news_func.h	Sat Sep 13 10:19:51 2008 +0000
@@ -7,6 +7,7 @@
 
 #include "news_type.h"
 #include "vehicle_type.h"
+#include "station_type.h"
 
 void AddNewsItem(StringID string, NewsSubtype subtype, uint data_a, uint data_b, void *free_data = NULL);
 void NewsLoop();
@@ -24,4 +25,7 @@
  */
 void DeleteVehicleNews(VehicleID, StringID news);
 
+/** Delete news associated with given station */
+void DeleteStationNews(StationID);
+
 #endif /* NEWS_FUNC_H */
--- a/src/news_gui.cpp	Sat Sep 13 10:04:36 2008 +0000
+++ b/src/news_gui.cpp	Sat Sep 13 10:19:51 2008 +0000
@@ -579,6 +579,29 @@
 	}
 }
 
+/** Remove news regarding given station so there are no 'unknown station now accepts Mail'
+ * or 'First train arrived at unknown station' news items.
+ * @param sid station to remove news about
+ */
+void DeleteStationNews(StationID sid)
+{
+	NewsItem *ni = _oldest_news;
+
+	while (ni != NULL) {
+		NewsItem *next = ni->next;
+		switch (ni->subtype) {
+			case NS_ARRIVAL_PLAYER:
+			case NS_ARRIVAL_OTHER:
+			case NS_ACCEPTANCE:
+				if (ni->data_b == sid) DeleteNewsItem(ni);
+				break;
+			default:
+				break;
+		}
+		ni = next;
+	}
+}
+
 void RemoveOldNewsItems()
 {
 	NewsItem *next;
--- a/src/roadveh_cmd.cpp	Sat Sep 13 10:04:36 2008 +0000
+++ b/src/roadveh_cmd.cpp	Sat Sep 13 10:19:51 2008 +0000
@@ -807,7 +807,8 @@
 				v->u.road.roadtype == ROADTYPE_ROAD ? STR_902F_CITIZENS_CELEBRATE_FIRST : STR_CITIZENS_CELEBRATE_FIRST_PASSENGER_TRAM,
 				(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
 				v->index,
-				0);
+				st->index
+			);
 		}
 	} else {
 		/* Check if station was ever visited before */
@@ -818,7 +819,7 @@
 				v->u.road.roadtype == ROADTYPE_ROAD ? STR_9030_CITIZENS_CELEBRATE_FIRST : STR_CITIZENS_CELEBRATE_FIRST_CARGO_TRAM,
 				(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
 				v->index,
-				0
+				st->index
 			);
 		}
 	}
--- a/src/ship_cmd.cpp	Sat Sep 13 10:04:36 2008 +0000
+++ b/src/ship_cmd.cpp	Sat Sep 13 10:19:51 2008 +0000
@@ -351,7 +351,8 @@
 			STR_9833_CITIZENS_CELEBRATE_FIRST,
 			(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
 			v->index,
-			0);
+			st->index
+		);
 	}
 }
 
--- a/src/station.cpp	Sat Sep 13 10:04:36 2008 +0000
+++ b/src/station.cpp	Sat Sep 13 10:19:51 2008 +0000
@@ -31,6 +31,7 @@
 #include "settings_type.h"
 #include "command_func.h"
 #include "order_func.h"
+#include "news_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
@@ -84,6 +85,9 @@
 	/* Subsidies need removal as well */
 	DeleteSubsidyWithStation(index);
 
+	/* Remove all news items */
+	DeleteStationNews(this->index);
+
 	xy = 0;
 
 	for (CargoID c = 0; c < NUM_CARGO; c++) {
--- a/src/station_cmd.cpp	Sat Sep 13 10:04:36 2008 +0000
+++ b/src/station_cmd.cpp	Sat Sep 13 10:19:51 2008 +0000
@@ -411,7 +411,7 @@
 	}
 
 	SetDParam(0, st->index);
-	AddNewsItem(msg, NS_ACCEPTANCE, st->xy, 0);
+	AddNewsItem(msg, NS_ACCEPTANCE, st->xy, st->index);
 }
 
 /**
--- a/src/train_cmd.cpp	Sat Sep 13 10:04:36 2008 +0000
+++ b/src/train_cmd.cpp	Sat Sep 13 10:19:51 2008 +0000
@@ -3251,7 +3251,7 @@
 			STR_8801_CITIZENS_CELEBRATE_FIRST,
 			v->owner == _local_player ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
 			v->index,
-			0
+			st->index
 		);
 	}