mirror of https://github.com/OpenRCT2/OpenRCT2.git
Move Date to GameState_t
This commit is contained in:
parent
26d65b37ea
commit
1f1377a8ef
|
@ -157,5 +157,16 @@ void DateUpdateRealTimeOfDay()
|
|||
|
||||
Date& GetDate()
|
||||
{
|
||||
return OpenRCT2::GetContext()->GetGameState()->GetDate();
|
||||
return GetGameState().Date;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006C4494
|
||||
*/
|
||||
void ResetDate()
|
||||
{
|
||||
auto& gameState = GetGameState();
|
||||
gameState.Date = OpenRCT2::Date();
|
||||
gCurrentRealTimeTicks = 0;
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ struct RealWorldTime
|
|||
};
|
||||
|
||||
OpenRCT2::Date& GetDate();
|
||||
void ResetDate();
|
||||
|
||||
extern RealWorldTime gRealTimeOfDay;
|
||||
|
||||
int32_t DateGetMonth(int32_t months);
|
||||
|
|
|
@ -317,15 +317,15 @@ void GameState::UpdateLogic()
|
|||
}
|
||||
}
|
||||
|
||||
auto& gameState = GetGameState();
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
// Stash the current day number before updating the date so that we
|
||||
// know if the day number changes on this tick.
|
||||
auto day = _date.GetDay();
|
||||
auto day = gameState.Date.GetDay();
|
||||
#endif
|
||||
|
||||
_date.Update();
|
||||
gameState.Date.Update();
|
||||
|
||||
auto& gameState = GetGameState();
|
||||
ScenarioUpdate(gameState);
|
||||
ClimateUpdate();
|
||||
MapUpdateTiles();
|
||||
|
@ -340,7 +340,7 @@ void GameState::UpdateLogic()
|
|||
|
||||
if (!(gScreenFlags & SCREEN_FLAGS_EDITOR))
|
||||
{
|
||||
_park->Update(_date);
|
||||
_park->Update(gameState.Date);
|
||||
}
|
||||
|
||||
ResearchUpdate();
|
||||
|
@ -374,7 +374,7 @@ void GameState::UpdateLogic()
|
|||
auto& hookEngine = GetContext()->GetScriptEngine().GetHookEngine();
|
||||
hookEngine.Call(HOOK_TYPE::INTERVAL_TICK, true);
|
||||
|
||||
if (day != _date.GetDay())
|
||||
if (day != gameState.Date.GetDay())
|
||||
{
|
||||
hookEngine.Call(HOOK_TYPE::INTERVAL_DAY, true);
|
||||
}
|
||||
|
@ -394,17 +394,3 @@ void GameState::CreateStateSnapshot()
|
|||
snapshots->LinkSnapshot(snapshot, GetGameState().CurrentTicks, ScenarioRandState().s0);
|
||||
}
|
||||
|
||||
void GameState::SetDate(Date newDate)
|
||||
{
|
||||
_date = newDate;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006C4494
|
||||
*/
|
||||
void GameState::ResetDate()
|
||||
{
|
||||
_date = OpenRCT2::Date();
|
||||
gCurrentRealTimeTicks = 0;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ namespace OpenRCT2
|
|||
struct GameState_t
|
||||
{
|
||||
uint32_t CurrentTicks{};
|
||||
::OpenRCT2::Date Date;
|
||||
uint64_t ParkFlags;
|
||||
uint16_t ParkRating;
|
||||
money64 ParkEntranceFee;
|
||||
|
@ -163,16 +164,11 @@ namespace OpenRCT2
|
|||
{
|
||||
private:
|
||||
std::unique_ptr<Park> _park;
|
||||
Date _date;
|
||||
|
||||
public:
|
||||
GameState();
|
||||
GameState(const GameState&) = delete;
|
||||
|
||||
Date& GetDate()
|
||||
{
|
||||
return _date;
|
||||
}
|
||||
Park& GetPark()
|
||||
{
|
||||
return *_park;
|
||||
|
@ -181,8 +177,6 @@ namespace OpenRCT2
|
|||
void InitAll(const TileCoordsXY& mapSize);
|
||||
void Tick();
|
||||
void UpdateLogic();
|
||||
void SetDate(Date newDate);
|
||||
void ResetDate();
|
||||
|
||||
private:
|
||||
void CreateStateSnapshot();
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "../ui/WindowManager.h"
|
||||
#include "../windows/Intent.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
ParkSetDateAction::ParkSetDateAction(int32_t year, int32_t month, int32_t day)
|
||||
: _year(year)
|
||||
, _month(month)
|
||||
|
@ -69,6 +71,7 @@ GameActions::Result ParkSetDateAction::Query() const
|
|||
|
||||
GameActions::Result ParkSetDateAction::Execute() const
|
||||
{
|
||||
OpenRCT2::GetContext()->GetGameState()->SetDate(OpenRCT2::Date::FromYMD(_year, _month, _day));
|
||||
auto& gameState = GetGameState();
|
||||
gameState.Date = OpenRCT2::Date::FromYMD(_year, _month, _day);
|
||||
return GameActions::Result();
|
||||
}
|
||||
|
|
|
@ -488,8 +488,7 @@ namespace OpenRCT2
|
|||
uint32_t monthsElapsed;
|
||||
cs.ReadWrite(monthTicks);
|
||||
cs.ReadWrite(monthsElapsed);
|
||||
// TODO: Use the passed gameState instead of the global one.
|
||||
GetContext()->GetGameState()->SetDate(Date(monthsElapsed, monthTicks));
|
||||
gameState.Date = Date(monthsElapsed, monthTicks);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -2145,7 +2145,7 @@ namespace RCT1
|
|||
// Date and srand
|
||||
gameState.CurrentTicks = _s4.Ticks;
|
||||
ScenarioRandSeed(_s4.RandomA, _s4.RandomB);
|
||||
GetContext()->GetGameState()->SetDate(Date(_s4.Month, _s4.Day));
|
||||
gameState.Date = Date(_s4.Month, _s4.Day);
|
||||
|
||||
// Park rating
|
||||
gameState.ParkRating = _s4.ParkRating;
|
||||
|
|
|
@ -251,7 +251,7 @@ namespace RCT2
|
|||
gameState.ScenarioDetails = loadMaybeUTF8(_s6.ScenarioDescription);
|
||||
}
|
||||
|
||||
OpenRCT2::GetContext()->GetGameState()->SetDate(OpenRCT2::Date(_s6.ElapsedMonths, _s6.CurrentDay));
|
||||
gameState.Date = OpenRCT2::Date(_s6.ElapsedMonths, _s6.CurrentDay);
|
||||
gameState.CurrentTicks = _s6.GameTicks1;
|
||||
|
||||
ScenarioRandSeed(_s6.ScenarioSrand0, _s6.ScenarioSrand1);
|
||||
|
|
|
@ -149,7 +149,7 @@ void ScenarioReset(GameState_t& gameState)
|
|||
FinanceResetHistory();
|
||||
AwardReset();
|
||||
ResetAllRideBuildDates();
|
||||
GetContext()->GetGameState()->ResetDate();
|
||||
ResetDate();
|
||||
Duck::RemoveAll();
|
||||
ParkCalculateSize();
|
||||
MapCountRemainingLandRights();
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace OpenRCT2::Scripting
|
|||
void monthsElapsed_set(int32_t value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
GetContext()->GetGameState()->SetDate(Date(value, GetDate().GetMonthTicks()));
|
||||
GetGameState().Date = Date(value, GetDate().GetMonthTicks());
|
||||
}
|
||||
|
||||
uint32_t monthProgress_get() const
|
||||
|
@ -58,7 +58,7 @@ namespace OpenRCT2::Scripting
|
|||
void monthProgress_set(int32_t value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
GetContext()->GetGameState()->SetDate(Date(GetDate().GetMonthsElapsed(), value));
|
||||
GetGameState().Date = Date(GetDate().GetMonthsElapsed(), value);
|
||||
}
|
||||
|
||||
uint32_t yearsElapsed_get() const
|
||||
|
@ -74,27 +74,17 @@ namespace OpenRCT2::Scripting
|
|||
|
||||
int32_t day_get() const
|
||||
{
|
||||
const auto& date = GetDate();
|
||||
return date.GetDay() + 1;
|
||||
return GetGameState().Date.GetDay() + 1;
|
||||
}
|
||||
|
||||
int32_t month_get() const
|
||||
{
|
||||
const auto& date = GetDate();
|
||||
return date.GetMonth();
|
||||
return GetGameState().Date.GetMonth();
|
||||
}
|
||||
|
||||
int32_t year_get() const
|
||||
{
|
||||
const auto& date = GetDate();
|
||||
return date.GetYear() + 1;
|
||||
}
|
||||
|
||||
private:
|
||||
const Date& GetDate() const
|
||||
{
|
||||
auto gameState = GetContext()->GetGameState();
|
||||
return gameState->GetDate();
|
||||
return GetGameState().Date.GetYear() + 1;
|
||||
}
|
||||
};
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
|
|
@ -48,7 +48,7 @@ TEST(MultiLaunchTest, all)
|
|||
auto gs = context->GetGameState();
|
||||
ASSERT_NE(gs, nullptr);
|
||||
|
||||
auto& date = gs->GetDate();
|
||||
auto& date = GetGameState().Date;
|
||||
// NOTE: This value is saved in the SV6 file, after the import this will be the current state.
|
||||
// In case the save file gets replaced this needs to be adjusted.
|
||||
ASSERT_EQ(date.GetMonthTicks(), 0x1e98);
|
||||
|
|
Loading…
Reference in New Issue