From 5f822dabc71bed5a0ce6b4c3f852b6b611666f9a Mon Sep 17 00:00:00 2001
From: Christian Semmler <mail@csemmler.com>
Date: Mon, 28 Oct 2024 10:32:55 -0700
Subject: [PATCH] Implement/match PizzeriaState::PizzeriaState (#1124)

---
 LEGO1/lego/legoomni/include/legostate.h       | 19 ++++++-----
 LEGO1/lego/legoomni/include/pizzeria.h        | 13 ++-----
 LEGO1/lego/legoomni/src/actors/pizzeria.cpp   | 34 +++++++++++++++++--
 LEGO1/lego/legoomni/src/actors/radio.cpp      | 18 +++++-----
 LEGO1/lego/legoomni/src/worlds/infocenter.cpp | 19 ++++++-----
 5 files changed, 63 insertions(+), 40 deletions(-)

diff --git a/LEGO1/lego/legoomni/include/legostate.h b/LEGO1/lego/legoomni/include/legostate.h
index 9aabc4da..23a8599e 100644
--- a/LEGO1/lego/legoomni/include/legostate.h
+++ b/LEGO1/lego/legoomni/include/legostate.h
@@ -27,6 +27,7 @@ public:
 		};
 
 		// FUNCTION: LEGO1 0x10017c00
+		// FUNCTION: BETA10 0x10031dc0
 		Playlist()
 		{
 			m_objectIds = NULL;
@@ -35,28 +36,30 @@ public:
 			m_nextIndex = 0;
 		}
 
-		Playlist(MxU32* p_objectIds, MxS16 p_length)
+		// FUNCTION: BETA10 0x10031e10
+		Playlist(MxU32* p_objectIds, MxS16 p_length, MxS16 p_mode)
 		{
 			m_objectIds = p_objectIds;
 			m_length = p_length;
-			m_mode = e_loop;
+			m_mode = p_mode;
 			m_nextIndex = 0;
 		}
 
 		// FUNCTION: LEGO1 0x10071800
-		Playlist& operator=(const Playlist& p_shuffle)
+		// FUNCTION: BETA10 0x10031e70
+		Playlist& operator=(const Playlist& p_playlist)
 		{
-			m_objectIds = p_shuffle.m_objectIds;
-			m_length = p_shuffle.m_length;
-			m_nextIndex = p_shuffle.m_nextIndex;
-			m_mode = p_shuffle.m_mode;
+			m_objectIds = p_playlist.m_objectIds;
+			m_length = p_playlist.m_length;
+			m_nextIndex = p_playlist.m_nextIndex;
+			m_mode = p_playlist.m_mode;
 			return *this;
 		}
 
 		MxU32 Next();
 		MxBool Contains(MxU32 p_objectId);
 
