/** * get list of available dialogs with NPC */ void NPC::getDialogNodes(std::vector<int> &result) { result.clear(); if (!talker) return; std::string group; typedef std::vector<int> Dialogs; typedef std::map<std::string, Dialogs > DialogGroups; DialogGroups groups; for (size_t i=dialog.size(); i>0; i--) { bool is_available = true; bool is_grouped = false; for (size_t j=0; j<dialog[i-1].size(); j++) { if (dialog[i-1][j].type == EC_NPC_DIALOG_GROUP) { is_grouped = true; group = dialog[i-1][j].s; } else { if (camp->checkAllRequirements(dialog[i-1][j])) continue; is_available = false; break; } } if (is_available) { if (!is_grouped) { result.push_back(static_cast<int>(i-1)); } else { DialogGroups::iterator it; it = groups.find(group); if (it == groups.end()) { groups.insert(DialogGroups::value_type(group, Dialogs())); } else it->second.push_back(static_cast<int>(i-1)); } } } /* Iterate over dialoggroups and roll a dialog to add to result */ DialogGroups::iterator it; it = groups.begin(); if (it == groups.end()) return; while (it != groups.end()) { /* roll a dialog for this group and add to result */ int di = it->second[rand() % it->second.size()]; result.push_back(di); ++it; } }
/** * get list of available dialogs with NPC */ void NPC::getDialogNodes(std::vector<int> &result) { result.clear(); if (!talker) return; std::string group; typedef std::vector<int> Dialogs; typedef std::map<std::string, Dialogs > DialogGroups; DialogGroups groups; for (int i=dialog.size()-1; i>=0; i--) { bool is_available = true; bool is_grouped = false; for (unsigned int j=0; j<dialog[i].size(); j++) { if (dialog[i][j].type == "requires_status") { if (camp->checkStatus(dialog[i][j].s)) continue; is_available = false; break; } else if (dialog[i][j].type == "requires_not") { if (!camp->checkStatus(dialog[i][j].s)) continue; is_available = false; break; } else if (dialog[i][j].type == "requires_item") { if (camp->checkItem(dialog[i][j].x)) continue; is_available = false; break; } else if (dialog[i][j].type == "requires_level") { if (camp->hero->level >= dialog[i][j].x) continue; is_available = false; break; } else if (dialog[i][j].type == "requires_not_level") { if (camp->hero->level < dialog[i][j].x) continue; is_available = false; break; } else if (dialog[i][j].type == "group") { is_grouped = true; group = dialog[i][j].s; } } if (is_available) { if (!is_grouped) { result.push_back(i); } else { DialogGroups::iterator it; it = groups.find(group); if (it == groups.end()) { groups.insert(DialogGroups::value_type(group, Dialogs())); } else it->second.push_back(i); } } } /* Iterate over dialoggroups and roll a dialog to add to result */ DialogGroups::iterator it; it = groups.begin(); if (it == groups.end()) return; while (it != groups.end()) { /* roll a dialog for this group and add to result */ int di = it->second[rand() % it->second.size()]; result.push_back(di); ++it; } }