diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 671b513657..7a5ed75f78 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -1661,11 +1661,11 @@ static int32_t cc_assert([[maybe_unused]] InteractiveConsole& console, [[maybe_u static int32_t cc_add_news_item([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv) { printf("argv.size() = %zu\n", argv.size()); - if (argv.size() < 3) + if (argv.size() < 2) { console.WriteLineWarning("Too few arguments"); static_assert(News::ItemTypeCount == 10, "News::ItemType::Count changed, update console command!"); - console.WriteLine("add_news_item "); + console.WriteLine("add_news_item [assoc]"); console.WriteLine("type is one of:"); console.WriteLine(" 0 (News::ItemType::Null)"); console.WriteLine(" 1 (News::ItemType::Ride)"); @@ -1678,13 +1678,32 @@ static int32_t cc_add_news_item([[maybe_unused]] InteractiveConsole& console, [[ console.WriteLine(" 8 (News::ItemType::Award)"); console.WriteLine(" 9 (News::ItemType::Graph)"); console.WriteLine("message is the message to display, wrapped in quotes for multiple words"); - console.WriteLine("assoc is the associated id of ride/peep/tile/etc."); + console.WriteLine("assoc is the associated id of ride/peep/tile/etc. If the selected ItemType doesn't need an assoc " + "(Null, Money, Award, Graph), you can leave this field blank"); return 1; } + auto type = atoi(argv[0].c_str()); auto msg = argv[1].c_str(); - auto assoc = atoi(argv[2].c_str()); - News::AddItemToQueue(static_cast(type), msg, assoc); + auto assoc = 0; + + News::ItemType itemType = static_cast(type); + + if (argv.size() == 3) // 3 arguments passed, set assoc + { + assoc = atoi(argv[2].c_str()); + } + else + { + if (News::CheckIfItemRequiresAssoc(itemType)) + { + console.WriteLine("Selected ItemType requires an assoc"); + return 0; + } + } + + News::AddItemToQueue(itemType, msg, assoc); + console.WriteLine("Successfully added News Item"); return 0; } diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index 006a63853e..5286ac4aa4 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -315,7 +315,7 @@ News::Item* News::AddItemToQueue(News::ItemType type, const utf8* text, uint32_t News::Item* newsItem = gNewsItems.FirstOpenOrNewSlot(); newsItem->Type = type; newsItem->Flags = 0; - newsItem->Assoc = assoc; + newsItem->Assoc = assoc; // Make optional for Award, Money, Graph and Null newsItem->Ticks = 0; newsItem->MonthYear = static_cast(gDateMonthsElapsed); newsItem->Day = ((days_in_month[date_get_month(newsItem->MonthYear)] * gDateMonthTicks) >> 16) + 1; @@ -324,6 +324,25 @@ News::Item* News::AddItemToQueue(News::ItemType type, const utf8* text, uint32_t return newsItem; } +/** + * Checks if News::ItemType requires an assoc + * @return A boolean if assoc is required. + */ + +bool News::CheckIfItemRequiresAssoc(News::ItemType type) +{ + switch (type) + { + case News::ItemType::Null: + case News::ItemType::Award: + case News::ItemType::Money: + case News::ItemType::Graph: + return false; + default: + return true; // Everything else requires assoc + } +} + /** * Opens the window/tab for the subject of the news item * diff --git a/src/openrct2/management/NewsItem.h b/src/openrct2/management/NewsItem.h index 88129dcab9..9bfbfee416 100644 --- a/src/openrct2/management/NewsItem.h +++ b/src/openrct2/management/NewsItem.h @@ -292,6 +292,8 @@ namespace News News::Item* AddItemToQueue(News::ItemType type, rct_string_id string_id, uint32_t assoc, const Formatter& formatter); News::Item* AddItemToQueue(News::ItemType type, const utf8* text, uint32_t assoc); + bool CheckIfItemRequiresAssoc(News::ItemType type); + void OpenSubject(News::ItemType type, int32_t subject); void DisableNewsItems(News::ItemType type, uint32_t assoc);