mirror of https://github.com/AxioDL/metaforce.git
CScriptMazeNode: Renaming & more cleanup
This commit is contained in:
parent
c23a047a93
commit
df2d191be8
|
@ -191,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;
|
||||||
std::unique_ptr<CScriptMazeState> xf70_currentMaze;
|
std::unique_ptr<CMazeState> xf70_currentMaze;
|
||||||
|
|
||||||
TUniqueId xf74_lastTrigger = kInvalidUniqueId;
|
TUniqueId xf74_lastTrigger = kInvalidUniqueId;
|
||||||
TUniqueId xf76_lastRelay = kInvalidUniqueId;
|
TUniqueId xf76_lastRelay = kInvalidUniqueId;
|
||||||
|
@ -420,9 +420,9 @@ public:
|
||||||
return static_cast<CPlatformAndDoorList&>(*x808_objLists[7]);
|
return static_cast<CPlatformAndDoorList&>(*x808_objLists[7]);
|
||||||
}
|
}
|
||||||
std::pair<u32, u32> CalculateScanCompletionRate() const;
|
std::pair<u32, u32> CalculateScanCompletionRate() const;
|
||||||
void SetCurrentMaze(std::unique_ptr<CScriptMazeState> maze) { xf70_currentMaze = std::move(maze); }
|
void SetCurrentMaze(std::unique_ptr<CMazeState> maze) { xf70_currentMaze = std::move(maze); }
|
||||||
void ClearCurrentMaze() { xf70_currentMaze.reset(); }
|
void ClearCurrentMaze() { xf70_currentMaze.reset(); }
|
||||||
CScriptMazeState* GetCurrentMaze() { return xf70_currentMaze.get(); }
|
CMazeState* GetCurrentMaze() { return xf70_currentMaze.get(); }
|
||||||
void SetLastTriggerId(TUniqueId uid) { xf74_lastTrigger = uid; }
|
void SetLastTriggerId(TUniqueId uid) { xf74_lastTrigger = uid; }
|
||||||
TUniqueId GetLastTriggerId() const { return xf74_lastTrigger; }
|
TUniqueId GetLastTriggerId() const { return xf74_lastTrigger; }
|
||||||
void SetLastRelayId(TUniqueId uid) { xf76_lastRelay = uid; }
|
void SetLastRelayId(TUniqueId uid) { xf76_lastRelay = uid; }
|
||||||
|
|
|
@ -12,14 +12,14 @@ namespace urde {
|
||||||
std::array<s32, 300> sMazeSeeds;
|
std::array<s32, 300> 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 col, s32 row, s32 side,
|
||||||
const zeus::CVector3f& actorPos, const zeus::CVector3f& triggerPos,
|
const zeus::CVector3f& actorPos, const zeus::CVector3f& triggerPos,
|
||||||
const zeus::CVector3f& effectPos)
|
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_col(w1)
|
, xe8_col(col)
|
||||||
, xec_row(w2)
|
, xec_row(row)
|
||||||
, xf0_(w3)
|
, xf0_side(static_cast<ESide>(side))
|
||||||
, x100_actorPos(actorPos)
|
, x100_actorPos(actorPos)
|
||||||
, x110_triggerPos(triggerPos)
|
, x110_triggerPos(triggerPos)
|
||||||
, x120_effectPos(effectPos) {}
|
, x120_effectPos(effectPos) {}
|
||||||
|
@ -32,15 +32,15 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
if (auto* maze = mgr.GetCurrentMaze()) {
|
if (auto* maze = mgr.GetCurrentMaze()) {
|
||||||
bool shouldGenObjs = false;
|
bool shouldGenObjs = false;
|
||||||
auto& cell = maze->GetCell(xe8_col, xec_row);
|
auto& cell = maze->GetCell(xe8_col, xec_row);
|
||||||
if (xf0_ == 0 && cell.x0_24_) {
|
if (xf0_side == ESide::Top && cell.x0_24_openTop) {
|
||||||
if (cell.x0_28_) {
|
if (cell.x0_28_gateTop) {
|
||||||
shouldGenObjs = true;
|
shouldGenObjs = true;
|
||||||
x13c_25_ = true;
|
x13c_25_hasGate = true;
|
||||||
}
|
}
|
||||||
} else if (xf0_ == 1 && cell.x0_25_) {
|
} else if (xf0_side == ESide::Right && cell.x0_25_openRight) {
|
||||||
if (cell.x0_29_) {
|
if (cell.x0_29_gateRight) {
|
||||||
shouldGenObjs = true;
|
shouldGenObjs = true;
|
||||||
x13c_25_ = true;
|
x13c_25_hasGate = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
shouldGenObjs = true;
|
shouldGenObjs = true;
|
||||||
|
@ -48,10 +48,10 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
if (shouldGenObjs) {
|
if (shouldGenObjs) {
|
||||||
GenerateObjects(mgr);
|
GenerateObjects(mgr);
|
||||||
}
|
}
|
||||||
if (xf0_ == 1 && cell.x1_24_) {
|
if (xf0_side == ESide::Right && cell.x1_24_puddle) {
|
||||||
x13c_24_ = true;
|
x13c_24_hasPuddle = true;
|
||||||
}
|
}
|
||||||
if (x13c_25_) {
|
if (x13c_25_hasGate) {
|
||||||
const auto origin = GetTranslation();
|
const auto origin = GetTranslation();
|
||||||
for (const auto& conn : GetConnectionList()) {
|
for (const auto& conn : GetConnectionList()) {
|
||||||
if (conn.x0_state != EScriptObjectState::Modify || conn.x4_msg != EScriptObjectMessage::Activate) {
|
if (conn.x0_state != EScriptObjectState::Modify || conn.x4_msg != EScriptObjectMessage::Activate) {
|
||||||
|
@ -63,7 +63,7 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
const auto genObj = mgr.GenerateObject(conn.x8_objId);
|
const auto genObj = mgr.GenerateObject(conn.x8_objId);
|
||||||
mgr.SetIsGeneratingObject(wasGeneratingObject);
|
mgr.SetIsGeneratingObject(wasGeneratingObject);
|
||||||
|
|
||||||
xf4_ = genObj.second;
|
xf4_gateEffectId = genObj.second;
|
||||||
if (TCastToPtr<CActor> actor = mgr.ObjectById(genObj.second)) {
|
if (TCastToPtr<CActor> actor = mgr.ObjectById(genObj.second)) {
|
||||||
actor->SetTranslation(origin + x120_effectPos);
|
actor->SetTranslation(origin + x120_effectPos);
|
||||||
mgr.SendScriptMsg(actor, GetUniqueId(), EScriptObjectMessage::Activate);
|
mgr.SendScriptMsg(actor, GetUniqueId(), EScriptObjectMessage::Activate);
|
||||||
|
@ -71,7 +71,7 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (x13c_24_) {
|
if (x13c_24_hasPuddle) {
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for (const auto& conn : GetConnectionList()) {
|
for (const auto& conn : GetConnectionList()) {
|
||||||
if ((conn.x0_state == EScriptObjectState::Closed || conn.x0_state == EScriptObjectState::DeactivateState) &&
|
if ((conn.x0_state == EScriptObjectState::Closed || conn.x0_state == EScriptObjectState::DeactivateState) &&
|
||||||
|
@ -79,7 +79,7 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x12c_.reserve(count);
|
x12c_puddleObjectIds.reserve(count);
|
||||||
for (const auto& conn : GetConnectionList()) {
|
for (const auto& conn : GetConnectionList()) {
|
||||||
if ((conn.x0_state == EScriptObjectState::Closed || conn.x0_state == EScriptObjectState::DeactivateState) &&
|
if ((conn.x0_state == EScriptObjectState::Closed || conn.x0_state == EScriptObjectState::DeactivateState) &&
|
||||||
conn.x4_msg == EScriptObjectMessage::Activate) {
|
conn.x4_msg == EScriptObjectMessage::Activate) {
|
||||||
|
@ -88,7 +88,7 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
const auto genObj = mgr.GenerateObject(conn.x8_objId);
|
const auto genObj = mgr.GenerateObject(conn.x8_objId);
|
||||||
mgr.SetIsGeneratingObject(wasGeneratingObject);
|
mgr.SetIsGeneratingObject(wasGeneratingObject);
|
||||||
|
|
||||||
x12c_.push_back(genObj.second);
|
x12c_puddleObjectIds.push_back(genObj.second);
|
||||||
if (TCastToPtr<CActor> actor = mgr.ObjectById(genObj.second)) {
|
if (TCastToPtr<CActor> actor = mgr.ObjectById(genObj.second)) {
|
||||||
actor->SetTransform(GetTransform());
|
actor->SetTransform(GetTransform());
|
||||||
if (conn.x0_state == EScriptObjectState::Closed) {
|
if (conn.x0_state == EScriptObjectState::Closed) {
|
||||||
|
@ -101,8 +101,9 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
}
|
}
|
||||||
} else if (msg == EScriptObjectMessage::SetToZero) {
|
} else if (msg == EScriptObjectMessage::SetToZero) {
|
||||||
auto* maze = mgr.GetCurrentMaze();
|
auto* maze = mgr.GetCurrentMaze();
|
||||||
if (x13c_24_ && maze != nullptr && std::any_of(x12c_.cbegin(), x12c_.cend(), [=](auto v) { return v == uid; })) {
|
if (x13c_24_hasPuddle && maze != nullptr &&
|
||||||
for (const auto& id : x12c_) {
|
std::any_of(x12c_puddleObjectIds.cbegin(), x12c_puddleObjectIds.cend(), [=](auto v) { return v == uid; })) {
|
||||||
|
for (const auto& id : x12c_puddleObjectIds) {
|
||||||
if (auto* ent = mgr.ObjectById(id)) {
|
if (auto* ent = mgr.ObjectById(id)) {
|
||||||
if (ent->GetActive()) {
|
if (ent->GetActive()) {
|
||||||
mgr.SendScriptMsg(ent, GetUniqueId(), EScriptObjectMessage::Activate);
|
mgr.SendScriptMsg(ent, GetUniqueId(), EScriptObjectMessage::Activate);
|
||||||
|
@ -113,37 +114,36 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
}
|
}
|
||||||
for (const auto& ent : mgr.GetAllObjectList()) {
|
for (const auto& ent : mgr.GetAllObjectList()) {
|
||||||
if (TCastToPtr<CScriptMazeNode> node = ent) {
|
if (TCastToPtr<CScriptMazeNode> node = ent) {
|
||||||
s32 col = xe8_col - 1;
|
if (node->xe8_col == xe8_col - 1 && node->xec_row == xec_row && node->xf0_side == ESide::Right) {
|
||||||
if (node->xe8_col == col && node->xec_row == xec_row && node->xf0_ == 1) {
|
auto& cell = maze->GetCell(xe8_col - 1, xec_row);
|
||||||
auto& cell = maze->GetCell(col, xec_row);
|
if (!cell.x0_25_openRight) {
|
||||||
if (!cell.x0_25_) {
|
cell.x0_25_openRight = true;
|
||||||
cell.x0_25_ = true;
|
|
||||||
node->Reset(mgr);
|
node->Reset(mgr);
|
||||||
node->x13c_25_ = false;
|
node->x13c_25_hasGate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node->xe8_col == xe8_col && node->xec_row == xec_row && node->xf0_ == 1) {
|
if (node->xe8_col == xe8_col && node->xec_row == xec_row && node->xf0_side == ESide::Right) {
|
||||||
auto& cell = maze->GetCell(xe8_col, xec_row);
|
auto& cell = maze->GetCell(xe8_col, xec_row);
|
||||||
if (!cell.x0_25_) {
|
if (!cell.x0_25_openRight) {
|
||||||
cell.x0_25_ = true;
|
cell.x0_25_openRight = true;
|
||||||
node->Reset(mgr);
|
node->Reset(mgr);
|
||||||
node->x13c_25_ = false;
|
node->x13c_25_hasGate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node->xe8_col == xe8_col && node->xec_row == xec_row && node->xf0_ == 0) {
|
if (node->xe8_col == xe8_col && node->xec_row == xec_row && node->xf0_side == ESide::Top) {
|
||||||
auto& cell = maze->GetCell(xe8_col, xec_row);
|
auto& cell = maze->GetCell(xe8_col, xec_row);
|
||||||
if (!cell.x0_24_) {
|
if (!cell.x0_24_openTop) {
|
||||||
cell.x0_24_ = true;
|
cell.x0_24_openTop = true;
|
||||||
node->Reset(mgr);
|
node->Reset(mgr);
|
||||||
node->x13c_25_ = false;
|
node->x13c_25_hasGate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node->xe8_col == xe8_col && node->xec_row == xec_row + 1 && node->xf0_ == 0) {
|
if (node->xe8_col == xe8_col && node->xec_row == xec_row + 1 && node->xf0_side == ESide::Top) {
|
||||||
auto& cell = maze->GetCell(xe8_col, xec_row + 1);
|
auto& cell = maze->GetCell(xe8_col, xec_row + 1);
|
||||||
if (!cell.x0_24_) {
|
if (!cell.x0_24_openTop) {
|
||||||
cell.x0_24_ = true;
|
cell.x0_24_openTop = true;
|
||||||
node->Reset(mgr);
|
node->Reset(mgr);
|
||||||
node->x13c_25_ = false;
|
node->x13c_25_hasGate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,10 +153,10 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
Reset(mgr);
|
Reset(mgr);
|
||||||
} else if (msg == EScriptObjectMessage::InitializedInArea) {
|
} else if (msg == EScriptObjectMessage::InitializedInArea) {
|
||||||
if (mgr.GetCurrentMaze() == nullptr) {
|
if (mgr.GetCurrentMaze() == nullptr) {
|
||||||
auto maze = std::make_unique<CScriptMazeState>(4, 4, 5, 3);
|
auto maze = std::make_unique<CMazeState>(skTargetCol, skTargetRow, skEnterCol, skEnterRow);
|
||||||
maze->Reset(sMazeSeeds[mgr.GetActiveRandom()->Next() % sMazeSeeds.size()]);
|
maze->Reset(sMazeSeeds[mgr.GetActiveRandom()->Next() % sMazeSeeds.size()]);
|
||||||
maze->Initialize();
|
maze->Initialize();
|
||||||
maze->sub_802899c8();
|
maze->GenerateObstacles();
|
||||||
mgr.SetCurrentMaze(std::move(maze));
|
mgr.SetCurrentMaze(std::move(maze));
|
||||||
}
|
}
|
||||||
} else if (msg == EScriptObjectMessage::Deleted) {
|
} else if (msg == EScriptObjectMessage::Deleted) {
|
||||||
|
@ -168,17 +168,17 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScriptMazeNode::Think(float dt, CStateManager& mgr) {
|
void CScriptMazeNode::Think(float dt, CStateManager& mgr) {
|
||||||
if (!GetActive() || !x13c_25_) {
|
if (!GetActive() || !x13c_25_hasGate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xf8_msgTimer -= dt;
|
xf8_msgTimer -= dt;
|
||||||
if (xf8_msgTimer <= 0.f) {
|
if (xf8_msgTimer <= 0.f) {
|
||||||
xf8_msgTimer = 1.f;
|
xf8_msgTimer = 1.f;
|
||||||
if (x13c_26_) {
|
if (x13c_26_gateActive) {
|
||||||
x13c_26_ = false;
|
x13c_26_gateActive = false;
|
||||||
SendScriptMsgs(mgr, EScriptObjectMessage::Deactivate);
|
SendScriptMsgs(mgr, EScriptObjectMessage::Deactivate);
|
||||||
} else {
|
} else {
|
||||||
x13c_26_ = true;
|
x13c_26_gateActive = true;
|
||||||
SendScriptMsgs(mgr, EScriptObjectMessage::Activate);
|
SendScriptMsgs(mgr, EScriptObjectMessage::Activate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ void CScriptMazeNode::GenerateObjects(CStateManager& mgr) {
|
||||||
TCastToConstPtr<CScriptEffect> scriptEffect{ent};
|
TCastToConstPtr<CScriptEffect> scriptEffect{ent};
|
||||||
TCastToConstPtr<CScriptActor> scriptActor{ent};
|
TCastToConstPtr<CScriptActor> scriptActor{ent};
|
||||||
TCastToConstPtr<CScriptTrigger> scriptTrigger{ent};
|
TCastToConstPtr<CScriptTrigger> scriptTrigger{ent};
|
||||||
if ((scriptEffect || scriptActor || scriptTrigger) && (!scriptEffect || !x13c_25_)) {
|
if ((scriptEffect || scriptActor || scriptTrigger) && (!scriptEffect || !x13c_25_hasGate)) {
|
||||||
bool wasGeneratingObject = mgr.GetIsGeneratingObject();
|
bool wasGeneratingObject = mgr.GetIsGeneratingObject();
|
||||||
mgr.SetIsGeneratingObject(true);
|
mgr.SetIsGeneratingObject(true);
|
||||||
const auto genObj = mgr.GenerateObject(conn.x8_objId);
|
const auto genObj = mgr.GenerateObject(conn.x8_objId);
|
||||||
|
@ -231,8 +231,8 @@ void CScriptMazeNode::Reset(CStateManager& mgr) {
|
||||||
mgr.FreeScriptObject(x11c_effectId);
|
mgr.FreeScriptObject(x11c_effectId);
|
||||||
mgr.FreeScriptObject(xfc_actorId);
|
mgr.FreeScriptObject(xfc_actorId);
|
||||||
mgr.FreeScriptObject(x10c_triggerId);
|
mgr.FreeScriptObject(x10c_triggerId);
|
||||||
mgr.FreeScriptObject(xf4_);
|
mgr.FreeScriptObject(xf4_gateEffectId);
|
||||||
xf4_ = kInvalidUniqueId;
|
xf4_gateEffectId = kInvalidUniqueId;
|
||||||
xfc_actorId = kInvalidUniqueId;
|
xfc_actorId = kInvalidUniqueId;
|
||||||
x10c_triggerId = kInvalidUniqueId;
|
x10c_triggerId = kInvalidUniqueId;
|
||||||
x11c_effectId = kInvalidUniqueId;
|
x11c_effectId = kInvalidUniqueId;
|
||||||
|
@ -242,125 +242,112 @@ void CScriptMazeNode::SendScriptMsgs(CStateManager& mgr, EScriptObjectMessage ms
|
||||||
mgr.SendScriptMsg(x11c_effectId, GetUniqueId(), msg);
|
mgr.SendScriptMsg(x11c_effectId, GetUniqueId(), msg);
|
||||||
mgr.SendScriptMsg(xfc_actorId, GetUniqueId(), msg);
|
mgr.SendScriptMsg(xfc_actorId, GetUniqueId(), msg);
|
||||||
mgr.SendScriptMsg(x10c_triggerId, GetUniqueId(), msg);
|
mgr.SendScriptMsg(x10c_triggerId, GetUniqueId(), msg);
|
||||||
mgr.SendScriptMsg(xf4_, GetUniqueId(), msg);
|
mgr.SendScriptMsg(xf4_gateEffectId, GetUniqueId(), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScriptMazeState::Reset(s32 seed) {
|
void CMazeState::Reset(s32 seed) {
|
||||||
x0_rand.SetSeed(seed);
|
x0_rand.SetSeed(seed);
|
||||||
x94_24_initialized = false;
|
x94_24_initialized = false;
|
||||||
x4_cells.fill({});
|
x4_cells.fill({});
|
||||||
|
|
||||||
std::array<s32, 4> states{};
|
std::array<ESide, 4> sides{};
|
||||||
s32 cellIdx = 0;
|
s32 cellIdx = 0;
|
||||||
for (u32 i = skMazeColumns * skMazeRows - 1; i != 0;) {
|
for (u32 i = skMazeCols * skMazeRows - 1; i != 0;) {
|
||||||
u32 acc = 0;
|
u32 acc = 0;
|
||||||
if (cellIdx - skMazeColumns > 0) {
|
if (cellIdx - skMazeCols > 0 && !GetCell(cellIdx - skMazeCols).IsOpen()) {
|
||||||
auto& cell = GetCell(cellIdx - skMazeColumns);
|
sides[acc++] = ESide::Top;
|
||||||
if (!cell.x0_24_ && !cell.x0_25_ && !cell.x0_26_ && !cell.x0_27_) {
|
|
||||||
states[acc++] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (cellIdx < x4_cells.size() - 2 && (cellIdx + 1) % skMazeColumns != 0) {
|
if (cellIdx < x4_cells.size() - 2 && (cellIdx + 1) % skMazeCols != 0 && !GetCell(cellIdx + 1).IsOpen()) {
|
||||||
auto& cell = GetCell(cellIdx + 1);
|
sides[acc++] = ESide::Right;
|
||||||
if (!cell.x0_24_ && !cell.x0_25_ && !cell.x0_26_ && !cell.x0_27_) {
|
|
||||||
states[acc++] = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (cellIdx + skMazeColumns < x4_cells.size()) {
|
if (cellIdx + skMazeCols < x4_cells.size() && !GetCell(cellIdx + skMazeCols).IsOpen()) {
|
||||||
auto& cell = GetCell(cellIdx + skMazeColumns);
|
sides[acc++] = ESide::Bottom;
|
||||||
if (!cell.x0_24_ && !cell.x0_25_ && !cell.x0_26_ && !cell.x0_27_) {
|
|
||||||
states[acc++] = 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (cellIdx > 0 && cellIdx % skMazeColumns != 0) {
|
if (cellIdx > 0 && cellIdx % skMazeCols != 0 && !GetCell(cellIdx - 1).IsOpen()) {
|
||||||
auto& cell = GetCell(cellIdx - 1);
|
sides[acc++] = ESide::Left;
|
||||||
if (!cell.x0_24_ && !cell.x0_25_ && !cell.x0_26_ && !cell.x0_27_) {
|
|
||||||
states[acc++] = 3;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (acc == 0) {
|
if (acc == 0) {
|
||||||
while (true) {
|
do {
|
||||||
cellIdx++;
|
cellIdx++;
|
||||||
if (cellIdx > x4_cells.size() - 1) {
|
if (cellIdx > x4_cells.size() - 1) {
|
||||||
cellIdx = 0;
|
cellIdx = 0;
|
||||||
}
|
}
|
||||||
auto& cell = GetCell(cellIdx);
|
} while (!GetCell(cellIdx).IsOpen());
|
||||||
if (cell.x0_24_ || cell.x0_25_ || cell.x0_26_ || cell.x0_27_) {
|
continue;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
};
|
i--;
|
||||||
} else {
|
ESide side = sides[x0_rand.Next() % acc];
|
||||||
i--;
|
if (side == ESide::Bottom) {
|
||||||
s32 state = states[x0_rand.Next() % acc];
|
GetCell(cellIdx).x0_26_openBottom = true;
|
||||||
if (state == 2) {
|
GetCell(cellIdx + skMazeCols).x0_24_openTop = true;
|
||||||
GetCell(cellIdx).x0_26_ = true;
|
cellIdx += skMazeCols;
|
||||||
GetCell(cellIdx + skMazeColumns).x0_24_ = true;
|
} else if (side == ESide::Top) {
|
||||||
cellIdx += skMazeColumns;
|
GetCell(cellIdx).x0_24_openTop = true;
|
||||||
} else if (state == 0) {
|
GetCell(cellIdx - skMazeCols).x0_26_openBottom = true;
|
||||||
GetCell(cellIdx).x0_24_ = true;
|
cellIdx -= skMazeCols;
|
||||||
GetCell(cellIdx - skMazeColumns).x0_26_ = true;
|
} else if (side == ESide::Right) {
|
||||||
cellIdx -= skMazeColumns;
|
GetCell(cellIdx).x0_25_openRight = true;
|
||||||
} else if (state == 1) {
|
GetCell(cellIdx + 1).x0_27_openLeft = true;
|
||||||
GetCell(cellIdx).x0_25_ = true;
|
cellIdx++;
|
||||||
GetCell(cellIdx + 1).x0_27_ = true;
|
} else if (side == ESide::Left) {
|
||||||
cellIdx++;
|
GetCell(cellIdx).x0_27_openLeft = true;
|
||||||
} else if (state == 3) {
|
GetCell(cellIdx - 1).x0_25_openRight = true;
|
||||||
GetCell(cellIdx).x0_27_ = true;
|
cellIdx--;
|
||||||
GetCell(cellIdx - 1).x0_25_ = true;
|
|
||||||
cellIdx--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScriptMazeState::Initialize() {
|
void CMazeState::Initialize() {
|
||||||
std::array<s32, skMazeRows * skMazeColumns> arr{};
|
std::array<s32, skMazeRows * skMazeCols> path{};
|
||||||
arr[0] = x84_startCol + x88_startRow * skMazeColumns;
|
path[0] = x84_targetCol + x88_targetRow * skMazeCols;
|
||||||
GetCell(arr[0]).x1_26_ = true;
|
GetCell(path[0]).x1_26_checked = true;
|
||||||
s32 i = 1;
|
s32 pathLength = 1;
|
||||||
while (arr[0] != x8c_endCol + x90_endRow * skMazeColumns) {
|
while (path[0] != x8c_enterCol + x90_enterRow * skMazeCols) {
|
||||||
if (GetCell(arr[0]).x0_24_) {
|
if (GetCell(path[0]).x0_24_openTop) {
|
||||||
if (!GetCell(arr[0] - skMazeColumns).x1_26_) {
|
if (!GetCell(path[0] - skMazeCols).x1_26_checked) {
|
||||||
arr[i] = arr[0] - skMazeColumns;
|
path[pathLength] = path[0] - skMazeCols;
|
||||||
i++;
|
pathLength++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GetCell(arr[0]).x0_25_) {
|
if (GetCell(path[0]).x0_25_openRight) {
|
||||||
if (!GetCell(arr[0] + 1).x1_26_) {
|
if (!GetCell(path[0] + 1).x1_26_checked) {
|
||||||
arr[i] = arr[0] + 1;
|
path[pathLength] = path[0] + 1;
|
||||||
i++;
|
pathLength++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GetCell(arr[0]).x0_26_) {
|
if (GetCell(path[0]).x0_26_openBottom) {
|
||||||
if (!GetCell(arr[0] + skMazeColumns).x1_26_) {
|
if (!GetCell(path[0] + skMazeCols).x1_26_checked) {
|
||||||
arr[i] = arr[0] + skMazeColumns;
|
path[pathLength] = path[0] + skMazeCols;
|
||||||
i++;
|
pathLength++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GetCell(arr[0]).x0_27_) {
|
if (GetCell(path[0]).x0_27_openLeft) {
|
||||||
if (!GetCell(arr[0] - 1).x1_26_) {
|
if (!GetCell(path[0] - 1).x1_26_checked) {
|
||||||
arr[i] = arr[0] - 1;
|
path[pathLength] = path[0] - 1;
|
||||||
i++;
|
pathLength++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (arr[0] == arr[i - 1]) {
|
if (path[0] == path[pathLength - 1]) {
|
||||||
i--;
|
pathLength--;
|
||||||
}
|
}
|
||||||
arr[0] = arr[i - 1];
|
path[0] = path[pathLength - 1];
|
||||||
GetCell(arr[0]).x1_26_ = true;
|
GetCell(path[0]).x1_26_checked = true;
|
||||||
}
|
}
|
||||||
s32* v = &arr[i];
|
s32* idx = &path[pathLength];
|
||||||
while (i != 0) {
|
while (pathLength != 0) {
|
||||||
i--;
|
pathLength--;
|
||||||
v--;
|
idx--;
|
||||||
if (GetCell(*v).x1_26_) {
|
auto& cell = GetCell(*idx);
|
||||||
GetCell(*v).x1_25_ = true;
|
if (cell.x1_26_checked) {
|
||||||
|
cell.x1_25_onPath = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x94_24_initialized = true;
|
x94_24_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScriptMazeState::sub_802899c8() {
|
void CMazeState::GenerateObstacles() {
|
||||||
if (!x94_24_initialized) {
|
if (!x94_24_initialized) {
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
@ -369,95 +356,90 @@ void CScriptMazeState::sub_802899c8() {
|
||||||
s32 tmp = x0_rand.Next();
|
s32 tmp = x0_rand.Next();
|
||||||
return tmp + ((tmp / 5) * -5) + offset;
|
return tmp + ((tmp / 5) * -5) + offset;
|
||||||
};
|
};
|
||||||
s32 rand1 = GetRandom(9);
|
s32 gate1Idx = GetRandom(9);
|
||||||
s32 rand2 = GetRandom(21);
|
s32 gate2Idx = GetRandom(21);
|
||||||
s32 rand3 = GetRandom(33);
|
s32 gate3Idx = GetRandom(33);
|
||||||
s32 rand4 = GetRandom(13);
|
s32 puddle1Idx = GetRandom(13);
|
||||||
s32 rand5 = GetRandom(29);
|
s32 puddle2Idx = GetRandom(29);
|
||||||
|
|
||||||
u32 state = -1;
|
ESide side = ESide::Invalid;
|
||||||
s32 idx = 0;
|
s32 idx = 0;
|
||||||
|
|
||||||
s32 prevCol = x84_startCol;
|
s32 prevCol = x84_targetCol;
|
||||||
s32 prevRow = x88_startRow;
|
s32 prevRow = x88_targetRow;
|
||||||
s32 col = x84_startCol;
|
s32 col = x84_targetCol;
|
||||||
s32 row = x88_startRow;
|
s32 row = x88_targetRow;
|
||||||
|
|
||||||
while (col != x8c_endCol || row != x90_endRow) {
|
while (col != x8c_enterCol || row != x90_enterRow) {
|
||||||
if (idx == rand1 || idx == rand2 || idx == rand3) {
|
if (idx == gate1Idx || idx == gate2Idx || idx == gate3Idx) {
|
||||||
if (state == 2) {
|
if (side == ESide::Bottom) {
|
||||||
GetCell(col, row).x0_28_ = true;
|
GetCell(col, row).x0_28_gateTop = true;
|
||||||
GetCell(prevCol, prevRow).x0_30_ = true;
|
GetCell(prevCol, prevRow).x0_30_gateBottom = true;
|
||||||
} else if (state == 0) {
|
} else if (side == ESide::Top) {
|
||||||
GetCell(col, row).x0_30_ = true;
|
GetCell(col, row).x0_30_gateBottom = true;
|
||||||
GetCell(prevCol, prevRow).x0_28_ = true;
|
GetCell(prevCol, prevRow).x0_28_gateTop = true;
|
||||||
} else if (state == 1) {
|
} else if (side == ESide::Right) {
|
||||||
GetCell(col, row).x0_31_ = true;
|
GetCell(col, row).x0_31_gateLeft = true;
|
||||||
GetCell(prevCol, prevRow).x0_29_ = true;
|
GetCell(prevCol, prevRow).x0_29_gateRight = true;
|
||||||
} else if (state == 3) {
|
} else if (side == ESide::Left) {
|
||||||
GetCell(col, row).x0_29_ = true;
|
GetCell(col, row).x0_29_gateRight = true;
|
||||||
GetCell(prevCol, prevRow).x0_31_ = true;
|
GetCell(prevCol, prevRow).x0_31_gateLeft = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s32 nextCol = col;
|
|
||||||
|
|
||||||
|
s32 nextCol = col;
|
||||||
s32 nextRow = -1;
|
s32 nextRow = -1;
|
||||||
if (row < 1 || state == 2 || !GetCell(col, row).x0_24_ || !GetCell(col, row - 1).x1_25_) {
|
if (row < 1 || side == ESide::Bottom || !GetCell(col, row).x0_24_openTop || !GetCell(col, row - 1).x1_25_onPath) {
|
||||||
if (row < 6 && state != 0 && GetCell(col, row).x0_26_ && GetCell(col, row + 1).x1_25_) {
|
if (row < skMazeRows - 1 && side != ESide::Top && GetCell(col, row).x0_26_openBottom &&
|
||||||
state = 2;
|
GetCell(col, row + 1).x1_25_onPath) {
|
||||||
|
side = ESide::Bottom;
|
||||||
nextRow = row + 1;
|
nextRow = row + 1;
|
||||||
} else {
|
} else {
|
||||||
nextRow = row;
|
nextRow = row;
|
||||||
if (col < 1 || state == 1 || !GetCell(col, row).x0_27_ || !GetCell((col + row * skMazeColumns) - 1).x1_25_) {
|
if (col < 1 || side == ESide::Right || !GetCell(col, row).x0_27_openLeft ||
|
||||||
if (col > skMazeRows) {
|
!GetCell(col - 1, row).x1_25_onPath) {
|
||||||
|
if (col > skMazeRows || side == ESide::Left || !GetCell(col, row).x0_25_openRight ||
|
||||||
|
!GetCell(col + 1, row).x1_25_onPath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state == 3) {
|
side = ESide::Right;
|
||||||
return;
|
|
||||||
}
|
|
||||||
s32 iVar4_ = col + row * skMazeColumns;
|
|
||||||
if (!GetCell(iVar4_).x0_25_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!GetCell(iVar4_ + 1).x1_25_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
state = 1;
|
|
||||||
nextCol = col + 1;
|
nextCol = col + 1;
|
||||||
} else {
|
} else {
|
||||||
state = 3;
|
side = ESide::Left;
|
||||||
nextCol = col - 1;
|
nextCol = col - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state = 0;
|
side = ESide::Top;
|
||||||
nextRow = row - 1;
|
nextRow = row - 1;
|
||||||
}
|
}
|
||||||
if (idx == rand4 || idx == rand5) {
|
|
||||||
if (col == 0 || row == 0 || col == 8 || row == 6) {
|
if (idx == puddle1Idx || idx == puddle2Idx) {
|
||||||
if (idx == rand4) {
|
if (col == 0 || row == 0 || col == skMazeCols - 1 || row == skMazeRows - 1) {
|
||||||
rand4++;
|
if (idx == puddle1Idx) {
|
||||||
|
puddle1Idx++;
|
||||||
} else {
|
} else {
|
||||||
rand5++;
|
puddle2Idx++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto& cell = GetCell(col, row);
|
auto& cell = GetCell(col, row);
|
||||||
cell.x1_24_ = true;
|
cell.x1_24_puddle = true;
|
||||||
if (state == 2) {
|
if (side == ESide::Bottom) {
|
||||||
GetCell(nextCol, nextRow).x0_24_ = false;
|
GetCell(nextCol, nextRow).x0_24_openTop = false;
|
||||||
cell.x0_26_ = false;
|
cell.x0_26_openBottom = false;
|
||||||
} else if (state == 0) {
|
} else if (side == ESide::Top) {
|
||||||
GetCell(nextCol, nextRow).x0_26_ = false;
|
GetCell(nextCol, nextRow).x0_26_openBottom = false;
|
||||||
cell.x0_24_ = false;
|
cell.x0_24_openTop = false;
|
||||||
} else if (state == 1) {
|
} else if (side == ESide::Right) {
|
||||||
GetCell(nextCol, nextRow).x0_27_ = false;
|
GetCell(nextCol, nextRow).x0_27_openLeft = false;
|
||||||
cell.x0_25_ = false;
|
cell.x0_25_openRight = false;
|
||||||
} else if (state == 3) {
|
} else if (side == ESide::Left) {
|
||||||
GetCell(nextCol, nextRow).x0_25_ = false;
|
GetCell(nextCol, nextRow).x0_25_openRight = false;
|
||||||
cell.x0_27_ = false;
|
cell.x0_27_openLeft = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idx++;
|
idx++;
|
||||||
prevCol = col;
|
prevCol = col;
|
||||||
prevRow = row;
|
prevRow = row;
|
||||||
|
|
|
@ -11,46 +11,63 @@
|
||||||
#include <zeus/CVector3f.hpp>
|
#include <zeus/CVector3f.hpp>
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
constexpr s32 skMazeCols = 9;
|
||||||
constexpr s32 skMazeRows = 7;
|
constexpr s32 skMazeRows = 7;
|
||||||
constexpr s32 skMazeColumns = 9;
|
constexpr s32 skTargetCol = 4;
|
||||||
|
constexpr s32 skTargetRow = 4;
|
||||||
|
constexpr s32 skEnterCol = 5;
|
||||||
|
constexpr s32 skEnterRow = 3;
|
||||||
|
|
||||||
struct CScriptMazeStateCell {
|
enum class ESide {
|
||||||
bool x0_24_ : 1 = false;
|
Invalid = -1,
|
||||||
bool x0_25_ : 1 = false;
|
Top = 0,
|
||||||
bool x0_26_ : 1 = false;
|
Right = 1,
|
||||||
bool x0_27_ : 1 = false;
|
Bottom = 2,
|
||||||
bool x0_28_ : 1 = false;
|
Left = 3,
|
||||||
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 CScriptMazeState {
|
struct SMazeCell {
|
||||||
|
bool x0_24_openTop : 1 = false;
|
||||||
|
bool x0_25_openRight : 1 = false;
|
||||||
|
bool x0_26_openBottom : 1 = false;
|
||||||
|
bool x0_27_openLeft : 1 = false;
|
||||||
|
bool x0_28_gateTop : 1 = false;
|
||||||
|
bool x0_29_gateRight : 1 = false;
|
||||||
|
bool x0_30_gateBottom : 1 = false;
|
||||||
|
bool x0_31_gateLeft : 1 = false;
|
||||||
|
bool x1_24_puddle : 1 = false;
|
||||||
|
bool x1_25_onPath : 1 = false;
|
||||||
|
bool x1_26_checked : 1 = false;
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr bool IsOpen() const {
|
||||||
|
return x0_24_openTop || x0_25_openRight || x0_26_openBottom || x0_27_openLeft;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CMazeState {
|
||||||
CRandom16 x0_rand{0};
|
CRandom16 x0_rand{0};
|
||||||
std::array<CScriptMazeStateCell, skMazeRows * skMazeColumns> x4_cells{};
|
std::array<SMazeCell, skMazeRows * skMazeCols> x4_cells{};
|
||||||
s32 x84_startCol;
|
s32 x84_targetCol;
|
||||||
s32 x88_startRow;
|
s32 x88_targetRow;
|
||||||
s32 x8c_endCol;
|
s32 x8c_enterCol;
|
||||||
s32 x90_endRow;
|
s32 x90_enterRow;
|
||||||
bool x94_24_initialized : 1 = false;
|
bool x94_24_initialized : 1 = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CScriptMazeState(s32 w1, s32 w2, s32 w3, s32 w4) : x84_startCol(w1), x88_startRow(w2), x8c_endCol(w3), x90_endRow(w4) {}
|
CMazeState(s32 targetCol, s32 targetRow, s32 enterCol, s32 enterRow)
|
||||||
|
: x84_targetCol(targetCol), x88_targetRow(targetRow), x8c_enterCol(enterCol), x90_enterRow(enterRow) {}
|
||||||
void Reset(s32 seed);
|
void Reset(s32 seed);
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void sub_802899c8();
|
void GenerateObstacles();
|
||||||
|
|
||||||
[[nodiscard]] CScriptMazeStateCell& GetCell(u32 col, u32 row) {
|
[[nodiscard]] SMazeCell& GetCell(u32 col, u32 row) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
assert(col < skMazeColumns);
|
assert(col < skMazeCols);
|
||||||
assert(row < skMazeRows);
|
assert(row < skMazeRows);
|
||||||
#endif
|
#endif
|
||||||
return x4_cells[col + row * skMazeColumns];
|
return x4_cells[col + row * skMazeCols];
|
||||||
}
|
}
|
||||||
[[nodiscard]] CScriptMazeStateCell& GetCell(u32 idx) {
|
[[nodiscard]] SMazeCell& GetCell(u32 idx) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
assert(idx < x4_cells.size());
|
assert(idx < x4_cells.size());
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,8 +78,8 @@ public:
|
||||||
class CScriptMazeNode : public CActor {
|
class CScriptMazeNode : public CActor {
|
||||||
s32 xe8_col;
|
s32 xe8_col;
|
||||||
s32 xec_row;
|
s32 xec_row;
|
||||||
s32 xf0_;
|
ESide xf0_side;
|
||||||
TUniqueId xf4_ = kInvalidUniqueId;
|
TUniqueId xf4_gateEffectId = kInvalidUniqueId;
|
||||||
float xf8_msgTimer = 1.f;
|
float xf8_msgTimer = 1.f;
|
||||||
TUniqueId xfc_actorId = kInvalidUniqueId;
|
TUniqueId xfc_actorId = kInvalidUniqueId;
|
||||||
zeus::CVector3f x100_actorPos;
|
zeus::CVector3f x100_actorPos;
|
||||||
|
@ -70,14 +87,14 @@ class CScriptMazeNode : public CActor {
|
||||||
zeus::CVector3f x110_triggerPos;
|
zeus::CVector3f x110_triggerPos;
|
||||||
TUniqueId x11c_effectId = kInvalidUniqueId;
|
TUniqueId x11c_effectId = kInvalidUniqueId;
|
||||||
zeus::CVector3f x120_effectPos;
|
zeus::CVector3f x120_effectPos;
|
||||||
std::vector<TUniqueId> x12c_;
|
std::vector<TUniqueId> x12c_puddleObjectIds;
|
||||||
bool x13c_24_ : 1 = false;
|
bool x13c_24_hasPuddle : 1 = false;
|
||||||
bool x13c_25_ : 1 = false;
|
bool x13c_25_hasGate : 1 = false;
|
||||||
bool x13c_26_ : 1 = true;
|
bool x13c_26_gateActive : 1 = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CScriptMazeNode(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
|
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& actorPos,
|
bool active, s32 col, s32 row, s32 side, const zeus::CVector3f& actorPos,
|
||||||
const zeus::CVector3f& triggerPos, const zeus::CVector3f& effectPos);
|
const zeus::CVector3f& triggerPos, const zeus::CVector3f& effectPos);
|
||||||
|
|
||||||
void Accept(IVisitor& visitor) override;
|
void Accept(IVisitor& visitor) override;
|
||||||
|
|
Loading…
Reference in New Issue