mirror of https://github.com/OpenRCT2/OpenRCT2.git
Move awards to GameState_t (#21601)
This commit is contained in:
parent
9bb678688e
commit
8a6de886be
|
@ -1183,7 +1183,9 @@ static constexpr WindowParkAward _parkAwards[] = {
|
|||
auto screenCoords = windowPos
|
||||
+ ScreenCoordsXY{ widgets[WIDX_PAGE_BACKGROUND].left + 4, widgets[WIDX_PAGE_BACKGROUND].top + 4 };
|
||||
|
||||
for (const auto& award : GetAwards())
|
||||
auto& currentAwards = OpenRCT2::GetGameState().CurrentAwards;
|
||||
|
||||
for (const auto& award : currentAwards)
|
||||
{
|
||||
GfxDrawSprite(dpi, ImageId(_parkAwards[EnumValue(award.Type)].sprite), screenCoords);
|
||||
DrawTextWrapped(dpi, screenCoords + ScreenCoordsXY{ 34, 6 }, 180, _parkAwards[EnumValue(award.Type)].text);
|
||||
|
@ -1191,7 +1193,7 @@ static constexpr WindowParkAward _parkAwards[] = {
|
|||
screenCoords.y += 32;
|
||||
}
|
||||
|
||||
if (GetAwards().empty())
|
||||
if (currentAwards.empty())
|
||||
DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ 6, 6 }, STR_NO_RECENT_AWARDS);
|
||||
}
|
||||
#pragma endregion
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Editor.h"
|
||||
#include "Limits.h"
|
||||
#include "interface/ZoomLevel.h"
|
||||
#include "management/Award.h"
|
||||
#include "management/Finance.h"
|
||||
#include "management/NewsItem.h"
|
||||
#include "ride/Ride.h"
|
||||
|
@ -130,6 +131,8 @@ namespace OpenRCT2
|
|||
|
||||
ObjectEntryIndex LastEntranceStyle;
|
||||
|
||||
std::vector<Award> CurrentAwards;
|
||||
|
||||
/**
|
||||
* Probability out of 65535, of gaining a new guest per game tick.
|
||||
* new guests per second = 40 * (probability / 65535)
|
||||
|
|
|
@ -69,13 +69,6 @@ static constexpr StringId AwardNewsStrings[] = {
|
|||
STR_NEWS_ITEM_BEST_GENTLE_RIDES,
|
||||
};
|
||||
|
||||
static std::vector<Award> _currentAwards;
|
||||
|
||||
std::vector<Award>& GetAwards()
|
||||
{
|
||||
return _currentAwards;
|
||||
}
|
||||
|
||||
bool AwardIsPositive(AwardType type)
|
||||
{
|
||||
return AwardPositiveMap[EnumValue(type)];
|
||||
|
@ -602,7 +595,7 @@ static bool AwardIsDeserved(AwardType awardType, int32_t activeAwardTypes)
|
|||
|
||||
void AwardReset()
|
||||
{
|
||||
_currentAwards.clear();
|
||||
GetGameState().CurrentAwards.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -613,17 +606,18 @@ void AwardUpdateAll()
|
|||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
auto& currentAwards = GetGameState().CurrentAwards;
|
||||
// Decrease award times
|
||||
for (auto& award : _currentAwards)
|
||||
for (auto& award : currentAwards)
|
||||
{
|
||||
--award.Time;
|
||||
}
|
||||
// Remove any 0 time awards
|
||||
auto res = std::remove_if(
|
||||
std::begin(_currentAwards), std::end(_currentAwards), [](const Award& award) { return award.Time == 0; });
|
||||
if (res != std::end(_currentAwards))
|
||||
std::begin(currentAwards), std::end(currentAwards), [](const Award& award) { return award.Time == 0; });
|
||||
if (res != std::end(currentAwards))
|
||||
{
|
||||
_currentAwards.erase(res, std::end(_currentAwards));
|
||||
currentAwards.erase(res, std::end(currentAwards));
|
||||
WindowInvalidateByClass(WindowClass::ParkInformation);
|
||||
}
|
||||
|
||||
|
@ -632,13 +626,13 @@ void AwardUpdateAll()
|
|||
{
|
||||
// Set active award types as flags
|
||||
int32_t activeAwardTypes = 0;
|
||||
for (auto& award : _currentAwards)
|
||||
for (auto& award : currentAwards)
|
||||
{
|
||||
activeAwardTypes |= (1 << EnumValue(award.Type));
|
||||
}
|
||||
|
||||
// Check if there was a free award entry
|
||||
if (_currentAwards.size() < OpenRCT2::Limits::MaxAwards)
|
||||
if (currentAwards.size() < OpenRCT2::Limits::MaxAwards)
|
||||
{
|
||||
// Get a random award type not already active
|
||||
AwardType awardType;
|
||||
|
@ -651,7 +645,7 @@ void AwardUpdateAll()
|
|||
if (AwardIsDeserved(awardType, activeAwardTypes))
|
||||
{
|
||||
// Add award
|
||||
_currentAwards.push_back(Award{ 5u, awardType });
|
||||
currentAwards.push_back(Award{ 5u, awardType });
|
||||
if (gConfigNotifications.ParkAward)
|
||||
{
|
||||
News::AddItemToQueue(News::ItemType::Award, AwardNewsStrings[EnumValue(awardType)], 0, {});
|
||||
|
|
|
@ -42,8 +42,6 @@ struct Award
|
|||
AwardType Type;
|
||||
};
|
||||
|
||||
std::vector<Award>& GetAwards();
|
||||
|
||||
bool AwardIsPositive(AwardType type);
|
||||
void AwardReset();
|
||||
void AwardUpdateAll();
|
||||
|
|
|
@ -862,15 +862,16 @@ namespace OpenRCT2
|
|||
});
|
||||
|
||||
// Awards
|
||||
auto& currentAwards = gameState.CurrentAwards;
|
||||
if (version <= 6)
|
||||
{
|
||||
Award awards[RCT2::Limits::MaxAwards]{};
|
||||
cs.ReadWriteArray(awards, [&cs](Award& award) {
|
||||
cs.ReadWriteArray(awards, [&cs, ¤tAwards](Award& award) {
|
||||
if (award.Time != 0)
|
||||
{
|
||||
cs.ReadWrite(award.Time);
|
||||
cs.ReadWrite(award.Type);
|
||||
GetAwards().push_back(award);
|
||||
currentAwards.push_back(award);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -879,7 +880,7 @@ namespace OpenRCT2
|
|||
}
|
||||
else
|
||||
{
|
||||
cs.ReadWriteVector(GetAwards(), [&cs](Award& award) {
|
||||
cs.ReadWriteVector(currentAwards, [&cs](Award& award) {
|
||||
cs.ReadWrite(award.Time);
|
||||
cs.ReadWrite(award.Type);
|
||||
});
|
||||
|
|
|
@ -2162,12 +2162,12 @@ namespace RCT1
|
|||
}
|
||||
|
||||
// Awards
|
||||
auto& awards = GetAwards();
|
||||
auto& currentAwards = gameState.CurrentAwards;
|
||||
for (auto& src : _s4.Awards)
|
||||
{
|
||||
if (src.Time != 0)
|
||||
{
|
||||
awards.push_back(Award{ src.Time, static_cast<AwardType>(src.Type) });
|
||||
currentAwards.push_back(Award{ src.Time, static_cast<AwardType>(src.Type) });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -378,12 +378,12 @@ namespace RCT2
|
|||
std::memcpy(gameState.PeepWarningThrottle, _s6.PeepWarningThrottle, sizeof(_s6.PeepWarningThrottle));
|
||||
|
||||
// Awards
|
||||
auto& awards = GetAwards();
|
||||
auto& currentAwards = gameState.CurrentAwards;
|
||||
for (auto& src : _s6.Awards)
|
||||
{
|
||||
if (src.Time != 0)
|
||||
{
|
||||
awards.push_back(Award{ src.Time, static_cast<AwardType>(src.Type) });
|
||||
currentAwards.push_back(Award{ src.Time, static_cast<AwardType>(src.Type) });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -617,7 +617,7 @@ uint32_t Park::CalculateGuestGenerationProbability() const
|
|||
}
|
||||
|
||||
// Reward or penalties for park awards
|
||||
for (const auto& award : GetAwards())
|
||||
for (const auto& award : GetGameState().CurrentAwards)
|
||||
{
|
||||
// +/- 0.25% of the probability
|
||||
if (AwardIsPositive(award.Type))
|
||||
|
|
Loading…
Reference in New Issue