2020-01-15 04:07:48 -08:00
|
|
|
#include "Runtime/MP1/CStateSetterFlow.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CArchitectureMessage.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/MP1/MP1.hpp"
|
|
|
|
|
2021-04-10 01:42:06 -07:00
|
|
|
namespace metaforce::MP1 {
|
2017-01-16 17:23:19 -08:00
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
CStateSetterFlow::CStateSetterFlow() : CIOWin("") {}
|
2017-01-16 17:23:19 -08:00
|
|
|
|
2018-12-07 21:30:43 -08: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-10-17 21:51:59 -07:00
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
if (m->m_warpWorldIdx > -1) {
|
|
|
|
CResLoader* loader = g_ResFactory->GetResLoader();
|
|
|
|
CAssetId worldId;
|
|
|
|
for (const auto& pak : loader->GetPaks()) {
|
2022-03-02 00:26:24 -08:00
|
|
|
if (*(pak->GetPath().end() - 5) == '0' + m->m_warpWorldIdx) {
|
2018-12-07 21:30:43 -08:00
|
|
|
worldId = pak->GetMLVLId();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 21:51:59 -07:00
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
if (worldId.IsValid()) {
|
|
|
|
m->ResetGameState();
|
2018-10-17 21:51:59 -07:00
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
g_GameState->SetCurrentWorldId(worldId);
|
2019-02-09 20:41:35 -08:00
|
|
|
CWorldState& ws = g_GameState->StateForWorld(worldId);
|
2021-06-03 23:08:05 -07:00
|
|
|
CScriptLayerManager& layers = *ws.GetLayerState();
|
2018-12-07 21:30:43 -08:00
|
|
|
if (m->m_warpAreaId < layers.GetAreaCount()) {
|
2019-02-09 20:41:35 -08:00
|
|
|
ws.SetAreaId(m->m_warpAreaId);
|
2018-12-07 21:30:43 -08: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);
|
|
|
|
}
|
2021-06-03 23:08:05 -07:00
|
|
|
CScriptMailbox& relays = *ws.Mailbox();
|
2019-02-09 20:41:35 -08:00
|
|
|
for (const auto& r : m->m_warpMemoryRelays)
|
2021-06-03 14:39:49 -07:00
|
|
|
relays.AddMsg(r);
|
2018-10-17 21:51:59 -07:00
|
|
|
}
|
2018-12-07 21:30:43 -08:00
|
|
|
g_GameState->GameOptions().ResetToDefaults();
|
|
|
|
g_GameState->WriteBackupBuf();
|
2017-11-04 23:29:22 -07:00
|
|
|
return EMessageReturn::RemoveIOWinAndExit;
|
2018-12-07 21:30:43 -08:00
|
|
|
}
|
2017-11-04 23:29:22 -07:00
|
|
|
}
|
2017-01-16 17:23:19 -08:00
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
m->RefreshGameState();
|
|
|
|
return EMessageReturn::RemoveIOWinAndExit;
|
|
|
|
}
|
|
|
|
return EMessageReturn::Exit;
|
2017-01-16 17:23:19 -08:00
|
|
|
}
|
2018-12-07 21:30:43 -08:00
|
|
|
|
2021-04-10 01:42:06 -07:00
|
|
|
} // namespace metaforce::MP1
|