-		void SetUnknown0x08(MxS16 p_unk0x08) { m_nextIndex = p_unk0x08; }
+		void SetNextIndex(MxS16 p_nextIndex) { m_nextIndex = p_nextIndex; }
 
 		MxResult ReadFromFile(LegoFile* p_file)
 		{
diff --git a/LEGO1/lego/legoomni/include/pizzeria.h b/LEGO1/lego/legoomni/include/pizzeria.h
index 9544a071..69ea1b9d 100644
--- a/LEGO1/lego/legoomni/include/pizzeria.h
+++ b/LEGO1/lego/legoomni/include/pizzeria.h
@@ -11,15 +11,6 @@ class PizzaMissionState;
 // SIZE 0x58
 class PizzeriaState : public LegoState {
 public:
-	// SIZE 0x14
-	struct StateStruct {
-		undefined4 m_unk0x00; // 0x00
-		undefined4 m_unk0x04; // 0x04
-		undefined4 m_unk0x08; // 0x08
-		undefined4 m_unk0x0c; // 0x0c
-		undefined4 m_unk0x10; // 0x10
-	};
-
 	PizzeriaState();
 
 	// FUNCTION: LEGO1 0x10017c20
@@ -45,8 +36,8 @@ public:
 
 	// TODO: Most likely getters/setters are not used according to BETA.
 
-	Playlist m_unk0x08[5]; // 0x08
-	StateStruct m_unk0x44; // 0x44
+	Playlist m_unk0x08[5];   // 0x08
+	undefined4 m_unk0x44[5]; // 0x44
 };
 
 // VTABLE: LEGO1 0x100d5520
diff --git a/LEGO1/lego/legoomni/src/actors/pizzeria.cpp b/LEGO1/lego/legoomni/src/actors/pizzeria.cpp
index c9135eb1..2f8e2642 100644
--- a/LEGO1/lego/legoomni/src/actors/pizzeria.cpp
+++ b/LEGO1/lego/legoomni/src/actors/pizzeria.cpp
@@ -13,7 +13,26 @@
 
 DECOMP_SIZE_ASSERT(Pizzeria, 0x84)
 DECOMP_SIZE_ASSERT(PizzeriaState, 0x58)
-DECOMP_SIZE_ASSERT(PizzeriaState::StateStruct, 0x14)
+
+// GLOBAL: LEGO1 0x100f0ce8
+IsleScript::Script g_unk0x100f0ce8[] =
+	{IsleScript::c_ppz107ma_RunAnim, IsleScript::c_ppz114pa_RunAnim, IsleScript::c_ppz114pa_RunAnim};
+
+// GLOBAL: LEGO1 0x100f0cf8
+IsleScript::Script g_unk0x100f0cf8[] =
+	{IsleScript::c_ppz001pe_RunAnim, IsleScript::c_ppz006pa_RunAnim, IsleScript::c_ppz007pa_RunAnim};
+
+// GLOBAL: LEGO1 0x100f0d08
+IsleScript::Script g_unk0x100f0d08[] =
+	{IsleScript::c_ppz054ma_RunAnim, IsleScript::c_ppz055ma_RunAnim, IsleScript::c_ppz056ma_RunAnim};
+
+// GLOBAL: LEGO1 0x100f0d18
+IsleScript::Script g_unk0x100f0d18[] =
+	{IsleScript::c_ppz031ma_RunAnim, IsleScript::c_ppz035pa_RunAnim, IsleScript::c_ppz036pa_RunAnim};
+
+// GLOBAL: LEGO1 0x100f0d28
+IsleScript::Script g_unk0x100f0d28[] =
+	{IsleScript::c_ppz075pa_RunAnim, IsleScript::c_ppz082pa_RunAnim, IsleScript::c_ppz084pa_RunAnim};
 
 // FUNCTION: LEGO1 0x100179c0
 MxResult Pizzeria::Create(MxDSAction& p_dsAction)
@@ -28,6 +47,7 @@ MxResult Pizzeria::Create(MxDSAction& p_dsAction)
 }
 
 // FUNCTION: LEGO1 0x100179f0
+// FUNCTION: BETA10 0x100efbfc
 void Pizzeria::CreateState()
 {
 	LegoGameState* gameState = GameState();
@@ -46,6 +66,7 @@ void Pizzeria::CreateState()
 }
 
 // FUNCTION: LEGO1 0x10017a50
