Isle
Loading...
Searching...
No Matches
legogamestate.h
Go to the documentation of this file.
1#ifndef LEGOGAMESTATE_H
2#define LEGOGAMESTATE_H
3
4#include "actionsfwd.h"
5#include "decomp.h"
6#include "mxtypes.h"
7#include "mxvariable.h"
8
9#include <string.h>
10
11class LegoFile;
12class LegoState;
13class LegoStorage;
14class MxVariableTable;
15class MxString;
16
17extern const char* g_actorNames[7];
18
23 const char* m_targetName;
24 const char* m_colorName;
25};
26
31public:
33 LegoBackgroundColor(const char* p_key, const char* p_value);
34
38 void SetValue(const char* p_colorString) override;
39
44 void SetLightColor(float p_r, float p_g, float p_b);
45
47 void SetLightColor();
48
51 void ToggleDayNight(MxBool p_sun);
52
54 void ToggleSkyColor();
55
56private:
57 float m_h;
58 float m_s;
59 float m_v;
60};
61
66public:
68 LegoFullScreenMovie(const char* p_key, const char* p_value);
69
72 void SetValue(const char* p_option) override;
73};
74
79public:
82 enum Act {
86 e_act3
87 };
88
92 enum Area {
159 e_unk66 = 66
160 };
161
164 struct Username {
165 Username();
168 void Set(Username& p_other) { memcpy(m_letters, p_other.m_letters, sizeof(m_letters)); }
169
172 MxResult Serialize(LegoStorage* p_storage);
174 Username& operator=(const Username& p_other);
175
177 };
178
181 struct ScoreItem {
184 MxResult Serialize(LegoStorage* p_storage);
185
190 };
191
194 struct History {
195 History();
197 void WriteScoreHistory();
199 MxResult Serialize(LegoStorage* p_storage);
205 ScoreItem* FUN_1003cc90(Username* p_player, MxS16 p_unk0x24, MxS32& p_unk0x2c);
206
208 MxS16 GetCount() { return m_count; }
209
212 ScoreItem* GetScore(MxS32 p_index) { return p_index >= m_count ? NULL : &m_scores[p_index]; }
213
217 };
218
221
225 void SetActor(MxU8 p_actorId);
226
229 void RemoveActor();
230
232 void ResetROI();
233
236 MxResult Save(MxULong p_slot);
237
240
243 MxResult Load(MxULong p_slot);
244
247 void SerializePlayersInfo(MxS16 p_flags);
248
252 MxResult AddPlayer(Username& p_player);
253
257 void SwitchPlayer(MxS16 p_playerId);
258
262 MxS16 FindPlayer(Username& p_player);
263
266 void SerializeScoreHistory(MxS16 p_flags);
267
270 void SetSavePath(char* p_savePath);
271
274 LegoState* GetState(const char* p_stateName);
275
278 LegoState* CreateState(const char* p_stateName);
279
283 void GetFileSavePath(MxString* p_outPath, MxS16 p_slotn);
284
288 void StopArea(Area p_area);
289
293 void SwitchArea(Area p_area);
294
296 void Init();
297
299 MxU8 GetActorId() { return m_actorId; }
300
302 const char* GetActorName() { return g_actorNames[GetActorId()]; }
303
305 Act GetCurrentAct() { return m_currentAct; }
306
308 Act GetLoadedAct() { return m_loadedAct; }
313
316 void SetDirty(MxBool p_isDirty) { m_isDirty = p_isDirty; }
317
320 void SetPreviousArea(Area p_previousArea) { m_previousArea = p_previousArea; }
321
324 void SetActorId(MxU8 p_actorId) { m_actorId = p_actorId; }
325
328 Username* GetPlayersIndex(MxS32 p_index) { return &m_players[p_index]; }
329
332
334 LegoBackgroundColor* GetBackgroundColor() { return m_backgroundColor; }
335
338 void SetCurrentAct(Act p_currentAct);
339
341 void FindLoadedAct();
342
345 void RegisterState(LegoState* p_state);
346
347private:
352 MxResult WriteVariable(LegoStorage* p_storage, MxVariableTable* p_from, const char* p_variableName);
353
356 MxResult WriteEndOfVariables(LegoStorage* p_storage);
357
361 MxS32 ReadVariable(LegoStorage* p_storage, MxVariableTable* p_to);
362
364 void SetColors();
365
367 void SetROIColorOverride();
368
369 // === Main persistent game state variables ===
370
371 char* m_savePath;
372 MxS16 m_stateCount;
373 LegoState** m_stateArray;
374 MxU8 m_actorId;
375 Act m_currentAct;
376 Act m_loadedAct;
377 LegoBackgroundColor* m_backgroundColor;
378 LegoBackgroundColor* m_tempBackgroundColor;
379 LegoFullScreenMovie* m_fullScreenMovie;
380
381 // === Exposed/game-managed slots for player and area data ===
382
383public:
394};
395
402MxBool ROIColorOverride(const char* p_input, char* p_output, MxU32 p_copyLen);
403
404#endif // LEGOGAMESTATE_H
Variable controlling the sky background color (HSV) and related light color in the game.
Definition: legogamestate.h:30
void SetLightColor()
Sets the light color according to the current HSV parameters. [AI].
void SetValue(const char *p_colorString) override
Sets the value of the background color using a command string.
void ToggleSkyColor()
Rotates hue to cycle sky color (e.g. progressing through the day), updating all visuals....
void ToggleDayNight(MxBool p_sun)
Adjusts the saturation (day/night) and updates sky color and light accordingly.
Implementation of LegoStorage for file-backed storage using stdio FILE*.
Definition: legostorage.h:387
Variable controlling full screen movie playback in the video manager.
Definition: legogamestate.h:65
void SetValue(const char *p_option) override
Sets the option to enable or disable fullscreen movies.
Comprehensive persistent game state manager: handles save/load, player selection, area switching,...
Definition: legogamestate.h:78
MxS16 GetPlayerCount()
Gets the number of player slots currently used. [AI].
void GetFileSavePath(MxString *p_outPath, MxS16 p_slotn)
Writes the full save path for the given slot to the output string object.
Username * GetPlayersIndex(MxS32 p_index)
Gets a pointer to a player username in the array by index.
MxS16 m_playerCount
Number of player usernames registered. [AI].
void SwitchPlayer(MxS16 p_playerId)
Make the specified player (by ID/index) the current player.
Act GetCurrentAct()
Returns the active act that is currently in play. [AI].
Area GetUnknown0x42c()
Gets the value of m_unk0x42c (used for act area save/load mechanics). [AI].
void SerializeScoreHistory(MxS16 p_flags)
Serializes the score history table to score file.
MxS16 m_unk0x24
Serial/generation marker used for score records. [AI].
void SwitchArea(Area p_area)
Switches the whole game state into a new area/world; manages transitions/scene loads.
void SetPreviousArea(Area p_previousArea)
Sets the previous area for reload/stop logic.
JukeboxScript::Script m_jukeboxMusic
Which jukebox music is currently set to play. [AI].
History m_history
High score table/history for current game. [AI].
void SetCurrentAct(Act p_currentAct)
Sets the current game act.
const char * GetActorName()
Returns the actor name, based on the current actor ID. [AI].
void Init()
Re-initializes all world/variable state to the current act's defaults. [AI].
void ResetROI()
Re-applies the current actor's ROI to the 3D world (remove/add for update). [AI].
Area m_currentArea
Area/world the player is presently in. [AI].
MxBool m_isDirty
TRUE if unsaved changes present. [AI].
Area m_unk0x42c
Used for act area storage on save/load. [AI].
void SetSavePath(char *p_savePath)
Sets the path for current save slot directory; creates a copy of input string.
void SetActorId(MxU8 p_actorId)
Directly sets the current actor ID (preferred: use SetActor).
LegoState * CreateState(const char *p_stateName)
Creates an instance of given state, registers it, and returns pointer.
LegoBackgroundColor * GetBackgroundColor()
Gets the main background color variable object. [AI].
Act
Indicates which main storyline section (Act 1/2/3) is currently active.
Definition: legogamestate.h:82
@ e_act3
Act 3: final main story segment. [AI].
Definition: legogamestate.h:86
@ e_act1
Act 1: the first main segment of the game. [AI].
Definition: legogamestate.h:84
@ e_actNotFound
No act currently loaded (does not correspond to valid play). [AI].
Definition: legogamestate.h:83
@ e_act2
Act 2: main story segment two. [AI].
Definition: legogamestate.h:85
void StopArea(Area p_area)
Calls cleanup logic for the specified area (removes actors, VMs, closes handles, etc....
undefined2 m_unk0x41a
Unknown (padding or unused). [AI].
void RegisterState(LegoState *p_state)
Registers a state object, replacing by class if already present.
MxResult DeleteState()
Destroys and removes all current state objects, freeing memory and unregistering. [AI].
MxU8 GetActorId()
Returns the current selected actor ID. [AI].
void SerializePlayersInfo(MxS16 p_flags)
Serializes all player info (usernames, player count) to the appropriate storage.
Area m_previousArea
Where player was before last area switch. [AI].
Username m_players[9]
Array of all known player usernames (max 9, ranked). [AI].
MxResult Save(MxULong p_slot)
Saves persistent game state (world variables, actor, etc.) to a file slot.
void RemoveActor()
Removes (and deletes) the current user actor from the world.
void FindLoadedAct()
Analyses the loaded Lego worlds to determine which act is present. [AI].
LegoState * GetState(const char *p_stateName)
Find an existing state (LegoState-derived) object by its registered script/class name.
MxS16 FindPlayer(Username &p_player)
Finds the player index for a username; returns -1 if not found.
Area
Enumeration of all major in-game locations ("areas") for area/scene management and serialization.
Definition: legogamestate.h:92
@ e_infomain
Information Center, main screen. [AI].
Definition: legogamestate.h:96
@ e_unk20
Unknown [AI].
@ e_unk43
Unknown [AI].
@ e_previousArea
Alias: go to previous area. [AI].
Definition: legogamestate.h:94
@ e_unk31
Unknown [AI].
@ e_motocycle
Motorcycle (vehicle, spawn). [AI].
@ e_dunecarbuild
Vehicle construction: dune buggy. [AI].
@ e_unk49
Unknown [AI].
@ e_racecarbuild
Vehicle construction: racecar. [AI].
@ e_bike
Bike minigame (spawns). [AI].
@ e_police
Police Station interior. [AI].
@ e_elevdown
Elevator moving down (animated). [AI].
@ e_unk50
Unknown [AI].
@ e_copter
Helicopter (vehicle, spawn). [AI].
@ e_unk66
Used for some spawn locations. [AI].
@ e_hospitalExterior
Hospital, seen from outside. [AI].
@ e_unk40
Unknown [AI].
@ e_dunecar
Dune buggy (vehicle, for spawn). [AI].
@ e_act3script
Act 3 world/script main. [AI].
@ e_unk41
Unknown [AI].
@ e_act2main
Act 2 world main screen. [AI].
@ e_jetraceExterior
Jetski race transition? [AI].
@ e_carrace
Car race (track, main). [AI].
@ e_elevride2
Elevator ride/cab down (animated). [AI].
@ e_garageExterior
Garage (vehicle construction) exterior. [AI].
@ e_unk42
Unknown [AI].
@ e_garage
Garage (build vehicle) interior. [AI].
@ e_unk55
Unknown [AI].
@ e_garadoor
Garage door or doorway. [AI].
@ e_copterbuild
Vehicle construction: helicopter. [AI].
@ e_jetrace
Jetski race area, "interior"/main. [AI].
@ e_polidoor
Police Station door. [AI].
@ e_jukeboxw
Western Jukebox (special minigame). [AI].
@ e_isle
Open world (LEGO Island main map). [AI].
Definition: legogamestate.h:95
@ e_regbook
Registration book "new game" area. [AI].
@ e_unk51
Unknown [AI].
@ e_histbook
History book (scoreboard). [AI].
@ e_jetrace2
Jetski race (exterior). [AI].
@ e_pizzeriaExterior
Pizzeria, seen from outside. [AI].
@ e_unk28
Used for certain spawn locations. [AI].
@ e_unk45
Unknown [AI].
@ e_infoscor
Info Center hi-score area. [AI].
@ e_towtrack
Towtruck (vehicle, spawn). [AI].
@ e_undefined
Undefined or unset area. [AI].
Definition: legogamestate.h:93
@ e_unk33
Used for certain player spawns. [AI].
@ e_skateboard
Skateboard (vehicle, spawn). [AI].
@ e_elevride
Elevator ride/cab up (animated). [AI].
@ e_jetskibuild
Vehicle construction: jetski. [AI].
@ e_unk4
Unknown / possibly reserved. [AI].
Definition: legogamestate.h:98
@ e_jukeboxExterior
Jukebox, seen from outside. [AI].
@ e_unk23
Unknown [AI].
@ e_elevbott
Elevator bottom. [AI].
Definition: legogamestate.h:99
@ e_unk24
Unknown [AI].
@ e_unk44
Unknown [AI].
@ e_unk21
Unknown [AI].
@ e_unk48
Unknown [AI].
@ e_observe
Observatory interior. [AI].
@ e_ambulance
Ambulance (vehicle, spawn). [AI].
@ e_hospital
Hospital interior. [AI].
@ e_policeExterior
Police Station, from outside. [AI].
@ e_carraceExterior
Car race exterior/transition. [AI].
@ e_infodoor
Info Center door/title view. [AI].
Definition: legogamestate.h:97
@ e_seaview
Ocean-side view at observatory. [AI].
@ e_unk52
Unknown [AI].
@ e_elevopen
Elevator doors open. [AI].
@ e_unk17
Unknown. [AI].
@ e_jetski
Jetski (vehicle, spawn). [AI].
MxResult Load(MxULong p_slot)
Loads persistent game state from specified save slot.
Area GetPreviousArea()
Gets the last area before the current one. [AI].
Act GetLoadedAct()
Returns the act that is currently loaded in memory. [AI].
void SetActor(MxU8 p_actorId)
Change the player character in the world to the given actor ID.
void SetDirty(MxBool p_isDirty)
Sets whether there are unsaved changes to the state.
MxResult AddPlayer(Username &p_player)
Adds a new player (username), moves others down, manages slot files.
[AI] Base class for game state blocks which encapsulate serializable and/or resettable aspects of the...
Definition: legostate.h:17
Abstract base class providing an interface for file-like storage with binary and text read/write oper...
Definition: legostorage.h:16
Mindscape custom string class for managing dynamic C-strings within the game engine.
Definition: mxstring.h:14
MxVariableTable is a specialized hash table for storing key/value string variables used by the LEGO I...
[AI] Represents a key-value variable as used in the variable table for the LEGO Island engine.
Definition: mxvariable.h:16
unsigned short undefined2
Definition: decomp.h:27
const char * g_actorNames[7]
Array of actor names indexed by actor ID. [AI].
Definition: legoactor.cpp:13
MxBool ROIColorOverride(const char *p_input, char *p_output, MxU32 p_copyLen)
Helper for ROI color override mechanism, mapping special part labels to variable table values.
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
signed short MxS16
[AI]
Definition: mxtypes.h:26
unsigned char MxU8
[AI]
Definition: mxtypes.h:8
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned int MxULong
[AI]
Definition: mxtypes.h:93
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
Key-value pair tying a ROI color key name to a LEGO color string.
Definition: legogamestate.h:22
const char * m_targetName
The internal ROI color key (e.g. "c_rcsidey0"). [AI].
Definition: legogamestate.h:23
const char * m_colorName
The LEGO color name for that part (e.g. "lego red"). [AI].
Definition: legogamestate.h:24
Collection of best scores for all recent plays/players (high score table).
ScoreItem * FUN_1003cc90(Username *p_player, MxS16 p_unk0x24, MxS32 &p_unk0x2c)
Looks up a score entry for player and attempt index, or returns NULL if not found.
MxS16 m_unk0x372
Serial/sequence field incremented for each player. [AI].
ScoreItem m_scores[20]
Score history; sorted by total score descending. [AI].
void WriteScoreHistory()
Rebuilds the high score table from current state objects, sorts it descending. [AI].
ScoreItem * GetScore(MxS32 p_index)
Gets pointer to score entry at index, or NULL if out of range.
MxResult Serialize(LegoStorage *p_storage)
Serializes whole history, including all score item slots, to the provided storage/backend....
MxS16 m_count
Count of active/used score history entries. [AI].
MxS16 GetCount()
Current number of score entries in the history. [AI].
Single score record for a player, including high score grids for all major games.
Username m_name
Username this score belongs to. [AI].
MxResult Serialize(LegoStorage *p_storage)
Reads/writes the ScoreItem to/from storage.
MxS16 m_totalScore
The total score calculated from all minigames. [AI].
MxU8 m_scores[5][5]
Scores by (minigame,row,column): custom packed format for all 5 game types. [AI].
MxS16 m_unk0x2a
(Purpose: Each play/attempt index?) [AI]
Player "username", stored as 7 short integers (character codes).
MxS16 m_letters[7]
Array of 7 wide characters: player name (filled by registration). [AI].
void Set(Username &p_other)
Set this username by copying another.
Username & operator=(const Username &p_other)
Assignment, deep-copy of letter buffer [AI].
MxResult Serialize(LegoStorage *p_storage)
Reads or writes username as S16 array to/from the given storage.