void save_auto_pickup(bool bCharacter) { std::ofstream fout; std::string sFile = "data/auto_pickup.txt"; if (bCharacter) { sFile = "save/" + base64_encode(g->u.name) + ".apu.txt"; std::ifstream fin; fin.open(("save/" + base64_encode(g->u.name) + ".sav").c_str()); if(!fin.is_open()) { return; } fin.close(); } fout.open(sFile.c_str()); if(!fout.is_open()) { return; } fout << auto_pickup_header(bCharacter) << std::endl; for(int i = 0; i < vAutoPickupRules[(bCharacter) ? 2 : 1].size(); i++) { fout << vAutoPickupRules[(bCharacter) ? 2 : 1][i].sRule << ";"; fout << (vAutoPickupRules[(bCharacter) ? 2 : 1][i].bActive ? "T" : "F") << ";"; fout << (vAutoPickupRules[(bCharacter) ? 2 : 1][i].bExclude ? "T" : "F"); fout << "\n"; } if (!bCharacter) { merge_vector(); createPickupRules(); } }
void removePickupRule(std::string sRule) { for (int i = 0; i < vAutoPickupRules[2].size(); i++) { if (sRule.length() == (vAutoPickupRules[2][i].sRule).length() && ci_find_substr(sRule, vAutoPickupRules[2][i].sRule) != -1) { vAutoPickupRules[2].erase(vAutoPickupRules[2].begin() + i); merge_vector(); createPickupRules(); break; } } }
void addPickupRule(std::string sRule) { vAutoPickupRules[2].push_back(cPickupRules(sRule, true, false)); merge_vector(); createPickupRules(); if (!OPTIONS["AUTO_PICKUP"] && query_yn(_("Autopickup is not enabled in the options. Enable it now?")) ) { OPTIONS["AUTO_PICKUP"].setNext(); save_options(true); } }
void removePickupRule(std::string sRule) { for (std::vector<cPickupRules>::iterator it = vAutoPickupRules[APU_CHARACTER].begin(); it != vAutoPickupRules[APU_CHARACTER].end(); ++it) { if (sRule.length() == it->sRule.length() && ci_find_substr(sRule, it->sRule) != -1) { vAutoPickupRules[APU_CHARACTER].erase(it); merge_vector(); createPickupRules(); break; } } }
static bool select_autopickup_items( std::vector<item> &here, std::vector<bool> &getitem ) { bool bFoundSomething = false; //Loop through Items lowest Volume first bool bPickup = false; for(size_t iVol = 0, iNumChecked = 0; iNumChecked < here.size(); iVol++) { for (size_t i = 0; i < here.size(); i++) { bPickup = false; if (here[i].volume() == (int)iVol) { iNumChecked++; const std::string sItemName = here[i].tname( 1, false ); //Auto Pickup all items with 0 Volume and Weight <= AUTO_PICKUP_ZERO * 50 if (OPTIONS["AUTO_PICKUP_ZERO"]) { if (here[i].volume() == 0 && here[i].weight() <= OPTIONS["AUTO_PICKUP_ZERO"] * 50 && checkExcludeRules(sItemName)) { bPickup = true; } } //Check the Pickup Rules if ( mapAutoPickupItems[sItemName] == "true" ) { bPickup = true; } else if ( mapAutoPickupItems[sItemName] != "false" ) { //No prematched pickup rule found //items with damage, (fits) or a container createPickupRules(sItemName); if ( mapAutoPickupItems[sItemName] == "true" ) { bPickup = true; } } } if (bPickup) { getitem[i] = bPickup; bFoundSomething = true; } } } return bFoundSomething; }
bool save_auto_pickup(bool bCharacter) { std::ofstream fout; std::string sFile = FILENAMES["autopickup"]; if (bCharacter) { sFile = world_generator->active_world->world_path + "/" + base64_encode(g->u.name) + ".apu.txt"; std::ifstream fin; fin.open((world_generator->active_world->world_path + "/" + base64_encode(g->u.name) + ".sav").c_str()); if(!fin.is_open()) { return true; } fin.close(); } fout.exceptions(std::ios::badbit | std::ios::failbit); try { assure_dir_exist(FILENAMES["config_dir"]); fout.open(sFile.c_str()); fout << auto_pickup_header(bCharacter) << std::endl; for (std::vector<cPickupRules>::iterator it = vAutoPickupRules[(bCharacter) ? APU_CHARACTER : APU_GLOBAL].begin(); it != vAutoPickupRules[(bCharacter) ? APU_CHARACTER : APU_GLOBAL].end(); ++it) { fout << it->sRule << ";"; fout << (it->bActive ? "T" : "F") << ";"; fout << (it->bExclude ? "T" : "F"); fout << "\n"; } if (!bCharacter) { merge_vector(); createPickupRules(); } fout.close(); return true; } catch(std::ios::failure &) { popup(_("Failed to write autopickup rules to %s"), sFile.c_str()); return false; } }
bool save_auto_pickup(bool bCharacter) { std::ofstream fout; std::string sFile = "data/auto_pickup.txt"; if (bCharacter) { sFile = world_generator->active_world->world_path + "/" + base64_encode(g->u.name) + ".apu.txt"; std::ifstream fin; fin.open((world_generator->active_world->world_path + "/" + base64_encode(g->u.name) + ".sav").c_str()); if(!fin.is_open()) { return true; } fin.close(); } fout.exceptions(std::ios::badbit | std::ios::failbit); try { fout.open(sFile.c_str()); fout << auto_pickup_header(bCharacter) << std::endl; for (unsigned i = 0; i < vAutoPickupRules[(bCharacter) ? 2 : 1].size(); i++) { fout << vAutoPickupRules[(bCharacter) ? 2 : 1][i].sRule << ";"; fout << (vAutoPickupRules[(bCharacter) ? 2 : 1][i].bActive ? "T" : "F") << ";"; fout << (vAutoPickupRules[(bCharacter) ? 2 : 1][i].bExclude ? "T" : "F"); fout << "\n"; } if (!bCharacter) { merge_vector(); createPickupRules(); } fout.close(); return true; } catch(std::ios::failure &) { popup(_("Failed to write autopickup rules to %s"), sFile.c_str()); return false; } }
void addPickupRule(std::string sRule) { vAutoPickupRules[2].push_back(cPickupRules(sRule, true, false)); merge_vector(); createPickupRules(); }
void load_auto_pickup(bool bCharacter) { std::ifstream fin; std::string sFile = "data/auto_pickup.txt"; if (bCharacter) { sFile = "save/" + base64_encode(g->u.name) + ".apu.txt"; } fin.open(sFile.c_str()); if(!fin.is_open()) { fin.close(); create_default_auto_pickup(bCharacter); fin.open(sFile.c_str()); if(!fin.is_open()) { DebugLog() << "Could neither read nor create " << sFile << "\n"; return; } } vAutoPickupRules[(bCharacter) ? 2 : 1].clear(); std::string sLine; while(!fin.eof()) { getline(fin, sLine); if(sLine != "" && sLine[0] != '#') { int iNum = std::count(sLine.begin(), sLine.end(), ';'); if(iNum != 2) { /*int iNum = std::count(sLine.begin(), sLine.end(), ' '); if(iNum == 1) { //its an option! hurray } else {*/ DebugLog() << "Bad Rule: " << sLine << "\n"; //} } else { std::string sRule = ""; bool bActive = true; bool bExclude = false; size_t iPos = 0; int iCol = 1; do { iPos = sLine.find(";"); std::string sTemp = (iPos == std::string::npos) ? sLine : sLine.substr(0, iPos); if (iCol == 1) { sRule = sTemp; } else if (iCol == 2) { bActive = (sTemp == "T" || sTemp == "True") ? true : false; } else if (iCol == 3) { bExclude = (sTemp == "T" || sTemp == "True") ? true : false; } iCol++; if (iPos != std::string::npos) { sLine = sLine.substr(iPos+1, sLine.size()); } } while(iPos != std::string::npos); vAutoPickupRules[(bCharacter) ? 2 : 1].push_back(cPickupRules(sRule, bActive, bExclude)); } } } fin.close(); merge_vector(); createPickupRules(); }
void load_auto_pickup(bool bCharacter) { std::ifstream fin; std::string sFile = FILENAMES["autopickup"]; if (bCharacter) { sFile = world_generator->active_world->world_path + "/" + base64_encode(g->u.name) + ".apu.txt"; } bool legacy_autopickup_loaded = false; fin.open(sFile.c_str()); if(!fin.is_open()) { if( !bCharacter ) { fin.open(FILENAMES["legacy_autopickup"].c_str()); } if( !fin.is_open() ) { assure_dir_exist(FILENAMES["config_dir"]); create_default_auto_pickup(bCharacter); fin.open(sFile.c_str()); } else { legacy_autopickup_loaded = true; } if(!fin.is_open()) { DebugLog( D_ERROR, DC_ALL ) << "Could neither read nor create " << sFile; return; } } vAutoPickupRules[(bCharacter) ? APU_CHARACTER : APU_GLOBAL].clear(); std::string sLine; while(!fin.eof()) { getline(fin, sLine); if(sLine != "" && sLine[0] != '#') { int iNum = std::count(sLine.begin(), sLine.end(), ';'); if(iNum != 2) { DebugLog( D_ERROR, DC_ALL ) << "Bad Rule: " << sLine; } else { std::string sRule = ""; bool bActive = true; bool bExclude = false; size_t iPos = 0; int iCol = 1; do { iPos = sLine.find(";"); std::string sTemp = (iPos == std::string::npos) ? sLine : sLine.substr(0, iPos); if (iCol == 1) { sRule = sTemp; } else if (iCol == 2) { bActive = (sTemp == "T" || sTemp == "True") ? true : false; } else if (iCol == 3) { bExclude = (sTemp == "T" || sTemp == "True") ? true : false; } iCol++; if (iPos != std::string::npos) { sLine = sLine.substr(iPos + 1, sLine.size()); } } while(iPos != std::string::npos); vAutoPickupRules[(bCharacter) ? APU_CHARACTER : APU_GLOBAL].push_back(cPickupRules(sRule, bActive, bExclude)); } } } fin.close(); merge_vector(); createPickupRules(); if( legacy_autopickup_loaded ) { assure_dir_exist(FILENAMES["config_dir"]); save_auto_pickup( bCharacter ); } }