void createPickupRules(const std::string sItemNameIn) { if (sItemNameIn == "") { mapAutoPickupItems.clear(); } std::string sItemName = ""; //Includes only for (std::vector<cPickupRules>::iterator pattern_it = vAutoPickupRules[APU_MERGED].begin(); pattern_it != vAutoPickupRules[APU_MERGED].end(); ++pattern_it) { if (!pattern_it->bExclude) { if (sItemNameIn != "") { if (pattern_it->bActive && auto_pickup_match(sItemNameIn, pattern_it->sRule)) { mapAutoPickupItems[sItemNameIn] = "true"; break; } } else { //Check include paterns against all itemfactory items for (std::vector<std::string>::iterator itype_it = standard_itype_ids.begin(); itype_it != standard_itype_ids.end(); ++itype_it) { sItemName = item_controller-> find_template(*itype_it)->nname(1); if (pattern_it->bActive && auto_pickup_match(sItemName, pattern_it->sRule)){ mapAutoPickupItems[sItemName] = "true"; } } } } } //Excludes only for (std::vector<cPickupRules>::iterator pattern_it = vAutoPickupRules[APU_MERGED].begin(); pattern_it != vAutoPickupRules[APU_MERGED].end(); ++pattern_it) { if (pattern_it->bExclude) { if (sItemNameIn != "") { if (pattern_it->bActive && auto_pickup_match(sItemNameIn, pattern_it->sRule)) { mapAutoPickupItems[sItemNameIn] = "false"; return; } } else { //Check exclude paterns against all included items for (std::map<std::string, std::string>::iterator iter = mapAutoPickupItems.begin(); iter != mapAutoPickupItems.end(); ++iter) { if (pattern_it->bActive && auto_pickup_match(iter->first, pattern_it->sRule)) { mapAutoPickupItems[iter->first] = "false"; } } } } } }
void createPickupRules() { mapAutoPickupItems.clear(); std::string sItemName = ""; for (int iPattern = 0; iPattern < vAutoPickupRules[0].size(); iPattern++) { //Includes only if (!vAutoPickupRules[0][iPattern].bExclude) { //Check include paterns against all itemfactory items for (int i = 0; i < standard_itype_ids.size(); i++) { sItemName = item_controller->find_template(standard_itype_ids[i])->name; if (vAutoPickupRules[0][iPattern].bActive && auto_pickup_match(sItemName, vAutoPickupRules[0][iPattern].sRule)) { mapAutoPickupItems[sItemName] = true; } } } } for (int iPattern = 0; iPattern < vAutoPickupRules[0].size(); iPattern++) { //Excludes only if (vAutoPickupRules[0][iPattern].bExclude) { //Check exclude paterns against all included items for (std::map<std::string, bool>::iterator iter = mapAutoPickupItems.begin(); iter != mapAutoPickupItems.end(); ++iter) { if (vAutoPickupRules[0][iPattern].bActive && auto_pickup_match(iter->first, vAutoPickupRules[0][iPattern].sRule)) { mapAutoPickupItems[iter->first] = false; } } } } }
void createPickupRules(const std::string sItemNameIn) { if (sItemNameIn == "") { mapAutoPickupItems.clear(); } std::string sItemName = ""; for (unsigned iPattern = 0; iPattern < vAutoPickupRules[0].size(); iPattern++) { //Includes only if (!vAutoPickupRules[0][iPattern].bExclude) { if (sItemNameIn != "") { if (vAutoPickupRules[0][iPattern].bActive && auto_pickup_match(sItemNameIn, vAutoPickupRules[0][iPattern].sRule)) { mapAutoPickupItems[sItemNameIn] = "true"; break; } } else { //Check include paterns against all itemfactory items for (unsigned i = 0; i < standard_itype_ids.size(); i++) { sItemName = item_controller->find_template(standard_itype_ids[i])->name; if (vAutoPickupRules[0][iPattern].bActive && auto_pickup_match(sItemName, vAutoPickupRules[0][iPattern].sRule)) { mapAutoPickupItems[sItemName] = "true"; } } } } } for (unsigned iPattern = 0; iPattern < vAutoPickupRules[0].size(); iPattern++) { //Excludes only if (vAutoPickupRules[0][iPattern].bExclude) { if (sItemNameIn != "") { if (vAutoPickupRules[0][iPattern].bActive && auto_pickup_match(sItemNameIn, vAutoPickupRules[0][iPattern].sRule)) { mapAutoPickupItems[sItemNameIn] = "false"; return; } } else { //Check exclude paterns against all included items for (std::map<std::string, std::string>::iterator iter = mapAutoPickupItems.begin(); iter != mapAutoPickupItems.end(); ++iter) { if (vAutoPickupRules[0][iPattern].bActive && auto_pickup_match(iter->first, vAutoPickupRules[0][iPattern].sRule)) { mapAutoPickupItems[iter->first] = "false"; } } } } } }
void createPickupRules(const std::string sItemNameIn) { if (sItemNameIn == "") { mapAutoPickupItems.clear(); } std::string sItemName = ""; //Includes only for( auto &elem : vAutoPickupRules[APU_MERGED] ) { if( !elem.bExclude ) { if (sItemNameIn != "") { if( elem.bActive && auto_pickup_match( sItemNameIn, elem.sRule ) ) { mapAutoPickupItems[sItemNameIn] = "true"; break; } } else { //Check include paterns against all itemfactory items for( auto &p : item_controller->get_all_itypes() ) { sItemName = p.second->nname(1); if( elem.bActive && auto_pickup_match( sItemName, elem.sRule ) ) { mapAutoPickupItems[sItemName] = "true"; } } } } } //Excludes only for( auto &elem : vAutoPickupRules[APU_MERGED] ) { if( elem.bExclude ) { if (sItemNameIn != "") { if( elem.bActive && auto_pickup_match( sItemNameIn, elem.sRule ) ) { mapAutoPickupItems[sItemNameIn] = "false"; return; } } else { //Check exclude paterns against all included items for (std::map<std::string, std::string>::iterator iter = mapAutoPickupItems.begin(); iter != mapAutoPickupItems.end(); ++iter) { if( elem.bActive && auto_pickup_match( iter->first, elem.sRule ) ) { mapAutoPickupItems[iter->first] = "false"; } } } } } }
bool checkExcludeRules(const std::string sItemNameIn) { for( auto &elem : vAutoPickupRules[APU_MERGED] ) { if( elem.bExclude && elem.bActive && auto_pickup_match( sItemNameIn, elem.sRule ) ) { return false; } } return true; }
bool checkExcludeRules(const std::string sItemNameIn) { for (std::vector<cPickupRules>::iterator pattern_it = vAutoPickupRules[APU_MERGED].begin(); pattern_it != vAutoPickupRules[APU_MERGED].end(); ++pattern_it) { if (pattern_it->bExclude && pattern_it->bActive && auto_pickup_match(sItemNameIn, pattern_it->sRule)) { return false; } } return true; }
void test_pattern(int iCurrentPage, int iCurrentLine) { std::vector<std::string> vMatchingItems; std::string sItemName = ""; if (vAutoPickupRules[iCurrentPage][iCurrentLine].sRule == "") { return; } //Loop through all itemfactory items //TODO: somehow generate damaged, fitting or container items for (int i = 0; i < standard_itype_ids.size(); i++) { sItemName = item_controller->find_template(standard_itype_ids[i])->name; if (vAutoPickupRules[iCurrentPage][iCurrentLine].bActive && auto_pickup_match(sItemName, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule)) { vMatchingItems.push_back(sItemName); } } const int iOffsetX = 15 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0); const int iOffsetY = 5 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0); int iStartPos = 0; const int iContentHeight = FULL_SCREEN_HEIGHT - 8; const int iContentWidth = FULL_SCREEN_WIDTH - 30; char ch; std::stringstream sTemp; WINDOW* w_test_rule_border = newwin(iContentHeight + 2, iContentWidth, iOffsetY, iOffsetX); WINDOW* w_test_rule_content = newwin(iContentHeight, iContentWidth - 2, 1 + iOffsetY, 1 + iOffsetX); wborder(w_test_rule_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); int nmatch = vMatchingItems.size(); std::string buf = string_format(ngettext("%1$d item matches: %2$s", "%1$d items match: %2$s", nmatch), nmatch, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule.c_str()); mvwprintz(w_test_rule_border, 0, iContentWidth/2 - utf8_width(buf.c_str())/2, hilite(c_white), buf.c_str()); mvwprintz(w_test_rule_border, iContentHeight + 1, 1, red_background(c_white), _("Won't display damaged, fits and can/bottle items")); wrefresh(w_test_rule_border); iCurrentLine = 0; do { // Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { mvwputch(w_test_rule_content, i, j, c_black, ' '); } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, vMatchingItems.size()); // display auto pickup for (int i = iStartPos; i < vMatchingItems.size(); i++) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > vMatchingItems.size()) ? vMatchingItems.size() : iContentHeight)) { nc_color cLineColor = c_white; sTemp.str(""); sTemp << i + 1; mvwprintz(w_test_rule_content, i - iStartPos, 0, cLineColor, sTemp.str().c_str()); mvwprintz(w_test_rule_content, i - iStartPos, 4, cLineColor, ""); if (iCurrentLine == i) { wprintz(w_test_rule_content, c_yellow, ">> "); } else { wprintz(w_test_rule_content, c_yellow, " "); } wprintz(w_test_rule_content, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, vMatchingItems[i].c_str()); } } wrefresh(w_test_rule_content); ch = (char)input(); switch(ch) { case 'j': //move down iCurrentLine++; if (iCurrentLine >= vMatchingItems.size()) { iCurrentLine = 0; } break; case 'k': //move up iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = vMatchingItems.size()-1; } break; } } while(ch == 'j' || ch == 'k'); werase(w_test_rule_border); werase(w_test_rule_content); }
void test_pattern(int iCurrentPage, int iCurrentLine) { std::vector<std::string> vMatchingItems; std::string sItemName = ""; if (vAutoPickupRules[iCurrentPage][iCurrentLine].sRule == "") { return; } //Loop through all itemfactory items //APU now ignores prefixes, bottled items and suffix combinations still not generated for( auto &p : item_controller->get_all_itypes() ) { sItemName = p.second->nname(1); if (vAutoPickupRules[iCurrentPage][iCurrentLine].bActive && auto_pickup_match(sItemName, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule)) { vMatchingItems.push_back(sItemName); } } const int iOffsetX = 15 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0); const int iOffsetY = 5 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0); int iStartPos = 0; const int iContentHeight = FULL_SCREEN_HEIGHT - 8; const int iContentWidth = FULL_SCREEN_WIDTH - 30; std::stringstream sTemp; WINDOW *w_test_rule_border = newwin(iContentHeight + 2, iContentWidth, iOffsetY, iOffsetX); WINDOW_PTR w_test_rule_borderptr( w_test_rule_border ); WINDOW *w_test_rule_content = newwin(iContentHeight, iContentWidth - 2, 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_test_rule_contentptr( w_test_rule_content ); draw_border(w_test_rule_border); int nmatch = vMatchingItems.size(); std::string buf = string_format(ngettext("%1$d item matches: %2$s", "%1$d items match: %2$s", nmatch), nmatch, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule.c_str()); mvwprintz(w_test_rule_border, 0, iContentWidth / 2 - utf8_width(buf.c_str()) / 2, hilite(c_white), "%s", buf.c_str()); mvwprintz(w_test_rule_border, iContentHeight + 1, 1, red_background(c_white), _("Won't display bottled and suffixes=(fits)")); wrefresh(w_test_rule_border); iCurrentLine = 0; input_context ctxt("AUTO_PICKUP_TEST"); ctxt.register_updown(); ctxt.register_action("QUIT"); while(true) { // Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { mvwputch(w_test_rule_content, i, j, c_black, ' '); } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, vMatchingItems.size()); // display auto pickup for (int i = iStartPos; i < (int)vMatchingItems.size(); i++) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > (int)vMatchingItems.size()) ? (int)vMatchingItems.size() : iContentHeight)) { nc_color cLineColor = c_white; sTemp.str(""); sTemp << i + 1; mvwprintz(w_test_rule_content, i - iStartPos, 0, cLineColor, "%s", sTemp.str().c_str()); mvwprintz(w_test_rule_content, i - iStartPos, 4, cLineColor, ""); if (iCurrentLine == i) { wprintz(w_test_rule_content, c_yellow, ">> "); } else { wprintz(w_test_rule_content, c_yellow, " "); } wprintz(w_test_rule_content, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, vMatchingItems[i].c_str()); } } wrefresh(w_test_rule_content); const std::string action = ctxt.handle_input(); if (action == "DOWN") { iCurrentLine++; if (iCurrentLine >= (int)vMatchingItems.size()) { iCurrentLine = 0; } } else if (action == "UP") { iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = vMatchingItems.size() - 1; } } else { break; } } }