+// FUNCTION: BETA10 0x100efc91
 MxLong Pizzeria::HandleClick()
 {
 	if (FUN_1003ef60() && m_pizzaMissionState->m_unk0x0c == 0) {
@@ -64,10 +85,16 @@ MxLong Pizzeria::HandleClick()
 	return 1;
 }
 
-// STUB: LEGO1 0x10017af0
+// FUNCTION: LEGO1 0x10017af0
+// FUNCTION: BETA10 0x100efd14
 PizzeriaState::PizzeriaState()
 {
-	// TODO
+	m_unk0x08[0] = Playlist((MxU32*) g_unk0x100f0ce8, sizeOfArray(g_unk0x100f0ce8), Playlist::e_once);
+	m_unk0x08[1] = Playlist((MxU32*) g_unk0x100f0cf8, sizeOfArray(g_unk0x100f0cf8), Playlist::e_once);
+	m_unk0x08[2] = Playlist((MxU32*) g_unk0x100f0d08, sizeOfArray(g_unk0x100f0d08), Playlist::e_once);
+	m_unk0x08[3] = Playlist((MxU32*) g_unk0x100f0d18, sizeOfArray(g_unk0x100f0d18), Playlist::e_once);
+	m_unk0x08[4] = Playlist((MxU32*) g_unk0x100f0d28, sizeOfArray(g_unk0x100f0d28), Playlist::e_once);
+	memset(m_unk0x44, -1, sizeof(m_unk0x44));
 }
 
 // STUB: LEGO1 0x10017d50
@@ -77,6 +104,7 @@ MxS16 PizzeriaState::FUN_10017d50()
 }
 
 // STUB: LEGO1 0x10017d70
