Skip to content

Commit

Permalink
Implement/match LegoPlantManager::CreatePlant (isledecomp#1039)
Browse files Browse the repository at this point in the history
* Implement/match LegoPlantManager::CreatePlant

* Update names

* Fix name

* Fix

* Fix
  • Loading branch information
foxtacles authored Jun 18, 2024
1 parent 1a46d37 commit e507f42
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 179 deletions.
4 changes: 2 additions & 2 deletions LEGO1/lego/legoomni/include/legoanimationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class LegoAnimationManager : public MxCore {
void Resume();
void FUN_1005f6d0(MxBool p_unk0x400);
void EnableCamAnims(MxBool p_enableCamAnims);
MxResult LoadScriptInfo(MxS32 p_scriptIndex);
MxResult LoadWorldInfo(MxS32 p_worldId);
MxBool FindVehicle(const char* p_name, MxU32& p_index);
MxResult ReadAnimInfo(LegoFile* p_file, AnimInfo* p_info);
MxResult ReadModelInfo(LegoFile* p_file, ModelInfo* p_info);
Expand Down Expand Up @@ -244,7 +244,7 @@ class LegoAnimationManager : public MxCore {
void FUN_100648f0(LegoTranInfo* p_tranInfo, MxLong p_unk0x404);
void FUN_10064b50(MxLong p_time);

MxS32 m_scriptIndex; // 0x08
MxS32 m_worldId; // 0x08
MxU16 m_animCount; // 0x0c
MxU16 m_unk0x0e; // 0x0e
MxU16 m_unk0x10; // 0x10
Expand Down
2 changes: 1 addition & 1 deletion LEGO1/lego/legoomni/include/legobuildingmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class LegoBuildingManager : public MxCore {

void Init();
void FUN_1002fa00();
void UpdatePosition(MxS32 p_index, LegoWorld* p_world);
void CreateBuilding(MxS32 p_index, LegoWorld* p_world);
void FUN_1002fb30();
MxResult Write(LegoStorage* p_storage);
MxResult Read(LegoStorage* p_storage);
Expand Down
28 changes: 14 additions & 14 deletions LEGO1/lego/legoomni/include/legomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ class LegoOmni : public MxOmni {
};

// SIZE 0x1c
struct ScriptContainer {
struct WorldContainer {
// FUNCTION: LEGO1 0x1005ac40
ScriptContainer()
WorldContainer()
{
m_index = -1;
m_id = -1;
m_atomId = NULL;
}

ScriptContainer(MxS32 p_index, const char* p_key, MxAtomId* p_atomId)
WorldContainer(MxS32 p_id, const char* p_key, MxAtomId* p_atomId)
{
m_index = p_index;
m_id = p_id;

if (p_key) {
strcpy(m_key, p_key);
Expand All @@ -58,18 +58,18 @@ class LegoOmni : public MxOmni {
}

// FUNCTION: LEGO1 0x1005ac50
ScriptContainer& operator=(const ScriptContainer& p_container)
WorldContainer& operator=(const WorldContainer& p_container)
{
m_index = p_container.m_index;
m_id = p_container.m_id;
strcpy(m_key, p_container.m_key);
m_atomId = p_container.m_atomId;
return *this;
}

inline MxS32 GetIndex() { return m_index; }
inline MxS32 GetId() { return m_id; }
inline const char* GetKey() { return m_key; }

MxS32 m_index; // 0x00
MxS32 m_id; // 0x00
char m_key[20]; // 0x04
MxAtomId* m_atomId; // 0x18
};
Expand Down Expand Up @@ -110,10 +110,10 @@ class LegoOmni : public MxOmni {
void FUN_1005b4f0(MxBool p_disable, MxU16 p_flags);
void CreateBackgroundAudio();
void RemoveWorld(const MxAtomId& p_atom, MxLong p_objectId);
MxResult RegisterScripts();
const char* GetScriptName(MxU32 p_index);
MxAtomId* GetScriptAtom(MxU32 p_index);
MxS32 GetScriptIndex(const char* p_key);
MxResult RegisterWorlds();
const char* GetWorldName(MxU32 p_id);
MxAtomId* GetWorldAtom(MxU32 p_id);
MxS32 GetWorldId(const char* p_key);
void DeleteAction();

static MxS32 GetCurrPathInfo(LegoPathBoundary**, MxS32&);
Expand Down Expand Up @@ -154,7 +154,7 @@ class LegoOmni : public MxOmni {
// LegoOmni::`scalar deleting destructor'

private:
ScriptContainer* m_scripts; // 0x68
WorldContainer* m_worlds; // 0x68
ViewLODListManager* m_viewLODListManager; // 0x6c
LegoInputManager* m_inputManager; // 0x70
LegoTextureContainer* m_textureContainer; // 0x74
Expand Down
7 changes: 5 additions & 2 deletions LEGO1/lego/legoomni/include/legoplantmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class LegoEntity;
class LegoPathBoundary;
class LegoROI;
class LegoStorage;
class LegoWorld;

// VTABLE: LEGO1 0x100d6758
// SIZE 0x2c
Expand All @@ -26,7 +27,7 @@ class LegoPlantManager : public MxCore {
}

void Init();
void FUN_10026360(MxS32 p_scriptIndex);
void LoadWorldInfo(MxS32 p_worldId);
void FUN_100263a0(undefined4 p_und);
MxResult Write(LegoStorage* p_storage);
MxResult Read(LegoStorage* p_storage);
Expand All @@ -47,9 +48,11 @@ class LegoPlantManager : public MxCore {
// LegoPlantManager::`scalar deleting destructor'

private:
LegoEntity* CreatePlant(MxS32 p_index, LegoWorld* p_world, MxS32 p_worldId);

static char* g_customizeAnimFile;

undefined4 m_unk0x08; // 0x08
MxS32 m_worldId; // 0x08
undefined m_unk0x0c; // 0x0c
undefined m_unk0x10[0x17]; // 0x10
undefined m_unk0x24; // 0x24
Expand Down
19 changes: 10 additions & 9 deletions LEGO1/lego/legoomni/include/legoplants.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class LegoPathBoundary;

// SIZE 0x54
struct LegoPlantInfo {
enum {
c_flag1 = 0x01,
c_flag2 = 0x02,
c_flag5 = 0x10,
c_flag6 = 0x20,
c_flag16 = 0x8000,
c_flag17 = 0x10000
// See LegoOmni::RegisterWorlds for IDs
enum Worlds {
c_act1 = 1 << 0,
c_imain = 1 << 1,
c_ielev = 1 << 4,
c_iisle = 1 << 5,
c_act2 = 1 << 15,
c_act3 = 1 << 16
};

enum Variant {
Expand All @@ -34,8 +35,8 @@ struct LegoPlantInfo {
};

LegoEntity* m_entity; // 0x00
MxU32 m_flags; // 0x04
Variant m_variant; // 0x08
MxU32 m_worlds; // 0x04 - see enum for possible bit flags
MxU8 m_variant; // 0x08 - see enum for possible values
MxU32 m_sound; // 0x0c
MxU32 m_move; // 0x10
MxU8 m_mood; // 0x14
Expand Down
6 changes: 3 additions & 3 deletions LEGO1/lego/legoomni/include/legoworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ class LegoWorld : public LegoEntity {

inline LegoCameraController* GetCamera() { return m_cameraController; }
inline LegoEntityList* GetEntityList() { return m_entityList; }
inline MxS32 GetScriptIndex() { return m_scriptIndex; }
inline MxS32 GetWorldId() { return m_worldId; }
inline MxBool GetUnknown0xd0Empty() { return m_set0xd0.empty(); }
inline list<LegoROI*>& GetROIList() { return m_roiList; }
inline LegoHideAnimPresenter* GetHideAnimPresenter() { return m_hideAnimPresenter; }

inline void SetScriptIndex(MxS32 p_scriptIndex) { m_scriptIndex = p_scriptIndex; }
inline void SetWorldId(MxS32 p_worldId) { m_worldId = p_worldId; }

// SYNTHETIC: LEGO1 0x1001dee0
// LegoWorld::`scalar deleting destructor'
Expand All @@ -111,7 +111,7 @@ class LegoWorld : public LegoEntity {
MxPresenterList m_controlPresenters; // 0xb8
MxCoreSet m_set0xd0; // 0xd0
list<LegoROI*> m_roiList; // 0xe0
MxS32 m_scriptIndex; // 0xec
MxS32 m_worldId; // 0xec
LegoHideAnimPresenter* m_hideAnimPresenter; // 0xf0
MxS16 m_startupTicks; // 0xf4
MxBool m_worldStarted; // 0xf6
Expand Down
24 changes: 12 additions & 12 deletions LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void LegoAnimationManager::Suspend()
m_animState = (AnimState*) GameState()->CreateState("AnimState");
}

if (m_scriptIndex == 0) {
if (m_worldId == 0) {
m_animState->FUN_10065240(m_animCount, m_anims, m_lastExtraCharacterId);
}

Expand Down Expand Up @@ -494,7 +494,7 @@ void LegoAnimationManager::Resume()
void LegoAnimationManager::Init()
{
m_unk0x402 = FALSE;
m_scriptIndex = -1;
m_worldId = -1;
m_animCount = 0;
m_anims = NULL;
m_unk0x18 = 0;
Expand Down Expand Up @@ -579,12 +579,12 @@ void LegoAnimationManager::EnableCamAnims(MxBool p_enableCamAnims)
}

// FUNCTION: LEGO1 0x1005f720
MxResult LegoAnimationManager::LoadScriptInfo(MxS32 p_scriptIndex)
MxResult LegoAnimationManager::LoadWorldInfo(MxS32 p_worldId)
{
MxResult result = FAILURE;
MxS32 i, j, k;

if (m_scriptIndex != p_scriptIndex) {
if (m_worldId != p_worldId) {
if (m_tranInfoList != NULL) {
delete m_tranInfoList;
m_tranInfoList = NULL;
Expand Down Expand Up @@ -614,22 +614,22 @@ MxResult LegoAnimationManager::LoadScriptInfo(MxS32 p_scriptIndex)
m_animState = (AnimState*) GameState()->CreateState("AnimState");
}

if (m_scriptIndex == 0) {
if (m_worldId == 0) {
m_animState->FUN_10065240(m_animCount, m_anims, m_lastExtraCharacterId);
}

DeleteAnimations();

LegoFile file;

if (p_scriptIndex == -1) {
if (p_worldId == -1) {
result = SUCCESS;
goto done;
}

char filename[128];
char path[1024];
sprintf(filename, "lego\\data\\%sinf.dta", Lego()->GetScriptName(p_scriptIndex));
sprintf(filename, "lego\\data\\%sinf.dta", Lego()->GetWorldName(p_worldId));
sprintf(path, "%s", MxOmni::GetHD());

if (path[strlen(path) - 1] != '\\') {
Expand Down Expand Up @@ -708,7 +708,7 @@ MxResult LegoAnimationManager::LoadScriptInfo(MxS32 p_scriptIndex)
}
}

m_scriptIndex = p_scriptIndex;
m_worldId = p_worldId;
m_tranInfoList = new LegoTranInfoList();
m_tranInfoList2 = new LegoTranInfoList();

Expand All @@ -726,7 +726,7 @@ MxResult LegoAnimationManager::LoadScriptInfo(MxS32 p_scriptIndex)
m_unk0x402 = FALSE;
}

if (p_scriptIndex == 0) {
if (p_worldId == 0) {
m_animState->FUN_100651d0(m_animCount, m_anims, m_lastExtraCharacterId);
}
}
Expand Down Expand Up @@ -934,7 +934,7 @@ MxResult LegoAnimationManager::FUN_100605e0(
{
MxResult result = FAILURE;

if (m_scriptIndex != -1 && p_index < m_animCount && m_tranInfoList != NULL) {
if (m_worldId != -1 && p_index < m_animCount && m_tranInfoList != NULL) {
PurgeExtra(FALSE);
FUN_10062770();

Expand Down Expand Up @@ -983,7 +983,7 @@ MxResult LegoAnimationManager::FUN_100605e0(
char buf[256];
sprintf(buf, "%s:%d", g_strANIMMAN_ID, tranInfo->m_index);

action.SetAtomId(*Lego()->GetScriptAtom(m_scriptIndex));
action.SetAtomId(*Lego()->GetWorldAtom(m_worldId));
action.SetObjectId(animInfo.m_objectId);
action.SetUnknown24(-1);
action.AppendExtra(strlen(buf) + 1, buf);
Expand Down Expand Up @@ -1050,7 +1050,7 @@ MxResult LegoAnimationManager::FUN_100609f0(MxU32 p_objectId, MxMatrix* p_matrix
char buf[256];
sprintf(buf, "%s:%d", g_strANIMMAN_ID, info->m_index);

action.SetAtomId(*Lego()->GetScriptAtom(m_scriptIndex));
action.SetAtomId(*Lego()->GetWorldAtom(m_worldId));
action.SetObjectId(p_objectId);
action.SetUnknown24(-1);
action.AppendExtra(strlen(buf) + 1, buf);
Expand Down
6 changes: 3 additions & 3 deletions LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void LegoBuildingManager::FUN_1002fa00()
LegoWorld* world = CurrentWorld();

for (i = 0; i < sizeOfArray(g_buildingInfo); i++) {
UpdatePosition(i, world);
CreateBuilding(i, world);
}

if (g_buildingManagerConfig <= 1) {
Expand All @@ -287,7 +287,7 @@ void LegoBuildingManager::FUN_1002fa00()

// FUNCTION: LEGO1 0x1002fa90
// FUNCTION: BETA10 0x10063b88
void LegoBuildingManager::UpdatePosition(MxS32 p_index, LegoWorld* p_world)
void LegoBuildingManager::CreateBuilding(MxS32 p_index, LegoWorld* p_world)
{
LegoEntity* entity = (LegoEntity*) p_world->Find("MxEntity", g_buildingInfo[p_index].m_variant);

Expand Down Expand Up @@ -457,7 +457,7 @@ MxBool LegoBuildingManager::SwitchVariant(LegoEntity* p_entity)

roi->SetVisibility(FALSE);
info->m_variant = g_buildingInfoVariants[m_nextVariant];
UpdatePosition(12, CurrentWorld());
CreateBuilding(12, CurrentWorld());

if (info->m_entity != NULL) {
info->m_entity->GetROI()->SetVisibility(TRUE);
Expand Down
Loading

0 comments on commit e507f42

Please sign in to comment.