From 554bf8e58601483b3fc4b520972e4b2137cc6fda Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 10 Feb 2012 22:01:31 +0100 Subject: [PATCH] Improvement in the dialogue manager --- apps/openmw/mwdialogue/dialoguemanager.cpp | 78 ++++++++++++++-------- apps/openmw/mwdialogue/dialoguemanager.hpp | 1 + 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 053e3987bf..8e70778700 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -36,6 +36,7 @@ namespace return lowerCase; } + template bool selectCompare (char comp, T1 value1, T2 value2) { @@ -399,8 +400,39 @@ namespace MWDialogue { std::cout << "talking with " << MWWorld::Class::get (actor).getName (actor) << std::endl; + //initialise the GUI + mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue); + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->startDialogue(MWWorld::Class::get (actor).getName (actor)); + + actorKnownTopics.clear(); + ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; + for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) + { + ESM::Dialogue ndialogue = it->second; + if(ndialogue.type == ESM::Dialogue::Type::Topic) + { + for (std::vector::const_iterator iter (it->second.mInfo.begin()); + iter!=it->second.mInfo.end(); ++iter) + { + if (isMatching (actor, *iter)) + { + actorKnownTopics[it->first] = iter->response; + if(knownTopics.find(toLower(it->first)) != knownTopics.end()) + { + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->addKeyword(it->first,iter->response); + //std::cout << it->first; + //std::cout << "match found!!"; + break; + } + } + } + } + } + const ESM::Dialogue *dialogue = mEnvironment.mWorld->getStore().dialogs.find ("hello"); - + for (std::vector::const_iterator iter (dialogue->mInfo.begin()); iter!=dialogue->mInfo.end(); ++iter) { @@ -421,43 +453,31 @@ namespace MWDialogue std::cout << "script: " << iter->resultScript << std::endl; // TODO execute script } - - mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue); - MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - win->startDialogue(MWWorld::Class::get (actor).getName (actor)); win->addText(iter->response); break; } } + } - ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; - for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) - { - ESM::Dialogue ndialogue = it->second; - if(ndialogue.type == ESM::Dialogue::Type::Topic) - { - for (std::vector::const_iterator iter (it->second.mInfo.begin()); - iter!=it->second.mInfo.end(); ++iter) - { - if (isMatching (actor, *iter)) - { - if(knownTopics.find(toLower(it->first)) != knownTopics.end()) - { - MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - win->addKeyword(it->first,iter->response); - //std::cout << it->first; - //std::cout << "match found!!"; - break; - } - } - } - } - } + //helper function + std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos) + { + return toLower(str).find(toLower(substr),pos); } void DialogueManager::keywordSelected(std::string keyword) { - std::cout << "keyword" << keyword; + std::string text = actorKnownTopics[keyword]; + std::map::iterator it; + for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++) + { + if(find_str_ci(text,it->second,0) !=std::string::npos) + { + knownTopics[it->first] = true; + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->addKeyword(it->first,it->second); + } + } } void DialogueManager::goodbyeSelected() diff --git a/apps/openmw/mwdialogue/dialoguemanager.hpp b/apps/openmw/mwdialogue/dialoguemanager.hpp index cafad7c6ec..88ae9e35c7 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.hpp +++ b/apps/openmw/mwdialogue/dialoguemanager.hpp @@ -22,6 +22,7 @@ namespace MWDialogue bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const; std::map knownTopics;// Those are the topics the player knows. + std::map actorKnownTopics; public: