Isle
Loading...
Searching...
No Matches
police.cpp
Go to the documentation of this file.
1#include "police.h"
2
3#include "jukebox.h"
4#include "jukebox_actions.h"
6#include "legogamestate.h"
7#include "legoinputmanager.h"
8#include "legomain.h"
9#include "misc.h"
12#include "mxmisc.h"
14#include "mxtransitionmanager.h"
15#include "police_actions.h"
16#include "scripts.h"
17
20
21// FUNCTION: LEGO1 0x1005e130
23{
24 m_policeState = NULL;
25 m_destLocation = LegoGameState::e_undefined;
27}
28
29// FUNCTION: LEGO1 0x1005e320
31{
32 if (InputManager()->GetWorld() == this) {
34 }
35
37 InputManager()->UnRegister(this);
39}
40
41// FUNCTION: LEGO1 0x1005e3e0
43{
44 MxResult ret = LegoWorld::Create(p_dsAction);
45 if (ret == SUCCESS) {
46 InputManager()->SetWorld(this);
47 ControlManager()->Register(this);
48 }
49
51 InputManager()->Register(this);
52
53 LegoGameState* gameState = GameState();
54 PoliceState* policeState = (PoliceState*) gameState->GetState("PoliceState");
55 if (!policeState) {
56 policeState = (PoliceState*) gameState->CreateState("PoliceState");
57 }
58
59 m_policeState = policeState;
62 return ret;
63}
64
65// FUNCTION: LEGO1 0x1005e480
66// FUNCTION: BETA10 0x100f04a3
68{
69 MxLong result = 0;
70 MxNotificationParam& param = (MxNotificationParam&) p_param;
71 LegoWorld::Notify(p_param);
72
73 if (m_worldStarted) {
74 switch (param.GetNotification()) {
76 result = HandleEndAction((MxEndActionNotificationParam&) p_param);
77 break;
79 result = HandleKeyPress(((LegoEventNotificationParam&) p_param));
80 break;
82 result = HandleControl((LegoControlManagerNotificationParam&) p_param);
83 break;
85 GameState()->SwitchArea(m_destLocation);
86 break;
87 }
88 }
89
90 return result;
91}
92
93// FUNCTION: LEGO1 0x1005e530
95{
99}
100
101// FUNCTION: LEGO1 0x1005e550
102MxLong Police::HandleControl(LegoControlManagerNotificationParam& p_param)
103{
104 if (p_param.m_unk0x28 == 1) {
105 switch (p_param.m_clickedObjectId) {
108 if (m_policeState->GetUnknown0x0c() == 1) {
110 }
111
113 m_destLocation = LegoGameState::Area::e_polidoor;
115 break;
117 if (m_policeState->GetUnknown0x0c() == 1) {
119 }
120
122 m_destLocation = LegoGameState::Area::e_infomain;
124 break;
126 if (m_policeState->GetUnknown0x0c() == 1) {
128 }
129
131 m_destLocation = LegoGameState::Area::e_copterbuild;
133 break;
135 m_policeState->FUN_1005ea40();
136 }
137 }
138
139 return 1;
140}
141
142// FUNCTION: LEGO1 0x1005e6a0
143MxLong Police::HandleEndAction(MxEndActionNotificationParam& p_param)
144{
145 MxDSAction* action = p_param.GetAction();
146
147 if (m_radio.Notify(p_param) == 0 && m_atomId == action->GetAtomId()) {
148 if (m_policeState->GetUnknown0x0c() == 1) {
149 m_policeState->SetUnknown0x0c(0);
150 return 1;
151 }
152
153 return 0;
154 }
155
156 return 0;
157}
158
159// FUNCTION: LEGO1 0x1005e6f0
160MxLong Police::HandleKeyPress(LegoEventNotificationParam& p_param)
161{
162 MxLong result = 0;
163
164 if (p_param.GetKey() == VK_SPACE && m_policeState->GetUnknown0x0c() == 1) {
166 m_policeState->SetUnknown0x0c(0);
167 return 1;
168 }
169
170 return 0;
171}
172
173// FUNCTION: LEGO1 0x1005e740
174void Police::Enable(MxBool p_enable)
175{
176 LegoWorld::Enable(p_enable);
177
178 if (p_enable) {
179 InputManager()->SetWorld(this);
181 }
182 else {
183 if (InputManager()->GetWorld() == this) {
185 }
186 }
187}
188
189// FUNCTION: LEGO1 0x1005e790
191{
193 m_destLocation = LegoGameState::e_infomain;
194 return TRUE;
195}
196
197// FUNCTION: LEGO1 0x1005e7c0
199{
200 m_unk0x0c = 0;
202}
203
204// FUNCTION: LEGO1 0x1005e990
205// FUNCTION: BETA10 0x100f08b0
207{
208 LegoState::Serialize(p_storage);
209
210 if (p_storage->IsReadMode()) {
211 p_storage->ReadS32((MxS32&) m_policeScript);
212 }
213 else {
214 p_storage->WriteS32(m_policeScript);
215 }
216
217 return SUCCESS;
218}
219
220// FUNCTION: LEGO1 0x1005ea40
222{
223 PoliceScript::Script policeScript;
224
225 if (m_unk0x0c == 1) {
226 return;
227 }
228
229 switch (UserActor()->GetActorId()) {
232 m_policeScript = policeScript;
233 break;
236 m_policeScript = policeScript;
237 break;
238 default:
239 policeScript = m_policeScript;
242 }
243
244 {
245 MxDSAction action;
246 action.SetObjectId(policeScript);
247 action.SetAtomId(*g_policeScript);
248 Start(&action);
249 }
250
251 m_unk0x0c = 1;
252}
@ c_nick
Nick ([AI])
Definition: legoactor.h:20
@ c_laura
Laura ([AI])
Definition: legoactor.h:21
[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]
MxS16 m_unk0x28
[AI] Undetermined; settable via SetUnknown0x28. [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.
Notification parameter class for LEGO event notifications such as mouse events and modifier keys.
MxU8 GetKey() const
Returns the keycode for this event, or 0 if not used.
Comprehensive persistent game state manager: handles save/load, player selection, area switching,...
Definition: legogamestate.h:78
void SwitchArea(Area p_area)
Switches the whole game state into a new area/world; manages transitions/scene loads.
Area m_currentArea
Area/world the player is presently in. [AI].
LegoState * CreateState(const char *p_stateName)
Creates an instance of given state, registers it, and returns pointer.
void StopArea(Area p_area)
Calls cleanup logic for the specified area (removes actors, VMs, closes handles, etc....
LegoState * GetState(const char *p_stateName)
Find an existing state (LegoState-derived) object by its registered script/class name.
@ e_infomain
Information Center, main screen. [AI].
Definition: legogamestate.h:96
@ e_previousArea
Alias: go to previous area. [AI].
Definition: legogamestate.h:94
@ e_police
Police Station interior. [AI].
@ e_copterbuild
Vehicle construction: helicopter. [AI].
@ e_polidoor
Police Station door. [AI].
@ e_undefined
Undefined or unset area. [AI].
Definition: legogamestate.h:93
void UnRegister(MxCore *)
[AI] Unregister a previously registered recipient so it will no longer receive input notifications.
void ClearWorld()
[AI] Remove any world assignment (used to clear targeting/scene changes). [AI]
void SetWorld(LegoWorld *p_world)
[AI] Assigns the current world to receive mouse/click/pick notifications.
void Register(MxCore *)
[AI] Register a core object as a recipient for keyboard events; safe for concurrent multi-threading.
@ c_clearScreen
[AI] When set, clears the display surface. [AI]
Definition: legomain.h:49
@ c_disable3d
[AI] When set, disables 3D rendering. [AI]
Definition: legomain.h:48
@ c_disableInput
[AI] When set, disables input processing. [AI]
Definition: legomain.h:47
virtual MxResult Serialize(LegoStorage *p_storage)
[AI] Serialize state to a storage (for save/load).
Definition: legostate.h:141
Abstract base class providing an interface for file-like storage with binary and text read/write oper...
Definition: legostorage.h:16
LegoStorage * ReadS32(MxS32 &p_data)
Reads a 32-bit signed value from storage.
Definition: legostorage.h:240
virtual LegoBool IsReadMode()
Returns TRUE if object was opened in read mode.
Definition: legostorage.h:78
LegoStorage * WriteS32(MxS32 p_data)
Writes a 32-bit signed value to storage.
Definition: legostorage.h:133
virtual void ReadyWorld()
Called when the world is ready to be used—typically for custom scene setup after startup.
Definition: legoworld.cpp:874
virtual void Enable(MxBool p_enable)
Enables or disables (pauses) the world and its main components.
Definition: legoworld.cpp:684
MxBool m_worldStarted
Indicates if the world has successfully started and is considered active.
Definition: legoworld.h:388
MxLong Notify(MxParam &p_param) override
Notification callback responding to registered events such as EndAction and NewPresenter.
Definition: legoworld.cpp:212
MxResult Create(MxDSAction &p_dsAction) override
Initializes the world using an action, creating entity and sound lists, and camera controller.
Definition: legoworld.cpp:58
MxDSAction * GetAction()
[AI] Direct access to the underlying action.
void Stop()
[AI] Immediately stops all background music, clears all actions and presenters, and resets tickle sta...
[AI] Represents an action deserialized from SI chunks, holding key animation or script parameters suc...
Definition: mxdsaction.h:17
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
[AI] Notification parameter marking the end of an action, specialization of MxActionNotificationParam...
MxAtomId m_atomId
The AtomId associated with this entity, used for resource and script identification.
Definition: mxentity.h:124
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
MxResult StartTransition(TransitionType p_animationType, MxS32 p_speed, MxBool p_doCopy, MxBool p_playMusicInAnim)
[AI] Begins a new transition animation of type p_animationType at the specified speed,...
@ e_mosaic
[AI] Complex mosaic block-out effect.
[AI] Represents the state information specific to the Police area of the game.
Definition: police.h:19
void SetUnknown0x0c(undefined4 p_unk0x0c)
[AI] Set the value of the internal state variable at offset 0x0c.
Definition: police.h:53
void FUN_1005ea40()
[AI] Trigger the "donut" animation event.
Definition: police.cpp:221
PoliceState()
[AI] Constructs a new PoliceState. Initializes script and internal state. [AI]
Definition: police.cpp:198
MxResult Serialize(LegoStorage *p_storage) override
[AI] Serialize the PoliceState to or from the provided storage.
Definition: police.cpp:206
undefined4 GetUnknown0x0c()
[AI] Returns the value of the internal state variable at offset 0x0c.
Definition: police.h:49
PoliceScript::Script m_policeScript
[AI] The currently active animation/script for the Police state (e.g. which minifig or animation runs...
Definition: police.h:60
undefined4 m_unk0x0c
[AI] Internal flag to indicate whether the donut animation has started (1), finished (0),...
Definition: police.h:64
[AI] Main world object for the Police Station area in LEGO Island.
Definition: police.h:71
void Enable(MxBool p_enable) override
[AI] Enables or disables the Police world for input and activity.
Definition: police.cpp:174
~Police() override
[AI] Destructor: deregisters world from managers and clears input/world pointers. [AI]
Definition: police.cpp:30
MxBool Escape() override
[AI] Handles user request to exit the Police area (e.g., Escape key).
Definition: police.cpp:190
MxResult Create(MxDSAction &p_dsAction) override
[AI] Handles world creation, input setup, and PoliceState initialization.
Definition: police.cpp:42
MxLong Notify(MxParam &p_param) override
[AI] Handle incoming notifications (key presses, controls, end actions, transitions).
Definition: police.cpp:67
void ReadyWorld() override
[AI] Prepares the Police world for activation, setting music and disabling user input/3d as needed....
Definition: police.cpp:94
MxLong Notify(MxParam &p_param) override
[AI] Handles system notifications (end actions, control events) relevant to the radio.
Definition: radio.cpp:85
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
LegoGameState * GameState()
[AI] Accessor for the game's central game state controller. [AI]
Definition: misc.cpp:61
void DeleteObjects(MxAtomId *p_id, MxS32 p_first, MxS32 p_last)
[AI] Batch deletes objects, given by atom id, and within the entity id range [p_first,...
Definition: misc.cpp:237
MxTransitionManager * TransitionManager()
[AI] Accessor for the MxTransitionManager, handling level transitions, fades, and world changes....
Definition: misc.cpp:208
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
void FUN_10015820(MxBool p_disable, MxU16 p_flags)
[AI] Utility for enabling or disabling functionality in LegoOmni based on certain flags.
Definition: misc.cpp:143
void PlayMusic(JukeboxScript::Script p_objectId)
[AI] Starts music playback by scripting the background audio manager to play the music piece referenc...
Definition: misc.cpp:216
LegoPathActor * UserActor()
[AI] Accessor for the user (player-controllable) LegoPathActor. [AI]
Definition: misc.cpp:85
void SetIsWorldActive(MxBool p_isWorldActive)
[AI] Toggles whether the world should be considered active (enables/disables camera/user control etc)...
Definition: misc.cpp:228
LegoInputManager * InputManager()
[AI] Accessor for the input manager, which handles keyboard, mouse, and controller input....
Definition: misc.cpp:45
MxResult Start(MxDSAction *p_dsAction)
[AI] Schedules and initiates execution of a script action.
Definition: mxmisc.cpp:97
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_notificationKeyPress
[AI] Keyboard key press detected [AI]
@ c_notificationTransitioned
[AI] Object has transitioned states or locations [AI]
@ c_notificationEndAction
[AI] Indicates the end of an action [AI]
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
int MxLong
[AI]
Definition: mxtypes.h:83
signed int MxS32
[AI]
Definition: mxtypes.h:38
@ c_PoliceStation_Music
[AI] Music played inside or near the police station.
[AI] Contains global script AtomId pointers and utility functions for managing script AtomIds in LEGO...
MxAtomId * g_policeScript
[AI] Script AtomId for the police station script logic.
Definition: scripts.cpp:57