+// FUNCTION: BETA10 0x100effc0
 MxU32 PizzeriaState::FUN_10017d70()
 {
 	return 0;
diff --git a/LEGO1/lego/legoomni/src/actors/radio.cpp b/LEGO1/lego/legoomni/src/actors/radio.cpp
index 4704ca29..3a22ed16 100644
--- a/LEGO1/lego/legoomni/src/actors/radio.cpp
+++ b/LEGO1/lego/legoomni/src/actors/radio.cpp
@@ -18,7 +18,7 @@ DECOMP_SIZE_ASSERT(Radio, 0x10)
 DECOMP_SIZE_ASSERT(RadioState, 0x30)
 
 // GLOBAL: LEGO1 0x100f3218
-JukeboxScript::Script g_unk0x100f3218[6] = {
+JukeboxScript::Script g_unk0x100f3218[] = {
 	JukeboxScript::c_sns002ra_Audio,
 	JukeboxScript::c_sns001ja_Audio,
 	JukeboxScript::c_snsc01js_Audio,
@@ -28,7 +28,7 @@ JukeboxScript::Script g_unk0x100f3218[6] = {
 };
 
 // GLOBAL: LEGO1 0x100f3230
-JukeboxScript::Script g_unk0x100f3230[14] = {
+JukeboxScript::Script g_unk0x100f3230[] = {
 	JukeboxScript::c_ham035ra_Audio,
 	JukeboxScript::c_ham039ra_Audio,
 	JukeboxScript::c_sns005ra_Audio,
@@ -46,7 +46,7 @@ JukeboxScript::Script g_unk0x100f3230[14] = {
 };
 
 // GLOBAL: LEGO1 0x100f3268
-JukeboxScript::Script g_unk0x100f3268[9] = {
+JukeboxScript::Script g_unk0x100f3268[] = {
 	JukeboxScript::c_CentralRoads_Music,
 	JukeboxScript::c_BeachBlvd_Music,
 	JukeboxScript::c_ResidentalArea_Music,
@@ -214,14 +214,14 @@ RadioState::RadioState()
 	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[0] = Playlist((MxU32*) g_unk0x100f3218, sizeOfArray(g_unk0x100f3218), Playlist::e_loop);
+	m_unk0x08[0].SetNextIndex(rand() % sizeOfArray(g_unk0x100f3218));
 
-	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[1] = Playlist((MxU32*) g_unk0x100f3230, sizeOfArray(g_unk0x100f3230), Playlist::e_loop);
+	m_unk0x08[1].SetNextIndex(rand() % sizeOfArray(g_unk0x100f3230));
 
-	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_unk0x08[2] = Playlist((MxU32*) g_unk0x100f3268, sizeOfArray(g_unk0x100f3268), Playlist::e_loop);
+	m_unk0x08[2].SetNextIndex(rand() % sizeOfArray(g_unk0x100f3268));
 
 	m_active = FALSE;
 }
diff --git a/LEGO1/lego/legoomni/src/worlds/infocenter.cpp b/LEGO1/lego/legoomni/src/worlds/infocenter.cpp
index 48e04d38..8e882e75 100644
--- a/LEGO1/lego/legoomni/src/worlds/infocenter.cpp
+++ b/LEGO1/lego/legoomni/src/worlds/infocenter.cpp
@@ -1549,28 +1549,29 @@ void Infocenter::StopBookAnimation()
 // FUNCTION: LEGO1 0x10071600
 InfocenterState::InfocenterState()
 {
-	m_exitDialogueAct1 = LegoState::Playlist((MxU32*) g_exitDialogueAct1, sizeOfArray(g_exitDialogueAct1));
-	m_exitDialogueAct23 = LegoState::Playlist((MxU32*) g_exitDialogueAct23, sizeOfArray(g_exitDialogueAct23) - 1);
+	m_exitDialogueAct1 = Playlist((MxU32*) g_exitDialogueAct1, sizeOfArray(g_exitDialogueAct1), Playlist::e_loop);
+	m_exitDialogueAct23 =
+		Playlist((MxU32*) g_exitDialogueAct23, sizeOfArray(g_exitDialogueAct23) - 1, Playlist::e_loop);
 
 	m_returnDialogue[LegoGameState::e_act1] =
-		LegoState::Playlist((MxU32*) g_returnDialogueAct1, sizeOfArray(g_returnDialogueAct1) - 1);
+		Playlist((MxU32*) g_returnDialogueAct1, sizeOfArray(g_returnDialogueAct1) - 1, Playlist::e_loop);
 
 	m_returnDialogue[LegoGameState::e_act2] =
-		LegoState::Playlist((MxU32*) g_returnDialogueAct2, sizeOfArray(g_returnDialogueAct2) - 1);
+		Playlist((MxU32*) g_returnDialogueAct2, sizeOfArray(g_returnDialogueAct2) - 1, Playlist::e_loop);
 
 	m_returnDialogue[LegoGameState::e_act3] =
-		LegoState::Playlist((MxU32*) g_returnDialogueAct3, sizeOfArray(g_returnDialogueAct3));
+		Playlist((MxU32*) g_returnDialogueAct3, sizeOfArray(g_returnDialogueAct3), Playlist::e_loop);
 
 	m_leaveDialogue[LegoGameState::e_act1] =
-		LegoState::Playlist((MxU32*) g_leaveDialogueAct1, sizeOfArray(g_leaveDialogueAct1));
+		Playlist((MxU32*) g_leaveDialogueAct1, sizeOfArray(g_leaveDialogueAct1), Playlist::e_loop);
 
 	m_leaveDialogue[LegoGameState::e_act2] =
-		LegoState::Playlist((MxU32*) g_leaveDialogueAct2, sizeOfArray(g_leaveDialogueAct2));
+		Playlist((MxU32*) g_leaveDialogueAct2, sizeOfArray(g_leaveDialogueAct2), Playlist::e_loop);
 
 	m_leaveDialogue[LegoGameState::e_act3] =
-		LegoState::Playlist((MxU32*) g_leaveDialogueAct3, sizeOfArray(g_leaveDialogueAct3) - 1);
+		Playlist((MxU32*) g_leaveDialogueAct3, sizeOfArray(g_leaveDialogueAct3) - 1, Playlist::e_loop);
 
-	m_bricksterDialogue = LegoState::Playlist((MxU32*) g_bricksterDialogue, sizeOfArray(g_bricksterDialogue));
+	m_bricksterDialogue = Playlist((MxU32*) g_bricksterDialogue, sizeOfArray(g_bricksterDialogue), Playlist::e_loop);
 
 	memset(m_letters, 0, sizeof(m_letters));
 }