diff options
author | frosch <frosch@openttd.org> | 2012-05-26 14:16:03 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-05-26 14:16:03 +0000 |
commit | a8c88f43b678b6d44e1fb4f78a51cdb7fb08a8aa (patch) | |
tree | 38b53a0432d536abc9dcfbbdd0b5c7c74bd55f99 | |
parent | a0be398da9f80ac316b2d8959ddf96345414dde2 (diff) | |
download | openttd-a8c88f43b678b6d44e1fb4f78a51cdb7fb08a8aa.tar.xz |
(svn r24284) -Codechange: Remove NewsSubtypes and directly use NewsTypes and NewsFlag instead.
-rw-r--r-- | src/aircraft_cmd.cpp | 7 | ||||
-rw-r--r-- | src/company_cmd.cpp | 2 | ||||
-rw-r--r-- | src/currency.cpp | 2 | ||||
-rw-r--r-- | src/disaster_cmd.cpp | 14 | ||||
-rw-r--r-- | src/economy.cpp | 4 | ||||
-rw-r--r-- | src/engine.cpp | 2 | ||||
-rw-r--r-- | src/industry_cmd.cpp | 26 | ||||
-rw-r--r-- | src/news_func.h | 18 | ||||
-rw-r--r-- | src/news_gui.cpp | 94 | ||||
-rw-r--r-- | src/news_type.h | 51 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 6 | ||||
-rw-r--r-- | src/script/api/script_news.hpp | 7 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 2 | ||||
-rw-r--r-- | src/station_cmd.cpp | 2 | ||||
-rw-r--r-- | src/subsidy.cpp | 8 | ||||
-rw-r--r-- | src/town_cmd.cpp | 4 | ||||
-rw-r--r-- | src/train_cmd.cpp | 7 | ||||
-rw-r--r-- | src/water_cmd.cpp | 2 |
18 files changed, 98 insertions, 160 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 8f5be8da3..fc59f6553 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1163,10 +1163,7 @@ static void CrashAirplane(Aircraft *v) AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING)); Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING)); - AddVehicleNewsItem(newsitem, - NS_ACCIDENT, - v->index, - st != NULL ? st->index : INVALID_STATION); + AddVehicleNewsItem(newsitem, NT_ACCIDENT, v->index, st != NULL ? st->index : INVALID_STATION); ModifyStationRatingAround(v->tile, v->owner, -160, 30); SndPlayVehicleFx(SND_12_EXPLOSION, v); @@ -1222,7 +1219,7 @@ static void AircraftEntersTerminal(Aircraft *v) /* show newsitem of celebrating citizens */ AddVehicleNewsItem( STR_NEWS_FIRST_AIRCRAFT_ARRIVAL, - (v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER, + (v->owner == _local_company) ? NT_ARRIVAL_COMPANY : NT_ARRIVAL_OTHER, v->index, st->index ); diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 1137fe0d2..e5c62ea2f 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -375,7 +375,7 @@ set_name:; SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION); SetDParamStr(2, cni->company_name); SetDParam(3, t->index); - AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_INFO, NR_TILE, c->last_build_coordinate, NR_NONE, UINT32_MAX, cni); + AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate, NR_NONE, UINT32_MAX, cni); } return; } diff --git a/src/currency.cpp b/src/currency.cpp index e39871141..005ad9842 100644 --- a/src/currency.cpp +++ b/src/currency.cpp @@ -170,7 +170,7 @@ void CheckSwitchToEuro() _currency_specs[_settings_game.locale.currency].to_euro != CF_ISEURO && _cur_year >= _currency_specs[_settings_game.locale.currency].to_euro) { _settings_game.locale.currency = 2; // this is the index of euro above. - AddNewsItem(STR_NEWS_EURO_INTRODUCTION, NS_ECONOMY); + AddNewsItem(STR_NEWS_EURO_INTRODUCTION, NT_ECONOMY, NF_NORMAL); } } diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index 25e48a772..916a9b4c9 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -218,9 +218,7 @@ static bool DisasterTick_Zeppeliner(DisasterVehicle *v) v->age = 0; SetDParam(0, GetStationIndex(v->tile)); - AddVehicleNewsItem(STR_NEWS_DISASTER_ZEPPELIN, - NS_ACCIDENT, - v->index); // Delete the news, when the zeppelin is gone + AddVehicleNewsItem(STR_NEWS_DISASTER_ZEPPELIN, NT_ACCIDENT, v->index); // Delete the news, when the zeppelin is gone AI::NewEvent(GetTileOwner(v->tile), new ScriptEventDisasterZeppelinerCrashed(GetStationIndex(v->tile))); } } @@ -353,9 +351,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) if (u->crashed_ctr == 0) { u->Crash(); - AddVehicleNewsItem(STR_NEWS_DISASTER_SMALL_UFO, - NS_ACCIDENT, - u->index); // delete the news, when the roadvehicle is gone + AddVehicleNewsItem(STR_NEWS_DISASTER_SMALL_UFO, NT_ACCIDENT, u->index); // delete the news, when the roadvehicle is gone AI::NewEvent(u->owner, new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO)); Game::NewEvent(new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO)); @@ -434,7 +430,7 @@ static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16 image_override, boo DestructIndustry(i); SetDParam(0, i->town->index); - AddIndustryNewsItem(news_message, NS_ACCIDENT, i->index); // delete the news, when the industry closes + AddIndustryNewsItem(news_message, NT_ACCIDENT, i->index); // delete the news, when the industry closes SndPlayTileFx(SND_12_EXPLOSION, i->location.tile); } } else if (v->current_order.GetDestination() == 0) { @@ -530,7 +526,7 @@ static bool DisasterTick_Big_Ufo(DisasterVehicle *v) Town *t = ClosestTownFromTile(v->dest_tile, UINT_MAX); SetDParam(0, t->index); - AddTileNewsItem(STR_NEWS_DISASTER_BIG_UFO, NS_ACCIDENT, v->tile); + AddTileNewsItem(STR_NEWS_DISASTER_BIG_UFO, NT_ACCIDENT, v->tile); if (!Vehicle::CanAllocateItem(2)) { delete v; @@ -875,7 +871,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); - AddTileNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE, NS_ACCIDENT, i->location.tile + TileDiffXY(1, 1)); // keep the news, even when the mine closes + AddTileNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE, NT_ACCIDENT, i->location.tile + TileDiffXY(1, 1)); // keep the news, even when the mine closes { TileIndex tile = i->location.tile; diff --git a/src/economy.cpp b/src/economy.cpp index f65dbcf92..66972b862 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -792,10 +792,10 @@ static void HandleEconomyFluctuations() if (_economy.fluct == 0) { _economy.fluct = -(int)GB(Random(), 0, 2); - AddNewsItem(STR_NEWS_BEGIN_OF_RECESSION, NS_ECONOMY); + AddNewsItem(STR_NEWS_BEGIN_OF_RECESSION, NT_ECONOMY, NF_NORMAL); } else if (_economy.fluct == -12) { _economy.fluct = GB(Random(), 0, 8) + 312; - AddNewsItem(STR_NEWS_END_OF_RECESSION, NS_ECONOMY); + AddNewsItem(STR_NEWS_END_OF_RECESSION, NT_ECONOMY, NF_NORMAL); } } diff --git a/src/engine.cpp b/src/engine.cpp index 63f391d22..1500b9d89 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -893,7 +893,7 @@ static void NewVehicleAvailable(Engine *e) SetDParam(0, GetEngineCategoryName(index)); SetDParam(1, index); - AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, NR_ENGINE, index); + AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NT_NEW_VEHICLES, NF_VEHICLE, NR_ENGINE, index); /* Update the toolbar. */ if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD); diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 5349f7d93..fd8387e2d 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1595,7 +1595,7 @@ static void AdvertiseIndustryOpening(const Industry *ind) } else { SetDParam(1, ind->town->index); } - AddIndustryNewsItem(ind_spc->new_industry_text, NS_INDUSTRY_OPEN, ind->index); + AddIndustryNewsItem(ind_spc->new_industry_text, NT_INDUSTRY_OPEN, ind->index); AI::BroadcastNewEvent(new ScriptEventIndustryOpen(ind->index)); Game::NewEvent(new ScriptEventIndustryOpen(ind->index)); } @@ -2415,12 +2415,12 @@ static int WhoCanServiceIndustry(Industry *ind) */ static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent) { - NewsSubtype ns; + NewsType nt; switch (WhoCanServiceIndustry(ind)) { - case 0: ns = NS_INDUSTRY_NOBODY; break; - case 1: ns = NS_INDUSTRY_OTHER; break; - case 2: ns = NS_INDUSTRY_COMPANY; break; + case 0: nt = NT_INDUSTRY_NOBODY; break; + case 1: nt = NT_INDUSTRY_OTHER; break; + case 2: nt = NT_INDUSTRY_COMPANY; break; default: NOT_REACHED(); } SetDParam(2, abs(percent)); @@ -2428,7 +2428,7 @@ static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int SetDParam(1, ind->index); AddIndustryNewsItem( percent >= 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH, - ns, + nt, ind->index ); } @@ -2600,17 +2600,17 @@ static void ChangeIndustryProduction(Industry *i, bool monthly) } if (!suppress_message && str != STR_NULL) { - NewsSubtype ns; + NewsType nt; /* Compute news category */ if (closeit) { - ns = NS_INDUSTRY_CLOSE; + nt = NT_INDUSTRY_CLOSE; AI::BroadcastNewEvent(new ScriptEventIndustryClose(i->index)); Game::NewEvent(new ScriptEventIndustryClose(i->index)); } else { switch (WhoCanServiceIndustry(i)) { - case 0: ns = NS_INDUSTRY_NOBODY; break; - case 1: ns = NS_INDUSTRY_OTHER; break; - case 2: ns = NS_INDUSTRY_COMPANY; break; + case 0: nt = NT_INDUSTRY_NOBODY; break; + case 1: nt = NT_INDUSTRY_OTHER; break; + case 2: nt = NT_INDUSTRY_COMPANY; break; default: NOT_REACHED(); } } @@ -2628,9 +2628,9 @@ static void ChangeIndustryProduction(Industry *i, bool monthly) } /* and report the news to the user */ if (closeit) { - AddTileNewsItem(str, ns, i->location.tile + TileDiffXY(1, 1)); + AddTileNewsItem(str, nt, i->location.tile + TileDiffXY(1, 1)); } else { - AddIndustryNewsItem(str, ns, i->index); + AddIndustryNewsItem(str, nt, i->index); } } } diff --git a/src/news_func.h b/src/news_func.h index 239e787b3..b825c686f 100644 --- a/src/news_func.h +++ b/src/news_func.h @@ -17,11 +17,11 @@ #include "station_type.h" #include "industry_type.h" -void AddNewsItem(StringID string, NewsSubtype subtype, NewsReferenceType reftype1 = NR_NONE, uint32 ref1 = UINT32_MAX, NewsReferenceType reftype2 = NR_NONE, uint32 ref2 = UINT32_MAX, void *free_data = NULL); +void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1 = NR_NONE, uint32 ref1 = UINT32_MAX, NewsReferenceType reftype2 = NR_NONE, uint32 ref2 = UINT32_MAX, void *free_data = NULL); static inline void AddCompanyNewsItem(StringID string, CompanyNewsInformation *cni) { - AddNewsItem(string, NS_COMPANY_INFO, NR_NONE, UINT32_MAX, NR_NONE, UINT32_MAX, cni); + AddNewsItem(string, NT_COMPANY_INFO, NF_COMPANY, NR_NONE, UINT32_MAX, NR_NONE, UINT32_MAX, cni); } /** @@ -29,9 +29,9 @@ static inline void AddCompanyNewsItem(StringID string, CompanyNewsInformation *c * * @warning The DParams may not reference the vehicle due to autoreplace stuff. See AddVehicleAdviceNewsItem for how that can be done. */ -static inline void AddVehicleNewsItem(StringID string, NewsSubtype subtype, VehicleID vehicle, StationID station = INVALID_STATION) +static inline void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station = INVALID_STATION) { - AddNewsItem(string, subtype, NR_VEHICLE, vehicle, station == INVALID_STATION ? NR_NONE : NR_STATION, station); + AddNewsItem(string, type, NF_NO_TRANSPARENT | NF_SHADE | NF_THIN, NR_VEHICLE, vehicle, station == INVALID_STATION ? NR_NONE : NR_STATION, station); } /** @@ -41,17 +41,17 @@ static inline void AddVehicleNewsItem(StringID string, NewsSubtype subtype, Vehi */ static inline void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle) { - AddNewsItem(string, NS_ADVICE, NR_VEHICLE, vehicle); + AddNewsItem(string, NT_ADVICE, NF_INCOLOUR | NF_SMALL, NR_VEHICLE, vehicle); } -static inline void AddTileNewsItem(StringID string, NewsSubtype subtype, TileIndex tile, void *free_data = NULL) +static inline void AddTileNewsItem(StringID string, NewsType type, TileIndex tile, void *free_data = NULL) { - AddNewsItem(string, subtype, NR_TILE, tile, NR_NONE, UINT32_MAX, free_data); + AddNewsItem(string, type, NF_NO_TRANSPARENT | NF_SHADE | NF_THIN, NR_TILE, tile, NR_NONE, UINT32_MAX, free_data); } -static inline void AddIndustryNewsItem(StringID string, NewsSubtype subtype, IndustryID industry) +static inline void AddIndustryNewsItem(StringID string, NewsType type, IndustryID industry) { - AddNewsItem(string, subtype, NR_INDUSTRY, industry); + AddNewsItem(string, type, NF_NO_TRANSPARENT | NF_SHADE | NF_THIN, NR_INDUSTRY, industry); } void NewsLoop(); diff --git a/src/news_gui.cpp b/src/news_gui.cpp index d7d9fc702..023cd2082 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -202,37 +202,22 @@ static const WindowDesc _small_news_desc( ); /** - * Data common to all news items of a given subtype (structure) + * Window layouts for news items. */ -struct NewsSubtypeData { - NewsType type; ///< News category @see NewsType - NewsFlag flags; ///< Initial NewsFlags bits @see NewsFlag - const WindowDesc *desc; ///< Window description for displaying this news. +static const WindowDesc* _news_window_layout[] = { + &_thin_news_desc, ///< NF_THIN + &_small_news_desc, ///< NF_SMALL + &_normal_news_desc, ///< NF_NORMAL + &_vehicle_news_desc, ///< NF_VEHICLE + &_company_news_desc, ///< NF_COMPANY }; -/** - * Data common to all news items of a given subtype (actual data) - */ -static const NewsSubtypeData _news_subtype_data[] = { - /* type, display_mode, flags, window description, callback */ - { NT_ARRIVAL_COMPANY, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ARRIVAL_COMPANY - { NT_ARRIVAL_OTHER, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ARRIVAL_OTHER - { NT_ACCIDENT, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_ACCIDENT - { NT_COMPANY_INFO, NF_NONE, &_company_news_desc }, ///< NS_COMPANY_INFO - { NT_INDUSTRY_OPEN, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_OPEN - { NT_INDUSTRY_CLOSE, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_CLOSE - { NT_ECONOMY, NF_NONE, &_normal_news_desc }, ///< NS_ECONOMY - { NT_INDUSTRY_COMPANY, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_COMPANY - { NT_INDUSTRY_OTHER, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_OTHER - { NT_INDUSTRY_NOBODY, (NF_NO_TRANSPARENT | NF_SHADE), &_thin_news_desc }, ///< NS_INDUSTRY_NOBODY - { NT_ADVICE, NF_INCOLOUR, &_small_news_desc }, ///< NS_ADVICE - { NT_NEW_VEHICLES, NF_NONE, &_vehicle_news_desc }, ///< NS_NEW_VEHICLES - { NT_ACCEPTANCE, NF_INCOLOUR, &_small_news_desc }, ///< NS_ACCEPTANCE - { NT_SUBSIDIES, NF_NONE, &_normal_news_desc }, ///< NS_SUBSIDIES - { NT_GENERAL, NF_NONE, &_normal_news_desc }, ///< NS_GENERAL -}; - -assert_compile(lengthof(_news_subtype_data) == NS_END); +const WindowDesc* GetNewsWindowLayout(NewsFlag flags) +{ + uint layout = GB(flags, NFB_WINDOW_LAYOUT, NFB_WINDOW_LAYOUT_COUNT); + assert(layout < lengthof(_news_window_layout)); + return _news_window_layout[layout]; +} /** * Per-NewsType data @@ -532,10 +517,10 @@ private: /** Open up an own newspaper window for the news item */ static void ShowNewspaper(const NewsItem *ni) { - SoundFx sound = _news_type_data[_news_subtype_data[ni->subtype].type].sound; + SoundFx sound = _news_type_data[ni->type].sound; if (sound != 0) SndPlayFx(sound); - new NewsWindow(_news_subtype_data[ni->subtype].desc, ni); + new NewsWindow(GetNewsWindowLayout(ni->flags), ni); } /** Show news item in the ticker */ @@ -597,7 +582,7 @@ static void MoveToNextItem() if (_current_news != _latest_news) { _current_news = (_current_news == NULL) ? _oldest_news : _current_news->next; const NewsItem *ni = _current_news; - const NewsType type = _news_subtype_data[ni->subtype].type; + const NewsType type = ni->type; /* check the date, don't show too old items */ if (_date - _news_type_data[type].age > ni->date) return; @@ -622,7 +607,8 @@ static void MoveToNextItem() /** * Add a new newsitem to be shown. * @param string String to display - * @param subtype news category, any of the NewsSubtype enums (NS_) + * @param type news category + * @param flags display flags for the news * @param reftype1 Type of ref1 * @param ref1 Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleteing the news when the object is deleted. * @param reftype2 Type of ref2 @@ -631,7 +617,7 @@ static void MoveToNextItem() * * @see NewsSubtype */ -void AddNewsItem(StringID string, NewsSubtype subtype, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data) +void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, void *free_data) { if (_game_mode == GM_MENU) return; @@ -639,8 +625,8 @@ void AddNewsItem(StringID string, NewsSubtype subtype, NewsReferenceType reftype NewsItem *ni = new NewsItem; ni->string_id = string; - ni->subtype = subtype; - ni->flags = _news_subtype_data[subtype].flags; + ni->type = type; + ni->flags = flags; /* show this news message in colour? */ if (_cur_year >= _settings_client.gui.coloured_news_year) ni->flags |= NF_INCOLOUR; @@ -674,7 +660,7 @@ void AddNewsItem(StringID string, NewsSubtype subtype, NewsReferenceType reftype * @param tile unused * @param flags type of operation * @param p1 various bitstuffed elements - * - p1 = (bit 0 - 7) - NewsSubtype of the message. + * - p1 = (bit 0 - 7) - NewsType of the message. * - p1 = (bit 8 - 15) - NewsReferenceType of first reference. * - p1 = (bit 16 - 23) - Company this news message is for. * @param p2 First reference of the news message. @@ -685,12 +671,12 @@ CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, ui { if (_current_company != OWNER_DEITY) return CMD_ERROR; - NewsSubtype subtype = (NewsSubtype)GB(p1, 0, 8); + NewsType type = (NewsType)GB(p1, 0, 8); NewsReferenceType reftype1 = (NewsReferenceType)GB(p1, 8, 8); CompanyID company = (CompanyID)GB(p1, 16, 8); if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR; - if (subtype >= NS_END) return CMD_ERROR; + if (type >= NT_END) return CMD_ERROR; if (StrEmpty(text)) return CMD_ERROR; switch (reftype1) { @@ -722,34 +708,12 @@ CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, ui default: return CMD_ERROR; } - const WindowDesc *desc = _news_subtype_data[subtype].desc; - for (int i = 0; i < desc->nwid_length; i++) { - if (desc->nwid_parts[i].type == NWID_VIEWPORT && reftype1 != NR_VEHICLE && GetReferenceTile(reftype1, p2) == INVALID_TILE) { - return CMD_ERROR; - } - } - - switch (subtype) { - /* These sub types require more parameters that are never passed. */ - case NS_COMPANY_INFO: - return CMD_ERROR; - - /* This one only accepts engines. */ - case NS_NEW_VEHICLES: - if (reftype1 != NR_ENGINE) return CMD_ERROR; - break; - - /* The rest, in theory, accepts everything. */ - default: - break; - } - if (company != INVALID_OWNER && company != _local_company) return CommandCost(); if (flags & DC_EXEC) { char *news = strdup(text); SetDParamStr(0, news); - AddNewsItem(STR_NEWS_CUSTOM_ITEM, subtype, reftype1, p2, NR_NONE, UINT32_MAX, news); + AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news); } return CommandCost(); @@ -867,7 +831,7 @@ static void RemoveOldNewsItems() NewsItem *next; for (NewsItem *cur = _oldest_news; _total_news > MIN_NEWS_AMOUNT && cur != NULL; cur = next) { next = cur->next; - if (_date - _news_type_data[_news_subtype_data[cur->subtype].type].age * _settings_client.gui.news_message_timeout > cur->date) DeleteNewsItem(cur); + if (_date - _news_type_data[cur->type].age * _settings_client.gui.news_message_timeout > cur->date) DeleteNewsItem(cur); } } @@ -887,10 +851,10 @@ void ChangeVehicleNews(VehicleID from_index, VehicleID to_index) * 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. + * Currently only NT_ADVICE news have vehicle IDs in their DParams. + * And all NT_ADVICE news have the ID in param 0. */ - if (ni->subtype == NS_ADVICE && ni->params[0] == from_index) ni->params[0] = to_index; + if (ni->type == NT_ADVICE && ni->params[0] == from_index) ni->params[0] = to_index; } } diff --git a/src/news_type.h b/src/news_type.h index 811ac49d9..602989075 100644 --- a/src/news_type.h +++ b/src/news_type.h @@ -34,8 +34,8 @@ enum MessageOptionsSpace { * Type of news. */ enum NewsType { - NT_ARRIVAL_COMPANY, ///< Cargo arrived for company - NT_ARRIVAL_OTHER, ///< Cargo arrived for competitor + NT_ARRIVAL_COMPANY, ///< First vehicle arrived for company + NT_ARRIVAL_OTHER, ///< First vehicle arrived for competitor NT_ACCIDENT, ///< An accident or disaster has occurred NT_COMPANY_INFO, ///< Company info (new companies, bankruptcy messages) NT_INDUSTRY_OPEN, ///< Opening of industries @@ -53,28 +53,6 @@ enum NewsType { }; /** - * News subtypes. - */ -enum NewsSubtype { - NS_ARRIVAL_COMPANY, ///< NT_ARRIVAL_COMPANY - NS_ARRIVAL_OTHER, ///< NT_ARRIVAL_OTHER - NS_ACCIDENT, ///< NT_ACCIDENT - NS_COMPANY_INFO, ///< NT_COMPANY_INFO - NS_INDUSTRY_OPEN, ///< NT_INDUSTRY_OPEN - NS_INDUSTRY_CLOSE, ///< NT_INDUSTRY_CLOSE - NS_ECONOMY, ///< NT_ECONOMY - NS_INDUSTRY_COMPANY, ///< NT_INDUSTRY_COMPANY - NS_INDUSTRY_OTHER, ///< NT_INDUSTRY_OTHER - NS_INDUSTRY_NOBODY, ///< NT_INDUSTRY_NOBODY - NS_ADVICE, ///< NT_ADVICE - NS_NEW_VEHICLES, ///< NT_NEW_VEHICLES - NS_ACCEPTANCE, ///< NT_ACCEPTANCE - NS_SUBSIDIES, ///< NT_SUBSIDIES - NS_GENERAL, ///< NT_GENERAL - NS_END, ///< end-of-array marker -}; - -/** * References to objects in news. * * @warning @@ -98,14 +76,21 @@ enum NewsReferenceType { * @note #NF_INCOLOUR is set automatically if needed. */ enum NewsFlag { - NFB_INCOLOUR = 0, ///< News item is shown in colour (otherwise it is shown in black & white). - NFB_NO_TRANSPARENT = 1, ///< News item disables transparency in the viewport. - NFB_SHADE = 2, ///< News item uses shaded colours. - - NF_NONE = 0, ///< No flag is set. - NF_INCOLOUR = 1 << 0, ///< Bit value for coloured news. - NF_NO_TRANSPARENT = 1 << 1, ///< Bit value for disabling transparency. - NF_SHADE = 1 << 2, ///< Bit value for enabling shading. + NFB_INCOLOUR = 0, ///< News item is shown in colour (otherwise it is shown in black & white). + NFB_NO_TRANSPARENT = 1, ///< News item disables transparency in the viewport. + NFB_SHADE = 2, ///< News item uses shaded colours. + NFB_WINDOW_LAYOUT = 3, ///< First bit for window layout. + NFB_WINDOW_LAYOUT_COUNT = 3, ///< Number of bits for window layout. + + NF_INCOLOUR = 1 << NFB_INCOLOUR, ///< Bit value for coloured news. + NF_NO_TRANSPARENT = 1 << NFB_NO_TRANSPARENT, ///< Bit value for disabling transparency. + NF_SHADE = 1 << NFB_SHADE, ///< Bit value for enabling shading. + + NF_THIN = 0 << NFB_WINDOW_LAYOUT, ///< Thin news item. (Newspaper with headline and viewport) + NF_SMALL = 1 << NFB_WINDOW_LAYOUT, ///< Small news item. (Information window with text and viewport) + NF_NORMAL = 2 << NFB_WINDOW_LAYOUT, ///< Normal news item. (Newspaper with text only) + NF_VEHICLE = 3 << NFB_WINDOW_LAYOUT, ///< Vehicle news item. (new engine available) + NF_COMPANY = 4 << NFB_WINDOW_LAYOUT, ///< Company news item. (Newspaper with face) }; DECLARE_ENUM_AS_BIT_SET(NewsFlag) @@ -152,7 +137,7 @@ struct NewsItem { NewsItem *next; ///< Next news item StringID string_id; ///< Message text Date date; ///< Date of the news - NewsSubtype subtype; ///< News subtype @see NewsSubtype + NewsType type; ///< Type of the news NewsFlag flags; ///< NewsFlags bits @see NewsFlag NewsReferenceType reftype1; ///< Type of ref1 diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 6a8225050..9e242e2cf 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -526,7 +526,7 @@ static void RoadVehCrash(RoadVehicle *v) AddVehicleNewsItem( (pass == 1) ? STR_NEWS_ROAD_VEHICLE_CRASH_DRIVER : STR_NEWS_ROAD_VEHICLE_CRASH, - NS_ACCIDENT, + NT_ACCIDENT, v->index ); @@ -664,7 +664,7 @@ static void RoadVehArrivesAt(const RoadVehicle *v, Station *st) SetDParam(0, st->index); AddVehicleNewsItem( v->roadtype == ROADTYPE_ROAD ? STR_NEWS_FIRST_BUS_ARRIVAL : STR_NEWS_FIRST_PASSENGER_TRAM_ARRIVAL, - (v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER, + (v->owner == _local_company) ? NT_ARRIVAL_COMPANY : NT_ARRIVAL_OTHER, v->index, st->index ); @@ -678,7 +678,7 @@ static void RoadVehArrivesAt(const RoadVehicle *v, Station *st) SetDParam(0, st->index); AddVehicleNewsItem( v->roadtype == ROADTYPE_ROAD ? STR_NEWS_FIRST_TRUCK_ARRIVAL : STR_NEWS_FIRST_CARGO_TRAM_ARRIVAL, - (v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER, + (v->owner == _local_company) ? NT_ARRIVAL_COMPANY : NT_ARRIVAL_OTHER, v->index, st->index ); diff --git a/src/script/api/script_news.hpp b/src/script/api/script_news.hpp index 3c40e6f33..0867b91fe 100644 --- a/src/script/api/script_news.hpp +++ b/src/script/api/script_news.hpp @@ -25,10 +25,9 @@ public: * Enumeration for the news types that a script can create news for. */ enum NewsType { - /* Note: these values represent part of the in-game NewsSubtype enum */ - NT_ECONOMY = ::NS_ECONOMY, ///< Category economy. - NT_SUBSIDIES = ::NS_SUBSIDIES, ///< Category subsidies. - NT_GENERAL = ::NS_GENERAL, ///< Category general. + NT_ECONOMY = ::NT_ECONOMY, ///< Category economy. + NT_SUBSIDIES = ::NT_SUBSIDIES, ///< Category subsidies. + NT_GENERAL = ::NT_GENERAL, ///< Category general. }; /** diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index ebb6d9bff..6c09b0a28 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -375,7 +375,7 @@ static void ShipArrivesAt(const Vehicle *v, Station *st) SetDParam(0, st->index); AddVehicleNewsItem( STR_NEWS_FIRST_SHIP_ARRIVAL, - (v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER, + (v->owner == _local_company) ? NT_ARRIVAL_COMPANY : NT_ARRIVAL_OTHER, v->index, st->index ); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 5a56d7a45..e3e4d27b2 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -442,7 +442,7 @@ static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *c } SetDParam(0, st->index); - AddNewsItem(msg, NS_ACCEPTANCE, NR_STATION, st->index); + AddNewsItem(msg, NT_ACCEPTANCE, NF_INCOLOUR | NF_SMALL, NR_STATION, st->index); } /** diff --git a/src/subsidy.cpp b/src/subsidy.cpp index d6ad2666d..1005f14eb 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -54,7 +54,7 @@ void Subsidy::AwardTo(CompanyID company) SetDParamStr(0, cn); AddNewsItem( STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF + _settings_game.difficulty.subsidy_multiplier, - NS_SUBSIDIES, + NT_SUBSIDIES, NF_NORMAL, (NewsReferenceType)reftype.a, this->src, (NewsReferenceType)reftype.b, this->dst, cn ); @@ -223,7 +223,7 @@ void CreateSubsidy(CargoID cid, SourceType src_type, SourceID src, SourceType ds s->awarded = INVALID_COMPANY; Pair reftype = SetupSubsidyDecodeParam(s, false); - AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); + AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NT_SUBSIDIES, NF_NORMAL, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); SetPartOfSubsidyFlag(s->src_type, s->src, POS_SRC); SetPartOfSubsidyFlag(s->dst_type, s->dst, POS_DST); AI::BroadcastNewEvent(new ScriptEventSubsidyOffer(s->index)); @@ -464,13 +464,13 @@ void SubsidyMonthlyLoop() if (--s->remaining == 0) { if (!s->IsAwarded()) { Pair reftype = SetupSubsidyDecodeParam(s, true); - AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); + AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NT_SUBSIDIES, NF_NORMAL, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); AI::BroadcastNewEvent(new ScriptEventSubsidyOfferExpired(s->index)); Game::NewEvent(new ScriptEventSubsidyOfferExpired(s->index)); } else { if (s->awarded == _local_company) { Pair reftype = SetupSubsidyDecodeParam(s, true); - AddNewsItem(STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); + AddNewsItem(STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE, NT_SUBSIDIES, NF_NORMAL, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); } AI::BroadcastNewEvent(new ScriptEventSubsidyExpired(s->index)); Game::NewEvent(new ScriptEventSubsidyExpired(s->index)); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 01b60cac2..341aaeb0c 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); - AddTileNewsItem(STR_NEWS_NEW_TOWN, NS_INDUSTRY_OPEN, tile, cn); + AddTileNewsItem(STR_NEWS_NEW_TOWN, NT_INDUSTRY_OPEN, tile, cn); AI::BroadcastNewEvent(new ScriptEventTownFounded(t->index)); Game::NewEvent(new ScriptEventTownFounded(t->index)); } @@ -2700,7 +2700,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags) SetDParam(0, t->index); SetDParamStr(1, cn); - AddNewsItem(STR_NEWS_ROAD_REBUILDING, NS_GENERAL, NR_TOWN, t->index, NR_NONE, UINT32_MAX, cn); + AddNewsItem(STR_NEWS_ROAD_REBUILDING, NT_GENERAL, NF_NORMAL, NR_TOWN, t->index, NR_NONE, UINT32_MAX, cn); } return CommandCost(); } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 674da416d..2a639666d 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2785,7 +2785,7 @@ static void TrainEnterStation(Train *v, StationID station) SetDParam(0, st->index); AddVehicleNewsItem( STR_NEWS_FIRST_TRAIN_ARRIVAL, - v->owner == _local_company ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER, + v->owner == _local_company ? NT_ARRIVAL_COMPANY : NT_ARRIVAL_OTHER, v->index, st->index ); @@ -3019,10 +3019,7 @@ static bool CheckTrainCollision(Train *v) if (tcc.num == 0) return false; SetDParam(0, tcc.num); - AddVehicleNewsItem(STR_NEWS_TRAIN_CRASH, - NS_ACCIDENT, - v->index - ); + AddVehicleNewsItem(STR_NEWS_TRAIN_CRASH, NT_ACCIDENT, v->index); ModifyStationRatingAround(v->tile, v->owner, -160, 30); SndPlayVehicleFx(SND_13_BIG_CRASH, v); diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 8fbdf17f1..42afbabcd 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -913,7 +913,7 @@ static void FloodVehicle(Vehicle *v) AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED)); Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED)); SetDParam(0, pass); - AddVehicleNewsItem(STR_NEWS_DISASTER_FLOOD_VEHICLE, NS_ACCIDENT, v->index); + AddVehicleNewsItem(STR_NEWS_DISASTER_FLOOD_VEHICLE, NT_ACCIDENT, v->index); CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); SndPlayVehicleFx(SND_12_EXPLOSION, v); } |