diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 2a583f14b..34cd51f25 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -550,25 +550,23 @@ namespace MWDialogue void DialogueManager::parseText(std::string text) { - std::map >::iterator it; + std::cout << "PARSE"; + std::list::iterator it; for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++) { MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - size_t pos = find_str_ci(text,it->first,0); + size_t pos = find_str_ci(text,*it,0); if(pos !=std::string::npos) { - if(!it->second.empty()) + if(pos==0) { - if(pos==0) - { - knownTopics[it->first] = true; - win->addKeyword(it->first); - } - else if(text.substr(pos -1,1) == " ") - { - knownTopics[it->first] = true; - win->addKeyword(it->first); - } + knownTopics[*it] = true; + win->addKeyword(*it); + } + else if(text.substr(pos -1,1) == " ") + { + knownTopics[*it] = true; + win->addKeyword(*it); } } @@ -583,38 +581,25 @@ namespace MWDialogue mActor = actor; + mDialogueMap.clear(); + actorKnownTopics.clear(); + ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; + for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) + { + mDialogueMap[it->first] = it->second; + } + //initialise the GUI mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue); MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); win->startDialogue(MWWorld::Class::get (actor).getName (actor)); //setup the list of topics known by the actor. Topics who are also on the knownTopics list will be added to the GUI - 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::Topic) - { - for (std::vector::const_iterator iter (it->second.mInfo.begin()); - iter!=it->second.mInfo.end(); ++iter) - { - if (isMatching (actor, *iter) && functionFilter(mActor,*iter,false)) - { - actorKnownTopics[it->first].push_back(*iter); - //does the player know the topic? - if(knownTopics.find(toLower(it->first)) != knownTopics.end()) - { - MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - win->addKeyword(it->first); - } - } - } - } - } + updateTopics(); //greeting bool greetingFound = false; + //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; @@ -647,7 +632,6 @@ namespace MWDialogue bool DialogueManager::compile (const std::string& cmd,std::vector& code) { - std::cout << cmd << std::endl; try { mErrorHandler.reset(); @@ -707,37 +691,70 @@ namespace MWDialogue } } - void DialogueManager::keywordSelected(std::string keyword) + void DialogueManager::updateTopics() { - if(!mIsInChoice) + actorKnownTopics.clear(); + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; + for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) { - if(!actorKnownTopics[keyword].empty()) + ESM::Dialogue ndialogue = it->second; + if(ndialogue.type == ESM::Dialogue::Topic) { - for(std::list::iterator it = actorKnownTopics[keyword].begin(); it != actorKnownTopics[keyword].end();it++) + for (std::vector::const_iterator iter (it->second.mInfo.begin()); + iter!=it->second.mInfo.end(); ++iter) { - ESM::DialInfo dial = *it; - if(functionFilter(mActor,dial,true) && isMatching (mActor,dial)) + if (isMatching (mActor, *iter) && functionFilter(mActor,*iter,false)) { - std::string text = it->response; - std::string script = it->resultScript; - - parseText(text); - - MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - win->addTitle(keyword); - win->addText(it->response); - - executeScript(script); - - mLastTopic = keyword; - mLastDialogue = dial; - break; + actorKnownTopics.push_back(it->first); + //does the player know the topic? + if(knownTopics.find(toLower(it->first)) != knownTopics.end()) + { + win->addKeyword(it->first); + } } } } } } + void DialogueManager::keywordSelected(std::string keyword) + { + if(!mIsInChoice) + { + if(mDialogueMap.find(keyword) != mDialogueMap.end()) + { + ESM::Dialogue ndialogue = mDialogueMap[keyword]; + std::vector::const_iterator iter; + if(ndialogue.type == ESM::Dialogue::Topic) + { + for (iter = ndialogue.mInfo.begin(); + iter!=ndialogue.mInfo.end(); ++iter) + { + if (isMatching (mActor, *iter) && functionFilter(mActor,*iter,true)) + { + std::string text = iter->response; + std::string script = iter->resultScript; + + parseText(text); + + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->addTitle(keyword); + win->addText(iter->response); + + executeScript(script); + + mLastTopic = keyword; + mLastDialogue = *iter; + break; + } + } + } + } + } + updateTopics(); + } + void DialogueManager::goodbyeSelected() { mEnvironment.mInputManager->setGuiMode(MWGui::GM_Game); @@ -748,31 +765,47 @@ namespace MWDialogue if(mChoiceMap.find(answere) != mChoiceMap.end()) { mChoice = mChoiceMap[answere]; - std::list dials = actorKnownTopics[mLastTopic]; - std::cout << actorKnownTopics[mLastTopic].size() << mLastTopic; - std::list::iterator iter; - for(iter = actorKnownTopics[mLastTopic].begin(); iter->id != mLastDialogue.id;iter++) + //ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; + bool found = false; + //ESMS::RecListT::MapType::iterator it; + std::vector::const_iterator iter; + //for(it = dialogueList.begin(); it!=dialogueList.end();it++) + if(mDialogueMap.find(mLastTopic) != mDialogueMap.end()) { - } - for(std::list::iterator it = iter; it!=actorKnownTopics[mLastTopic].begin();) - { - it--; - if(functionFilter(mActor,*it,true) && isMatching (mActor,*it)) + ESM::Dialogue ndialogue = mDialogueMap[mLastTopic]; + if(ndialogue.type == ESM::Dialogue::Topic) { - mChoiceMap.clear(); - mChoice = -1; - mIsInChoice = false; - MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - std::string text = it->response; - parseText(text); - win->addText(text); - executeScript(it->resultScript); - mLastTopic = mLastTopic; - mLastDialogue = *it; - break; + for (iter = ndialogue.mInfo.begin(); + iter!=ndialogue.mInfo.end(); ++iter) + { + if(iter->id == mLastDialogue.id) found = true; + if(found) break; + } + } + if(found) + { + for (std::vector::const_iterator iter2 = iter; + iter2!=ndialogue.mInfo.begin(); --iter2) + { + if (isMatching (mActor, *iter2) && functionFilter(mActor,*iter2,true)) + { + mChoiceMap.clear(); + mChoice = -1; + mIsInChoice = false; + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + std::string text = iter2->response; + parseText(text); + win->addText(text); + executeScript(iter2->resultScript); + mLastTopic = mLastTopic; + mLastDialogue = *iter2; + break; + } + } } } + updateTopics(); } } diff --git a/apps/openmw/mwdialogue/dialoguemanager.hpp b/apps/openmw/mwdialogue/dialoguemanager.hpp index 2ea157562..260d8e339 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.hpp +++ b/apps/openmw/mwdialogue/dialoguemanager.hpp @@ -30,8 +30,11 @@ namespace MWDialogue void parseText(std::string text); + void updateTopics(); + + std::map mDialogueMap; std::map knownTopics;// Those are the topics the player knows. - std::map > actorKnownTopics; + std::list actorKnownTopics; MWScript::CompilerContext mCompilerContext; std::ostream mErrorStream;