int item::pick_reload_ammo(player &u, bool interactive) { if( is_null() ) return false; if (!type->is_gun() && !type->is_tool()) { debugmsg("RELOADING NON-GUN NON-TOOL"); return false; } int has_spare_mag = has_gunmod (itm_spare_mag); std::vector<int> am; // List of indicies of valid ammo if (type->is_gun()) { if(charges <= 0 && has_spare_mag != -1 && contents[has_spare_mag].charges > 0) { // Special return to use magazine for reloading. return -2; } it_gun* tmp = dynamic_cast<it_gun*>(type); // If there's room to load more ammo into the gun or a spare mag, stash the ammo. // If the gun is partially loaded make sure the ammo matches. // If the gun is empty, either the spre mag is empty too and anything goes, // or the spare mag is loaded and we're doing a tactical reload. if (charges < clip_size() || (has_spare_mag != -1 && contents[has_spare_mag].charges < tmp->clip)) { std::vector<int> tmpammo = u.has_ammo(ammo_type()); for (int i = 0; i < tmpammo.size(); i++) if (charges >= 0 || u.inv[tmpammo[i]].typeId() == curammo->id) am.push_back(tmpammo[i]); } // ammo for gun attachments (shotgun attachments, grenade attachments, etc.) // for each attachment, find its associated ammo & append it to the ammo vector for (int i = 0; i < contents.size(); i++) if (contents[i].is_gunmod() && contents[i].has_flag(IF_MODE_AUX) && contents[i].charges < (dynamic_cast<it_gunmod*>(contents[i].type))->clip) { std::vector<int> tmpammo = u.has_ammo((dynamic_cast<it_gunmod*>(contents[i].type))->newtype); for(int j = 0; j < tmpammo.size(); j++) if (contents[i].charges >= 0 || u.inv[tmpammo[j]].typeId() == contents[i].curammo->id) am.push_back(tmpammo[j]); } } else { //non-gun. am = u.has_ammo(ammo_type()); } int index = -1; if (am.size() > 1 && interactive) {// More than one option; list 'em and pick WINDOW* w_ammo = newwin(am.size() + 1, 80, 0, 0); char ch; clear(); it_ammo* ammo_type; mvwprintw(w_ammo, 0, 0, "\ Choose ammo type: Damage Armor Pierce Range Accuracy"); for (int i = 0; i < am.size(); i++) { ammo_type = dynamic_cast<it_ammo*>(u.inv[am[i]].type); mvwaddch(w_ammo, i + 1, 1, i + 'a'); mvwprintw(w_ammo, i + 1, 3, "%s (%d)", u.inv[am[i]].tname().c_str(), u.inv[am[i]].charges); mvwprintw(w_ammo, i + 1, 27, "%d", ammo_type->damage); mvwprintw(w_ammo, i + 1, 38, "%d", ammo_type->pierce); mvwprintw(w_ammo, i + 1, 55, "%d", ammo_type->range); mvwprintw(w_ammo, i + 1, 65, "%d", 100 - ammo_type->accuracy); } refresh(); wrefresh(w_ammo); do ch = getch(); while ((ch < 'a' || ch - 'a' > am.size() - 1) && ch != ' ' && ch != 27); werase(w_ammo); delwin(w_ammo); erase(); if (ch == ' ' || ch == 27) index = -1; else index = am[ch - 'a']; }
int item::pick_reload_ammo(player &u, bool interactive) { if (!type->is_gun() && !type->is_tool()) { debugmsg("RELOADING NON-GUN NON-TOOL"); return false; } bool has_m203 = false; for (int i = 0; i < contents.size() && !has_m203; i++) { if (contents[i].type->id == itm_m203) has_m203 = true; } std::vector<int> am; // List of indicies of valid ammo if (type->is_gun()) { if (charges > 0) { itype_id aid = itype_id(curammo->id); for (int i = 0; i < u.inv.size(); i++) { if (u.inv[i].type->id == aid) am.push_back(i); } } else { it_gun* tmp = dynamic_cast<it_gun*>(type); am = u.has_ammo(ammo_type()); if (has_m203) { std::vector<int> grenades = u.has_ammo(AT_40MM); for (int i = 0; i < grenades.size(); i++) am.push_back(grenades[i]); } } } else { it_tool* tmp = dynamic_cast<it_tool*>(type); am = u.has_ammo(ammo_type()); } int index = -1; if (am.size() > 1 && interactive) {// More than one option; list 'em and pick WINDOW* w_ammo = newwin(am.size() + 1, 80, 0, 0); if (charges == 0) { char ch; clear(); it_ammo* ammo_type; mvwprintw(w_ammo, 0, 0, _("\ Choose ammo type: Damage Armor Pierce Range Accuracy")); for (int i = 0; i < am.size(); i++) { ammo_type = dynamic_cast<it_ammo*>(u.inv[am[i]].type); mvwaddch(w_ammo, i + 1, 1, i + 'a'); mvwprintw(w_ammo, i + 1, 3, "%s (%d)", u.inv[am[i]].tname().c_str(), u.inv[am[i]].charges); mvwprintw(w_ammo, i + 1, 27, "%d", ammo_type->damage); mvwprintw(w_ammo, i + 1, 38, "%d", ammo_type->pierce); mvwprintw(w_ammo, i + 1, 55, "%d", ammo_type->range); mvwprintw(w_ammo, i + 1, 65, "%d", 100 - ammo_type->accuracy); } refresh(); wrefresh(w_ammo); do ch = getch(); while ((ch < 'a' || ch - 'a' > am.size() - 1) && ch != ' ' && ch != 27); werase(w_ammo); delwin(w_ammo); erase(); if (ch == ' ' || ch == 27) index = -1; else index = am[ch - 'a']; } else {