From 656e7fc674e1d61d549eb8ae49d042727b18749a Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Wed, 19 Jun 2024 12:02:54 -0400 Subject: [PATCH] Implement/match more LegoPlantManager functions (#1040) --- .../legoomni/include/legobuildingmanager.h | 2 +- .../lego/legoomni/include/legoplantmanager.h | 14 +- .../src/common/legobuildingmanager.cpp | 2 +- .../legoomni/src/common/legoplantmanager.cpp | 127 ++++++++++++++++-- LEGO1/lego/legoomni/src/entity/legoworld.cpp | 8 +- 5 files changed, 132 insertions(+), 21 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legobuildingmanager.h b/LEGO1/lego/legoomni/include/legobuildingmanager.h index 5ca8a06f..8514985f 100644 --- a/LEGO1/lego/legoomni/include/legobuildingmanager.h +++ b/LEGO1/lego/legoomni/include/legobuildingmanager.h @@ -68,7 +68,7 @@ class LegoBuildingManager : public MxCore { void Init(); void FUN_1002fa00(); void CreateBuilding(MxS32 p_index, LegoWorld* p_world); - void FUN_1002fb30(); + void Reset(); MxResult Write(LegoStorage* p_storage); MxResult Read(LegoStorage* p_storage); LegoBuildingInfo* GetInfo(LegoEntity* p_entity); diff --git a/LEGO1/lego/legoomni/include/legoplantmanager.h b/LEGO1/lego/legoomni/include/legoplantmanager.h index 2db3dc6e..f1eb0544 100644 --- a/LEGO1/lego/legoomni/include/legoplantmanager.h +++ b/LEGO1/lego/legoomni/include/legoplantmanager.h @@ -28,7 +28,7 @@ class LegoPlantManager : public MxCore { void Init(); void LoadWorldInfo(MxS32 p_worldId); - void FUN_100263a0(undefined4 p_und); + void Reset(MxS32 p_worldId); MxResult Write(LegoStorage* p_storage); MxResult Read(LegoStorage* p_storage); MxBool SwitchColor(LegoEntity* p_entity); @@ -49,14 +49,16 @@ class LegoPlantManager : public MxCore { private: LegoEntity* CreatePlant(MxS32 p_index, LegoWorld* p_world, MxS32 p_worldId); + void RemovePlant(MxS32 p_index, MxS32 p_worldId); + void FUN_10026860(MxS32 p_index); static char* g_customizeAnimFile; - MxS32 m_worldId; // 0x08 - undefined m_unk0x0c; // 0x0c - undefined m_unk0x10[0x17]; // 0x10 - undefined m_unk0x24; // 0x24 - undefined4 m_unk0x28; // 0x28 + MxS32 m_worldId; // 0x08 + undefined m_unk0x0c; // 0x0c + undefined* m_unk0x10[5]; // 0x10 + MxS8 m_unk0x24; // 0x24 + undefined4 m_unk0x28; // 0x28 }; #endif // LEGOPLANTMANAGER_H diff --git a/LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp b/LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp index ad4551c8..88b443b5 100644 --- a/LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp @@ -304,7 +304,7 @@ void LegoBuildingManager::CreateBuilding(MxS32 p_index, LegoWorld* p_world) } // FUNCTION: LEGO1 0x1002fb30 -void LegoBuildingManager::FUN_1002fb30() +void LegoBuildingManager::Reset() { MxU32 i; diff --git a/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp b/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp index 793de4f5..09739ae6 100644 --- a/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp @@ -5,6 +5,9 @@ #include "legoplants.h" #include "legoworld.h" #include "misc.h" +#include "misc/legostorage.h" +#include "scripts.h" +#include "sndanim_actions.h" #include @@ -18,6 +21,12 @@ const char* g_plantLodNames[4][5] = { {"palmwht", "palmblk", "palmyel", "palmred", "palm"} }; +// GLOBAL: LEGO1 0x100f16b0 +float g_unk0x100f16b0[] = {0.1f, 0.7f, 0.5f, 0.9f}; + +// GLOBAL: LEGO1 0x100f16c0 +MxU8 g_unk0x100f16c0[] = {1, 2, 2, 3}; + // GLOBAL: LEGO1 0x100f3188 char* LegoPlantManager::g_customizeAnimFile = NULL; @@ -63,10 +72,24 @@ void LegoPlantManager::LoadWorldInfo(MxS32 p_worldId) m_unk0x0c = 0; } -// STUB: LEGO1 0x100263a0 -void LegoPlantManager::FUN_100263a0(undefined4 p_und) +// FUNCTION: LEGO1 0x100263a0 +void LegoPlantManager::Reset(MxS32 p_worldId) { - // TODO + MxU32 i; + DeleteObjects(g_sndAnimScript, SndanimScript::c_AnimC1, SndanimScript::c_AnimBld18); + + for (i = 0; i < m_unk0x24; i++) { + delete m_unk0x10[i]; + } + + m_unk0x24 = 0; + + for (i = 0; i < sizeOfArray(g_plantInfo); i++) { + RemovePlant(i, p_worldId); + } + + m_worldId = -1; + m_unk0x0c = 0; } // FUNCTION: LEGO1 0x10026590 @@ -108,20 +131,106 @@ LegoEntity* LegoPlantManager::CreatePlant(MxS32 p_index, LegoWorld* p_world, MxS return entity; } -// STUB: LEGO1 0x10026720 +// FUNCTION: LEGO1 0x100266c0 +// FUNCTION: BETA10 0x100c5859 +void LegoPlantManager::RemovePlant(MxS32 p_index, MxS32 p_worldId) +{ + if (p_index < sizeOfArray(g_plantInfo)) { + MxU32 world = 1 << (MxU8) p_worldId; + + if (g_plantInfo[p_index].m_worlds & world && g_plantInfo[p_index].m_entity != NULL) { + CharacterManager()->ReleaseAutoROI(g_plantInfo[p_index].m_entity->GetROI()); + g_plantInfo[p_index].m_entity = NULL; + } + } +} + +// FUNCTION: LEGO1 0x10026720 // FUNCTION: BETA10 0x100c5918 MxResult LegoPlantManager::Write(LegoStorage* p_storage) { - // TODO - return SUCCESS; + MxResult result = FAILURE; + + for (MxS32 i = 0; i < sizeOfArray(g_plantInfo); i++) { + LegoPlantInfo* info = &g_plantInfo[i]; + + if (p_storage->Write(&info->m_variant, sizeof(info->m_variant)) != SUCCESS) { + goto done; + } + if (p_storage->Write(&info->m_sound, sizeof(info->m_sound)) != SUCCESS) { + goto done; + } + if (p_storage->Write(&info->m_move, sizeof(info->m_move)) != SUCCESS) { + goto done; + } + if (p_storage->Write(&info->m_mood, sizeof(info->m_mood)) != SUCCESS) { + goto done; + } + if (p_storage->Write(&info->m_color, sizeof(info->m_color)) != SUCCESS) { + goto done; + } + if (p_storage->Write(&info->m_initialUnk0x16, sizeof(info->m_initialUnk0x16)) != SUCCESS) { + goto done; + } + } + + result = SUCCESS; + +done: + return result; } -// STUB: LEGO1 0x100267b0 +// FUNCTION: LEGO1 0x100267b0 // FUNCTION: BETA10 0x100c5a76 MxResult LegoPlantManager::Read(LegoStorage* p_storage) { - // TODO - return SUCCESS; + MxResult result = FAILURE; + + for (MxS32 i = 0; i < sizeOfArray(g_plantInfo); i++) { + LegoPlantInfo* info = &g_plantInfo[i]; + + if (p_storage->Read(&info->m_variant, sizeof(info->m_variant)) != SUCCESS) { + goto done; + } + if (p_storage->Read(&info->m_sound, sizeof(info->m_sound)) != SUCCESS) { + goto done; + } + if (p_storage->Read(&info->m_move, sizeof(info->m_move)) != SUCCESS) { + goto done; + } + if (p_storage->Read(&info->m_mood, sizeof(info->m_mood)) != SUCCESS) { + goto done; + } + if (p_storage->Read(&info->m_color, sizeof(info->m_color)) != SUCCESS) { + goto done; + } + if (p_storage->Read(&info->m_unk0x16, sizeof(info->m_unk0x16)) != SUCCESS) { + goto done; + } + + info->m_initialUnk0x16 = info->m_unk0x16; + FUN_10026860(i); + } + + result = SUCCESS; + +done: + return result; +} + +// FUNCTION: LEGO1 0x10026860 +// FUNCTION: BETA10 0x100c5be0 +void LegoPlantManager::FUN_10026860(MxS32 p_index) +{ + MxU8 variant = g_plantInfo[p_index].m_variant; + + if (g_plantInfo[p_index].m_unk0x16 >= 0) { + float value = g_unk0x100f16c0[variant] - g_plantInfo[p_index].m_unk0x16; + g_plantInfo[p_index].m_position[1] = g_plantInfoInit[p_index].m_position[1] - value * g_unk0x100f16b0[variant]; + } + else { + g_plantInfo[p_index].m_position[1] = g_plantInfoInit[p_index].m_position[1]; + } } // STUB: LEGO1 0x10026920 diff --git a/LEGO1/lego/legoomni/src/entity/legoworld.cpp b/LEGO1/lego/legoomni/src/entity/legoworld.cpp index 608ec193..de9c3c63 100644 --- a/LEGO1/lego/legoomni/src/entity/legoworld.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoworld.cpp @@ -178,8 +178,8 @@ void LegoWorld::Destroy(MxBool p_fromDestructor) } if (m_worldId != -1 && m_set0xd0.empty()) { - PlantManager()->FUN_100263a0(m_worldId); - BuildingManager()->FUN_1002fb30(); + PlantManager()->Reset(m_worldId); + BuildingManager()->Reset(); } if (m_entityList) { @@ -715,8 +715,8 @@ void LegoWorld::Enable(MxBool p_enable) m_set0xd0.insert(this); if (m_worldId != -1) { - PlantManager()->FUN_100263a0(m_worldId); - BuildingManager()->FUN_1002fb30(); + PlantManager()->Reset(m_worldId); + BuildingManager()->Reset(); } MxPresenterListCursor controlPresenterCursor(&m_controlPresenters);