one step toward function filters and end choices.

This commit is contained in:
gugus 2012-03-14 18:47:29 +01:00
parent 82c6b0f92a
commit 07d8d654cd
4 changed files with 234 additions and 180 deletions

View file

@ -142,6 +142,38 @@ namespace MWDialogue
return toLower(str).find(toLower(substr),pos); return toLower(str).find(toLower(substr),pos);
} }
bool DialogueManager::functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info)
{
for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.selects.begin());
iter != info.selects.end(); ++iter)
{
ESM::DialInfo::SelectStruct select = *iter;
char type = select.selectRule[1];
if(type == '1')
{
char comp = select.selectRule[4];
std::string name = select.selectRule.substr (5);
std::string function = select.selectRule.substr(1,2);
std::cout << function;
int ifunction;
std::istringstream iss(function);
iss >> ifunction;
switch(ifunction)
{
case 4://choice
if(!selectCompare(comp,mChoice,select.i)) return false;
break;
default:
break;
}
}
}
return true;
}
bool DialogueManager::isMatching (const MWWorld::Ptr& actor, bool DialogueManager::isMatching (const MWWorld::Ptr& actor,
const ESM::DialInfo::SelectStruct& select) const const ESM::DialInfo::SelectStruct& select) const
@ -152,6 +184,8 @@ namespace MWDialogue
{ {
char comp = select.selectRule[4]; char comp = select.selectRule[4];
std::string name = select.selectRule.substr (5); std::string name = select.selectRule.substr (5);
std::string function = select.selectRule.substr(1,2);
std::cout << function;
// TODO types 4, 5, 6, 7, 8, 9, A, B, C // TODO types 4, 5, 6, 7, 8, 9, A, B, C
//new TOTO: 5,6,9 //new TOTO: 5,6,9
@ -415,6 +449,7 @@ namespace MWDialogue
mEnvironment (environment),mCompilerContext (MWScript::CompilerContext::Type_Dialgoue, environment), mEnvironment (environment),mCompilerContext (MWScript::CompilerContext::Type_Dialgoue, environment),
mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream) mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream)
{ {
mChoice = -1;
mCompilerContext.setExtensions (&extensions); mCompilerContext.setExtensions (&extensions);
} }
@ -425,24 +460,27 @@ namespace MWDialogue
void DialogueManager::parseText(std::string text) void DialogueManager::parseText(std::string text)
{ {
std::map<std::string,ESM::DialInfo>::iterator it; std::map<std::string,std::list<ESM::DialInfo>>::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->first,0);
if(pos !=std::string::npos) if(pos !=std::string::npos)
{
if(!it->second.empty())
{ {
if(pos==0) if(pos==0)
{ {
//std::cout << "fouuuuuuuuuuund"; //std::cout << "fouuuuuuuuuuund";
knownTopics[it->first] = true; knownTopics[it->first] = true;
win->addKeyword(it->first,it->second.response); win->addKeyword(it->first,it->second.front().response);
} }
else if(text.substr(pos -1,1) == " ") else if(text.substr(pos -1,1) == " ")
{ {
//std::cout << "fouuuuuuuuuuund"; //std::cout << "fouuuuuuuuuuund";
knownTopics[it->first] = true; knownTopics[it->first] = true;
win->addKeyword(it->first,it->second.response); win->addKeyword(it->first,it->second.front().response);
}
} }
} }
@ -472,14 +510,14 @@ namespace MWDialogue
{ {
if (isMatching (actor, *iter)) if (isMatching (actor, *iter))
{ {
actorKnownTopics[it->first] = *iter; actorKnownTopics[it->first].push_back(*iter);
if(knownTopics.find(toLower(it->first)) != knownTopics.end()) if(knownTopics.find(toLower(it->first)) != knownTopics.end())
{ {
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow();
win->addKeyword(it->first,iter->response); win->addKeyword(it->first,iter->response);
//std::cout << it->first; //std::cout << it->first;
//std::cout << "match found!!"; //std::cout << "match found!!";
break; //break;
} }
} }
} }
@ -585,10 +623,21 @@ namespace MWDialogue
void DialogueManager::keywordSelected(std::string keyword) void DialogueManager::keywordSelected(std::string keyword)
{ {
std::string text = actorKnownTopics[keyword].response; if(!actorKnownTopics[keyword].empty())
std::string script = actorKnownTopics[keyword].resultScript; {
for(std::list<ESM::DialInfo>::iterator it = actorKnownTopics[keyword].begin(); it != actorKnownTopics[keyword].end();it++)
{
ESM::DialInfo dial = *it;
if(functionFilter(mActor,dial))
{
std::string text = actorKnownTopics[keyword].front().response;
std::string script = actorKnownTopics[keyword].front().resultScript;
parseText(text); parseText(text);
executeScript(script); executeScript(script);
break;
}
}
}
} }
void DialogueManager::goodbyeSelected() void DialogueManager::goodbyeSelected()

View file

@ -26,10 +26,12 @@ namespace MWDialogue
bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const; bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const;
bool functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info);
void parseText(std::string text); void parseText(std::string text);
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,ESM::DialInfo> actorKnownTopics; std::map<std::string,std::list<ESM::DialInfo>> actorKnownTopics;
MWScript::CompilerContext mCompilerContext; MWScript::CompilerContext mCompilerContext;
std::ostream mErrorStream; std::ostream mErrorStream;
@ -42,6 +44,8 @@ namespace MWDialogue
void printError(std::string error); void printError(std::string error);
int mChoice;
public: public:
DialogueManager (MWWorld::Environment& environment,const Compiler::Extensions& extensions); DialogueManager (MWWorld::Environment& environment,const Compiler::Extensions& extensions);

