Merge pull request #27231 from Gymnasiast/refactor/more-gamestate-stuff

Remove getGameState() calls from import and news, move news to ParkData
This commit is contained in:
Michael Steenbeek authored and GitHub committed 2026-10-04 16:11:57 +02:00
commit 66449cee0e
28 files changed
+226 -192

No files matched your search

@@ -441,7 +441,7 @@ namespace OpenRCT2::Title
auto intent = Intent(INTENT_ACTION_REFRESH_NEW_RIDES);
ContextBroadcastIntent(&intent);
Ui::Windows::WindowScenerySetDefaultPlacementConfiguration();
News::InitQueue(gameState);
News::InitQueue(gameState.park);
Drawing::LoadPalette();
gScreenAge = 0;
gGamePaused = false;
+3 -2
View File
@@ -12,6 +12,7 @@
#include <openrct2-ui/interface/Window.h>
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Context.h>
#include <openrct2/GameState.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/drawing/Rectangle.h>
#include <openrct2/drawing/Text.h>
@@ -109,8 +110,8 @@ namespace OpenRCT2::Ui::Windows
widgets[WIDX_PANEL_OUTSET].right = width - 1;
widgets[WIDX_PANEL_INSET].right = width - 3;
bool useFullToolbar = News::IsQueueEmpty() && (ThemeGetFlags() & UITHEME_FLAG_USE_GAME_STATUS_BAR)
&& gLegacyScene == LegacyScene::playing;
bool useFullToolbar = getGameState().park.newsItems.isEmpty()
&& (ThemeGetFlags() & UITHEME_FLAG_USE_GAME_STATUS_BAR) && gLegacyScene == LegacyScene::playing;
widgets[WIDX_PANEL_OUTSET].setVisible(useFullToolbar);
widgets[WIDX_PANEL_INSET].setVisible(useFullToolbar);
+12 -8
View File
@@ -113,7 +113,8 @@ namespace OpenRCT2::Ui::Windows
{
private:
int32_t _pressedNewsItemIndex{}, _pressedButtonIndex{}, _suspendUpdateTicks{};
WidgetIndex _baseCheckboxIndex;
WidgetIndex _baseCheckboxIndex{};
News::ItemQueues& _queues;
static int32_t CalculateNewsItemHeight()
{
@@ -363,14 +364,13 @@ namespace OpenRCT2::Ui::Windows
size_t j = _pressedNewsItemIndex;
_pressedNewsItemIndex = -1;
auto& gameState = getGameState();
if (j >= gameState.newsItems.getArchived().size())
if (j >= _queues.getArchived().size())
{
return;
}
const auto& newsItem = gameState.newsItems.getArchived()[j];
const auto& newsItem = _queues.getArchived()[j];
if (newsItem.hasButton())
{
return;
@@ -412,8 +412,7 @@ namespace OpenRCT2::Ui::Windows
ScreenSize onScrollGetSize(int32_t scrollIndex) override
{
int32_t scrollHeight = static_cast<int32_t>(getGameState().newsItems.getArchived().size())
* CalculateNewsItemHeight()
int32_t scrollHeight = static_cast<int32_t>(_queues.getArchived().size()) * CalculateNewsItemHeight()
- kItemSeparatorHeight;
return { kWindowSize.width, scrollHeight };
}
@@ -424,7 +423,7 @@ namespace OpenRCT2::Ui::Windows
int32_t i = 0;
int32_t buttonIndex = 0;
auto mutableScreenCoords = screenCoords;
for (const auto& newsItem : getGameState().newsItems.getArchived())
for (const auto& newsItem : _queues.getArchived())
{
if (mutableScreenCoords.y < itemHeight)
{
@@ -471,7 +470,7 @@ namespace OpenRCT2::Ui::Windows
const bool scrollbarVisible = scrolls[0].contentHeight > widgets[WIDX_SCROLL].height() - 1;
const auto scrollbarFill = scrollbarVisible ? 0 : kScrollBarWidth;
for (const auto& newsItem : getGameState().newsItems.getArchived())
for (const auto& newsItem : _queues.getArchived())
{
if (y >= rt.y + rt.height)
break;
@@ -607,6 +606,11 @@ namespace OpenRCT2::Ui::Windows
i++;
}
}
NewsWindow()
: _queues(getGameState().park.newsItems)
{
}
};
WindowBase* NewsOpen()
+8 -5
View File
@@ -53,9 +53,11 @@ namespace OpenRCT2::Ui::Windows
class NewsTicker final : public Window
{
private:
News::ItemQueues& _queues;
void drawNewsItem(RenderTarget& rt)
{
const auto* newsItem = News::GetItem(0);
const auto* newsItem = News::GetItem(_queues, 0);
if (newsItem == nullptr)
return;
@@ -172,6 +174,7 @@ namespace OpenRCT2::Ui::Windows
public:
NewsTicker()
: _queues(getGameState().park.newsItems)
{
setWidgets(kNewsTickerWidgets);
@@ -181,14 +184,14 @@ namespace OpenRCT2::Ui::Windows
void onMouseUp(WidgetIndex widgetIndex) override
{
const auto* newsItem = News::GetItem(0);
const auto* newsItem = News::GetItem(_queues, 0);
if (newsItem == nullptr)
return;
switch (widgetIndex)
{
case WIDX_PANEL_INSET:
News::CloseCurrentItem();
News::CloseCurrentItem(_queues);
break;
case WIDX_NEWS_SUBJECT:
News::OpenSubject(newsItem->type, newsItem->assoc);
@@ -227,7 +230,7 @@ namespace OpenRCT2::Ui::Windows
widgets[WIDX_NEWS_LOCATE].right = width - 6;
widgets[WIDX_NEWS_LOCATE].left = widgets[WIDX_NEWS_LOCATE].right - 24;
auto* newsItem = News::GetItem(0);
auto* newsItem = News::GetItem(_queues, 0);
setWidgetDisabled(WIDX_NEWS_SUBJECT, false);
setWidgetDisabled(WIDX_NEWS_LOCATE, false);
@@ -262,7 +265,7 @@ namespace OpenRCT2::Ui::Windows
if (currentFrame >= 24)
currentFrame = 0;
if (News::IsQueueEmpty())
if (_queues.isEmpty())
close();
}
};
+3 -3
View File
@@ -70,7 +70,7 @@ namespace OpenRCT2
UpdateConsolidatedPatrolAreas();
ResetDate();
Weather::reset();
News::InitQueue(gameState);
News::InitQueue(gameState.park);
gInMapInitCode = false;
@@ -322,17 +322,17 @@ namespace OpenRCT2
VehicleUpdateAll();
gameState.entities.updateAllMiscEntities();
Ride::updateAll();
auto& park = gameState.park;
if (!isInEditorMode())
{
auto& park = gameState.park;
Park::Update(park, gameState);
}
ResearchUpdate();
RideRating::UpdateAll();
RideMeasurementsUpdate();
News::UpdateCurrentItem();
News::UpdateCurrentItem(park.newsItems);
MapAnimations::InvalidateAndUpdateAll();
VehicleSoundsUpdate();
-3
View File
@@ -15,7 +15,6 @@
#include "core/Random.hpp"
#include "entity/EntityRegistry.h"
#include "interface/ZoomLevel.h"
#include "management/NewsItem.h"
#include "ride/Ride.h"
#include "ride/RideRatings.h"
#include "scenario/ScenarioOptions.h"
@@ -73,8 +72,6 @@ namespace OpenRCT2
std::vector<PeepSpawn> peepSpawns;
News::ItemQueues newsItems;
uint16_t grassSceneryTileLoopPosition;
CoordsXY widePathTileLoopPosition;
+4 -2
View File
@@ -344,7 +344,8 @@ namespace OpenRCT2
_currentRecording.reset();
News::Item* news = News::AddItemToQueue(News::ItemType::blank, "Replay recording stopped", 0);
News::Item* news = News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::blank, "Replay recording stopped", 0);
news->setFlags(News::ItemFlags::hasButton); // Has no subject.
return true;
@@ -470,7 +471,8 @@ namespace OpenRCT2
// During normal playback we pause the game if stopped.
if (_mode == ReplayMode::playing)
{
News::Item* news = News::AddItemToQueue(News::ItemType::blank, "Replay playback complete", 0);
News::Item* news = News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::blank, "Replay playback complete", 0);
news->setFlags(News::ItemFlags::hasButton); // Has no subject.
}
@@ -132,7 +132,7 @@ namespace OpenRCT2::GameActions
RideClearLeftoverEntrances(ride);
const auto rideId = ride.id;
News::DisableNewsItems(News::ItemType::ride, rideId.ToUnderlying());
News::DisableNewsItems(park.newsItems, News::ItemType::ride, rideId.ToUnderlying());
UnlinkAllBannersForRide(ride.id);
+8 -4
View File
@@ -1619,7 +1619,9 @@ namespace OpenRCT2
ft.Add<StringId>(shopItemDescriptor.Naming.Indefinite);
if (Config::Get().notifications.guestBoughtItem)
{
News::AddItemToQueue(News::ItemType::peepOnRide, STR_PEEP_TRACKING_NOTIFICATION_BOUGHT_X, guest.id, ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::peepOnRide, STR_PEEP_TRACKING_NOTIFICATION_BOUGHT_X,
guest.id, ft);
}
}
@@ -3552,7 +3554,8 @@ namespace OpenRCT2
if (Config::Get().notifications.rideWarnings)
{
News::AddItemToQueue(
News::ItemType::ride, STR_GUESTS_GETTING_STUCK_ON_RIDE, guest.currentRide.ToUnderlying(), ft);
getGameState().park.newsItems, News::ItemType::ride, STR_GUESTS_GETTING_STUCK_ON_RIDE,
guest.currentRide.ToUnderlying(), ft);
}
}
}
@@ -3857,7 +3860,7 @@ namespace OpenRCT2
if (Config::Get().notifications.guestOnRide)
{
News::AddItemToQueue(News::ItemType::peepOnRide, msg_string, id, ft);
News::AddItemToQueue(getGameState().park.newsItems, News::ItemType::peepOnRide, msg_string, id, ft);
}
}
@@ -5016,7 +5019,8 @@ namespace OpenRCT2
if (Config::Get().notifications.guestLeftRide)
{
News::AddItemToQueue(News::ItemType::peepOnRide, STR_PEEP_TRACKING_LEFT_RIDE_X, id, ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::peepOnRide, STR_PEEP_TRACKING_LEFT_RIDE_X, id, ft);
}
}
}
+35 -26
View File
@@ -730,14 +730,14 @@ namespace OpenRCT2
bool wasGuest = staff == nullptr;
if (wasGuest)
{
News::DisableNewsItems(News::ItemType::peepOnRide, peep->id.ToUnderlying());
News::DisableNewsItems(getGameState().park.newsItems, News::ItemType::peepOnRide, peep->id.ToUnderlying());
}
else
{
staff->clearPatrolArea();
UpdateConsolidatedPatrolAreas();
News::DisableNewsItems(News::ItemType::peep, staff->id.ToUnderlying());
News::DisableNewsItems(getGameState().park.newsItems, News::ItemType::peep, staff->id.ToUnderlying());
}
getGameState().entities.entityRemove(peep);
@@ -781,15 +781,16 @@ namespace OpenRCT2
if (action == PeepActionType::drowning)
return;
auto& park = getGameState().park;
if (Config::Get().notifications.guestDied)
{
auto ft = Formatter();
formatNameTo(ft);
News::AddItemToQueue(News::ItemType::blank, STR_NEWS_ITEM_GUEST_DROWNED, x | (y << 16), ft);
News::AddItemToQueue(park.newsItems, News::ItemType::blank, STR_NEWS_ITEM_GUEST_DROWNED, x | (y << 16), ft);
}
auto& gameState = getGameState();
gameState.park.ratingCasualtyPenalty = std::min(gameState.park.ratingCasualtyPenalty + 25, 1000);
park.ratingCasualtyPenalty = std::min(park.ratingCasualtyPenalty + 25, 1000);
remove();
return;
}
@@ -955,12 +956,14 @@ namespace OpenRCT2
*/
void PeepProblemWarningsUpdate()
{
auto& gameState = getGameState();
// TODO: pass ParkData& as a parameter, rename to GuestProblemWarningsUpdate() and move to Guest.cpp
auto& park = getGameState().park;
auto& newsItems = park.newsItems;
Ride* ride;
uint32_t hungerCounter = 0, lostCounter = 0, noexitCounter = 0, thirstCounter = 0, litterCounter = 0,
disgustCounter = 0, toiletCounter = 0, vandalismCounter = 0;
uint8_t* warningThrottle = gameState.park.peepWarningThrottle;
uint8_t* warningThrottle = park.peepWarningThrottle;
int32_t inQueueCounter = 0;
int32_t tooLongQueueCounter = 0;
@@ -1040,73 +1043,73 @@ namespace OpenRCT2
// could maybe be packed into a loop, would lose a lot of clarity though
if (warningThrottle[0])
--warningThrottle[0];
else if (hungerCounter >= kPeepHungerWarningThreshold && hungerCounter >= gameState.park.numGuestsInPark / 16)
else if (hungerCounter >= kPeepHungerWarningThreshold && hungerCounter >= park.numGuestsInPark / 16)
{
warningThrottle[0] = 4;
if (Config::Get().notifications.guestWarnings)
{
constexpr auto kThoughtId = static_cast<uint32_t>(PeepThoughtType::hungry);
News::AddItemToQueue(News::ItemType::peeps, STR_PEEPS_ARE_HUNGRY, kThoughtId, {});
News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_ARE_HUNGRY, kThoughtId, {});
}
}
if (warningThrottle[1])
--warningThrottle[1];
else if (thirstCounter >= kPeepThirstWarningThreshold && thirstCounter >= gameState.park.numGuestsInPark / 16)
else if (thirstCounter >= kPeepThirstWarningThreshold && thirstCounter >= park.numGuestsInPark / 16)
{
warningThrottle[1] = 4;
if (Config::Get().notifications.guestWarnings)
{
constexpr auto kThoughtId = static_cast<uint32_t>(PeepThoughtType::thirsty);
News::AddItemToQueue(News::ItemType::peeps, STR_PEEPS_ARE_THIRSTY, kThoughtId, {});
News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_ARE_THIRSTY, kThoughtId, {});
}
}
if (warningThrottle[2])
--warningThrottle[2];
else if (toiletCounter >= kPeepToiletWarningThreshold && toiletCounter >= gameState.park.numGuestsInPark / 16)
else if (toiletCounter >= kPeepToiletWarningThreshold && toiletCounter >= park.numGuestsInPark / 16)
{
warningThrottle[2] = 4;
if (Config::Get().notifications.guestWarnings)
{
constexpr auto kThoughtId = static_cast<uint32_t>(PeepThoughtType::toilet);
News::AddItemToQueue(News::ItemType::peeps, STR_PEEPS_CANT_FIND_TOILET, kThoughtId, {});
News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_CANT_FIND_TOILET, kThoughtId, {});
}
}
if (warningThrottle[3])
--warningThrottle[3];
else if (litterCounter >= kPeepLitterWarningThreshold && litterCounter >= gameState.park.numGuestsInPark / 32)
else if (litterCounter >= kPeepLitterWarningThreshold && litterCounter >= park.numGuestsInPark / 32)
{
warningThrottle[3] = 4;
if (Config::Get().notifications.guestWarnings)
{
constexpr auto kThoughtId = static_cast<uint32_t>(PeepThoughtType::badLitter);
News::AddItemToQueue(News::ItemType::peeps, STR_PEEPS_DISLIKE_LITTER, kThoughtId, {});
News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_DISLIKE_LITTER, kThoughtId, {});
}
}
if (warningThrottle[4])
--warningThrottle[4];
else if (disgustCounter >= kPeepDisgustWarningThreshold && disgustCounter >= gameState.park.numGuestsInPark / 32)
else if (disgustCounter >= kPeepDisgustWarningThreshold && disgustCounter >= park.numGuestsInPark / 32)
{
warningThrottle[4] = 4;
if (Config::Get().notifications.guestWarnings)
{
constexpr auto kThoughtId = static_cast<uint32_t>(PeepThoughtType::pathDisgusting);
News::AddItemToQueue(News::ItemType::peeps, STR_PEEPS_DISGUSTED_BY_PATHS, kThoughtId, {});
News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_DISGUSTED_BY_PATHS, kThoughtId, {});
}
}
if (warningThrottle[5])
--warningThrottle[5];
else if (vandalismCounter >= kPeepVandalismWarningThreshold && vandalismCounter >= gameState.park.numGuestsInPark / 32)
else if (vandalismCounter >= kPeepVandalismWarningThreshold && vandalismCounter >= park.numGuestsInPark / 32)
{
warningThrottle[5] = 4;
if (Config::Get().notifications.guestWarnings)
{
constexpr auto kThoughtId = static_cast<uint32_t>(PeepThoughtType::vandalism);
News::AddItemToQueue(News::ItemType::peeps, STR_PEEPS_DISLIKE_VANDALISM, kThoughtId, {});
News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_DISLIKE_VANDALISM, kThoughtId, {});
}
}
@@ -1118,7 +1121,7 @@ namespace OpenRCT2
if (Config::Get().notifications.guestWarnings)
{
constexpr auto kThoughtId = static_cast<uint32_t>(PeepThoughtType::cantFindExit);
News::AddItemToQueue(News::ItemType::peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, kThoughtId, {});
News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, kThoughtId, {});
}
}
else if (lostCounter >= kPeepLostWarningThreshold)
@@ -1127,7 +1130,7 @@ namespace OpenRCT2
if (Config::Get().notifications.guestWarnings)
{
constexpr auto kThoughtId = static_cast<uint32_t>(PeepThoughtType::lost);
News::AddItemToQueue(News::ItemType::peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, kThoughtId, {});
News::AddItemToQueue(newsItems, News::ItemType::peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, kThoughtId, {});
}
}
@@ -1143,7 +1146,8 @@ namespace OpenRCT2
queueComplainingGuestsMap.begin(), queueComplainingGuestsMap.end(),
[](auto& lhs, auto& rhs) { return lhs.second < rhs.second; });
auto rideId = rideWithMostQueueComplaints->first.ToUnderlying();
News::AddItemToQueue(News::ItemType::ride, STR_PEEPS_COMPLAINING_ABOUT_QUEUE_LENGTH_WARNING, rideId, {});
News::AddItemToQueue(
newsItems, News::ItemType::ride, STR_PEEPS_COMPLAINING_ABOUT_QUEUE_LENGTH_WARNING, rideId, {});
}
}
}
@@ -1648,7 +1652,9 @@ namespace OpenRCT2
ride->formatNameTo(ft);
if (Config::Get().notifications.guestQueuingForRide)
{
News::AddItemToQueue(News::ItemType::peepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->id, ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::peepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X,
guest->id, ft);
}
}
}
@@ -1708,7 +1714,9 @@ namespace OpenRCT2
guest->formatNameTo(ft);
if (Config::Get().notifications.guestLeftPark)
{
News::AddItemToQueue(News::ItemType::peepOnRide, STR_PEEP_TRACKING_LEFT_PARK, guest->id, ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::peepOnRide, STR_PEEP_TRACKING_LEFT_PARK, guest->id,
ft);
}
}
return true;
@@ -2101,7 +2109,8 @@ namespace OpenRCT2
if (Config::Get().notifications.guestQueuingForRide)
{
News::AddItemToQueue(
News::ItemType::peepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->id, ft);
getGameState().park.newsItems, News::ItemType::peepOnRide,
STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->id, ft);
}
}
@@ -2219,7 +2228,7 @@ namespace OpenRCT2
: STR_PEEP_TRACKING_PEEP_IS_ON_X;
if (Config::Get().notifications.guestUsedFacility)
{
News::AddItemToQueue(News::ItemType::peepOnRide, string_id, guest->id, ft);
News::AddItemToQueue(getGameState().park.newsItems, News::ItemType::peepOnRide, string_id, guest->id, ft);
}
}
}
@@ -1663,7 +1663,7 @@ static void ConsoleCommandAddNewsItem([[maybe_unused]] InteractiveConsole& conso
}
}
News::AddItemToQueue(itemType, msg, assoc);
News::AddItemToQueue(getGameState().park.newsItems, itemType, msg, assoc);
console.WriteLine("Successfully added News Item");
}
+3 -2
View File
@@ -620,10 +620,11 @@ void AwardReset()
static void AwardAdd(AwardType type)
{
getGameState().park.currentAwards.push_back(Award{ 5u, type });
auto& park = getGameState().park;
park.currentAwards.push_back(Award{ 5u, type });
if (Config::Get().notifications.parkAward)
{
News::AddItemToQueue(News::ItemType::award, AwardGetNews(type), 0, {});
News::AddItemToQueue(park.newsItems, News::ItemType::award, AwardGetNews(type), 0, {});
}
Ui::GetWindowManager()->InvalidateByClass(WindowClass::parkInformation);
}
+2 -1
View File
@@ -100,7 +100,8 @@ static void MarketingRaiseFinishedNotification(const MarketingCampaign& campaign
ft.Add<StringId>(GetShopItemDescriptor(campaign.shopItemType).Naming.Plural);
}
News::AddItemToQueue(News::ItemType::campaign, kMarketingCampaignNames[campaign.type][2], 0, ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::campaign, kMarketingCampaignNames[campaign.type][2], 0, ft);
}
}
+37 -43
View File
@@ -52,9 +52,9 @@ bool News::IsValidIndex(int32_t index)
return true;
}
News::Item* News::GetItem(int32_t index)
News::Item* News::GetItem(ItemQueues& queues, int32_t index)
{
return getGameState().newsItems.at(index);
return queues.at(index);
}
News::Item& News::ItemQueues::operator[](size_t index)
@@ -85,11 +85,6 @@ const News::Item* News::ItemQueues::at(int32_t index) const
return nullptr;
}
bool News::IsQueueEmpty()
{
return getGameState().newsItems.isEmpty();
}
bool News::ItemQueues::isEmpty() const
{
return _recent.empty();
@@ -105,13 +100,13 @@ void News::ItemQueues::clear()
_archived.clear();
}
void News::InitQueue(GameState_t& gameState)
void News::InitQueue(Park::ParkData& park)
{
gameState.newsItems.clear();
assert(gameState.newsItems.isEmpty());
park.newsItems.clear();
assert(park.newsItems.isEmpty());
// Throttles for warning types (PEEP_*_WARNING)
for (auto& warningThrottle : gameState.park.peepWarningThrottle)
for (auto& warningThrottle : park.peepWarningThrottle)
{
warningThrottle = 0;
}
@@ -125,9 +120,9 @@ uint16_t News::ItemQueues::incrementTicks()
return ++current().ticks;
}
static void TickCurrent()
static void TickCurrent(News::ItemQueues& queues)
{
int32_t ticks = getGameState().newsItems.incrementTicks();
int32_t ticks = queues.incrementTicks();
// Only play news item sound when in normal playing mode
if (ticks == 1 && (gLegacyScene == LegacyScene::playing))
{
@@ -154,33 +149,32 @@ bool News::ItemQueues::currentShouldBeArchived() const
*
* rct2: 0x0066E252
*/
void News::UpdateCurrentItem()
void News::UpdateCurrentItem(ItemQueues& queues)
{
PROFILED_FUNCTION();
auto& gameState = getGameState();
// Check if there is a current news item
if (gameState.newsItems.isEmpty())
if (queues.isEmpty())
return;
auto intent = Intent(INTENT_ACTION_UPDATE_NEWS_TICKER);
ContextBroadcastIntent(&intent);
// Update the current news item
TickCurrent();
TickCurrent(queues);
// Removal of current news item
if (gameState.newsItems.currentShouldBeArchived())
gameState.newsItems.archiveCurrent();
if (queues.currentShouldBeArchived())
queues.archiveCurrent();
}
/**
*
* rct2: 0x0066E377
*/
void News::CloseCurrentItem()
void News::CloseCurrentItem(ItemQueues& queues)
{
getGameState().newsItems.archiveCurrent();
queues.archiveCurrent();
}
void News::ItemQueues::archiveCurrent()
@@ -311,25 +305,27 @@ News::Item* News::ItemQueues::firstOpenOrNewSlot()
*
* rct2: 0x0066DF55
*/
News::Item* News::AddItemToQueue(ItemType type, StringId string_id, uint32_t assoc, const Formatter& formatter)
News::Item* News::AddItemToQueue(
ItemQueues& queues, ItemType type, StringId string_id, uint32_t assoc, const Formatter& formatter)
{
utf8 buffer[256];
// overflows possible?
FormatStringLegacy(buffer, 256, string_id, formatter.Data());
return AddItemToQueue(type, buffer, assoc);
return AddItemToQueue(queues, type, buffer, assoc);
}
// TODO: Use variant for assoc, requires strong type for each possible input.
News::Item* News::AddItemToQueue(ItemType type, StringId string_id, EntityId assoc, const Formatter& formatter)
News::Item* News::AddItemToQueue(
ItemQueues& queues, ItemType type, StringId string_id, EntityId assoc, const Formatter& formatter)
{
return AddItemToQueue(type, string_id, assoc.ToUnderlying(), formatter);
return AddItemToQueue(queues, type, string_id, assoc.ToUnderlying(), formatter);
}
News::Item* News::AddItemToQueue(ItemType type, const utf8* text, uint32_t assoc)
News::Item* News::AddItemToQueue(ItemQueues& queues, ItemType type, const utf8* text, uint32_t assoc)
{
auto& date = GetDate();
Item* newsItem = getGameState().newsItems.firstOpenOrNewSlot();
Item* newsItem = queues.firstOpenOrNewSlot();
newsItem->type = type;
newsItem->flags = 0;
newsItem->assoc = assoc; // Make optional for Award, Money, Graph and Null
@@ -437,15 +433,14 @@ void News::OpenSubject(ItemType type, int32_t subject)
*
* rct2: 0x0066E407
*/
void News::DisableNewsItems(ItemType type, uint32_t assoc)
void News::DisableNewsItems(ItemQueues& queues, ItemType type, uint32_t assoc)
{
auto& gameState = getGameState();
// TODO: write test invalidating windows
gameState.newsItems.foreachRecentNews([type, assoc, &gameState](auto& newsItem) {
queues.foreachRecentNews([type, assoc, &queues](auto& newsItem) {
if (type == newsItem.type && assoc == newsItem.assoc)
{
newsItem.setFlags(ItemFlags::hasButton);
if (&newsItem == &gameState.newsItems.current())
if (&newsItem == &queues.current())
{
auto intent = Intent(INTENT_ACTION_UPDATE_NEWS_TICKER);
ContextBroadcastIntent(&intent);
@@ -453,7 +448,7 @@ void News::DisableNewsItems(ItemType type, uint32_t assoc)
}
});
gameState.newsItems.foreachArchivedNews([type, assoc](auto& newsItem) {
queues.foreachArchivedNews([type, assoc](auto& newsItem) {
if (type == newsItem.type && assoc == newsItem.assoc)
{
newsItem.setFlags(ItemFlags::hasButton);
@@ -463,40 +458,39 @@ void News::DisableNewsItems(ItemType type, uint32_t assoc)
});
}
void News::AddItemToQueue(Item* newNewsItem)
void News::AddItemToQueue(ItemQueues& queues, Item* newNewsItem)
{
Item* newsItem = getGameState().newsItems.firstOpenOrNewSlot();
Item* newsItem = queues.firstOpenOrNewSlot();
*newsItem = *newNewsItem;
}
void News::RemoveItem(int32_t index)
void News::RemoveItem(ItemQueues& queues, int32_t index)
{
if (index < 0 || index >= MaxItems)
return;
auto& gameState = getGameState();
// News item is already null, no need to remove it
if (gameState.newsItems[index].type == ItemType::null)
if (queues[index].type == ItemType::null)
return;
size_t newsBoundary = index < ItemHistoryStart ? ItemHistoryStart : MaxItems;
for (size_t i = index; i < newsBoundary - 1; i++)
{
gameState.newsItems[i] = gameState.newsItems[i + 1];
queues[i] = queues[i + 1];
}
gameState.newsItems[newsBoundary - 1].type = ItemType::null;
queues[newsBoundary - 1].type = ItemType::null;
}
void News::importNewsItems(GameState_t& gameState, const std::span<const Item> recent, const std::span<const Item> archived)
void News::importNewsItems(ItemQueues& queues, const std::span<const Item> recent, const std::span<const Item> archived)
{
gameState.newsItems.clear();
queues.clear();
for (size_t i = 0; i < std::min<size_t>(recent.size(), ItemHistoryStart); i++)
{
gameState.newsItems[i] = recent[i];
queues[i] = recent[i];
}
for (size_t i = 0; i < std::min<size_t>(archived.size(), MaxItemsArchive); i++)
{
gameState.newsItems[ItemHistoryStart + i] = archived[i];
queues[ItemHistoryStart + i] = archived[i];
}
}
+16 -14
View File
@@ -25,7 +25,11 @@ struct CoordsXYZ;
namespace OpenRCT2
{
class Formatter;
struct GameState_t;
namespace Park
{
struct ParkData;
}
} // namespace OpenRCT2
namespace OpenRCT2::News
@@ -296,31 +300,29 @@ namespace OpenRCT2::News
ItemQueue<MaxItemsArchive> _archived;
};
void InitQueue(GameState_t& gameState);
void InitQueue(Park::ParkData& park);
void UpdateCurrentItem();
void CloseCurrentItem();
void UpdateCurrentItem(ItemQueues& queues);
void CloseCurrentItem(ItemQueues& queues);
std::optional<CoordsXYZ> GetSubjectLocation(ItemType type, int32_t subject);
Item* AddItemToQueue(ItemType type, StringId string_id, uint32_t assoc, const Formatter& formatter);
Item* AddItemToQueue(ItemType type, StringId string_id, EntityId assoc, const Formatter& formatter);
Item* AddItemToQueue(ItemType type, const utf8* text, uint32_t assoc);
Item* AddItemToQueue(ItemQueues& queues, ItemType type, StringId string_id, uint32_t assoc, const Formatter& formatter);
Item* AddItemToQueue(ItemQueues& queues, ItemType type, StringId string_id, EntityId assoc, const Formatter& formatter);
Item* AddItemToQueue(ItemQueues& queues, ItemType type, const utf8* text, uint32_t assoc);
bool CheckIfItemRequiresAssoc(ItemType type);
void OpenSubject(ItemType type, int32_t subject);
void DisableNewsItems(ItemType type, uint32_t assoc);
void DisableNewsItems(ItemQueues& queues, ItemType type, uint32_t assoc);
Item* GetItem(int32_t index);
bool IsQueueEmpty();
Item* GetItem(ItemQueues& queues, int32_t index);
bool IsValidIndex(int32_t index);
void AddItemToQueue(Item* newNewsItem);
void RemoveItem(int32_t index);
void AddItemToQueue(ItemQueues& queues, Item* newNewsItem);
void RemoveItem(ItemQueues& queues, int32_t index);
void importNewsItems(GameState_t& gameState, std::span<const Item> recent, std::span<const Item> archived);
void importNewsItems(ItemQueues& queues, std::span<const Item> recent, std::span<const Item> archived);
} // namespace OpenRCT2::News
+4 -2
View File
@@ -266,7 +266,8 @@ void ResearchFinishItem(const ResearchItem& researchItem)
{
if (Config::Get().notifications.rideResearched)
{
News::AddItemToQueue(News::ItemType::research, availabilityString, researchItem.rawValue, ft);
News::AddItemToQueue(
gameState.park.newsItems, News::ItemType::research, availabilityString, researchItem.rawValue, ft);
}
}
@@ -290,7 +291,8 @@ void ResearchFinishItem(const ResearchItem& researchItem)
if (Config::Get().notifications.rideResearched)
{
News::AddItemToQueue(
News::ItemType::research, STR_NEWS_ITEM_RESEARCH_NEW_SCENERY_SET_AVAILABLE, researchItem.rawValue, ft);
gameState.park.newsItems, News::ItemType::research, STR_NEWS_ITEM_RESEARCH_NEW_SCENERY_SET_AVAILABLE,
researchItem.rawValue, ft);
}
}
+9 -11
View File
@@ -175,7 +175,7 @@ namespace OpenRCT2
ReadWriteParkChunk(gameState, os);
ReadWriteClimateChunk(gameState, os);
ReadWriteResearchChunk(gameState, os);
ReadWriteNotificationsChunk(gameState, os);
ReadWriteNotificationsChunk(gameState.park.newsItems, os);
ReadWriteInterfaceChunk(gameState, os);
ReadWriteCheatsChunk(gameState, os);
ReadWriteRestrictedObjectsChunk(gameState, os);
@@ -217,7 +217,7 @@ namespace OpenRCT2
ReadWriteParkChunk(gameState, os);
ReadWriteClimateChunk(gameState, os);
ReadWriteResearchChunk(gameState, os);
ReadWriteNotificationsChunk(gameState, os);
ReadWriteNotificationsChunk(gameState.park.newsItems, os);
ReadWriteInterfaceChunk(gameState, os);
ReadWriteCheatsChunk(gameState, os);
ReadWriteRestrictedObjectsChunk(gameState, os);
@@ -1212,9 +1212,9 @@ namespace OpenRCT2
cs.readWrite(item.category);
}
void ReadWriteNotificationsChunk(GameState_t& gameState, OrcaStream& os)
void ReadWriteNotificationsChunk(News::ItemQueues& queues, OrcaStream& os)
{
os.readWriteChunk(ParkFileChunkType::notifications, [&gameState](OrcaStream::ChunkStream& cs) {
os.readWriteChunk(ParkFileChunkType::notifications, [&queues](OrcaStream::ChunkStream& cs) {
if (cs.getMode() == OrcaStream::Mode::reading)
{
std::vector<News::Item> recent;
@@ -1223,16 +1223,14 @@ namespace OpenRCT2
std::vector<News::Item> archived;
cs.readWriteVector(archived, [&cs](News::Item& item) { ReadWriteNewsItem(cs, item); });
News::importNewsItems(gameState, recent, archived);
News::importNewsItems(queues, recent, archived);
}
else
{
std::vector<News::Item> recent(
std::begin(gameState.newsItems.getRecent()), std::end(gameState.newsItems.getRecent()));
std::vector<News::Item> recent(std::begin(queues.getRecent()), std::end(queues.getRecent()));
cs.readWriteVector(recent, [&cs](News::Item& item) { ReadWriteNewsItem(cs, item); });
std::vector<News::Item> archived(
std::begin(gameState.newsItems.getArchived()), std::end(gameState.newsItems.getArchived()));
std::vector<News::Item> archived(std::begin(queues.getArchived()), std::end(queues.getArchived()));
cs.readWriteVector(archived, [&cs](News::Item& item) { ReadWriteNewsItem(cs, item); });
}
});
@@ -2801,7 +2799,7 @@ namespace OpenRCT2
T placeholder{};
auto index = cs.read<EntityId>();
auto* ent = getGameState().entities.createEntityAt<T>(index);
auto* ent = gameState.entities.createEntityAt<T>(index);
if (ent == nullptr)
{
// Unable to allocate entity
@@ -2822,7 +2820,7 @@ namespace OpenRCT2
os.readWriteChunk(ParkFileChunkType::entities, [this, &gameState, &os](OrcaStream::ChunkStream& cs) {
if (cs.getMode() == OrcaStream::Mode::reading)
{
getGameState().entities.resetAllEntities();
gameState.entities.resetAllEntities();
}
std::vector<uint16_t> entityIndices;
+14 -14
View File
@@ -2292,7 +2292,7 @@ namespace OpenRCT2::RCT1
// News items
auto recentMessages = convertNewsQueue(_s4.recentMessages);
auto archivedMessages = convertNewsQueue(_s4.archivedMessages);
News::importNewsItems(gameState, recentMessages, archivedMessages);
News::importNewsItems(park.newsItems, recentMessages, archivedMessages);
// Initial guest status
gameState.scenarioOptions.guestInitialCash = ToMoney64(_s4.GuestInitialCash);
@@ -2797,7 +2797,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<::Vehicle>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<::Vehicle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<::Vehicle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const Vehicle*>(&srcBase);
const auto* ride = GetRide(RideId::FromUnderlying(src->Ride));
if (ride == nullptr)
@@ -2920,7 +2920,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<Guest>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<Guest>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<Guest>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const Peep*>(&srcBase);
ImportPeep(dst, src);
@@ -3016,7 +3016,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<Staff>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<Staff>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<Staff>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const Peep*>(&srcBase);
ImportPeep(dst, src);
dst->assignedStaffType = StaffType(src->StaffType);
@@ -3035,7 +3035,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<Litter>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<Litter>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<Litter>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityLitter*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3046,7 +3046,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<SteamParticle>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<SteamParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<SteamParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntitySteamParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3057,7 +3057,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<MoneyEffect>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<MoneyEffect>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<MoneyEffect>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityMoneyEffect*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3072,7 +3072,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<VehicleCrashParticle>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<VehicleCrashParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<VehicleCrashParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityCrashedVehicleParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -3091,7 +3091,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<ExplosionCloud>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<ExplosionCloud>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<ExplosionCloud>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -3100,7 +3100,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<ExplosionFlare>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<ExplosionFlare>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<ExplosionFlare>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -3109,7 +3109,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<CrashSplashParticle>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<CrashSplashParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<CrashSplashParticle>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityParticle*>(&srcBase);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -3118,7 +3118,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<JumpingFountain>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<JumpingFountain>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<JumpingFountain>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityJumpingFountain*>(&srcBase);
auto fountainType = JumpingFountainType::water;
@@ -3138,7 +3138,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<Balloon>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<Balloon>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<Balloon>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityBalloon*>(&srcBase);
ImportEntityCommonProperties(dst, src);
@@ -3159,7 +3159,7 @@ namespace OpenRCT2::RCT1
template<>
void S4Importer::ImportEntity<Duck>(GameState_t& gameState, const RCT12EntityBase& srcBase)
{
auto* dst = getGameState().entities.createEntityAt<Duck>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* dst = gameState.entities.createEntityAt<Duck>(EntityId::FromUnderlying(srcBase.EntityIndex));
auto* src = static_cast<const RCT12EntityDuck*>(&srcBase);
ImportEntityCommonProperties(dst, src);
+17 -18
View File
@@ -565,7 +565,7 @@ namespace OpenRCT2::RCT2
ImportMapAnimations();
ImportRideRatingsCalcData();
ImportRideRatingsCalcData(gameState);
ImportRideMeasurements();
gameState.nextGuestNumber = _s6.NextGuestIndex;
gameState.grassSceneryTileLoopPosition = _s6.GrassAndSceneryTilepos;
@@ -595,7 +595,7 @@ namespace OpenRCT2::RCT2
// News items
auto recentMessages = convertNewsQueue(_s6.recentMessages);
auto archivedMessages = convertNewsQueue(_s6.archivedMessages);
News::importNewsItems(gameState, recentMessages, archivedMessages);
News::importNewsItems(park.newsItems, recentMessages, archivedMessages);
// Pad13CE730
// rct1_scenario_flags
@@ -1054,12 +1054,12 @@ namespace OpenRCT2::RCT2
}
}
void ImportRideRatingsCalcData()
void ImportRideRatingsCalcData(GameState_t& gameState)
{
const auto& src = _s6.RideRatingsCalcData;
// S6 has only one state, ensure we reset all states before reading the first one.
RideRating::ResetUpdateStates();
auto& rideRatingStates = getGameState().rideRatingUpdateStates;
auto& rideRatingStates = gameState.rideRatingUpdateStates;
auto& dst = rideRatingStates[0];
dst = {};
dst.Proximity = { src.ProximityX, src.ProximityY, src.ProximityZ };
@@ -1990,7 +1990,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::Vehicle>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::Vehicle>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::Vehicle>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const Vehicle*>(&baseSrc);
const auto& ride = _s6.Rides[src->Ride];
@@ -2116,7 +2116,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::Guest>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::Guest>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::Guest>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const Peep*>(&baseSrc);
ImportEntityPeep(dst, src);
@@ -2191,7 +2191,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::Staff>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::Staff>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::Staff>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const Peep*>(&baseSrc);
ImportEntityPeep(dst, src);
@@ -2212,7 +2212,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::SteamParticle>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::SteamParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::SteamParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntitySteamParticle*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->timeToMove = src->TimeToMove;
@@ -2222,7 +2222,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::MoneyEffect>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::MoneyEffect>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::MoneyEffect>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityMoneyEffect*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->moveDelay = src->MoveDelay;
@@ -2236,8 +2236,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::VehicleCrashParticle>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::VehicleCrashParticle>(
EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::VehicleCrashParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityCrashedVehicleParticle*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -2257,7 +2256,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::ExplosionCloud>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::ExplosionCloud>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::ExplosionCloud>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityParticle*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -2266,7 +2265,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::ExplosionFlare>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::ExplosionFlare>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::ExplosionFlare>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityParticle*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -2275,7 +2274,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::CrashSplashParticle>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::CrashSplashParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::CrashSplashParticle>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityParticle*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -2284,7 +2283,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::JumpingFountain>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::JumpingFountain>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::JumpingFountain>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityJumpingFountain*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->numTicksAlive = src->NumTicksAlive;
@@ -2301,7 +2300,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::Balloon>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::Balloon>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::Balloon>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityBalloon*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->popped = src->Popped;
@@ -2313,7 +2312,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::Duck>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::Duck>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::Duck>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityDuck*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->frame = src->Frame;
@@ -2325,7 +2324,7 @@ namespace OpenRCT2::RCT2
template<>
void S6Importer::ImportEntity<::Litter>(GameState_t& gameState, const RCT12EntityBase& baseSrc)
{
auto dst = getGameState().entities.createEntityAt<::Litter>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto dst = gameState.entities.createEntityAt<::Litter>(EntityId::FromUnderlying(baseSrc.EntityIndex));
auto src = static_cast<const RCT12EntityLitter*>(&baseSrc);
ImportEntityCommonProperties(dst, src);
dst->subType = ::Litter::Type(src->Type);
+15 -6
View File
@@ -1345,7 +1345,8 @@ namespace OpenRCT2
{
Formatter ft;
ride.formatNameTo(ft);
News::AddItemToQueue(News::ItemType::ride, STR_RIDE_IS_BROKEN_DOWN, ride.id.ToUnderlying(), ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::ride, STR_RIDE_IS_BROKEN_DOWN, ride.id.ToUnderlying(), ft);
}
}
@@ -1372,7 +1373,9 @@ namespace OpenRCT2
{
Formatter ft;
ride.formatNameTo(ft);
News::AddItemToQueue(News::ItemType::ride, STR_RIDE_IS_STILL_NOT_FIXED, ride.id.ToUnderlying(), ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::ride, STR_RIDE_IS_STILL_NOT_FIXED,
ride.id.ToUnderlying(), ft);
}
}
}
@@ -2062,7 +2065,9 @@ namespace OpenRCT2
ride.formatNameTo(ft);
if (Config::Get().notifications.rideWarnings)
{
News::AddItemToQueue(News::ItemType::ride, STR_ENTRANCE_NOT_CONNECTED, ride.id.ToUnderlying(), ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::ride, STR_ENTRANCE_NOT_CONNECTED, ride.id.ToUnderlying(),
ft);
}
ride.connectedMessageThrottle = 3;
}
@@ -2074,7 +2079,9 @@ namespace OpenRCT2
ride.formatNameTo(ft);
if (Config::Get().notifications.rideWarnings)
{
News::AddItemToQueue(News::ItemType::ride, STR_EXIT_NOT_CONNECTED, ride.id.ToUnderlying(), ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::ride, STR_EXIT_NOT_CONNECTED, ride.id.ToUnderlying(),
ft);
}
ride.connectedMessageThrottle = 3;
}
@@ -2141,7 +2148,8 @@ namespace OpenRCT2
{
Formatter ft;
ride2->formatNameTo(ft);
News::AddItemToQueue(News::ItemType::ride, STR_ENTRANCE_NOT_CONNECTED, ride2->id.ToUnderlying(), ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::ride, STR_ENTRANCE_NOT_CONNECTED, ride2->id.ToUnderlying(), ft);
}
ride2->connectedMessageThrottle = 3;
@@ -5039,7 +5047,8 @@ namespace OpenRCT2
{
Formatter ft;
formatNameTo(ft);
News::AddItemToQueue(News::ItemType::ride, STR_RIDE_HAS_CRASHED, id.ToUnderlying(), ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::ride, STR_RIDE_HAS_CRASHED, id.ToUnderlying(), ft);
}
}
+2 -2
View File
@@ -297,8 +297,8 @@ static void ride_train_crash(Ride& ride, uint16_t numFatalities)
{
ride.formatNameTo(ft);
News::AddItemToQueue(
News::ItemType::ride, numFatalities == 1 ? STR_X_PERSON_DIED_ON_X : STR_X_PEOPLE_DIED_ON_X,
ride.id.ToUnderlying(), ft);
getGameState().park.newsItems, News::ItemType::ride,
numFatalities == 1 ? STR_X_PERSON_DIED_ON_X : STR_X_PEOPLE_DIED_ON_X, ride.id.ToUnderlying(), ft);
}
// TODO: get park id from ride/vehicle
+2 -1
View File
@@ -1329,7 +1329,8 @@ void Vehicle::CheckIfMissing()
curRide->formatNameTo(ft);
ft.Add<StringId>(GetRideComponentName(GetRideTypeDescriptor(curRide->type).NameConvention.station).singular);
News::AddItemToQueue(News::ItemType::ride, STR_NEWS_VEHICLE_HAS_STALLED, ride.ToUnderlying(), ft);
News::AddItemToQueue(
getGameState().park.newsItems, News::ItemType::ride, STR_NEWS_VEHICLE_HAS_STALLED, ride.ToUnderlying(), ft);
}
}
+12 -8
View File
@@ -84,9 +84,9 @@ void ScenarioReset(GameState_t& gameState)
auto intent = Intent(INTENT_ACTION_SET_DEFAULT_SCENERY_CONFIG);
ContextBroadcastIntent(&intent);
News::InitQueue(gameState);
auto& park = gameState.park;
News::InitQueue(park);
park.rating = Park::CalculateParkRating(park, gameState);
Park::updateValuations(park, gameState);
park.historicalProfit = gameState.scenarioOptions.initialCash - park.bankLoan;
@@ -203,7 +203,7 @@ void ScenarioSuccessSubmitName(GameState_t& gameState, const char* name)
*/
static void ScenarioCheckEntranceFeeTooHigh()
{
const auto& park = getGameState().park;
auto& park = getGameState().park;
const auto max_fee = AddClamp(park.totalRideValueForMoney, park.totalRideValueForMoney / 2);
if (park.flags.has(ParkFlag::parkOpen) && Park::GetEntranceFee(park) > max_fee)
@@ -217,7 +217,7 @@ static void ScenarioCheckEntranceFeeTooHigh()
uint32_t packed_xy = (y << 16) | x;
if (Config::Get().notifications.parkWarnings)
{
News::AddItemToQueue(News::ItemType::blank, STR_ENTRANCE_FEE_TOO_HI, packed_xy, {});
News::AddItemToQueue(park.newsItems, News::ItemType::blank, STR_ENTRANCE_FEE_TOO_HI, packed_xy, {});
}
}
}
@@ -272,16 +272,20 @@ static void scenarioUpdateLowRatingDayCount(Park::ParkData& park, GameState_t& g
switch (park.scenarioParkRatingWarningDays)
{
case 1:
News::AddItemToQueue(News::ItemType::graph, STR_PARK_RATING_WARNING_4_WEEKS_REMAINING, 0, {});
News::AddItemToQueue(
park.newsItems, News::ItemType::graph, STR_PARK_RATING_WARNING_4_WEEKS_REMAINING, 0, {});
break;
case 8:
News::AddItemToQueue(News::ItemType::graph, STR_PARK_RATING_WARNING_3_WEEKS_REMAINING, 0, {});
News::AddItemToQueue(
park.newsItems, News::ItemType::graph, STR_PARK_RATING_WARNING_3_WEEKS_REMAINING, 0, {});
break;
case 15:
News::AddItemToQueue(News::ItemType::graph, STR_PARK_RATING_WARNING_2_WEEKS_REMAINING, 0, {});
News::AddItemToQueue(
park.newsItems, News::ItemType::graph, STR_PARK_RATING_WARNING_2_WEEKS_REMAINING, 0, {});
break;
case 22:
News::AddItemToQueue(News::ItemType::graph, STR_PARK_RATING_WARNING_1_WEEK_REMAINING, 0, {});
News::AddItemToQueue(
park.newsItems, News::ItemType::graph, STR_PARK_RATING_WARNING_1_WEEK_REMAINING, 0, {});
break;
}
}
+1 -1
View File
@@ -257,7 +257,7 @@ namespace OpenRCT2::Scenario
{
case ObjectiveType::guestsAndRating:
{
News::AddItemToQueue(News::ItemType::graph, STR_PARK_HAS_BEEN_CLOSED_DOWN, 0, {});
News::AddItemToQueue(park.newsItems, News::ItemType::graph, STR_PARK_HAS_BEEN_CLOSED_DOWN, 0, {});
park.flags.unset(ParkFlag::parkOpen);
gameState.scenarioOptions.guestInitialHappiness = 50;
break;
+1 -1
View File
@@ -198,7 +198,7 @@ void EditorScene::clearMapForEditing()
Weather::reset();
News::InitQueue(gameState);
News::InitQueue(park);
}
// NB: only called by LoadLandscape
@@ -356,12 +356,12 @@ namespace OpenRCT2::Scripting
{
JSValue result = JS_NewArray(ctx);
int64_t resultIdx = 0;
auto& gameState = getGameState();
for (size_t i = 0, newsSize = gameState.newsItems.getRecent().size(); i < newsSize; i++)
auto& newsItems = getGameState().park.newsItems;
for (size_t i = 0, newsSize = newsItems.getRecent().size(); i < newsSize; i++)
{
JS_SetPropertyInt64(ctx, result, resultIdx++, gScParkMessage.New(ctx, i));
}
for (size_t i = 0, newsSize = gameState.newsItems.getArchived().size(); i < newsSize; i++)
for (size_t i = 0, newsSize = newsItems.getArchived().size(); i < newsSize; i++)
{
auto offset = i + News::ItemHistoryStart;
JS_SetPropertyInt64(ctx, result, resultIdx++, gScParkMessage.New(ctx, offset));
@@ -373,15 +373,15 @@ namespace OpenRCT2::Scripting
{
int32_t index = 0;
int32_t archiveIndex = News::ItemHistoryStart;
auto& gameState = getGameState();
JSIterateArray(ctx, value, [&index, &archiveIndex, &gameState](JSContext* ctx2, JSValue item) {
auto& newsItems = getGameState().park.newsItems;
JSIterateArray(ctx, value, [&index, &archiveIndex, &newsItems](JSContext* ctx2, JSValue item) {
auto isArchived = AsOrDefault(ctx2, item, "isArchived", false);
auto newsItem = NewsItemFromJS(ctx2, item);
if (isArchived)
{
if (archiveIndex < News::MaxItems)
{
gameState.newsItems[archiveIndex] = newsItem;
newsItems[archiveIndex] = newsItem;
archiveIndex++;
}
}
@@ -389,7 +389,7 @@ namespace OpenRCT2::Scripting
{
if (index < News::ItemHistoryStart)
{
gameState.newsItems[index] = newsItem;
newsItems[index] = newsItem;
index++;
}
}
@@ -398,11 +398,11 @@ namespace OpenRCT2::Scripting
// End the lists by setting next item to null
if (index < News::ItemHistoryStart)
{
gameState.newsItems[index].type = News::ItemType::null;
newsItems[index].type = News::ItemType::null;
}
if (archiveIndex < News::MaxItems)
{
gameState.newsItems[archiveIndex].type = News::ItemType::null;
newsItems[archiveIndex].type = News::ItemType::null;
}
return JS_UNDEFINED;
}
@@ -440,7 +440,7 @@ namespace OpenRCT2::Scripting
assoc = JSToUint(ctx, subject);
}
}
News::AddItemToQueue(type, text.c_str(), assoc);
News::AddItemToQueue(getGameState().park.newsItems, type, text.c_str(), assoc);
return JS_UNDEFINED;
}
@@ -23,7 +23,7 @@ namespace OpenRCT2::Scripting
News::Item* ScParkMessage::GetMessage(JSValue thisVal)
{
auto index = gScParkMessage.GetOpaque<OpaqueParkMessageData*>(thisVal)->index;
return &getGameState().newsItems[index];
return &getGameState().park.newsItems[index];
}
JSValue ScParkMessage::isArchived_get(JSContext* ctx, JSValue thisVal)
@@ -173,7 +173,7 @@ namespace OpenRCT2::Scripting
JSValue ScParkMessage::remove(JSContext* ctx, JSValue thisVal, int argc, JSValue* argv)
{
auto index = gScParkMessage.GetOpaque<OpaqueParkMessageData*>(thisVal)->index;
News::RemoveItem(static_cast<int32_t>(index));
News::RemoveItem(getGameState().park.newsItems, static_cast<int32_t>(index));
return JS_UNDEFINED;
}
+3
View File
@@ -14,6 +14,7 @@
#include "../management/Award.h"
#include "../management/Finance.h"
#include "../management/Marketing.h"
#include "../management/NewsItem.h"
#include "Location.hpp"
#include <string>
@@ -130,5 +131,7 @@ namespace OpenRCT2::Park
std::vector<Award> currentAwards;
std::vector<MarketingCampaign> marketingCampaigns;
News::ItemQueues newsItems;
};
} // namespace OpenRCT2::Park