summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-05-26 14:15:57 +0000
committerfrosch <frosch@openttd.org>2012-05-26 14:15:57 +0000
commita0be398da9f80ac316b2d8959ddf96345414dde2 (patch)
tree3c1e5780cc1f3c1209a5e7f0de71934fa088f47a /src
parent00b3ff80bbc76bc5546239cfcfa9a4c3591404a1 (diff)
downloadopenttd-a0be398da9f80ac316b2d8959ddf96345414dde2.tar.xz
(svn r24283) -Codechange: Add AddTileNewsItem function to preemptively deduplicate code.
Diffstat (limited to 'src')
-rw-r--r--src/disaster_cmd.cpp8
-rw-r--r--src/industry_cmd.cpp9
-rw-r--r--src/news_func.h5
-rw-r--r--src/town_cmd.cpp2
4 files changed, 13 insertions, 11 deletions
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 61cf0e120..25e48a772 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -530,10 +530,7 @@ static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
Town *t = ClosestTownFromTile(v->dest_tile, UINT_MAX);
SetDParam(0, t->index);
- AddNewsItem(STR_NEWS_DISASTER_BIG_UFO,
- NS_ACCIDENT,
- NR_TILE,
- v->tile);
+ AddTileNewsItem(STR_NEWS_DISASTER_BIG_UFO, NS_ACCIDENT, v->tile);
if (!Vehicle::CanAllocateItem(2)) {
delete v;
@@ -878,8 +875,7 @@ static void Disaster_CoalMine_Init()
FOR_ALL_INDUSTRIES(i) {
if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) {
SetDParam(0, i->town->index);
- AddNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE,
- NS_ACCIDENT, NR_TILE, i->location.tile + TileDiffXY(1, 1)); // keep the news, even when the mine closes
+ AddTileNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE, NS_ACCIDENT, i->location.tile + TileDiffXY(1, 1)); // keep the news, even when the mine closes
{
TileIndex tile = i->location.tile;
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index e5329e15b..5349f7d93 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -2627,10 +2627,11 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
SetDParam(0, i->index);
}
/* and report the news to the user */
- AddNewsItem(str,
- ns,
- closeit ? NR_TILE : NR_INDUSTRY,
- closeit ? i->location.tile + TileDiffXY(1, 1) : i->index);
+ if (closeit) {
+ AddTileNewsItem(str, ns, i->location.tile + TileDiffXY(1, 1));
+ } else {
+ AddIndustryNewsItem(str, ns, i->index);
+ }
}
}
diff --git a/src/news_func.h b/src/news_func.h
index e28f446a5..239e787b3 100644
--- a/src/news_func.h
+++ b/src/news_func.h
@@ -44,6 +44,11 @@ static inline void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
AddNewsItem(string, NS_ADVICE, NR_VEHICLE, vehicle);
}
+static inline void AddTileNewsItem(StringID string, NewsSubtype subtype, TileIndex tile, void *free_data = NULL)
+{
+ AddNewsItem(string, subtype, NR_TILE, tile, NR_NONE, UINT32_MAX, free_data);
+}
+
static inline void AddIndustryNewsItem(StringID string, NewsSubtype subtype, IndustryID industry)
{
AddNewsItem(string, subtype, NR_INDUSTRY, industry);
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index e42dd8362..01b60cac2 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1694,7 +1694,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
SetDParamStr(0, cn);
SetDParam(1, t->index);
- AddNewsItem(STR_NEWS_NEW_TOWN, NS_INDUSTRY_OPEN, NR_TILE, tile, NR_NONE, UINT32_MAX, cn);
+ AddTileNewsItem(STR_NEWS_NEW_TOWN, NS_INDUSTRY_OPEN, tile, cn);
AI::BroadcastNewEvent(new ScriptEventTownFounded(t->index));
Game::NewEvent(new ScriptEventTownFounded(t->index));
}