mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-25 07:44:38 +01:00
Create operator[] in NewsItemQueue
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
#include "../windows/Intent.h"
|
||||
#include "../world/Sprite.h"
|
||||
|
||||
static NewsItemQueue gNewsItems;
|
||||
NewsItemQueue gNewsItems;
|
||||
|
||||
/** rct2: 0x0097BE7C */
|
||||
const uint8_t news_type_properties[] = {
|
||||
@@ -54,14 +54,19 @@ NewsItem* news_item_get(int32_t index)
|
||||
return gNewsItems.At(index);
|
||||
}
|
||||
|
||||
NewsItem& NewsItemQueue::operator[](size_t index)
|
||||
{
|
||||
if (index < MAX_RECENT_NEWS_ITEMS)
|
||||
return Recent[index];
|
||||
else
|
||||
return Old[index - MAX_RECENT_NEWS_ITEMS];
|
||||
}
|
||||
|
||||
NewsItem* NewsItemQueue::At(int32_t index)
|
||||
{
|
||||
if (news_item_is_valid_idx(index))
|
||||
{
|
||||
if (index < MAX_RECENT_NEWS_ITEMS)
|
||||
return &Recent[index];
|
||||
else
|
||||
return &Old[index - MAX_RECENT_NEWS_ITEMS];
|
||||
return &(*this)[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -63,8 +63,11 @@ constexpr int32_t MAX_RECENT_NEWS_ITEMS = 11;
|
||||
constexpr int32_t MAX_OLD_NEWS_ITEMS = 50;
|
||||
constexpr int32_t MAX_NEWS_ITEMS = MAX_RECENT_NEWS_ITEMS + MAX_OLD_NEWS_ITEMS;
|
||||
|
||||
extern const uint8_t news_type_properties[10];
|
||||
|
||||
struct NewsItemQueue
|
||||
{
|
||||
NewsItem& operator[](size_t index);
|
||||
NewsItem* At(int32_t index);
|
||||
bool IsEmpty() const;
|
||||
void Init();
|
||||
@@ -117,7 +120,7 @@ private:
|
||||
NewsItem Old[MAX_OLD_NEWS_ITEMS];
|
||||
};
|
||||
|
||||
extern const uint8_t news_type_properties[10];
|
||||
extern NewsItemQueue gNewsItems;
|
||||
|
||||
void news_item_init_queue();
|
||||
|
||||
|
||||
@@ -2531,7 +2531,7 @@ private:
|
||||
for (size_t i = 0; i < RCT12_MAX_NEWS_ITEMS; i++)
|
||||
{
|
||||
const rct12_news_item* src = &_s4.messages[i];
|
||||
NewsItem* dst = news_item_get(static_cast<int32_t>(i));
|
||||
NewsItem* dst = &gNewsItems[i];
|
||||
|
||||
dst->Type = src->Type;
|
||||
dst->Flags = src->Flags;
|
||||
|
||||
@@ -399,7 +399,7 @@ void S6Exporter::Export()
|
||||
// News items
|
||||
for (size_t i = 0; i < RCT12_MAX_NEWS_ITEMS; i++)
|
||||
{
|
||||
const NewsItem* src = news_item_get(static_cast<int32_t>(i));
|
||||
const NewsItem* src = &gNewsItems[i];
|
||||
rct12_news_item* dst = &_s6.news_items[i];
|
||||
|
||||
dst->Type = src->Type;
|
||||
|
||||
@@ -419,7 +419,7 @@ public:
|
||||
for (size_t i = 0; i < RCT12_MAX_NEWS_ITEMS; i++)
|
||||
{
|
||||
const rct12_news_item* src = &_s6.news_items[i];
|
||||
NewsItem* dst = news_item_get(static_cast<int32_t>(i));
|
||||
NewsItem* dst = &gNewsItems[i];
|
||||
if (src->Type < std::size(news_type_properties))
|
||||
{
|
||||
dst->Type = src->Type;
|
||||
|
||||
Reference in New Issue
Block a user