diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index b7c98434d4..15bd34ad4e 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -433,7 +433,7 @@ set_name:; SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION); SetDParamStr(2, cni->company_name); SetDParam(3, t->index); - AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NewsType::CompanyInfo, NewsStyle::Company, {}, NR_TILE, c->last_build_coordinate.base(), NR_NONE, UINT32_MAX, std::move(cni)); + AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NewsType::CompanyInfo, NewsStyle::Company, {}, NewsReferenceType::Tile, c->last_build_coordinate.base(), NewsReferenceType::None, UINT32_MAX, std::move(cni)); } return; } diff --git a/src/engine.cpp b/src/engine.cpp index 39df04e39a..3e71f43187 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -1131,7 +1131,7 @@ static void NewVehicleAvailable(Engine *e) if (!IsVehicleTypeDisabled(e->type, false) && !e->info.extra_flags.Test(ExtraEngineFlag::NoNews)) { SetDParam(0, GetEngineCategoryName(index)); SetDParam(1, PackEngineNameDParam(index, EngineNameContext::PreviewNews)); - AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NewsType::NewVehicles, NewsStyle::Vehicle, {}, NR_ENGINE, index); + AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NewsType::NewVehicles, NewsStyle::Vehicle, {}, NewsReferenceType::Engine, index); } /* Update the toolbar. */ diff --git a/src/news_func.h b/src/news_func.h index 98a44d29ee..61cff880cc 100644 --- a/src/news_func.h +++ b/src/news_func.h @@ -15,11 +15,11 @@ #include "station_type.h" #include "industry_type.h" -void AddNewsItem(StringID string, NewsType type, NewsStyle style, NewsFlags flags, NewsReferenceType reftype1 = NR_NONE, uint32_t ref1 = UINT32_MAX, NewsReferenceType reftype2 = NR_NONE, uint32_t ref2 = UINT32_MAX, std::unique_ptr &&data = nullptr, AdviceType advice_type = AdviceType::Invalid); +void AddNewsItem(StringID string, NewsType type, NewsStyle style, NewsFlags flags, NewsReferenceType reftype1 = NewsReferenceType::None, uint32_t ref1 = UINT32_MAX, NewsReferenceType reftype2 = NewsReferenceType::None, uint32_t ref2 = UINT32_MAX, std::unique_ptr &&data = nullptr, AdviceType advice_type = AdviceType::Invalid); inline void AddCompanyNewsItem(StringID string, std::unique_ptr cni) { - AddNewsItem(string, NewsType::CompanyInfo, NewsStyle::Company, {}, NR_NONE, UINT32_MAX, NR_NONE, UINT32_MAX, std::move(cni)); + AddNewsItem(string, NewsType::CompanyInfo, NewsStyle::Company, {}, NewsReferenceType::None, UINT32_MAX, NewsReferenceType::None, UINT32_MAX, std::move(cni)); } /** @@ -29,7 +29,7 @@ inline void AddCompanyNewsItem(StringID string, std::unique_ptr &&data = nullptr, StationID station = INVALID_STATION) { - AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NR_TILE, tile.base(), station == INVALID_STATION ? NR_NONE : NR_STATION, station, std::move(data)); + AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NewsReferenceType::Tile, tile.base(), station == INVALID_STATION ? NewsReferenceType::None : NewsReferenceType::Station, station, std::move(data)); } inline void AddIndustryNewsItem(StringID string, NewsType type, IndustryID industry, std::unique_ptr &&data = nullptr) { - AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NR_INDUSTRY, industry, NR_NONE, UINT32_MAX, std::move(data)); + AddNewsItem(string, type, NewsStyle::Thin, {NewsFlag::NoTransparency, NewsFlag::Shaded}, NewsReferenceType::Industry, industry, NewsReferenceType::None, UINT32_MAX, std::move(data)); } void NewsLoop(); diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 94a6fd36f3..9599e1b8da 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -90,11 +90,11 @@ const NewsContainer &GetNews() static TileIndex GetReferenceTile(NewsReferenceType reftype, uint32_t ref) { switch (reftype) { - case NR_TILE: return (TileIndex)ref; - case NR_STATION: return Station::Get((StationID)ref)->xy; - case NR_INDUSTRY: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1); - case NR_TOWN: return Town::Get((TownID)ref)->xy; - default: return INVALID_TILE; + case NewsReferenceType::Tile: return (TileIndex)ref; + case NewsReferenceType::Station: return Station::Get((StationID)ref)->xy; + case NewsReferenceType::Industry: return Industry::Get((IndustryID)ref)->location.tile + TileDiffXY(1, 1); + case NewsReferenceType::Town: return Town::Get((TownID)ref)->xy; + default: return INVALID_TILE; } } @@ -366,7 +366,7 @@ struct NewsWindow : Window { if (&desc == &_company_news_desc) this->GetWidget(WID_N_TITLE)->SetString(static_cast(std::get(this->ni->params[0]))); NWidgetCore *nwid = this->GetWidget(WID_N_SHOW_GROUP); - if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) { + if (ni->reftype1 == NewsReferenceType::Vehicle && nwid != nullptr) { const Vehicle *v = Vehicle::Get(ni->ref1); switch (v->type) { case VEH_TRAIN: @@ -391,7 +391,7 @@ struct NewsWindow : Window { /* Initialize viewport if it exists. */ NWidgetViewport *nvp = this->GetWidget(WID_N_VIEWPORT); if (nvp != nullptr) { - if (ni->reftype1 == NR_VEHICLE) { + if (ni->reftype1 == NewsReferenceType::Vehicle) { nvp->InitializeViewport(this, static_cast(ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS)); } else { nvp->InitializeViewport(this, GetReferenceTile(ni->reftype1, ni->ref1), ScaleZoomGUI(ZOOM_LVL_NEWS)); @@ -457,14 +457,14 @@ struct NewsWindow : Window { break; case WID_N_VEH_INFO: { - assert(this->ni->reftype1 == NR_ENGINE); + assert(this->ni->reftype1 == NewsReferenceType::Engine); EngineID engine = this->ni->ref1; str = GetEngineInfoString(engine); break; } case WID_N_SHOW_GROUP: - if (this->ni->reftype1 == NR_VEHICLE) { + if (this->ni->reftype1 == NewsReferenceType::Vehicle) { Dimension d2 = GetStringBoundingBox(this->GetWidget(WID_N_SHOW_GROUP)->GetString()); d2.height += WidgetDimensions::scaled.captiontext.Vertical(); d2.width += WidgetDimensions::scaled.captiontext.Horizontal(); @@ -541,14 +541,14 @@ struct NewsWindow : Window { break; case WID_N_VEH_SPR: { - assert(this->ni->reftype1 == NR_ENGINE); + assert(this->ni->reftype1 == NewsReferenceType::Engine); EngineID engine = this->ni->ref1; DrawVehicleEngine(r.left, r.right, CenterBounds(r.left, r.right, 0), CenterBounds(r.top, r.bottom, 0), engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW); GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_NEWSPAPER, FILLRECT_RECOLOUR); break; } case WID_N_VEH_INFO: { - assert(this->ni->reftype1 == NR_ENGINE); + assert(this->ni->reftype1 == NewsReferenceType::Engine); EngineID engine = this->ni->ref1; DrawStringMultiLine(r.left, r.right, r.top, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER); break; @@ -566,7 +566,7 @@ struct NewsWindow : Window { break; case WID_N_CAPTION: - if (this->ni->reftype1 == NR_VEHICLE) { + if (this->ni->reftype1 == NewsReferenceType::Vehicle) { const Vehicle *v = Vehicle::Get(this->ni->ref1); ShowVehicleViewWindow(v); } @@ -576,13 +576,13 @@ struct NewsWindow : Window { break; // Ignore clicks case WID_N_SHOW_GROUP: - if (this->ni->reftype1 == NR_VEHICLE) { + if (this->ni->reftype1 == NewsReferenceType::Vehicle) { const Vehicle *v = Vehicle::Get(this->ni->ref1); ShowCompanyGroupForVehicle(v); } break; default: - if (this->ni->reftype1 == NR_VEHICLE) { + if (this->ni->reftype1 == NewsReferenceType::Vehicle) { const Vehicle *v = Vehicle::Get(this->ni->ref1); ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos); } else { @@ -607,7 +607,7 @@ struct NewsWindow : Window { NWidgetViewport *nvp = this->GetWidget(WID_N_VIEWPORT); nvp->UpdateViewportCoordinates(this); - if (ni->reftype1 != NR_VEHICLE) { + if (ni->reftype1 != NewsReferenceType::Vehicle) { ScrollWindowToTile(GetReferenceTile(ni->reftype1, ni->ref1), this, true); // Re-center viewport. } } @@ -677,7 +677,7 @@ private: StringID GetNewVehicleMessageString(WidgetID widget) const { - assert(this->ni->reftype1 == NR_ENGINE); + assert(this->ni->reftype1 == NewsReferenceType::Engine); EngineID engine = this->ni->ref1; switch (widget) { @@ -930,28 +930,28 @@ CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceT if (text.empty()) return CMD_ERROR; switch (reftype1) { - case NR_NONE: break; - case NR_TILE: + case NewsReferenceType::None: break; + case NewsReferenceType::Tile: if (!IsValidTile(reference)) return CMD_ERROR; break; - case NR_VEHICLE: + case NewsReferenceType::Vehicle: if (!Vehicle::IsValidID(reference)) return CMD_ERROR; break; - case NR_STATION: + case NewsReferenceType::Station: if (!Station::IsValidID(reference)) return CMD_ERROR; break; - case NR_INDUSTRY: + case NewsReferenceType::Industry: if (!Industry::IsValidID(reference)) return CMD_ERROR; break; - case NR_TOWN: + case NewsReferenceType::Town: if (!Town::IsValidID(reference)) return CMD_ERROR; break; - case NR_ENGINE: + case NewsReferenceType::Engine: if (!Engine::IsValidID(reference)) return CMD_ERROR; break; @@ -962,7 +962,7 @@ CommandCost CmdCustomNewsItem(DoCommandFlag flags, NewsType type, NewsReferenceT if (flags & DC_EXEC) { SetDParamStr(0, text); - AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NewsStyle::Normal, {}, reftype1, reference, NR_NONE, UINT32_MAX); + AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NewsStyle::Normal, {}, reftype1, reference, NewsReferenceType::None, UINT32_MAX); } return CommandCost(); @@ -1000,7 +1000,7 @@ void DeleteNews(Tpredicate predicate) void DeleteVehicleNews(VehicleID vid, AdviceType advice_type) { DeleteNews([&](const auto &ni) { - return ((ni.reftype1 == NR_VEHICLE && ni.ref1 == vid) || (ni.reftype2 == NR_VEHICLE && ni.ref2 == vid)) && (advice_type == AdviceType::Invalid || ni.advice_type == advice_type); + return ((ni.reftype1 == NewsReferenceType::Vehicle && ni.ref1 == vid) || (ni.reftype2 == NewsReferenceType::Vehicle && ni.ref2 == vid)) && (advice_type == AdviceType::Invalid || ni.advice_type == advice_type); }); } @@ -1012,7 +1012,7 @@ void DeleteVehicleNews(VehicleID vid, AdviceType advice_type) void DeleteStationNews(StationID sid) { DeleteNews([&](const auto &ni) { - return (ni.reftype1 == NR_STATION && ni.ref1 == sid) || (ni.reftype2 == NR_STATION && ni.ref2 == sid); + return (ni.reftype1 == NewsReferenceType::Station && ni.ref1 == sid) || (ni.reftype2 == NewsReferenceType::Station && ni.ref2 == sid); }); } @@ -1023,7 +1023,7 @@ void DeleteStationNews(StationID sid) void DeleteIndustryNews(IndustryID iid) { DeleteNews([&](const auto &ni) { - return (ni.reftype1 == NR_INDUSTRY && ni.ref1 == iid) || (ni.reftype2 == NR_INDUSTRY && ni.ref2 == iid); + return (ni.reftype1 == NewsReferenceType::Industry && ni.ref1 == iid) || (ni.reftype2 == NewsReferenceType::Industry && ni.ref2 == iid); }); } @@ -1033,8 +1033,8 @@ void DeleteIndustryNews(IndustryID iid) void DeleteInvalidEngineNews() { DeleteNews([](const auto &ni) { - return (ni.reftype1 == NR_ENGINE && (!Engine::IsValidID(ni.ref1) || !Engine::Get(ni.ref1)->IsEnabled())) || - (ni.reftype2 == NR_ENGINE && (!Engine::IsValidID(ni.ref2) || !Engine::Get(ni.ref2)->IsEnabled())); + return (ni.reftype1 == NewsReferenceType::Engine && (!Engine::IsValidID(ni.ref1) || !Engine::Get(ni.ref1)->IsEnabled())) || + (ni.reftype2 == NewsReferenceType::Engine && (!Engine::IsValidID(ni.ref2) || !Engine::Get(ni.ref2)->IsEnabled())); }); } @@ -1054,8 +1054,8 @@ static void RemoveOldNewsItems() void ChangeVehicleNews(VehicleID from_index, VehicleID to_index) { for (auto &ni : _news) { - if (ni.reftype1 == NR_VEHICLE && ni.ref1 == from_index) ni.ref1 = to_index; - if (ni.reftype2 == NR_VEHICLE && ni.ref2 == from_index) ni.ref2 = to_index; + if (ni.reftype1 == NewsReferenceType::Vehicle && ni.ref1 == from_index) ni.ref1 = to_index; + if (ni.reftype2 == NewsReferenceType::Vehicle && ni.ref2 == from_index) ni.ref2 = to_index; if (ni.flags.Test(NewsFlag::VehicleParam0) && std::get(ni.params[0]) == from_index) ni.params[0] = to_index; } } diff --git a/src/news_type.h b/src/news_type.h index 749c566100..1cca28a5ad 100644 --- a/src/news_type.h +++ b/src/news_type.h @@ -65,14 +65,14 @@ enum class AdviceType : uint8_t { * You have to make sure, #ChangeVehicleNews catches the DParams of your message. * This is NOT ensured by the references. */ -enum NewsReferenceType : uint8_t { - NR_NONE, ///< Empty reference - NR_TILE, ///< Reference tile. Scroll to tile when clicking on the news. - NR_VEHICLE, ///< Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted. - NR_STATION, ///< Reference station. Scroll to station when clicking on the news. Delete news when station is deleted. - NR_INDUSTRY, ///< Reference industry. Scroll to industry when clicking on the news. Delete news when industry is deleted. - NR_TOWN, ///< Reference town. Scroll to town when clicking on the news. - NR_ENGINE, ///< Reference engine. +enum class NewsReferenceType : uint8_t { + None, ///< Empty reference + Tile, ///< Reference tile. Scroll to tile when clicking on the news. + Vehicle, ///< Reference vehicle. Scroll to vehicle when clicking on the news. Delete news when vehicle is deleted. + Station, ///< Reference station. Scroll to station when clicking on the news. Delete news when station is deleted. + Industry, ///< Reference industry. Scroll to industry when clicking on the news. Delete news when industry is deleted. + Town, ///< Reference town. Scroll to town when clicking on the news. + Engine, ///< Reference engine. }; /** News Window Styles. */ diff --git a/src/script/api/script_news.hpp b/src/script/api/script_news.hpp index 75daef912d..e3d3635a85 100644 --- a/src/script/api/script_news.hpp +++ b/src/script/api/script_news.hpp @@ -38,11 +38,11 @@ public: */ enum NewsReferenceType { /* Selection of useful game elements to refer to. */ - NR_NONE = ::NR_NONE, ///< No reference supplied. - NR_TILE = ::NR_TILE, ///< Reference location, scroll to the location when clicking on the news. - NR_STATION = ::NR_STATION, ///< Reference station, scroll to the station when clicking on the news. Delete news when the station is deleted. - NR_INDUSTRY = ::NR_INDUSTRY, ///< Reference industry, scrolls to the industry when clicking on the news. Delete news when the industry is deleted. - NR_TOWN = ::NR_TOWN, ///< Reference town, scroll to the town when clicking on the news. + NR_NONE = to_underlying(::NewsReferenceType::None), ///< No reference supplied. + NR_TILE = to_underlying(::NewsReferenceType::Tile), ///< Reference location, scroll to the location when clicking on the news. + NR_STATION = to_underlying(::NewsReferenceType::Station), ///< Reference station, scroll to the station when clicking on the news. Delete news when the station is deleted. + NR_INDUSTRY = to_underlying(::NewsReferenceType::Industry), ///< Reference industry, scrolls to the industry when clicking on the news. Delete news when the industry is deleted. + NR_TOWN = to_underlying(::NewsReferenceType::Town), ///< Reference town, scroll to the town when clicking on the news. }; /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 10b54dbf60..b54cd17e8d 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -532,7 +532,7 @@ static void ShowRejectOrAcceptNews(const Station *st, CargoTypes cargoes, bool r SetDParam(0, st->index); SetDParam(1, cargoes); StringID msg = reject ? STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO_LIST : STR_NEWS_STATION_NOW_ACCEPTS_CARGO_LIST; - AddNewsItem(msg, NewsType::Acceptance, NewsStyle::Small, NewsFlag::InColour, NR_STATION, st->index); + AddNewsItem(msg, NewsType::Acceptance, NewsStyle::Small, NewsFlag::InColour, NewsReferenceType::Station, st->index); } /** diff --git a/src/subsidy.cpp b/src/subsidy.cpp index b0f678497e..242bcdc2db 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -74,8 +74,8 @@ void Subsidy::AwardTo(CompanyID company) */ std::pair SetupSubsidyDecodeParam(const Subsidy *s, SubsidyDecodeParamType mode, uint parameter_offset) { - NewsReferenceType reftype1 = NR_NONE; - NewsReferenceType reftype2 = NR_NONE; + NewsReferenceType reftype1 = NewsReferenceType::None; + NewsReferenceType reftype2 = NewsReferenceType::None; /* Always use the plural form of the cargo name - trying to decide between plural or singular causes issues for translations */ const CargoSpec *cs = CargoSpec::Get(s->cargo_type); @@ -83,11 +83,11 @@ std::pair SetupSubsidyDecodeParam(const Su switch (s->src_type) { case SourceType::Industry: - reftype1 = NR_INDUSTRY; + reftype1 = NewsReferenceType::Industry; SetDParam(parameter_offset + 1, STR_INDUSTRY_NAME); break; case SourceType::Town: - reftype1 = NR_TOWN; + reftype1 = NewsReferenceType::Town; SetDParam(parameter_offset + 1, STR_TOWN_NAME); break; default: NOT_REACHED(); @@ -96,11 +96,11 @@ std::pair SetupSubsidyDecodeParam(const Su switch (s->dst_type) { case SourceType::Industry: - reftype2 = NR_INDUSTRY; + reftype2 = NewsReferenceType::Industry; SetDParam(parameter_offset + 4, STR_INDUSTRY_NAME); break; case SourceType::Town: - reftype2 = NR_TOWN; + reftype2 = NewsReferenceType::Town; SetDParam(parameter_offset + 4, STR_TOWN_NAME); break; default: NOT_REACHED(); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d44df2f4fa..7e0c599c19 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -3388,7 +3388,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags) AddNewsItem( TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_ROAD_REBUILDING_MINUTES : STR_NEWS_ROAD_REBUILDING_MONTHS, - NewsType::General, NewsStyle::Normal, {}, NR_TOWN, t->index, NR_NONE, UINT32_MAX); + NewsType::General, NewsStyle::Normal, {}, NewsReferenceType::Town, t->index, NewsReferenceType::None, UINT32_MAX); AI::BroadcastNewEvent(new ScriptEventRoadReconstruction((ScriptCompany::CompanyID)(Owner)_current_company, t->index)); Game::NewEvent(new ScriptEventRoadReconstruction((ScriptCompany::CompanyID)(Owner)_current_company, t->index)); } @@ -3543,7 +3543,7 @@ static CommandCost TownActionBuyRights(Town *t, DoCommandFlag flags) SetDParam(1, TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MINUTES : STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MONTHS); SetDParam(2, t->index); SetDParamStr(3, cni->company_name); - AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NewsType::General, NewsStyle::Company, {}, NR_TOWN, t->index, NR_NONE, UINT32_MAX, std::move(cni)); + AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NewsType::General, NewsStyle::Company, {}, NewsReferenceType::Town, t->index, NewsReferenceType::None, UINT32_MAX, std::move(cni)); AI::BroadcastNewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index)); Game::NewEvent(new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(Owner)_current_company, t->index)); }