2023-12-13 00:40:16 -05:00
|
|
|
#include "Game/NPC/TalkNodeCtrl.hpp"
|
|
|
|
|
#include "Game/System/MessageHolder.hpp"
|
|
|
|
|
#include "Game/Util.hpp"
|
2023-01-05 23:44:58 -05:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
|
|
void TalkMessageHistory::entry(u16 msgID) {
|
|
|
|
|
mHistory[mCount++] = msgID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TalkMessageHistory::search(u16 msgID) const {
|
|
|
|
|
for (s32 i = 0; i < mCount; i++) {
|
|
|
|
|
if (mHistory[i] == msgID) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TalkNodeCtrl::TalkNodeCtrl() : _0(0), mCurrentNodeIdx(-1), mMessageInfo() {
|
|
|
|
|
mHistory.mCount = 0;
|
2023-02-13 03:33:10 -05:00
|
|
|
_38 = nullptr;
|
|
|
|
|
mCurrentNode = nullptr;
|
2023-01-05 23:44:58 -05:00
|
|
|
mNodeData = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TalkNodeCtrl::resetFlowNode() {
|
|
|
|
|
if (mCurrentNode != _38) {
|
|
|
|
|
mCurrentNode = _38;
|
|
|
|
|
mFlowNode = _38;
|
|
|
|
|
updateMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TalkNodeCtrl::resetTempFlowNode() {
|
|
|
|
|
if (mCurrentNode != mFlowNode) {
|
|
|
|
|
mCurrentNode = mFlowNode;
|
|
|
|
|
updateMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TalkNodeCtrl::recordTempFlowNode() {
|
|
|
|
|
mFlowNode = mCurrentNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TalkNodeCtrl::forwardFlowNode() {
|
|
|
|
|
TalkNode* node = mCurrentNode;
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
if (node == nullptr) {
|
2023-01-05 23:44:58 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (node->mNodeType == 1) {
|
|
|
|
|
u16 idx = node->mNextIdx;
|
|
|
|
|
MessageData* msg = MessageSystem::getSceneMessageData();
|
|
|
|
|
mCurrentNode = msg->getNode(idx);
|
|
|
|
|
}
|
|
|
|
|
else if (node->mNodeType == 3) {
|
|
|
|
|
u16 idx = node->mNextIdx;
|
|
|
|
|
MessageData* msg = MessageSystem::getSceneMessageData();
|
|
|
|
|
mCurrentNode = msg->getBranchNode(idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateMessage();
|
|
|
|
|
}
|
2023-01-05 05:28:40 -05:00
|
|
|
|
|
|
|
|
bool TalkNodeCtrl::isExistNextNode() const {
|
2023-02-13 03:33:10 -05:00
|
|
|
return getNextNode() != nullptr;
|
2023-01-05 05:28:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TalkNodeCtrl::isNextNodeMessage() const {
|
|
|
|
|
TalkNode* next = getNextNode();
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
if (next != nullptr || next->mNodeType != 1) {
|
2023-01-05 05:28:40 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TalkNodeCtrl::isCurrentNodeEvent() const {
|
2023-02-13 03:33:10 -05:00
|
|
|
return getCurrentNodeEvent() != nullptr;
|
2023-01-05 05:28:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-05 23:44:58 -05:00
|
|
|
TalkNode* TalkNodeCtrl::getNextNode() const {
|
|
|
|
|
TalkNode* node = mCurrentNode;
|
|
|
|
|
u16 idx;
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
if (node == nullptr) {
|
|
|
|
|
return nullptr;
|
2023-01-05 23:44:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (node->mNodeType == 1) {
|
|
|
|
|
idx = node->mNextIdx;
|
|
|
|
|
if (idx != 0xFFFF) {
|
|
|
|
|
return MessageSystem::getSceneMessageData()->getNode(idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (node->mNodeType == 3) {
|
|
|
|
|
idx = node->mIndex;
|
|
|
|
|
MessageData* msg = MessageSystem::getSceneMessageData();
|
|
|
|
|
|
|
|
|
|
if (msg->isValidBranchNode(idx)) {
|
|
|
|
|
idx = node->mIndex;
|
|
|
|
|
MessageData* msg = MessageSystem::getSceneMessageData();
|
|
|
|
|
return msg->getBranchNode(idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
return nullptr;
|
2023-01-05 23:44:58 -05:00
|
|
|
}
|
2023-01-05 05:28:40 -05:00
|
|
|
|
|
|
|
|
TalkNode* TalkNodeCtrl::getNextNodeBranch() const {
|
|
|
|
|
TalkNode* node = getNextNode();
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
if (node == nullptr) {
|
|
|
|
|
return nullptr;
|
2023-01-05 05:28:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
return node->mNodeType != 2 ? nullptr : node;
|
2023-01-05 05:28:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TalkNode* TalkNodeCtrl::getCurrentNodeBranch() const {
|
2023-02-13 03:33:10 -05:00
|
|
|
if (mCurrentNode != nullptr && mCurrentNode->mNodeType == 2) {
|
2023-01-05 05:28:40 -05:00
|
|
|
return mCurrentNode;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
return nullptr;
|
2023-01-05 05:28:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TalkNode* TalkNodeCtrl::getCurrentNodeMessage() const {
|
2023-02-13 03:33:10 -05:00
|
|
|
if (mCurrentNode != nullptr && mCurrentNode->mNodeType == 1) {
|
2023-01-05 05:28:40 -05:00
|
|
|
return mCurrentNode;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
return nullptr;
|
2023-01-05 05:28:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TalkNode* TalkNodeCtrl::getCurrentNodeEvent() const {
|
2023-02-13 03:33:10 -05:00
|
|
|
if (mCurrentNode != nullptr && mCurrentNode->mNodeType == 3) {
|
2023-01-05 05:28:40 -05:00
|
|
|
return mCurrentNode;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
return nullptr;
|
2023-01-05 05:28:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TalkNode* TalkNodeCtrl::getNextNodeEvent() const {
|
|
|
|
|
TalkNode* node = getNextNode();
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
if (node == nullptr) {
|
|
|
|
|
return nullptr;
|
2023-01-05 05:28:40 -05:00
|
|
|
}
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
return node->mNodeType != 3 ? nullptr : node;
|
2023-01-05 23:44:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TalkNodeCtrl::updateMessage() {
|
|
|
|
|
u16 idx;
|
|
|
|
|
u8 groupID;
|
|
|
|
|
TalkNode* cur = mCurrentNode;
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
if (cur != nullptr) {
|
2023-01-05 23:44:58 -05:00
|
|
|
if (cur->mNodeType != 1) {
|
|
|
|
|
mMessageInfo._0 = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
idx = cur->mIndex;
|
|
|
|
|
groupID = cur->mGroupID;
|
|
|
|
|
MessageData* msg = MessageSystem::getSceneMessageData();
|
|
|
|
|
msg->getMessage(&mMessageInfo, groupID, idx);
|
|
|
|
|
mCurrentNodeIdx = cur->mIndex;
|
|
|
|
|
|
|
|
|
|
TalkNode* nextBranchNode = getNextNodeBranch();
|
|
|
|
|
|
2023-02-13 03:33:10 -05:00
|
|
|
if (nextBranchNode != nullptr) {
|
2023-01-05 23:44:58 -05:00
|
|
|
mNodeData = nextBranchNode->mIndex;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
mNodeData = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mMessageInfo.isEventTalk()) {
|
|
|
|
|
if (mHistory.search(mCurrentNodeIdx)) {
|
|
|
|
|
mMessageInfo.mTalkType = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s8 msgId = mMessageInfo._B;
|
|
|
|
|
|
|
|
|
|
if (msgId != -1) {
|
|
|
|
|
if (MR::isOnMessageAlreadyRead(msgId)) {
|
|
|
|
|
mMessageInfo.mTalkType = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TalkNodeCtrl::readMessage() {
|
|
|
|
|
if (mMessageInfo.isEventTalk()) {
|
|
|
|
|
if (!mHistory.search(mCurrentNodeIdx)) {
|
|
|
|
|
mHistory.entry(mCurrentNodeIdx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mMessageInfo.mTalkType = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mMessageInfo._B != -1) {
|
|
|
|
|
MR::onMessageAlreadyRead(mMessageInfo._B);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TalkNodeCtrl::forwardCurrentBranchNode(bool storeCurrent) {
|
|
|
|
|
TalkNode* cur = mCurrentNode;
|
|
|
|
|
|
|
|
|
|
if (storeCurrent) {
|
|
|
|
|
u16 group = cur->mNextGroup;
|
|
|
|
|
MessageData* msg = MessageSystem::getSceneMessageData();
|
|
|
|
|
mCurrentNode = msg->getBranchNode(group);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
u16 group = cur->mNextGroup;
|
|
|
|
|
MessageData* msg = MessageSystem::getSceneMessageData();
|
|
|
|
|
mCurrentNode = msg->getBranchNode(group + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef NON_MATCHING
|
|
|
|
|
// refuses to load the msgID before the getCurrentPlacementZoneName() call
|
|
|
|
|
void TalkNodeCtrl::createFlowNode(TalkMessageCtrl *pMsgCtrl, const JMapInfoIter &rIter, const char *pName, ActorCameraInfo **pCameraInf) {
|
|
|
|
|
char buf[0x100];
|
|
|
|
|
s32 msgID = MR::getMessageID(rIter);
|
|
|
|
|
snprintf(buf, 0x100, "%s_%s%03d", MR::getCurrentPlacementZoneName(), pName, msgID);
|
|
|
|
|
createFlowNodeDirect(pMsgCtrl, rIter, buf, pCameraInf);
|
|
|
|
|
}
|
|
|
|
|
#endif
|