std::vector<const ESM::DialInfo *> MWDialogue::Filter::list (const ESM::Dialogue& dialogue, bool fallbackToInfoRefusal, bool searchAll, bool invertDisposition) const { std::vector<const ESM::DialInfo *> infos; bool infoRefusal = false; // Iterate over topic responses to find a matching one for (ESM::Dialogue::InfoContainer::const_iterator iter = dialogue.mInfo.begin(); iter!=dialogue.mInfo.end(); ++iter) { if (testActor (*iter) && testPlayer (*iter) && testSelectStructs (*iter)) { if (testDisposition (*iter, invertDisposition)) { infos.push_back(&*iter); if (!searchAll) break; } else infoRefusal = true; } } if (infos.empty() && infoRefusal && fallbackToInfoRefusal) { // No response is valid because of low NPC disposition, // search a response in the topic "Info Refusal" const MWWorld::Store<ESM::Dialogue> &dialogues = MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>(); const ESM::Dialogue& infoRefusalDialogue = *dialogues.find ("Info Refusal"); for (ESM::Dialogue::InfoContainer::const_iterator iter = infoRefusalDialogue.mInfo.begin(); iter!=infoRefusalDialogue.mInfo.end(); ++iter) if (testActor (*iter) && testPlayer (*iter) && testSelectStructs (*iter) && testDisposition(*iter, invertDisposition)) { infos.push_back(&*iter); if (!searchAll) break; } } return infos; }
bool MWDialogue::Filter::responseAvailable (const ESM::Dialogue& dialogue) const { for (ESM::Dialogue::InfoContainer::const_iterator iter = dialogue.mInfo.begin(); iter!=dialogue.mInfo.end(); ++iter) { if (testActor (*iter) && testPlayer (*iter) && testSelectStructs (*iter)) return true; } return false; }
static void testPlayer(teams* node, iaClients* ia, char** s, int* n) { iaClients* _n; if (!node) return ; _n = node->list; while (_n) { testIa(_n, ia, s, n); _n = _n->next; } testPlayer(node->next, ia, s, n); }
bool TestDialogue::testSimple() { Game *game = new Game(); Engine::getEngine()->setCurrentGame(game); Dialogue *testDiag = new Dialogue("diag1", "Hello there, my name is", "Greetings", "greeting", Dialogue::UNLOCK_NONE); am_equalsStr("diag1", testDiag->getId()); am_equalsStr("Hello there, my name is", testDiag->getText()); am_equalsStr("Greetings", testDiag->getTitle()); am_equalsStr("greeting", testDiag->getSubject()); assert(Dialogue::UNLOCK_NONE == testDiag->getUnlockFlag()); game->removeAllDialogue(); game->addDialogue(testDiag); Dialogue *testDiag2 = new Dialogue("diag2", "My name is Melli", "Name", "name", Dialogue::UNLOCK_LOCKED); game->addDialogue(testDiag2); Handle<Character> testNPC(new Character()); testNPC->setDialogueComp(new DialogueComponent()); testNPC->getDialogueComp()->setDialogueAvailable("diag1"); testNPC->getDialogueComp()->setDialogueAvailable("diag2"); Handle<Character> testPlayer(new Character()); testPlayer->setDialogueComp(new DialogueComponent()); vector<Dialogue *> dialogues; game->getAvailableDialogues(dialogues, testPlayer, testNPC); am_equals(1u, dialogues.size()); assert(dialogues[0] == testDiag); dialogues.clear(); am_equals(0u, dialogues.size()); testPlayer->getDialogueComp()->setSubjectLock("name"); game->getAvailableDialogues(dialogues, testPlayer, testNPC); am_equals(2u, dialogues.size()); return true; }
bool MWDialogue::Filter::operator() (const ESM::DialInfo& info) const { return testActor (info) && testPlayer (info) && testSelectStructs (info); }