diff --git a/LEGO1/lego/legoomni/src/worlds/infocenter.cpp b/LEGO1/lego/legoomni/src/worlds/infocenter.cpp index b51011b5..45885c31 100644 --- a/LEGO1/lego/legoomni/src/worlds/infocenter.cpp +++ b/LEGO1/lego/legoomni/src/worlds/infocenter.cpp @@ -343,7 +343,7 @@ MxLong Infocenter::HandleEndAction(MxEndActionNotificationParam& p_param) MxLong result = m_radio.Notify(p_param); if (result || (action->GetAtomId() != m_atomId && action->GetAtomId() != *g_introScript && - !Extension::Call(ReplacedIn, *action, m_atomId, *g_introScript).value_or(false))) { + !Extension::Call(ReplacedIn, *action, m_atomId, *g_introScript).value_or(std::nullopt))) { return result; } diff --git a/LEGO1/lego/legoomni/src/worlds/isle.cpp b/LEGO1/lego/legoomni/src/worlds/isle.cpp index 876003d4..8e3c0535 100644 --- a/LEGO1/lego/legoomni/src/worlds/isle.cpp +++ b/LEGO1/lego/legoomni/src/worlds/isle.cpp @@ -5,6 +5,7 @@ #include "bike.h" #include "carrace.h" #include "dunebuggy.h" +#include "extensions/siloader.h" #include "helicopter.h" #include "isle_actions.h" #include "islepathactor.h" @@ -42,6 +43,8 @@ DECOMP_SIZE_ASSERT(Act1State, 0x26c) DECOMP_SIZE_ASSERT(LegoNamedPlane, 0x4c) DECOMP_SIZE_ASSERT(Isle, 0x140) +using namespace Extensions; + // GLOBAL: LEGO1 0x100f1198 MxU32 g_isleFlags = 0x7f; @@ -213,6 +216,14 @@ MxLong Isle::HandleEndAction(MxEndActionNotificationParam& p_param) result = 1; } } + else if (auto replacedObject = Extension::Call(ReplacedIn, *p_param.GetAction(), *g_jukeboxScript).value_or(std::nullopt)) { + MxS32 script = replacedObject->second; + + if (script >= JukeboxScript::c_JBMusic1 && script <= JukeboxScript::c_JBMusic6) { + m_jukebox->StopAction((JukeboxScript::Script) script); + result = 1; + } + } else if (m_act1state->m_planeActive) { MxS32 script = p_param.GetAction()->GetObjectId(); diff --git a/extensions/include/extensions/siloader.h b/extensions/include/extensions/siloader.h index e7618615..e581f6b1 100644 --- a/extensions/include/extensions/siloader.h +++ b/extensions/include/extensions/siloader.h @@ -29,7 +29,7 @@ class SiLoader { static MxBool HandleEndAction(MxEndActionNotificationParam& p_param); template - static bool ReplacedIn(MxDSAction& p_action, Args... p_args); + static std::optional ReplacedIn(MxDSAction& p_action, Args... p_args); static std::map options; static std::vector files; @@ -53,20 +53,22 @@ class SiLoader { #ifdef EXTENSIONS template -bool SiLoader::ReplacedIn(MxDSAction& p_action, Args... p_args) +std::optional SiLoader::ReplacedIn(MxDSAction& p_action, Args... p_args) { StreamObject object{p_action.GetAtomId(), p_action.GetObjectId()}; - auto checkAtomId = [&p_action, &object](const auto& p_atomId) -> bool { + auto checkAtomId = [&p_action, &object](const auto& p_atomId) -> std::optional { for (const auto& key : replace) { if (key.second == object && key.first.first == p_atomId) { - return true; + return key.first; } } - return false; + return std::nullopt; }; - return (checkAtomId(p_args) || ...); + std::optional result; + ((void) (!result.has_value() && (result = checkAtomId(p_args), true)), ...); + return result; } constexpr auto Load = &SiLoader::Load; @@ -85,9 +87,9 @@ constexpr decltype(&SiLoader::HandleWorld) HandleWorld = nullptr; constexpr decltype(&SiLoader::HandleRemove) HandleRemove = nullptr; constexpr decltype(&SiLoader::HandleDelete) HandleDelete = nullptr; constexpr decltype(&SiLoader::HandleEndAction) HandleEndAction = nullptr; -constexpr auto ReplacedIn = [](auto&&... args) { +constexpr auto ReplacedIn = [](auto&&... args) -> std::optional { ((void) args, ...); - return false; + return std::nullopt; }; #endif }; // namespace Extensions