From e486e01b2a73eb1a1b67e12bcebf3ec67c724b62 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sat, 19 Sep 2020 13:30:44 -0400 Subject: [PATCH] CScriptMazeNode: Implement GenerateObjects & more structures --- Runtime/CStateManager.hpp | 3 +- Runtime/World/CScriptMazeNode.cpp | 50 ++++++++++++++++++++++++++----- Runtime/World/CScriptMazeNode.hpp | 46 +++++++++++++++++++++------- 3 files changed, 81 insertions(+), 18 deletions(-) diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 0e7de9da1..4a2f1c153 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -28,6 +28,7 @@ #include "Runtime/World/CFluidPlaneManager.hpp" #include "Runtime/World/ScriptLoader.hpp" #include "Runtime/World/ScriptObjectSupport.hpp" +#include "Runtime/World/CScriptMazeNode.hpp" #include #include @@ -190,7 +191,7 @@ private: std::list xf3c_activeFlickerBats; std::list xf54_activeParasites; TUniqueId xf6c_playerActorHead = kInvalidUniqueId; - u32 xf70_ = 0; + std::unique_ptr xf70_currentMaze; TUniqueId xf74_lastTrigger = kInvalidUniqueId; TUniqueId xf76_lastRelay = kInvalidUniqueId; diff --git a/Runtime/World/CScriptMazeNode.cpp b/Runtime/World/CScriptMazeNode.cpp index 2185dc523..c8709b496 100644 --- a/Runtime/World/CScriptMazeNode.cpp +++ b/Runtime/World/CScriptMazeNode.cpp @@ -1,26 +1,28 @@ #include "Runtime/World/CScriptMazeNode.hpp" -#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Character/CModelData.hpp" +#include "Runtime/CStateManager.hpp" +#include "Runtime/GameGlobalObjects.hpp" #include "Runtime/World/CActorParameters.hpp" #include "TCastTo.hpp" // Generated file, do not modify include path namespace urde { -std::array CScriptMazeNode::sMazeSeeds{}; +std::array CScriptMazeNode::sMazeSeeds{}; CScriptMazeNode::CScriptMazeNode(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, bool active, s32 w1, s32 w2, s32 w3, - const zeus::CVector3f& vec1, const zeus::CVector3f& vec2, const zeus::CVector3f& vec3) + const zeus::CVector3f& actorPos, const zeus::CVector3f& triggerPos, + const zeus::CVector3f& effectPos) : CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(), kInvalidUniqueId) , xe8_(w1) , xec_(w1) , xf0_(w2) -, x100_(vec1) -, x110_(vec2) -, x120_(vec3) {} +, x100_actorPos(actorPos) +, x110_triggerPos(triggerPos) +, x120_effectPos(effectPos) {} void CScriptMazeNode::Accept(IVisitor& visitor) { visitor.Visit(this); } @@ -30,7 +32,41 @@ void CScriptMazeNode::LoadMazeSeeds() { const std::unique_ptr buf = g_ResFactory->LoadResourceSync(*tag); CMemoryInStream in(buf.get(), resSize); for (auto& seed : sMazeSeeds) { - seed = in.readUint32Big(); + seed = in.readInt32Big(); + } +} + +void CScriptMazeNode::GenerateObjects(CStateManager& mgr) { + for (const auto& conn : GetConnectionList()) { + if (conn.x0_state != EScriptObjectState::MaxReached || conn.x4_msg != EScriptObjectMessage::Activate) { + continue; + } + const auto* ent = mgr.GetObjectById(mgr.GetIdForScript(conn.x8_objId)); + TCastToConstPtr scriptEffect{ent}; + TCastToConstPtr scriptActor{ent}; + TCastToConstPtr scriptTrigger{ent}; + if ((scriptEffect || scriptActor || scriptTrigger) && (!scriptEffect || !x13c_25_)) { + bool wasGeneratingObject = mgr.GetIsGeneratingObject(); + mgr.SetIsGeneratingObject(true); + const auto genObj = mgr.GenerateObject(conn.x8_objId); + mgr.SetIsGeneratingObject(wasGeneratingObject); + auto* actor = static_cast(mgr.ObjectById(genObj.second)); + if (actor != nullptr) { + mgr.SendScriptMsg(actor, GetUniqueId(), EScriptObjectMessage::Activate); + if (scriptEffect) { + actor->SetTranslation(GetTranslation() + x120_effectPos); + x11c_effectId = genObj.second; + } + if (scriptActor) { + actor->SetTranslation(GetTranslation() + x100_actorPos); + xfc_actorId = genObj.second; + } + if (scriptTrigger) { + actor->SetTranslation(GetTranslation() + x110_triggerPos); + x10c_triggerId = genObj.second; + } + } + } } } } // namespace urde diff --git a/Runtime/World/CScriptMazeNode.hpp b/Runtime/World/CScriptMazeNode.hpp index e9a88901f..0c37bb968 100644 --- a/Runtime/World/CScriptMazeNode.hpp +++ b/Runtime/World/CScriptMazeNode.hpp @@ -3,28 +3,51 @@ #include #include +#include "Runtime/CRandom16.hpp" #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CActor.hpp" #include namespace urde { +struct CUnknownMazeNodeItem { + bool x0_24_ : 1 = false; + bool x0_25_ : 1 = false; + bool x0_26_ : 1 = false; + bool x0_27_ : 1 = false; + bool x0_28_ : 1 = false; + bool x0_29_ : 1 = false; + bool x0_30_ : 1 = false; + bool x0_31_ : 1 = false; + bool x1_24_ : 1 = false; + bool x1_25_ : 1 = false; + bool x1_26_ : 1 = false; +}; +class CUnknownMazeNode { + CRandom16 x0_rand{0}; + std::array x4_arr{}; + s32 x84_; + s32 x88_; + s32 x8c_; + s32 x90_; + bool x94_24_initialized : 1 = false; + + CUnknownMazeNode(s32 w1, s32 w2, s32 w3, s32 w4) : x84_(w1), x88_(w2), x8c_(w3), x90_(w4) {} +}; class CScriptMazeNode : public CActor { - static std::array sMazeSeeds; + static std::array sMazeSeeds; s32 xe8_; s32 xec_; s32 xf0_; TUniqueId xf4_ = kInvalidUniqueId; float xf8_ = 0.f; - TUniqueId xfc_ = kInvalidUniqueId; - zeus::CVector3f x100_; - TUniqueId x10c_ = kInvalidUniqueId; - zeus::CVector3f x110_; - TUniqueId x11c_ = kInvalidUniqueId; - zeus::CVector3f x120_; - s32 x130_ = 0; - s32 x134_ = 0; - s32 x138_ = 0; + TUniqueId xfc_actorId = kInvalidUniqueId; + zeus::CVector3f x100_actorPos; + TUniqueId x10c_triggerId = kInvalidUniqueId; + zeus::CVector3f x110_triggerPos; + TUniqueId x11c_effectId = kInvalidUniqueId; + zeus::CVector3f x120_effectPos; + std::vector x12c_; bool x13c_24_ : 1 = true; bool x13c_25_ : 1 = false; bool x13c_26_ : 1 = false; @@ -35,5 +58,8 @@ public: void Accept(IVisitor& visitor) override; static void LoadMazeSeeds(); + +private: + void GenerateObjects(CStateManager& mgr); }; } // namespace urde