CScriptMazeNode: Implement GenerateObjects & more structures

This commit is contained in:
Luke Street 2020-09-19 13:30:44 -04:00
parent 995f3bb356
commit e486e01b2a
3 changed files with 81 additions and 18 deletions

View File

@ -28,6 +28,7 @@
#include "Runtime/World/CFluidPlaneManager.hpp" #include "Runtime/World/CFluidPlaneManager.hpp"
#include "Runtime/World/ScriptLoader.hpp" #include "Runtime/World/ScriptLoader.hpp"
#include "Runtime/World/ScriptObjectSupport.hpp" #include "Runtime/World/ScriptObjectSupport.hpp"
#include "Runtime/World/CScriptMazeNode.hpp"
#include <zeus/CAABox.hpp> #include <zeus/CAABox.hpp>
#include <zeus/CVector2f.hpp> #include <zeus/CVector2f.hpp>
@ -190,7 +191,7 @@ private:
std::list<TUniqueId> xf3c_activeFlickerBats; std::list<TUniqueId> xf3c_activeFlickerBats;
std::list<TUniqueId> xf54_activeParasites; std::list<TUniqueId> xf54_activeParasites;
TUniqueId xf6c_playerActorHead = kInvalidUniqueId; TUniqueId xf6c_playerActorHead = kInvalidUniqueId;
u32 xf70_ = 0; std::unique_ptr<CUnknownMazeNode> xf70_currentMaze;
TUniqueId xf74_lastTrigger = kInvalidUniqueId; TUniqueId xf74_lastTrigger = kInvalidUniqueId;
TUniqueId xf76_lastRelay = kInvalidUniqueId; TUniqueId xf76_lastRelay = kInvalidUniqueId;

View File

@ -1,26 +1,28 @@
#include "Runtime/World/CScriptMazeNode.hpp" #include "Runtime/World/CScriptMazeNode.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Character/CModelData.hpp" #include "Runtime/Character/CModelData.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/World/CActorParameters.hpp" #include "Runtime/World/CActorParameters.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path #include "TCastTo.hpp" // Generated file, do not modify include path
namespace urde { namespace urde {
std::array<u32, 300> CScriptMazeNode::sMazeSeeds{}; std::array<s32, 300> CScriptMazeNode::sMazeSeeds{};
CScriptMazeNode::CScriptMazeNode(TUniqueId uid, std::string_view name, const CEntityInfo& info, 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::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(), : CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(),
kInvalidUniqueId) kInvalidUniqueId)
, xe8_(w1) , xe8_(w1)
, xec_(w1) , xec_(w1)
, xf0_(w2) , xf0_(w2)
, x100_(vec1) , x100_actorPos(actorPos)
, x110_(vec2) , x110_triggerPos(triggerPos)
, x120_(vec3) {} , x120_effectPos(effectPos) {}
void CScriptMazeNode::Accept(IVisitor& visitor) { visitor.Visit(this); } void CScriptMazeNode::Accept(IVisitor& visitor) { visitor.Visit(this); }
@ -30,7 +32,41 @@ void CScriptMazeNode::LoadMazeSeeds() {
const std::unique_ptr<u8[]> buf = g_ResFactory->LoadResourceSync(*tag); const std::unique_ptr<u8[]> buf = g_ResFactory->LoadResourceSync(*tag);
CMemoryInStream in(buf.get(), resSize); CMemoryInStream in(buf.get(), resSize);
for (auto& seed : sMazeSeeds) { 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<CScriptEffect> scriptEffect{ent};
TCastToConstPtr<CScriptActor> scriptActor{ent};
TCastToConstPtr<CScriptTrigger> 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<CActor*>(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 } // namespace urde

View File

@ -3,28 +3,51 @@
#include <array> #include <array>
#include <string_view> #include <string_view>
#include "Runtime/CRandom16.hpp"
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
#include "Runtime/World/CActor.hpp" #include "Runtime/World/CActor.hpp"
#include <zeus/CVector3f.hpp> #include <zeus/CVector3f.hpp>
namespace urde { 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<CUnknownMazeNodeItem, 63> 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 { class CScriptMazeNode : public CActor {
static std::array<u32, 300> sMazeSeeds; static std::array<s32, 300> sMazeSeeds;
s32 xe8_; s32 xe8_;
s32 xec_; s32 xec_;
s32 xf0_; s32 xf0_;
TUniqueId xf4_ = kInvalidUniqueId; TUniqueId xf4_ = kInvalidUniqueId;
float xf8_ = 0.f; float xf8_ = 0.f;
TUniqueId xfc_ = kInvalidUniqueId; TUniqueId xfc_actorId = kInvalidUniqueId;
zeus::CVector3f x100_; zeus::CVector3f x100_actorPos;
TUniqueId x10c_ = kInvalidUniqueId; TUniqueId x10c_triggerId = kInvalidUniqueId;
zeus::CVector3f x110_; zeus::CVector3f x110_triggerPos;
TUniqueId x11c_ = kInvalidUniqueId; TUniqueId x11c_effectId = kInvalidUniqueId;
zeus::CVector3f x120_; zeus::CVector3f x120_effectPos;
s32 x130_ = 0; std::vector<TUniqueId> x12c_;
s32 x134_ = 0;
s32 x138_ = 0;
bool x13c_24_ : 1 = true; bool x13c_24_ : 1 = true;
bool x13c_25_ : 1 = false; bool x13c_25_ : 1 = false;
bool x13c_26_ : 1 = false; bool x13c_26_ : 1 = false;
@ -35,5 +58,8 @@ public:
void Accept(IVisitor& visitor) override; void Accept(IVisitor& visitor) override;
static void LoadMazeSeeds(); static void LoadMazeSeeds();
private:
void GenerateObjects(CStateManager& mgr);
}; };
} // namespace urde } // namespace urde