1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 09:23:51 +00:00

Changed a lot of things. Topics can now change durring dialogue without bug.

Missing: ability to remove keyword
This commit is contained in:
gugus 2012-03-19 00:19:58 +01:00
parent ff5d4b24fc
commit 1a832a65f6
2 changed files with 114 additions and 78 deletions

View file

@ -550,25 +550,23 @@ namespace MWDialogue
void DialogueManager::parseText(std::string text) void DialogueManager::parseText(std::string text)
{ {
std::map<std::string,std::list <ESM::DialInfo> >::iterator it; std::cout << "PARSE";
std::list<std::string>::iterator it;
for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++) for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++)
{ {
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); 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(pos !=std::string::npos)
{
if(!it->second.empty())
{ {
if(pos==0) if(pos==0)
{ {
knownTopics[it->first] = true; knownTopics[*it] = true;
win->addKeyword(it->first); win->addKeyword(*it);
} }
else if(text.substr(pos -1,1) == " ") else if(text.substr(pos -1,1) == " ")
{ {
knownTopics[it->first] = true; knownTopics[*it] = true;
win->addKeyword(it->first); win->addKeyword(*it);
}
} }
} }
@ -583,38 +581,25 @@ namespace MWDialogue
mActor = actor; mActor = actor;
mDialogueMap.clear();
actorKnownTopics.clear();
ESMS::RecListT<ESM::Dialogue>::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list;
for(ESMS::RecListT<ESM::Dialogue>::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++)
{
mDialogueMap[it->first] = it->second;
}
//initialise the GUI //initialise the GUI
mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue); mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue);
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow();
win->startDialogue(MWWorld::Class::get (actor).getName (actor)); 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 //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(); updateTopics();
ESMS::RecListT<ESM::Dialogue>::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list;
for(ESMS::RecListT<ESM::Dialogue>::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++)
{
ESM::Dialogue ndialogue = it->second;
if(ndialogue.type == ESM::Dialogue::Topic)
{
for (std::vector<ESM::DialInfo>::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);
}
}
}
}
}
//greeting //greeting
bool greetingFound = false; bool greetingFound = false;
//ESMS::RecListT<ESM::Dialogue>::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list;
for(ESMS::RecListT<ESM::Dialogue>::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) for(ESMS::RecListT<ESM::Dialogue>::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++)
{ {
ESM::Dialogue ndialogue = it->second; ESM::Dialogue ndialogue = it->second;
@ -647,7 +632,6 @@ namespace MWDialogue
bool DialogueManager::compile (const std::string& cmd,std::vector<Interpreter::Type_Code>& code) bool DialogueManager::compile (const std::string& cmd,std::vector<Interpreter::Type_Code>& code)
{ {
std::cout << cmd << std::endl;
try try
{ {
mErrorHandler.reset(); mErrorHandler.reset();
@ -707,36 +691,69 @@ namespace MWDialogue
} }
} }
void DialogueManager::updateTopics()
{
actorKnownTopics.clear();
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow();
ESMS::RecListT<ESM::Dialogue>::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list;
for(ESMS::RecListT<ESM::Dialogue>::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++)
{
ESM::Dialogue ndialogue = it->second;
if(ndialogue.type == ESM::Dialogue::Topic)
{
for (std::vector<ESM::DialInfo>::const_iterator iter (it->second.mInfo.begin());
iter!=it->second.mInfo.end(); ++iter)
{
if (isMatching (mActor, *iter) && functionFilter(mActor,*iter,false))
{
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) void DialogueManager::keywordSelected(std::string keyword)
{ {
if(!mIsInChoice) if(!mIsInChoice)
{ {
if(!actorKnownTopics[keyword].empty()) if(mDialogueMap.find(keyword) != mDialogueMap.end())
{ {
for(std::list<ESM::DialInfo>::iterator it = actorKnownTopics[keyword].begin(); it != actorKnownTopics[keyword].end();it++) ESM::Dialogue ndialogue = mDialogueMap[keyword];
std::vector<ESM::DialInfo>::const_iterator iter;
if(ndialogue.type == ESM::Dialogue::Topic)
{ {
ESM::DialInfo dial = *it; for (iter = ndialogue.mInfo.begin();
if(functionFilter(mActor,dial,true) && isMatching (mActor,dial)) iter!=ndialogue.mInfo.end(); ++iter)
{ {
std::string text = it->response; if (isMatching (mActor, *iter) && functionFilter(mActor,*iter,true))
std::string script = it->resultScript; {
std::string text = iter->response;
std::string script = iter->resultScript;
parseText(text); parseText(text);
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow();
win->addTitle(keyword); win->addTitle(keyword);
win->addText(it->response); win->addText(iter->response);
executeScript(script); executeScript(script);
mLastTopic = keyword; mLastTopic = keyword;
mLastDialogue = dial; mLastDialogue = *iter;
break; break;
} }
} }
} }
} }
} }
updateTopics();
}
void DialogueManager::goodbyeSelected() void DialogueManager::goodbyeSelected()
{ {
@ -748,33 +765,49 @@ namespace MWDialogue
if(mChoiceMap.find(answere) != mChoiceMap.end()) if(mChoiceMap.find(answere) != mChoiceMap.end())
{ {
mChoice = mChoiceMap[answere]; mChoice = mChoiceMap[answere];
std::list<ESM::DialInfo> dials = actorKnownTopics[mLastTopic];
std::cout << actorKnownTopics[mLastTopic].size() << mLastTopic; //ESMS::RecListT<ESM::Dialogue>::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list;
std::list<ESM::DialInfo>::iterator iter; bool found = false;
for(iter = actorKnownTopics[mLastTopic].begin(); iter->id != mLastDialogue.id;iter++) //ESMS::RecListT<ESM::Dialogue>::MapType::iterator it;
std::vector<ESM::DialInfo>::const_iterator iter;
//for(it = dialogueList.begin(); it!=dialogueList.end();it++)
if(mDialogueMap.find(mLastTopic) != mDialogueMap.end())
{ {
ESM::Dialogue ndialogue = mDialogueMap[mLastTopic];
if(ndialogue.type == ESM::Dialogue::Topic)
{
for (iter = ndialogue.mInfo.begin();
iter!=ndialogue.mInfo.end(); ++iter)
{
if(iter->id == mLastDialogue.id) found = true;
if(found) break;
} }
for(std::list<ESM::DialInfo>::iterator it = iter; it!=actorKnownTopics[mLastTopic].begin();) }
if(found)
{ {
it--; for (std::vector<ESM::DialInfo>::const_iterator iter2 = iter;
if(functionFilter(mActor,*it,true) && isMatching (mActor,*it)) iter2!=ndialogue.mInfo.begin(); --iter2)
{
if (isMatching (mActor, *iter2) && functionFilter(mActor,*iter2,true))
{ {
mChoiceMap.clear(); mChoiceMap.clear();
mChoice = -1; mChoice = -1;
mIsInChoice = false; mIsInChoice = false;
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow();
std::string text = it->response; std::string text = iter2->response;
parseText(text); parseText(text);
win->addText(text); win->addText(text);
executeScript(it->resultScript); executeScript(iter2->resultScript);
mLastTopic = mLastTopic; mLastTopic = mLastTopic;
mLastDialogue = *it; mLastDialogue = *iter2;
break; break;
} }
} }
} }
} }
updateTopics();
}
}
void DialogueManager::printError(std::string error) void DialogueManager::printError(std::string error)
{ {

View file

@ -30,8 +30,11 @@ namespace MWDialogue
void parseText(std::string text); void parseText(std::string text);
void updateTopics();
std::map<std::string,ESM::Dialogue> mDialogueMap;
std::map<std::string,bool> knownTopics;// Those are the topics the player knows. std::map<std::string,bool> knownTopics;// Those are the topics the player knows.
std::map<std::string,std::list <ESM::DialInfo> > actorKnownTopics; std::list<std::string> actorKnownTopics;
MWScript::CompilerContext mCompilerContext; MWScript::CompilerContext mCompilerContext;
std::ostream mErrorStream; std::ostream mErrorStream;