metaforce/Runtime/MP1/CStateSetterFlow.cpp

54 lines
1.7 KiB
C++
Raw Normal View History

#include "Runtime/MP1/CStateSetterFlow.hpp"
#include "Runtime/CArchitectureMessage.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/MP1/MP1.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce::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() - 5) == '0' + m->m_warpWorldIdx) {
2018-12-08 05:30:43 +00:00
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);
CScriptLayerManager& 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);
}
CScriptMailbox& relays = *ws.Mailbox();
2019-02-10 04:41:35 +00:00
for (const auto& r : m->m_warpMemoryRelays)
relays.AddMsg(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
2021-04-10 08:42:06 +00:00
} // namespace metaforce::MP1