Mercurial > hg > openttd
changeset 19382:d28ff0d5504f draft
(svn r24283) -Codechange: Add AddTileNewsItem function to preemptively deduplicate code.
author | frosch <frosch@openttd.org> |
---|---|
date | Sat, 26 May 2012 14:15:57 +0000 |
parents | f37c5813696b |
children | 0c6420024e22 |
files | src/disaster_cmd.cpp src/industry_cmd.cpp src/news_func.h src/town_cmd.cpp |
diffstat | 4 files changed, 13 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -530,10 +530,7 @@ 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 @@ 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;
--- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2627,10 +2627,11 @@ 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); + } } }
--- a/src/news_func.h +++ b/src/news_func.h @@ -44,6 +44,11 @@ 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);
--- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1694,7 +1694,7 @@ 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)); }