2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptWorldTeleporter.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CGameState.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/IMain.hpp"
|
|
|
|
#include "Runtime/World/CWorld.hpp"
|
|
|
|
#include "Runtime/World/CWorldTransManager.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-04-20 21:07:18 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptWorldTeleporter::CScriptWorldTeleporter(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
2017-08-13 05:26:14 +00:00
|
|
|
bool active, CAssetId worldId, CAssetId areaId)
|
2017-07-30 11:00:30 +00:00
|
|
|
: CEntity(uid, info, active, name)
|
2017-08-08 22:12:14 +00:00
|
|
|
, x34_worldId(worldId)
|
2020-04-20 04:57:50 +00:00
|
|
|
, x38_areaId(areaId) {}
|
2017-08-08 22:12:14 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptWorldTeleporter::CScriptWorldTeleporter(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
2018-12-08 05:30:43 +00:00
|
|
|
bool active, CAssetId worldId, CAssetId areaId, CAssetId playerAncs,
|
|
|
|
u32 charIdx, u32 defaultAnim, const zeus::CVector3f& playerScale,
|
|
|
|
CAssetId platformModel, const zeus::CVector3f& platformScale,
|
|
|
|
CAssetId backgroundModel, const zeus::CVector3f& backgroundScale,
|
|
|
|
bool upElevator, u16 soundId, u8 volume, u8 panning)
|
2017-08-08 22:12:14 +00:00
|
|
|
: CEntity(uid, info, active, name)
|
|
|
|
, x34_worldId(worldId)
|
|
|
|
, x38_areaId(areaId)
|
|
|
|
, x3c_type(ETeleporterType::Elevator)
|
|
|
|
, x40_24_upElevator(upElevator)
|
|
|
|
, x50_playerAnim(playerAncs, charIdx, defaultAnim)
|
|
|
|
, x5c_playerScale(playerScale)
|
|
|
|
, x68_platformModel(platformModel)
|
|
|
|
, x6c_platformScale(platformScale)
|
|
|
|
, x78_backgroundModel(backgroundModel)
|
|
|
|
, x7c_backgroundScale(backgroundScale)
|
|
|
|
, x88_soundId(CSfxManager::TranslateSFXID(soundId))
|
|
|
|
, x8a_volume(volume)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x8b_panning(panning) {}
|
2017-08-08 22:12:14 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptWorldTeleporter::CScriptWorldTeleporter(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
2017-08-13 05:26:14 +00:00
|
|
|
bool active, CAssetId worldId, CAssetId areaId, u16 soundId, u8 volume,
|
|
|
|
u8 panning, CAssetId fontId, CAssetId stringId, bool fadeWhite,
|
2017-08-08 22:12:14 +00:00
|
|
|
float charFadeIn, float charsPerSecond, float showDelay)
|
|
|
|
: CEntity(uid, info, active, name)
|
|
|
|
, x34_worldId(worldId)
|
|
|
|
, x38_areaId(areaId)
|
|
|
|
, x3c_type(ETeleporterType::Text)
|
|
|
|
, x40_27_fadeWhite(fadeWhite)
|
|
|
|
, x44_charFadeIn(charFadeIn)
|
|
|
|
, x48_charsPerSecond(charsPerSecond)
|
|
|
|
, x4c_showDelay(showDelay)
|
|
|
|
, x88_soundId(CSfxManager::TranslateSFXID(soundId))
|
|
|
|
, x8a_volume(volume)
|
|
|
|
, x8b_panning(panning)
|
|
|
|
, x8c_fontId(fontId)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x90_stringId(stringId) {}
|
2017-08-08 22:12:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptWorldTeleporter::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-08-08 22:12:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptWorldTeleporter::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
if (GetActive()) {
|
|
|
|
const std::shared_ptr<CWorldTransManager>& transMgr = mgr.WorldTransManager();
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::Stop:
|
|
|
|
x40_25_inTransition = false;
|
|
|
|
transMgr->DisableTransition();
|
|
|
|
transMgr->SfxStop();
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Play:
|
|
|
|
StartTransition(mgr);
|
|
|
|
transMgr->SetSfx(x88_soundId, x8a_volume, x8b_panning);
|
|
|
|
transMgr->SfxStart();
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::SetToZero: {
|
2019-08-14 14:58:54 +00:00
|
|
|
const auto& world = mgr.GetWorld();
|
2018-12-08 05:30:43 +00:00
|
|
|
world->SetLoadPauseState(true);
|
|
|
|
CAssetId currentWorld = g_GameState->CurrentWorldAssetId();
|
|
|
|
g_GameState->SetCurrentWorldId(x34_worldId);
|
2017-08-08 22:12:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (g_ResFactory->GetResourceTypeById(x34_worldId) == SBIG('MLVL')) {
|
|
|
|
StartTransition(mgr);
|
|
|
|
g_GameState->SetCurrentWorldId(x34_worldId);
|
|
|
|
g_GameState->CurrentWorldState().SetDesiredAreaAssetId(x38_areaId);
|
2021-06-03 23:47:04 +00:00
|
|
|
g_Main->SetFlowState(EClientFlowStates::None);
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.SetShouldQuitGame(true);
|
|
|
|
} else {
|
|
|
|
x40_25_inTransition = false;
|
|
|
|
transMgr->DisableTransition();
|
|
|
|
g_GameState->SetCurrentWorldId(currentWorld);
|
|
|
|
}
|
|
|
|
break;
|
2017-08-08 22:12:14 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CEntity::AcceptScriptMsg(msg, uid, mgr);
|
2017-08-08 22:12:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptWorldTeleporter::StartTransition(CStateManager& mgr) {
|
2020-05-03 14:28:25 +00:00
|
|
|
if (x40_25_inTransition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& transMgr = mgr.WorldTransManager();
|
|
|
|
switch (x3c_type) {
|
|
|
|
case ETeleporterType::NoTransition:
|
|
|
|
transMgr->DisableTransition();
|
|
|
|
break;
|
|
|
|
case ETeleporterType::Elevator:
|
|
|
|
if (x50_playerAnim.GetACSFile().IsValid() && x50_playerAnim.GetCharacter() != u32(-1)) {
|
|
|
|
transMgr->EnableTransition(CAnimRes(x50_playerAnim.GetACSFile(), x50_playerAnim.GetCharacter(), x5c_playerScale,
|
|
|
|
x50_playerAnim.GetInitialAnimation(), true),
|
|
|
|
x68_platformModel, x6c_platformScale, x78_backgroundModel, x7c_backgroundScale,
|
|
|
|
x40_24_upElevator);
|
2018-12-08 05:30:43 +00:00
|
|
|
x40_25_inTransition = true;
|
2017-08-08 22:12:14 +00:00
|
|
|
}
|
2020-05-03 14:28:25 +00:00
|
|
|
break;
|
|
|
|
case ETeleporterType::Text:
|
|
|
|
transMgr->EnableTransition(x8c_fontId, x90_stringId, 0, x40_27_fadeWhite, x44_charFadeIn, x48_charsPerSecond,
|
|
|
|
x4c_showDelay);
|
|
|
|
x40_25_inTransition = true;
|
|
|
|
break;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-08-08 22:12:14 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|