2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptMazeNode.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/Character/CModelData.hpp"
|
2020-09-19 17:30:44 +00:00
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CActorParameters.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-08-14 21:38:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2016-08-14 21:38:05 +00:00
|
|
|
|
2020-09-19 17:30:44 +00:00
|
|
|
std::array<s32, 300> CScriptMazeNode::sMazeSeeds{};
|
2017-05-22 11:24:24 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptMazeNode::CScriptMazeNode(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
2016-08-14 21:38:05 +00:00
|
|
|
const zeus::CTransform& xf, bool active, s32 w1, s32 w2, s32 w3,
|
2020-09-19 17:30:44 +00:00
|
|
|
const zeus::CVector3f& actorPos, const zeus::CVector3f& triggerPos,
|
|
|
|
const zeus::CVector3f& effectPos)
|
2017-01-04 04:08:30 +00:00
|
|
|
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(),
|
|
|
|
kInvalidUniqueId)
|
|
|
|
, xe8_(w1)
|
|
|
|
, xec_(w1)
|
|
|
|
, xf0_(w2)
|
2020-09-19 17:30:44 +00:00
|
|
|
, x100_actorPos(actorPos)
|
|
|
|
, x110_triggerPos(triggerPos)
|
|
|
|
, x120_effectPos(effectPos) {}
|
2016-08-14 21:38:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptMazeNode::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-05-22 11:24:24 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptMazeNode::LoadMazeSeeds() {
|
|
|
|
const SObjectTag* tag = g_ResFactory->GetResourceIdByName("DUMB_MazeSeeds");
|
2020-04-12 19:23:26 +00:00
|
|
|
const u32 resSize = g_ResFactory->ResourceSize(*tag);
|
|
|
|
const std::unique_ptr<u8[]> buf = g_ResFactory->LoadResourceSync(*tag);
|
2018-12-08 05:30:43 +00:00
|
|
|
CMemoryInStream in(buf.get(), resSize);
|
2020-04-12 19:23:26 +00:00
|
|
|
for (auto& seed : sMazeSeeds) {
|
2020-09-19 17:30:44 +00:00
|
|
|
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);
|
2020-09-19 17:44:32 +00:00
|
|
|
if (auto* actor = static_cast<CActor*>(mgr.ObjectById(genObj.second))) {
|
2020-09-19 17:30:44 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 19:23:26 +00:00
|
|
|
}
|
2016-08-14 21:38:05 +00:00
|
|
|
}
|
2020-09-19 17:44:32 +00:00
|
|
|
|
|
|
|
void CScriptMazeNode::Reset(CStateManager& mgr) {
|
|
|
|
mgr.FreeScriptObject(x11c_effectId);
|
|
|
|
mgr.FreeScriptObject(xfc_actorId);
|
|
|
|
mgr.FreeScriptObject(x10c_triggerId);
|
|
|
|
mgr.FreeScriptObject(xf4_);
|
|
|
|
xf4_ = kInvalidUniqueId;
|
|
|
|
xfc_actorId = kInvalidUniqueId;
|
|
|
|
x10c_triggerId = kInvalidUniqueId;
|
|
|
|
x11c_effectId = kInvalidUniqueId;
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|