Made add_news_item argument assoc optional

This commit is contained in:
gsckoco 2020-09-28 12:28:31 +01:00
parent 8f5ee758ee
commit 391dabc4f9
3 changed files with 46 additions and 6 deletions

View file

@ -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 <type> <message> <assoc>");
console.WriteLine("add_news_item <type> <message> [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<News::ItemType>(type), msg, assoc);
auto assoc = 0;
News::ItemType itemType = static_cast<News::ItemType>(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;
}

View file

@ -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<uint16_t>(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
*

View file

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