Isle
Loading...
Searching...
No Matches
radio.cpp
Go to the documentation of this file.
1#include "radio.h"
2
3#include "isle_actions.h"
4#include "jukebox_actions.h"
6#include "legogamestate.h"
7#include "legoworld.h"
8#include "misc.h"
11#include "mxcontrolpresenter.h"
12#include "mxmisc.h"
14#include "mxtimer.h"
15#include "scripts.h"
16
19
20// GLOBAL: LEGO1 0x100f3218
28};
29
30// GLOBAL: LEGO1 0x100f3230
46};
47
48// GLOBAL: LEGO1 0x100f3268
59};
60
61// FUNCTION: LEGO1 0x1002c850
63{
65 ControlManager()->Register(this);
66
67 m_unk0x0c = TRUE;
69}
70
71// FUNCTION: LEGO1 0x1002c990
73{
74 if (m_state->IsActive()) {
76 m_state->SetActive(FALSE);
77 }
78
81}
82
83// FUNCTION: LEGO1 0x1002ca30
84// FUNCTION: BETA10 0x100f19e8
86{
87 MxLong result = 0;
88
89 if (m_unk0x0c) {
90 MxNotificationParam& param = (MxNotificationParam&) p_param;
91 switch (param.GetNotification()) {
93 result = HandleEndAction((MxEndActionNotificationParam&) p_param);
94 break;
96 result = HandleControl((LegoControlManagerNotificationParam&) p_param);
97 break;
98 }
99 }
100
101 return result;
102}
103
104// FUNCTION: LEGO1 0x1002ca70
106{
107 if (!m_state->IsActive()) {
108 CurrentWorld();
109
110 MxDSAction action;
111 action.SetObjectId(m_state->FUN_1002d090());
112 action.SetAtomId(*g_jukeboxScript);
113 action.SetLoopCount(1);
114
115 m_audioEnabled = BackgroundAudioManager()->GetEnabled();
116 if (!m_audioEnabled) {
118 }
119
121 m_state->SetActive(TRUE);
122 }
123}
124
125// FUNCTION: LEGO1 0x1002cb70
127{
128 if (m_state->IsActive()) {
129 LegoWorld* world = CurrentWorld();
130
132
133 if (presenter) {
134 presenter->VTable0x6c(0);
135 }
136
138 BackgroundAudioManager()->Enable(m_audioEnabled);
139 m_state->SetActive(FALSE);
140 }
141}
142
143// FUNCTION: LEGO1 0x1002cbc0
144// FUNCTION: BETA10 0x100f1ce1
145MxLong Radio::HandleControl(LegoControlManagerNotificationParam& p_param)
146{
147 MxDSAction action; // Unused
148
149 switch (p_param.m_clickedObjectId) {
151 if (m_state->IsActive()) {
152 Stop();
153 }
154 else {
155 Play();
156 }
157
158 if (CurrentWorld()) {
159#ifdef COMPAT_MODE
161 CurrentWorld()->Notify(param);
162#else
164#endif
165 }
166
167 return 1;
168 }
169
170 return 0;
171}
172
173// FUNCTION: LEGO1 0x1002ccc0
174MxLong Radio::HandleEndAction(MxEndActionNotificationParam& p_param)
175{
176 if (m_state->IsActive() &&
177 m_state->FUN_1002d0c0(p_param.GetAction()->GetAtomId(), p_param.GetAction()->GetObjectId())) {
178
179 MxDSAction action;
180 action.SetAtomId(*g_jukeboxScript);
181 action.SetObjectId(m_state->FUN_1002d090());
182 action.SetLoopCount(1);
183
185 return 1;
186 }
187
188 return 0;
189}
190
191// FUNCTION: LEGO1 0x1002cdc0
193{
194 if (m_unk0x0c != p_und) {
195 m_unk0x0c = p_und;
196 CreateState();
197 }
198}
199
200// FUNCTION: LEGO1 0x1002cde0
202{
203 LegoGameState* gameState = GameState();
204 RadioState* state = (RadioState*) gameState->GetState("RadioState");
205 if (state == NULL) {
206 state = (RadioState*) gameState->CreateState("RadioState");
207 }
208
209 m_state = state;
210}
211
212// FUNCTION: LEGO1 0x1002ce10
213// FUNCTION: BETA10 0x100f20f6
215{
216 srand(Timer()->GetTime());
217
218 MxS32 random = rand();
219 m_unk0x2c = random % 3;
220
223
226
229
230 m_active = FALSE;
231}
232
233// FUNCTION: LEGO1 0x1002d090
235{
236 if (m_unk0x2c == 2) {
237 m_unk0x2c = 0;
238 }
239 else {
240 m_unk0x2c++;
241 }
242
243 return m_unk0x08[m_unk0x2c].Next();
244}
245
246// FUNCTION: LEGO1 0x1002d0c0
248{
249 if (*g_jukeboxScript == p_atom) {
250 for (MxS16 i = 0; i < 3; i++) {
251 if (m_unk0x08[i].Contains(p_objectId)) {
252 return TRUE;
253 }
254 }
255 }
256
257 return FALSE;
258}
[AI] Notification parameter for the LegoControlManager, used to propagate information about control e...
MxS32 m_clickedObjectId
[AI] Object ID of the clicked control/presenter (or -1 if not set). [AI]
void Register(MxCore *p_listener)
[AI] Adds a listener to be notified of control events.
void Unregister(MxCore *p_listener)
[AI] Removes a listener so it no longer receives control events.
Comprehensive persistent game state manager: handles save/load, player selection, area switching,...
Definition: legogamestate.h:78
LegoState * CreateState(const char *p_stateName)
Creates an instance of given state, registers it, and returns pointer.
LegoState * GetState(const char *p_stateName)
Find an existing state (LegoState-derived) object by its registered script/class name.
Represents the active 3D world, holding all entity, animation, sound, path, and ROI objects.
Definition: legoworld.h:49
MxCore * Find(const char *p_class, const char *p_name)
Finds an object of a given class and name in the world.
Definition: legoworld.cpp:573
MxLong Notify(MxParam &p_param) override
Notification callback responding to registered events such as EndAction and NewPresenter.
Definition: legoworld.cpp:212
MxDSAction * GetAction()
[AI] Direct access to the underlying action.
[AI] Atomized (unique) string identifier, managed by reference counting.
Definition: mxatom.h:124
void Enable(MxBool p_enable)
[AI] Enables or disables the background audio manager.
MxBool GetEnabled()
[AI] Returns whether background audio management is currently enabled.
MxResult PlayMusic(MxDSAction &p_action, undefined4 p_speed, MxPresenter::TickleState p_tickleState)
[AI] Initiates playback of a new background music action with specified speed and target tickle state...
void Stop()
[AI] Immediately stops all background music, clears all actions and presenters, and resets tickle sta...
[AI] Presenter for UI controls, supporting toggles, grids, and "map" style controls with multiple int...
virtual void VTable0x6c(MxS16 p_unk0x4e)
[AI] Selects a state/sub-control by index, or advances the currently selected state if -1 is provided...
[AI] Represents an action deserialized from SI chunks, holding key animation or script parameters suc...
Definition: mxdsaction.h:17
void SetLoopCount(MxS32 p_loopCount)
[AI] Sets the loop count for this action.
Definition: mxdsaction.h:209
const MxAtomId & GetAtomId()
[AI] Returns a const-reference to the object's atom identifier.
Definition: mxdsobject.h:133
virtual void SetAtomId(MxAtomId p_atomId)
[AI] Sets the atom id for this object instance, used for indexing or lookup.
Definition: mxdsobject.h:118
void SetObjectId(MxU32 p_objectId)
[AI] Sets the object id (for serialization or lookup).
Definition: mxdsobject.h:147
MxU32 GetObjectId()
[AI] Returns the object id numeric value.
Definition: mxdsobject.h:130
[AI] Notification parameter marking the end of an action, specialization of MxActionNotificationParam...
MxAtomId & GetAtomId()
Returns a reference to the entity AtomId.
Definition: mxentity.h:98
void Unregister(MxCore *p_listener)
[AI] Removes a previously registered listener and flushes any pending notifications for it.
void Register(MxCore *p_listener)
[AI] Registers a listener object to receive notifications.
[AI] Parameter object representing a single notification or event, carrying an identifier and sender ...
NotificationId GetNotification() const
[AI] Retrieves the current notification type of this parameter.
[AI] MxParam serves as a polymorphic base class for parameter passing in event and notification syste...
Definition: mxparam.h:7
@ e_repeating
[AI] Presentation is repeating (e.g., looping media).
Definition: mxpresenter.h:28
[AI] Handles and stores state for the in-game radio, including track playlists, cycling,...
Definition: radio.h:18
MxBool FUN_1002d0c0(const MxAtomId &p_atom, MxU32 p_objectId)
[AI] Checks if the given atom/object ID matches one of the radio's playlists.
Definition: radio.cpp:247
undefined4 FUN_1002d090()
[AI] Cycles to the next playlist and returns the next object ID to play.
Definition: radio.cpp:234
MxS16 m_unk0x2c
[AI] Index for cycling among the three playlists (0-2).
Definition: radio.h:65
MxBool m_active
[AI] If TRUE, the radio is playing; FALSE otherwise.
Definition: radio.h:67
MxBool IsActive()
[AI] Indicates whether the radio is currently playing.
Definition: radio.h:46
Playlist m_unk0x08[3]
[AI] Radio playlists. Each is a collection of track IDs used by the radio (effects,...
Definition: radio.h:63
RadioState()
[AI] Constructs a new RadioState, randomizing playlist indices and initial state.
Definition: radio.cpp:214
void SetActive(MxBool p_active)
[AI] Sets active status of the radio.
Definition: radio.h:50
[AI] High-level manager for the in-game radio, handling notifications, playing/stopping,...
Definition: radio.h:77
void Play()
[AI] Starts playing radio music if it is not already active.
Definition: radio.cpp:105
void Stop()
[AI] Stops radio playback if currently active and updates audio state.
Definition: radio.cpp:126
~Radio() override
[AI] Destructor; shuts down radio playback and unregisters events.
Definition: radio.cpp:72
MxLong Notify(MxParam &p_param) override
[AI] Handles system notifications (end actions, control events) relevant to the radio.
Definition: radio.cpp:85
void CreateState()
[AI] Creates or retrieves a RadioState object in the game state manager.
Definition: radio.cpp:201
Radio()
[AI] Constructs a new Radio, registering for notifications and control events.
Definition: radio.cpp:62
void Initialize(MxBool p_und)
[AI] Sets radio system as enabled/disabled and resets state if changed.
Definition: radio.cpp:192
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define sizeOfArray(arr)
Definition: decomp.h:23
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
LegoGameState * GameState()
[AI] Accessor for the game's central game state controller. [AI]
Definition: misc.cpp:61
MxBackgroundAudioManager * BackgroundAudioManager()
[AI] Accessor for the background audio manager. Used for background music and ambient sounds....
Definition: misc.cpp:37
LegoControlManager * ControlManager()
[AI] Accessor for the control manager through the input manager; manages higher-level user/game contr...
Definition: misc.cpp:53
LegoWorld * CurrentWorld()
[AI] Accessor for the currently active LegoWorld instance. [AI]
Definition: misc.cpp:93
MxTimer * Timer()
[AI] Returns the global simulation timer.
Definition: mxmisc.cpp:33
MxNotificationManager * NotificationManager()
[AI] Returns the notification manager for system-wide state/update notifications.
Definition: mxmisc.cpp:17
@ c_notificationControl
[AI] UI control event [AI]
@ c_notificationType0
[AI] Undefined/Generic notification type [AI]
@ c_notificationEndAction
[AI] Indicates the end of an action [AI]
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
int MxLong
[AI]
Definition: mxtypes.h:83
signed short MxS16
[AI]
Definition: mxtypes.h:26
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
@ c_sns009ra_Audio
[AI] Asset-coded audio/event track.
@ c_ham035ra_Audio
[AI] Asset-coded audio/event track.
@ c_sns008ra_Audio
[AI] Asset-coded audio/event track.
@ c_sns005ra_Audio
[AI] Asset-coded audio/event track.
@ c_BeachBlvd_Music
[AI] Music for Beach Boulevard.
@ c_ham036ra_Audio
[AI] Asset-coded audio/event track.
@ c_snsa01js_Audio
[AI] Asset-coded audio/event track.
@ c_Radio4_Music
[AI] Fourth radio track.
@ c_Radio1_Music
[AI] First of several radio tracks available via the radio.
@ c_sns003ra_Audio
[AI] Asset-coded audio/event track.
@ c_snsc01js_Audio
[AI] Special area/event audio track, asset code derived.
@ c_ResidentalArea_Music
[AI] Music for the residential area environment.
@ c_sns079pa_Audio
[AI] Asset-coded audio/event track.
@ c_sns078pa_Audio
[AI] Asset-coded audio/event track.
@ c_Radio3_Music
[AI] Third radio track.
@ c_sns007ra_Audio
[AI] Asset-coded audio/event track.
@ c_sns002ra_Audio
[AI] Specific alternate background/ambience used in an area or event. (Name based on asset codes....
@ c_Radio2_Music
[AI] Second radio track.
@ c_sns001ja_Audio
[AI] Special music/ambience, asset code derived.
@ c_sns006ra_Audio
[AI] Asset-coded audio/event track.
@ c_snsb01js_Audio
[AI] Asset-coded audio/event track.
@ c_sns010ra_Audio
[AI] Asset-coded audio/event track.
@ c_ham039ra_Audio
[AI] Asset-coded audio/event track.
@ c_sns004ra_Audio
[AI] Asset-coded audio/event track.
@ c_hpz037ma_Audio
[AI] Asset-coded audio/event track.
@ c_Radio5_Music
[AI] Fifth radio track.
@ c_CentralRoads_Music
[AI] Background music for LEGO Island central roads.
@ c_Radio6_Music
[AI] Sixth radio track.
@ c_sns013ra_Audio
[AI] Asset-coded audio/event track.
JukeboxScript::Script g_unk0x100f3268[]
Definition: radio.cpp:49
JukeboxScript::Script g_unk0x100f3230[]
Definition: radio.cpp:31
JukeboxScript::Script g_unk0x100f3218[]
Definition: radio.cpp:21
[AI] Contains global script AtomId pointers and utility functions for managing script AtomIds in LEGO...
MxAtomId * g_jukeboxScript
[AI] Script AtomId for the Jukebox entity/event script.
Definition: scripts.cpp:70
[AI] Playlist structure representing an indexed list of object IDs with next-item selection strategie...
Definition: legostate.h:36
MxU32 Next()
[AI] Retrieves the object ID at the current position, advances next index according to playlist mode.
Definition: legostate.cpp:10
MxS16 m_nextIndex
[AI] Current index for next selection (suitable for sequential/random access). [AI]
Definition: legostate.h:110