metaforce/Runtime/MP1/CStateSetterFlow.cpp

52 lines
1.7 KiB
C++
Raw Normal View History

#include "CStateSetterFlow.hpp"
#include "CArchitectureMessage.hpp"
#include "GameGlobalObjects.hpp"
#include "MP1.hpp"
2018-12-08 05:30:43 +00:00
namespace urde::MP1 {
2018-12-08 05:30:43 +00:00
CStateSetterFlow::CStateSetterFlow() : CIOWin("") {}
2018-12-08 05:30:43 +00:00
CIOWin::EMessageReturn CStateSetterFlow::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) {
if (msg.GetType() == EArchMsgType::TimerTick) {
MP1::CMain* m = static_cast<MP1::CMain*>(g_Main);
2018-12-08 05:30:43 +00:00
if (m->m_warpWorldIdx > -1) {
CResLoader* loader = g_ResFactory->GetResLoader();
CAssetId worldId;
for (const auto& pak : loader->GetPaks()) {
if (*(pak->GetPath().end() - 6) == '0' + m->m_warpWorldIdx) {
worldId = pak->GetMLVLId();
break;
}
}
2018-12-08 05:30:43 +00:00
if (worldId.IsValid()) {
m->ResetGameState();
2018-12-08 05:30:43 +00:00
g_GameState->SetCurrentWorldId(worldId);
2019-02-10 04:41:35 +00:00
CWorldState& ws = g_GameState->StateForWorld(worldId);
CWorldLayerState& layers = *ws.GetLayerState();
2018-12-08 05:30:43 +00:00
if (m->m_warpAreaId < layers.GetAreaCount()) {
2019-02-10 04:41:35 +00:00
ws.SetAreaId(m->m_warpAreaId);
2018-12-08 05:30:43 +00:00
if (m->m_warpLayerBits) {
for (u32 i = 0; i < layers.GetAreaLayerCount(m->m_warpAreaId); ++i)
layers.SetLayerActive(m->m_warpAreaId, i, ((m->m_warpLayerBits >> i) & 1) != 0);
}
2019-02-10 04:41:35 +00:00
CRelayTracker& relays = *ws.RelayTracker();
for (const auto& r : m->m_warpMemoryRelays)
relays.AddRelay(r);
}
2018-12-08 05:30:43 +00:00
g_GameState->GameOptions().ResetToDefaults();
g_GameState->WriteBackupBuf();
return EMessageReturn::RemoveIOWinAndExit;
2018-12-08 05:30:43 +00:00
}
}
2018-12-08 05:30:43 +00:00
m->RefreshGameState();
return EMessageReturn::RemoveIOWinAndExit;
}
return EMessageReturn::Exit;
}
2018-12-08 05:30:43 +00:00
} // namespace urde::MP1