summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2024-04-23 22:29:27 +0100
committerLéo Lam <leo@leolam.fr>2024-04-23 22:30:20 +0100
commita196e0ca5a1f2544b1b6e12e34684401439365a3 (patch)
treecbb47049084cade459653fc1f253232aa762d5e5 /src
parent726d8a2b3120cee3e502f4c77b20c72774bffe54 (diff)
ksys/qst: match Manager::setQuestStep
I'm not a big fan of how the actual logic has to be inside the loop, but unfortunately std::find_if doesn't match and it's clear that the original version used iterators.
Diffstat (limited to 'src')
-rw-r--r--src/KingSystem/Quest/qstManager.cpp46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/KingSystem/Quest/qstManager.cpp b/src/KingSystem/Quest/qstManager.cpp
index a5929790..6237b931 100644
--- a/src/KingSystem/Quest/qstManager.cpp
+++ b/src/KingSystem/Quest/qstManager.cpp
@@ -102,38 +102,34 @@ bool Manager::setQuestStepFromEvent(const sead::SafeString& quest_name,
return setQuestStep(quest_name, step_name, true, force_run_telop, setAocVersionFlag1);
}
-// NON_MATCHING: quest is dereferenced several times
bool Manager::setQuestStep(const sead::SafeString& quest_name, const sead::SafeString& step_name,
bool copy_name, bool force_run_telop, bool setAocVersionFlag1) {
- u32 hash = sead::HashCRC32::calcStringHash(quest_name.cstr());
- Quest* quest;
- for (auto& q : mQuests) {
- if (q._c - 1 <= 1 && q.mNameHash == hash) {
- quest = &q;
- break;
- }
- }
- if (quest == nullptr)
- return false;
+ u32 hash = sead::HashCRC32::calcStringHash(quest_name);
+ for (auto it = mQuests.begin(), end = mQuests.end(); it != end; ++it) {
+ if ((it->_c != 1 && it->_c != 2) || it->mNameHash != hash)
+ continue;
- quest->setField31();
+ it->setField31();
- quest->_e8.copy(step_name);
+ it->_e8.copy(step_name);
- quest->_e0 = false;
- quest->mForceRunTelop = false;
+ it->_e0 = false;
+ it->mForceRunTelop = false;
+
+ if (copy_name) {
+ it->_e0 = true;
+ if (step_name.isEmpty())
+ it->_e8.copy(it->x_11());
+ }
+ if (force_run_telop)
+ it->mForceRunTelop = true;
+ if (setAocVersionFlag1)
+ it->mAocVersionFlags |= 1;
- if (copy_name) {
- quest->_e0 = true;
- const char* x = quest->x_11();
- if (step_name.isEmpty())
- quest->_e8.copy(sead::SafeString(x));
+ return true;
}
- if (force_run_telop)
- quest->mForceRunTelop = true;
- if (setAocVersionFlag1)
- quest->mAocVersionFlags |= 1;
- return true;
+
+ return false;
}
} // namespace ksys::qst