2023-06-29 04:10:08 -04:00
|
|
|
#include "radio.h"
|
|
|
|
|
2024-03-18 11:05:05 -04:00
|
|
|
#include "isle_actions.h"
|
2024-06-03 12:53:25 -04:00
|
|
|
#include "jukebox_actions.h"
|
2023-12-14 18:24:21 -05:00
|
|
|
#include "legocontrolmanager.h"
|
|
|
|
#include "legogamestate.h"
|
2024-05-03 12:19:12 -04:00
|
|
|
#include "legoworld.h"
|
2024-03-09 15:07:52 -05:00
|
|
|
#include "misc.h"
|
2024-05-03 12:19:12 -04:00
|
|
|
#include "mxactionnotificationparam.h"
|
2024-01-30 13:57:20 -05:00
|
|
|
#include "mxbackgroundaudiomanager.h"
|
|
|
|
#include "mxcontrolpresenter.h"
|
2024-03-09 15:07:52 -05:00
|
|
|
#include "mxmisc.h"
|
2023-12-14 18:24:21 -05:00
|
|
|
#include "mxnotificationmanager.h"
|
2024-06-03 12:53:25 -04:00
|
|
|
#include "mxtimer.h"
|
2024-05-04 08:06:32 -04:00
|
|
|
#include "scripts.h"
|
2023-12-14 18:24:21 -05:00
|
|
|
|
2024-03-22 21:30:58 -04:00
|
|
|
DECOMP_SIZE_ASSERT(Radio, 0x10)
|
2024-06-03 12:53:25 -04:00
|
|
|
DECOMP_SIZE_ASSERT(RadioState, 0x30)
|
|
|
|
|
|
|
|
// GLOBAL: LEGO1 0x100f3218
|
|
|
|
JukeboxScript::Script g_unk0x100f3218[6] = {
|
|
|
|
JukeboxScript::c_sns002ra_Audio,
|
|
|
|
JukeboxScript::c_sns001ja_Audio,
|
|
|
|
JukeboxScript::c_snsc01js_Audio,
|
|
|
|
JukeboxScript::c_snsb01js_Audio,
|
|
|
|
JukeboxScript::c_snsa01js_Audio,
|
|
|
|
JukeboxScript::c_sns009ra_Audio
|
|
|
|
};
|
|
|
|
|
|
|
|
// GLOBAL: LEGO1 0x100f3230
|
|
|
|
JukeboxScript::Script g_unk0x100f3230[14] = {
|
|
|
|
JukeboxScript::c_ham035ra_Audio,
|
|
|
|
JukeboxScript::c_ham039ra_Audio,
|
|
|
|
JukeboxScript::c_sns005ra_Audio,
|
|
|
|
JukeboxScript::c_sns078pa_Audio,
|
|
|
|
JukeboxScript::c_ham036ra_Audio,
|
|
|
|
JukeboxScript::c_sns006ra_Audio,
|
|
|
|
JukeboxScript::c_sns013ra_Audio,
|
|
|
|
JukeboxScript::c_sns004ra_Audio,
|
|
|
|
JukeboxScript::c_sns079pa_Audio,
|
|
|
|
JukeboxScript::c_sns007ra_Audio,
|
|
|
|
JukeboxScript::c_sns008ra_Audio,
|
|
|
|
JukeboxScript::c_hpz037ma_Audio,
|
|
|
|
JukeboxScript::c_sns003ra_Audio,
|
|
|
|
JukeboxScript::c_sns010ra_Audio,
|
|
|
|
};
|
|
|
|
|
|
|
|
// GLOBAL: LEGO1 0x100f3268
|
|
|
|
JukeboxScript::Script g_unk0x100f3268[9] = {
|
|
|
|
JukeboxScript::c_CentralRoads_Music,
|
|
|
|
JukeboxScript::c_BeachBlvd_Music,
|
|
|
|
JukeboxScript::c_ResidentalArea_Music,
|
|
|
|
JukeboxScript::c_Radio1_Music,
|
|
|
|
JukeboxScript::c_Radio2_Music,
|
|
|
|
JukeboxScript::c_Radio3_Music,
|
|
|
|
JukeboxScript::c_Radio4_Music,
|
|
|
|
JukeboxScript::c_Radio5_Music,
|
|
|
|
JukeboxScript::c_Radio6_Music,
|
|
|
|
};
|
2023-12-14 18:24:21 -05:00
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002c850
|
|
|
|
Radio::Radio()
|
|
|
|
{
|
|
|
|
NotificationManager()->Register(this);
|
|
|
|
ControlManager()->Register(this);
|
|
|
|
|
2024-01-29 16:17:17 -05:00
|
|
|
m_unk0x0c = TRUE;
|
2024-05-24 14:07:36 -04:00
|
|
|
CreateState();
|
2023-12-14 18:24:21 -05:00
|
|
|
}
|
|
|
|
|
2024-01-30 13:57:20 -05:00
|
|
|
// FUNCTION: LEGO1 0x1002c990
|
2023-06-29 04:10:08 -04:00
|
|
|
Radio::~Radio()
|
|
|
|
{
|
2024-01-30 13:57:20 -05:00
|
|
|
if (m_state->IsActive()) {
|
|
|
|
BackgroundAudioManager()->Stop();
|
|
|
|
m_state->SetActive(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlManager()->Unregister(this);
|
|
|
|
NotificationManager()->Unregister(this);
|
2023-10-25 14:51:59 -04:00
|
|
|
}
|
2023-12-14 18:24:21 -05:00
|
|
|
|
2024-01-30 13:57:20 -05:00
|
|
|
// FUNCTION: LEGO1 0x1002ca30
|
2024-01-20 18:04:46 -05:00
|
|
|
MxLong Radio::Notify(MxParam& p_param)
|
|
|
|
{
|
2024-01-30 13:57:20 -05:00
|
|
|
MxLong result = 0;
|
|
|
|
|
|
|
|
if (m_unk0x0c) {
|
2024-06-13 14:10:19 -04:00
|
|
|
switch (((MxNotificationParam&) p_param).GetNotification()) {
|
2024-01-30 13:57:20 -05:00
|
|
|
case c_notificationEndAction:
|
|
|
|
result = HandleEndAction((MxEndActionNotificationParam&) p_param);
|
|
|
|
break;
|
2024-05-30 09:54:24 -04:00
|
|
|
case c_notificationControl:
|
2024-06-16 10:47:53 -04:00
|
|
|
result = HandleControl((LegoControlManagerNotificationParam&) p_param);
|
2024-01-30 13:57:20 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002ca70
|
|
|
|
void Radio::Play()
|
|
|
|
{
|
|
|
|
if (!m_state->IsActive()) {
|
2024-02-02 12:18:46 -05:00
|
|
|
CurrentWorld();
|
2024-01-30 13:57:20 -05:00
|
|
|
|
|
|
|
MxDSAction action;
|
|
|
|
action.SetObjectId(m_state->FUN_1002d090());
|
|
|
|
action.SetAtomId(*g_jukeboxScript);
|
|
|
|
action.SetLoopCount(1);
|
|
|
|
|
2024-02-14 11:48:39 -05:00
|
|
|
m_audioEnabled = BackgroundAudioManager()->GetEnabled();
|
|
|
|
if (!m_audioEnabled) {
|
2024-01-30 13:57:20 -05:00
|
|
|
BackgroundAudioManager()->Enable(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundAudioManager()->PlayMusic(action, 3, 4);
|
|
|
|
m_state->SetActive(TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002cb70
|
|
|
|
void Radio::Stop()
|
|
|
|
{
|
|
|
|
if (m_state->IsActive()) {
|
2024-02-02 12:18:46 -05:00
|
|
|
LegoWorld* world = CurrentWorld();
|
2024-01-30 13:57:20 -05:00
|
|
|
|
2024-08-12 12:21:18 -04:00
|
|
|
MxControlPresenter* presenter = (MxControlPresenter*) world->Find(world->GetAtomId(), IsleScript::c_Radio_Ctl);
|
2024-01-30 13:57:20 -05:00
|
|
|
|
2024-02-01 15:42:10 -05:00
|
|
|
if (presenter) {
|
2024-01-30 13:57:20 -05:00
|
|
|
presenter->VTable0x6c(0);
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2024-01-30 13:57:20 -05:00
|
|
|
|
|
|
|
BackgroundAudioManager()->Stop();
|
2024-02-14 11:48:39 -05:00
|
|
|
BackgroundAudioManager()->Enable(m_audioEnabled);
|
2024-01-30 13:57:20 -05:00
|
|
|
m_state->SetActive(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002cbc0
|
2024-06-16 10:47:53 -04:00
|
|
|
MxLong Radio::HandleControl(LegoControlManagerNotificationParam& p_param)
|
2024-01-30 13:57:20 -05:00
|
|
|
{
|
|
|
|
MxDSAction action; // Unused
|
|
|
|
MxS32 objectId = p_param.GetClickedObjectId();
|
|
|
|
|
2024-03-18 11:05:05 -04:00
|
|
|
if (objectId == IsleScript::c_Radio_Ctl) {
|
2024-01-30 13:57:20 -05:00
|
|
|
if (m_state->IsActive()) {
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Play();
|
|
|
|
}
|
|
|
|
|
2024-02-02 12:18:46 -05:00
|
|
|
if (CurrentWorld()) {
|
2024-01-30 13:57:20 -05:00
|
|
|
#ifdef COMPAT_MODE
|
2024-05-31 17:15:35 -04:00
|
|
|
MxNotificationParam param(c_notificationType0, this);
|
2024-02-02 12:18:46 -05:00
|
|
|
CurrentWorld()->Notify(param);
|
2024-01-30 13:57:20 -05:00
|
|
|
#else
|
2024-02-02 12:18:46 -05:00
|
|
|
CurrentWorld()->Notify(MxNotificationParam(c_notificationType0, this));
|
2024-01-30 13:57:20 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002ccc0
|
|
|
|
MxLong Radio::HandleEndAction(MxEndActionNotificationParam& p_param)
|
|
|
|
{
|
|
|
|
if (m_state->IsActive() &&
|
|
|
|
m_state->FUN_1002d0c0(p_param.GetAction()->GetAtomId(), p_param.GetAction()->GetObjectId())) {
|
|
|
|
|
|
|
|
MxDSAction action;
|
|
|
|
action.SetAtomId(*g_jukeboxScript);
|
|
|
|
action.SetObjectId(m_state->FUN_1002d090());
|
|
|
|
action.SetLoopCount(1);
|
|
|
|
|
|
|
|
BackgroundAudioManager()->PlayMusic(action, 3, 4);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:04:46 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-01-21 12:38:22 -05:00
|
|
|
// FUNCTION: LEGO1 0x1002cdc0
|
|
|
|
void Radio::Initialize(MxBool p_und)
|
|
|
|
{
|
2024-01-29 16:17:17 -05:00
|
|
|
if (m_unk0x0c != p_und) {
|
|
|
|
m_unk0x0c = p_und;
|
2024-05-24 14:07:36 -04:00
|
|
|
CreateState();
|
2024-01-21 12:38:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-14 18:24:21 -05:00
|
|
|
// FUNCTION: LEGO1 0x1002cde0
|
2024-05-24 14:07:36 -04:00
|
|
|
void Radio::CreateState()
|
2023-12-14 18:24:21 -05:00
|
|
|
{
|
|
|
|
LegoGameState* gameState = GameState();
|
|
|
|
RadioState* state = (RadioState*) gameState->GetState("RadioState");
|
|
|
|
if (state == NULL) {
|
|
|
|
state = (RadioState*) gameState->CreateState("RadioState");
|
|
|
|
}
|
|
|
|
|
|
|
|
m_state = state;
|
|
|
|
}
|
2024-06-03 12:53:25 -04:00
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002ce10
|
|
|
|
RadioState::RadioState()
|
|
|
|
{
|
|
|
|
srand(Timer()->GetTime());
|
|
|
|
|
|
|
|
MxS32 random = rand();
|
|
|
|
m_unk0x2c = random % 3;
|
|
|
|
|
|
|
|
m_unk0x08[0] = LegoState::Playlist((MxU32*) g_unk0x100f3218, sizeof(g_unk0x100f3218) / sizeof(g_unk0x100f3218[0]));
|
|
|
|
m_unk0x08[0].SetUnknown0x08(rand() % (sizeof(g_unk0x100f3218) / sizeof(g_unk0x100f3218[0])));
|
|
|
|
|
|
|
|
m_unk0x08[1] = LegoState::Playlist((MxU32*) g_unk0x100f3230, sizeof(g_unk0x100f3230) / sizeof(g_unk0x100f3230[0]));
|
|
|
|
m_unk0x08[1].SetUnknown0x08(rand() % (sizeof(g_unk0x100f3230) / sizeof(g_unk0x100f3230[0])));
|
|
|
|
|
|
|
|
m_unk0x08[2] = LegoState::Playlist((MxU32*) g_unk0x100f3268, sizeof(g_unk0x100f3268) / sizeof(g_unk0x100f3268[0]));
|
|
|
|
m_unk0x08[2].SetUnknown0x08(rand() % (sizeof(g_unk0x100f3268) / sizeof(g_unk0x100f3268[0])));
|
|
|
|
|
|
|
|
m_active = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002cf50
|
|
|
|
MxBool RadioState::IsSerializable()
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002d090
|
|
|
|
MxU32 RadioState::FUN_1002d090()
|
|
|
|
{
|
|
|
|
if (m_unk0x2c == 2) {
|
|
|
|
m_unk0x2c = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_unk0x2c++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_unk0x08[m_unk0x2c].Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002d0c0
|
|
|
|
MxBool RadioState::FUN_1002d0c0(const MxAtomId& p_atom, MxU32 p_objectId)
|
|
|
|
{
|
|
|
|
if (*g_jukeboxScript == p_atom) {
|
|
|
|
for (MxS16 i = 0; i < 3; i++) {
|
|
|
|
if (m_unk0x08[i].Contains(p_objectId)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|