(svn r24283) -Codechange: Add AddTileNewsItem function to preemptively deduplicate code.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
frosch 12 years ago
parent 00b3ff80bb
commit a0be398da9

@ -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;

@ -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);
}
}
}

@ -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);

@ -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));
}

Loading…
Cancel
Save