2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2016-08-14 21:38:05 +00:00
|
|
|
|
2020-04-12 19:23:26 +00:00
|
|
|
#include <array>
|
2020-09-20 20:36:24 +00:00
|
|
|
#include <cassert>
|
2019-09-23 19:00:23 +00:00
|
|
|
#include <string_view>
|
|
|
|
|
2020-09-19 17:30:44 +00:00
|
|
|
#include "Runtime/CRandom16.hpp"
|
2020-09-22 00:42:54 +00:00
|
|
|
#include "Runtime/Graphics/CLineRenderer.hpp"
|
2019-09-23 19:00:23 +00:00
|
|
|
#include "Runtime/RetroTypes.hpp"
|
|
|
|
#include "Runtime/World/CActor.hpp"
|
|
|
|
|
|
|
|
#include <zeus/CVector3f.hpp>
|
2016-08-14 21:38:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2020-09-21 22:38:11 +00:00
|
|
|
constexpr s32 skMazeCols = 9;
|
2020-09-20 20:36:24 +00:00
|
|
|
constexpr s32 skMazeRows = 7;
|
2020-09-22 00:42:54 +00:00
|
|
|
constexpr s32 skEnterCol = 4;
|
|
|
|
constexpr s32 skEnterRow = 4;
|
|
|
|
constexpr s32 skTargetCol = 5;
|
|
|
|
constexpr s32 skTargetRow = 3;
|
2020-09-19 19:52:15 +00:00
|
|
|
|
2020-09-21 22:38:11 +00:00
|
|
|
enum class ESide {
|
|
|
|
Invalid = -1,
|
|
|
|
Top = 0,
|
|
|
|
Right = 1,
|
|
|
|
Bottom = 2,
|
|
|
|
Left = 3,
|
2020-09-19 17:30:44 +00:00
|
|
|
};
|
2020-09-19 18:52:43 +00:00
|
|
|
|
2020-09-21 22:38:11 +00:00
|
|
|
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 {
|
2020-09-19 17:30:44 +00:00
|
|
|
CRandom16 x0_rand{0};
|
2020-09-21 22:38:11 +00:00
|
|
|
std::array<SMazeCell, skMazeRows * skMazeCols> x4_cells{};
|
2020-09-22 00:42:54 +00:00
|
|
|
s32 x84_enterCol;
|
|
|
|
s32 x88_enterRow;
|
|
|
|
s32 x8c_targetCol;
|
|
|
|
s32 x90_targetRow;
|
2020-09-19 17:30:44 +00:00
|
|
|
bool x94_24_initialized : 1 = false;
|
|
|
|
|
2020-09-22 00:42:54 +00:00
|
|
|
std::vector<s32> m_path;
|
|
|
|
CLineRenderer m_renderer = {CLineRenderer::EPrimitiveMode::LineStrip, skMazeRows * skMazeCols, {}, true};
|
|
|
|
|
2020-09-19 18:52:43 +00:00
|
|
|
public:
|
2020-09-22 00:42:54 +00:00
|
|
|
CMazeState(s32 enterCol, s32 enterRow, s32 targetCol, s32 targetRow)
|
|
|
|
: x84_enterCol(enterCol), x88_enterRow(enterRow), x8c_targetCol(targetCol), x90_targetRow(targetRow) {}
|
2020-09-19 18:52:43 +00:00
|
|
|
void Reset(s32 seed);
|
|
|
|
void Initialize();
|
2020-09-21 22:38:11 +00:00
|
|
|
void GenerateObstacles();
|
2020-09-20 05:47:12 +00:00
|
|
|
|
2020-09-22 00:42:54 +00:00
|
|
|
void DebugRender();
|
|
|
|
|
2020-09-21 22:38:11 +00:00
|
|
|
[[nodiscard]] SMazeCell& GetCell(u32 col, u32 row) {
|
2020-09-20 20:36:24 +00:00
|
|
|
#ifndef NDEBUG
|
2020-09-21 22:38:11 +00:00
|
|
|
assert(col < skMazeCols);
|
2020-09-20 20:36:24 +00:00
|
|
|
assert(row < skMazeRows);
|
|
|
|
#endif
|
2020-09-21 22:38:11 +00:00
|
|
|
return x4_cells[col + row * skMazeCols];
|
2020-09-20 20:36:24 +00:00
|
|
|
}
|
2020-09-21 22:38:11 +00:00
|
|
|
[[nodiscard]] SMazeCell& GetCell(u32 idx) {
|
2020-09-20 20:36:24 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
assert(idx < x4_cells.size());
|
|
|
|
#endif
|
|
|
|
return x4_cells[idx];
|
2020-09-20 05:47:12 +00:00
|
|
|
}
|
2020-09-19 17:30:44 +00:00
|
|
|
};
|
2020-09-19 18:52:43 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CScriptMazeNode : public CActor {
|
2020-09-20 05:47:12 +00:00
|
|
|
s32 xe8_col;
|
|
|
|
s32 xec_row;
|
2020-09-21 22:38:11 +00:00
|
|
|
ESide xf0_side;
|
|
|
|
TUniqueId xf4_gateEffectId = kInvalidUniqueId;
|
2020-09-20 07:25:56 +00:00
|
|
|
float xf8_msgTimer = 1.f;
|
2020-09-19 17:30:44 +00:00
|
|
|
TUniqueId xfc_actorId = kInvalidUniqueId;
|
|
|
|
zeus::CVector3f x100_actorPos;
|
|
|
|
TUniqueId x10c_triggerId = kInvalidUniqueId;
|
|
|
|
zeus::CVector3f x110_triggerPos;
|
|
|
|
TUniqueId x11c_effectId = kInvalidUniqueId;
|
|
|
|
zeus::CVector3f x120_effectPos;
|
2020-09-21 22:38:11 +00:00
|
|
|
std::vector<TUniqueId> x12c_puddleObjectIds;
|
|
|
|
bool x13c_24_hasPuddle : 1 = false;
|
|
|
|
bool x13c_25_hasGate : 1 = false;
|
|
|
|
bool x13c_26_gateActive : 1 = true;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2016-08-14 21:38:05 +00:00
|
|
|
public:
|
2020-09-20 07:25:56 +00:00
|
|
|
CScriptMazeNode(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
|
2020-09-21 22:38:11 +00:00
|
|
|
bool active, s32 col, s32 row, s32 side, const zeus::CVector3f& actorPos,
|
2020-09-20 07:25:56 +00:00
|
|
|
const zeus::CVector3f& triggerPos, const zeus::CVector3f& effectPos);
|
2016-08-14 21:38:05 +00:00
|
|
|
|
2019-08-09 12:45:18 +00:00
|
|
|
void Accept(IVisitor& visitor) override;
|
2020-09-19 18:52:43 +00:00
|
|
|
void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) override;
|
2020-09-20 05:47:12 +00:00
|
|
|
void Think(float dt, CStateManager& mgr) override;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static void LoadMazeSeeds();
|
2020-09-19 17:30:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void GenerateObjects(CStateManager& mgr);
|
2020-09-19 17:44:32 +00:00
|
|
|
void Reset(CStateManager& mgr);
|
2020-09-20 05:47:12 +00:00
|
|
|
void SendScriptMsgs(CStateManager& mgr, EScriptObjectMessage msg);
|
2016-08-14 21:38:05 +00:00
|
|
|
};
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|