View file

@ -84,8 +84,8 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender)
//std::cout << "Clicked on key: " << key << std::endl; //std::cout << "Clicked on key: " << key << std::endl;
if(color == "#686EBA") if(color == "#686EBA")
{ {
mEnvironment.mDialogueManager->keywordSelected(lower_string(key));
displayTopicText(lower_string(key)); displayTopicText(lower_string(key));
mEnvironment.mDialogueManager->keywordSelected(lower_string(key));
} }
if(color == "#572D21") if(color == "#572D21")
{ {
@ -117,8 +117,8 @@ void DialogueWindow::onSelectTopic(MyGUI::List* _sender, size_t _index)
if (_index == MyGUI::ITEM_NONE) if (_index == MyGUI::ITEM_NONE)
return; return;
std::string topic = _sender->getItem(_index); std::string topic = _sender->getItem(_index);
mEnvironment.mDialogueManager->keywordSelected(lower_string(topic));
displayTopicText(topic); displayTopicText(topic);
mEnvironment.mDialogueManager->keywordSelected(lower_string(topic));
//const std::string* theTopic = topicsList->getItemDataAt<std::string>(_index); //const std::string* theTopic = topicsList->getItemDataAt<std::string>(_index);
//std::cout << "Selected: "<< theTopic << std::endl; //std::cout << "Selected: "<< theTopic << std::endl;

View file

@ -95,7 +95,8 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{ {
std::cout << "CHOICECHOICEHOCQSCHQSHD"; std::cout << "CHOICE" << arg0;
arg0 = 4;
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
MWDialogue::DialogueManager* dialogue = context.getEnvironment().mDialogueManager; MWDialogue::DialogueManager* dialogue = context.getEnvironment().mDialogueManager;
@ -130,7 +131,7 @@ namespace MWScript
extensions.registerInstruction ("setjournalindex", "cl", opcodeSetJournalIndex); extensions.registerInstruction ("setjournalindex", "cl", opcodeSetJournalIndex);
extensions.registerFunction ("getjournalindex", 'l', "c", opcodeGetJournalIndex); extensions.registerFunction ("getjournalindex", 'l', "c", opcodeGetJournalIndex);
extensions.registerInstruction ("addtopic", "S" , opcodeAddTopic); extensions.registerInstruction ("addtopic", "S" , opcodeAddTopic);
extensions.registerInstruction ("choice", "clcl", opcodeChoice); extensions.registerInstruction ("choice", "/SlSl", opcodeChoice);
} }
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)