void game::wishitem( player *p, int x, int y) { if ( p == NULL && x <= 0 ) { debugmsg("game::wishitem(): invalid parameters"); return; } int amount = 1; uimenu wmenu; wmenu.w_x = 0; wmenu.w_width = TERMX; wmenu.pad_right = ( TERMX / 2 > 40 ? TERMX - 40 : TERMX / 2 ); wmenu.return_invalid = true; wmenu.selected = uistate.wishitem_selected; wish_item_callback *cb = new wish_item_callback(); wmenu.callback = cb; for (int i = 0; i < standard_itype_ids.size(); i++) { itype *ity = item_controller->find_template(standard_itype_ids[i]); wmenu.addentry( i, true, 0, string_format("%s", ity->name.c_str()) ); wmenu.entries[i].extratxt.txt = string_format("%c", ity->sym); wmenu.entries[i].extratxt.color = ity->color; wmenu.entries[i].extratxt.left = 1; } do { wmenu.query(); if ( wmenu.ret >= 0 ) { amount = helper::to_int( string_input_popup( _("How many?"), 20, helper::to_string( amount ), item_controller->find_template(standard_itype_ids[wmenu.ret])->name.c_str() ) ); item granted = item_controller->create(standard_itype_ids[wmenu.ret], turn); int incontainer = dynamic_cast<wish_item_callback *>(wmenu.callback)->incontainer; if ( p != NULL ) { dynamic_cast<wish_item_callback *>(wmenu.callback)->tmp.invlet = nextinv; for (int i = 0; i < amount; i++) { p->i_add(!incontainer ? granted : granted.in_its_container(&itypes)); } advance_nextinv(); } else if ( x >= 0 && y >= 0 ) { m.add_item_or_charges(x, y, !incontainer ? granted : granted.in_its_container(&itypes)); wmenu.keypress = 'q'; } dynamic_cast<wish_item_callback *>(wmenu.callback)->msg = _("Item granted, choose another or 'q' to quit."); uistate.wishitem_selected = wmenu.ret; } } while ( wmenu.keypress != 'q' && wmenu.keypress != KEY_ESCAPE && wmenu.keypress != ' ' ); delete wmenu.callback; wmenu.callback = NULL; return; }
void game::complete_craft() { recipe making = recipes[u.activity.index]; // Which recipe is it? std::vector<component> will_use; // List of all items we're using, w/ count // Up to 5 components / tools for (int i = 0; i < 5; i++) { if (making.components[i].size() > 0) { // For each set of components in the recipe, fill you_have with the list of all // matching ingredients the player has. std::vector<component> you_have; for (int j = 0; j < making.components[i].size(); j++) { if (u.has_amount(making.components[i][j].type, making.components[i][j].count)) you_have.push_back(making.components[i][j]); } if (you_have.size() == 1) // Only one, so we'll definitely use it will_use.push_back(component(you_have[0].type, you_have[0].count)); else { // Let the player pick which component they want to use WINDOW* w = newwin(you_have.size() + 2, 30, 10, 25); wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); mvwprintz(w, 0, 5, c_red, "Use which component?"); for (int j = 0; j < you_have.size(); j++) mvwprintz(w, j + 1, 1, c_white, "%d: %s", j + 1, itypes[you_have[j].type]->name.c_str()); wrefresh(w); char ch; do ch = getch(); while (ch < '1' || ch >= '1' + you_have.size()); ch -= '1'; will_use.push_back(component(you_have[ch].type, you_have[ch].count)); delwin(w); } } // Done looking at components // Use charges of any tools that require charges used if (making.tools[i].size() > 0) { for (int j = 0; j < making.tools[i].size(); j++) { if (making.tools[i][j].count > 0) u.use_charges(making.tools[i][j].type, making.tools[i][j].count); } } } // Done finding the components/tools needed // # of dice is 75% primary skill, 25% secondary (unless secondary is null) int skill_dice = u.sklevel[making.sk_primary] * 3; if (making.sk_secondary == sk_null) skill_dice += u.sklevel[making.sk_primary]; else skill_dice += u.sklevel[making.sk_secondary]; // Sides on dice is 16 plus your current intelligence int skill_sides = 16 + u.int_cur; int diff_dice = making.difficulty * 4; // Since skill level is * 4 also int diff_sides = 24; // 16 + 8 (default intelligence) int skill_roll = dice(skill_dice, skill_sides); int diff_roll = dice(diff_dice, diff_sides); if (making.sk_primary != sk_null) u.practice(making.sk_primary, making.difficulty * 5 + 20); if (making.sk_secondary != sk_null) u.practice(making.sk_secondary, 5); // Messed up badly; waste some components. if (making.difficulty != 0 && diff_roll > skill_roll * (1 + 0.1 * rng(1, 5))) { add_msg("You fail to make the %s, and waste some materials.", itypes[making.result]->name.c_str()); int num_lost = rng(1, will_use.size()); for (int i = 0; i < num_lost; i++) { int n = rng(0, will_use.size() - 1); if (itypes[will_use[n].type]->is_ammo() && will_use[i].type != itm_gasoline) u.use_charges(will_use[n].type, will_use[n].count); else u.use_amount(will_use[n].type, will_use[n].count); will_use.erase(will_use.begin() + n); } u.activity.type = ACT_NULL; return; // Messed up slightly; no components wasted. } else if (diff_roll > skill_roll) { add_msg("You fail to make the %s, but don't waste any materials.", itypes[making.result]->name.c_str()); u.activity.type = ACT_NULL; return; } // If we're here, the craft was a success! // Use up the items in will_use for (int i = 0; i < will_use.size(); i++) { if (itypes[will_use[i].type]->is_ammo() && will_use[i].type != itm_gasoline) u.use_charges(will_use[i].type, will_use[i].count); else u.use_amount(will_use[i].type, will_use[i].count); } // Set up the new item, and pick an inventory letter int iter = 0; item newit(itypes[making.result], turn, nextinv); do { newit.invlet = nextinv; advance_nextinv(); iter++; } while (u.has_item(newit.invlet) && iter < 52); newit = newit.in_its_container(&itypes); // We might not have space for the item if (iter == 52 || u.volume_carried()+newit.volume() > u.volume_capacity()) { add_msg("There's no room in your inventory for the %s, so you drop it.", newit.tname().c_str()); m.add_item(u.posx, u.posy, newit); } else if (u.weight_carried() + newit.volume() > u.weight_capacity()) { add_msg("The %s is too heavy to carry, so you drop it.", newit.tname().c_str()); m.add_item(u.posx, u.posy, newit); } else { u.i_add(newit); add_msg("%c - %s", newit.invlet, newit.tname().c_str()); } }
void game::wish() { WINDOW* w_search = newwin(2, FULL_SCREEN_WIDTH, 0, 0); WINDOW* w_list = newwin(FULL_SCREEN_HEIGHT-2, 30, 2, 0); WINDOW* w_info = newwin(FULL_SCREEN_HEIGHT-2, 50, 2, 30); int a = 0, shift = 0, result_selected = 0; int ch = '.'; bool search = false; bool incontainer = false; bool changed = false; std::string pattern = ""; std::string info; std::vector<int> search_results; // use this item for info display, but NOT for instantiation item tmp; tmp.corpse = mtypes[0]; do { werase(w_search); werase(w_info); werase(w_list); mvwprintw(w_search, 0, 0, _("('/' to search, Esc to stop, <> to switch between results)")); mvwprintz(w_search, 1, 0, c_white, _("Wish for a: ")); if (search) { if (ch == '\n') { search = false; ch = '.'; } else if (ch == 27) // Escape to stop searching { search = false; ch = '.'; } else if (ch == KEY_BACKSPACE || ch == 127) { if (pattern.length() > 0) { pattern.erase(pattern.end() - 1); search_results.clear(); changed = true; } else { changed = false; } } else if (ch == '>' || ch == KEY_NPAGE) { if (!search_results.empty()) { result_selected++; if (result_selected >= search_results.size()) result_selected = 0; shift = search_results[result_selected]; a = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } } changed = false; } else if (ch == '<' || ch == KEY_PPAGE) { if (!search_results.empty()) { result_selected--; if (result_selected < 0) result_selected = search_results.size() - 1; shift = search_results[result_selected]; a = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } } changed = false; } else { pattern += ch; search_results.clear(); changed = true; } // If the pattern hasn't changed or we've stopped searching, no need to update if (search && changed) { // If the pattern is blank, search just returns all items, which will be listed anyway if (pattern.length() > 0) { for (int i = 0; i < standard_itype_ids.size(); i++) { if (item_controller->find_template(standard_itype_ids[i])->name.find(pattern) != std::string::npos) { shift = i; a = 0; result_selected = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } search_results.push_back(i); } } if (search_results.size() > 0) { shift = search_results[0]; a = 0; } } else // The pattern is blank, so jump back to the top of the list { shift = 0; } } } else { // Not searching; scroll by keys if (ch == 'j') a++; if (ch == 'k') a--; if (ch == '/') { search = true; } if (ch == 'f') incontainer = !incontainer; if (( ch == '>' || ch == KEY_NPAGE ) && !search_results.empty()) { result_selected++; if (result_selected >= search_results.size()) result_selected = 0; shift = search_results[result_selected]; a = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } } else if (( ch == '<' || ch == KEY_PPAGE ) && !search_results.empty()) { result_selected--; if (result_selected < 0) result_selected = search_results.size() - 1; shift = search_results[result_selected]; a = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } } } int search_string_length = pattern.length(); if (!search_results.empty()) mvwprintz(w_search, 1, 12, c_green, "%s", pattern.c_str()); else if (pattern.length() > 0) { mvwprintz(w_search, 1, 12, c_red, _("\"%s \" not found!"),pattern.c_str()); search_string_length += 1; } if (incontainer) mvwprintz(w_search, 0, 70, c_ltblue, _("contained")); if (a < 0) { a = 0; shift--; if (shift < 0) shift = 0; } if (a > 22) { a = 22; shift++; if (shift + 23 > standard_itype_ids.size()) shift = standard_itype_ids.size() - 23; } for (int i = 0; i < 23 && i+shift < standard_itype_ids.size(); i++) { nc_color col = c_ltgray; if (i == a) col = h_ltgray; mvwprintz(w_list, i, 0, col, item_controller->find_template(standard_itype_ids[i+shift])->name.c_str()); wprintz(w_list, item_controller->find_template(standard_itype_ids[i+shift])->color, "%c%", item_controller->find_template(standard_itype_ids[i+shift])->sym); } tmp.make(item_controller->find_template(standard_itype_ids[a + shift])); tmp.bday = turn; if (tmp.is_tool()) tmp.charges = dynamic_cast<it_tool*>(tmp.type)->max_charges; else if (tmp.is_ammo()) tmp.charges = 100; else if (tmp.is_gun()) tmp.charges = 0; else if (tmp.is_gunmod() && (tmp.has_flag("MODE_AUX") || tmp.typeId() == "spare_mag")) tmp.charges = 0; else tmp.charges = -1; // Should be a flag, but we're out at the moment if( tmp.is_stationary() ) { tmp.note = SNIPPET.assign( (dynamic_cast<it_stationary*>(tmp.type))->category ); } info = tmp.info(true); mvwprintw(w_info, 0, 0, info.c_str()); wrefresh(w_search); wrefresh(w_info); wrefresh(w_list); if (search) { curs_set(1); ch = mvgetch(1, search_string_length+12); } else { curs_set(0); ch = input(); } } while (ch != '\n' && !(ch==KEY_ESCAPE && !search)); clear(); if(ch=='\n') { // Allow for multiples curs_set(1); mvprintw(0, 0, _("How many do you want? (default is 1): ")); char str[5]; int count = 1; echo(); getnstr(str, 5); noecho(); count = atoi(str); if (count<=0) { count = 1; } curs_set(0); item granted = item_controller->create(standard_itype_ids[a + shift], turn); mvprintw(2, 0, _("Wish granted - %d x %s."), count, granted.type->name.c_str()); tmp.invlet = nextinv; for (int i=0; i<count; i++) { if (!incontainer) u.i_add(granted); else u.i_add(granted.in_its_container(&itypes)); } advance_nextinv(); getch(); } delwin(w_info); delwin(w_list); }
void game::wish() { WINDOW* w_list = newwin(25, 30, 0, 0); WINDOW* w_info = newwin(25, 50, 0, 30); int a = 0, shift = 0, result_selected = 0; int line; char ch = '.'; bool search = false, found = false; std::string pattern; std::string info; std::vector<int> search_results; item tmp; tmp.corpse = mtypes[0]; do { werase(w_info); werase(w_list); mvwprintw(w_list, 0, 0, _("Wish for a: ")); if (search) { found = false; if (ch == '\n') { search = false; found = true; ch = '.'; } else if (ch == KEY_BACKSPACE || ch == 127) { if (pattern.length() > 0) pattern.erase(pattern.end() - 1); } else if (ch == '>') { search = false; if (!search_results.empty()) { result_selected++; if (result_selected > search_results.size()) result_selected = 0; shift = search_results[result_selected]; a = 0; if (shift + 23 > itypes.size()) { a = shift + 23 - itypes.size(); shift = itypes.size() - 23; } } } else if (ch == '<') { search = false; if (!search_results.empty()) { result_selected--; if (result_selected < 0) result_selected = search_results.size() - 1; shift = search_results[result_selected]; a = 0; if (shift + 23 > itypes.size()) { a = shift + 23 - itypes.size(); shift = itypes.size() - 23; } } } else { pattern += ch; search_results.clear(); } if (search) { for (int i = 0; i < itypes.size(); i++) { if (itypes[i]->name.find(pattern) != std::string::npos) { shift = i; a = 0; result_selected = 0; if (shift + 23 > itypes.size()) { a = shift + 23 - itypes.size(); shift = itypes.size() - 23; } found = true; search_results.push_back(i); } } if (search_results.size() > 0) { shift = search_results[0]; a = 0; } } } else { // Not searching; scroll by keys if (ch == 'j') a++; if (ch == 'k') a--; if (ch == '/') { search = true; pattern = ""; found = false; search_results.clear(); } if (ch == '>' && !search_results.empty()) { result_selected++; if (result_selected > search_results.size()) result_selected = 0; shift = search_results[result_selected]; a = 0; if (shift + 23 > itypes.size()) { a = shift + 23 - itypes.size(); shift = itypes.size() - 23; } } else if (ch == '<' && !search_results.empty()) { result_selected--; if (result_selected < 0) result_selected = search_results.size() - 1; shift = search_results[result_selected]; a = 0; if (shift + 23 > itypes.size()) { a = shift + 23 - itypes.size(); shift = itypes.size() - 23; } } } if (!search_results.empty()) mvwprintz(w_list, 0, 11, c_green, "%s ", pattern.c_str()); else if (pattern.length() > 0) mvwprintz(w_list, 0, 11, c_red, _("%s not found! "),pattern.c_str()); if (a < 0) { a = 0; shift--; if (shift < 0) shift = 0; } if (a > 22) { a = 22; shift++; if (shift + 23 > itypes.size()) shift = itypes.size() - 23; } for (int i = 1; i < 24; i++) { nc_color col = c_white; if (i == a + 1) col = h_white; mvwprintz(w_list, i, 0, col, itypes[i-1+shift]->name.c_str()); wprintz(w_list, itypes[i-1+shift]->color, "%c%", itypes[i-1+shift]->sym); } tmp.make(itypes[a + shift]); if (tmp.is_tool()) tmp.charges = dynamic_cast<it_tool*>(tmp.type)->max_charges; else if (tmp.is_ammo()) tmp.charges = 100; else tmp.charges = -1; info = tmp.info(true); mvwprintw(w_info, 1, 0, info.c_str()); wrefresh(w_info); wrefresh(w_list); if (search) ch = getch(); else ch = input(); } while (ch != '\n'); clear(); mvprintw(0, 0, _("\nWish granted - %d (%d)."), tmp.type->id, itm_antibiotics); tmp.invlet = nextinv; u.i_add(tmp); advance_nextinv(); getch(); delwin(w_info); delwin(w_list); }
void game::wish() { WINDOW* w_list = newwin(25, 30, 0, 0); WINDOW* w_info = newwin(25, 50, 0, 30); int a = 0, shift = 0, result_selected = 0; int ch = '.'; bool search = false; bool incontainer = false; std::string pattern; std::string info; std::vector<int> search_results; item tmp; tmp.corpse = mtypes[0]; do { werase(w_info); werase(w_list); mvwprintw(w_list, 0, 0, "Wish for a ('/'searches): "); if (search) { if (ch == '\n') { search = false; ch = '.'; } else if (ch == KEY_BACKSPACE || ch == 127) { if (pattern.length() > 0) pattern.erase(pattern.end() - 1); } else if (ch == '>' || ch == KEY_NPAGE) { search = false; if (!search_results.empty()) { result_selected++; if (result_selected > search_results.size()) result_selected = 0; shift = search_results[result_selected]; a = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } } } else if (ch == '<' || ch == KEY_PPAGE) { search = false; if (!search_results.empty()) { result_selected--; if (result_selected < 0) result_selected = search_results.size() - 1; shift = search_results[result_selected]; a = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } } } else { pattern += ch; search_results.clear(); } if (search) { for (int i = 0; i < standard_itype_ids.size(); i++) { if (item_controller->find_template(standard_itype_ids[i])->name.find(pattern) != std::string::npos) { shift = i; a = 0; result_selected = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } search_results.push_back(i); } } if (search_results.size() > 0) { shift = search_results[0]; a = 0; } } } else { // Not searching; scroll by keys if (ch == 'j') a++; if (ch == 'k') a--; if (ch == '/') { search = true; pattern = ""; search_results.clear(); } if (ch == 'f') incontainer = !incontainer; if (( ch == '>' || ch == KEY_NPAGE ) && !search_results.empty()) { result_selected++; if (result_selected > search_results.size()) result_selected = 0; shift = search_results[result_selected]; a = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } } else if (( ch == '<' || ch == KEY_PPAGE ) && !search_results.empty()) { result_selected--; if (result_selected < 0) result_selected = search_results.size() - 1; shift = search_results[result_selected]; a = 0; if (shift + 23 > standard_itype_ids.size()) { a = shift + 23 - standard_itype_ids.size(); shift = standard_itype_ids.size() - 23; } } } if (!search_results.empty()) mvwprintz(w_list, 0, 25, c_green, "%s ", pattern.c_str()); else if (pattern.length() > 0) mvwprintz(w_list, 0, 11, c_red, "%s not found! ",pattern.c_str()); if (incontainer) mvwprintz(w_list, 1, 20, c_ltblue, "contained"); if (a < 0) { a = 0; shift--; if (shift < 0) shift = 0; } if (a > 22) { a = 22; shift++; if (shift + 23 > standard_itype_ids.size()) shift = standard_itype_ids.size() - 23; } for (int i = 1; i < 24 && i-1+shift < standard_itype_ids.size(); i++) { nc_color col = c_white; if (i == a + 1) col = h_white; mvwprintz(w_list, i, 0, col, item_controller->find_template(standard_itype_ids[i-1+shift])->name.c_str()); wprintz(w_list, item_controller->find_template(standard_itype_ids[i-1+shift])->color, "%c%", item_controller->find_template(standard_itype_ids[i-1+shift])->sym); } tmp.make(item_controller->find_template(standard_itype_ids[a + shift])); tmp.bday = turn; if (tmp.is_tool()) tmp.charges = dynamic_cast<it_tool*>(tmp.type)->max_charges; else if (tmp.is_ammo()) tmp.charges = 100; else if (tmp.is_gun()) tmp.charges = 0; else if (tmp.is_gunmod() && (tmp.has_flag(IF_MODE_AUX) || tmp.typeId() == "spare_mag")) tmp.charges = 0; else tmp.charges = -1; info = tmp.info(true); mvwprintw(w_info, 1, 0, info.c_str()); wrefresh(w_info); wrefresh(w_list); if (search) ch = getch(); else ch = input(); } while (ch != '\n'); clear(); mvprintw(0, 0, "\nWish granted - %d (%d).", tmp.type->id.c_str(), "antibiotics"); tmp.invlet = nextinv; if (!incontainer) u.i_add(tmp); else u.i_add(tmp.in_its_container(&itypes)); advance_nextinv(); getch(); delwin(w_info); delwin(w_list); }
void game::complete_craft() { recipe* making = recipes[u.activity.index]; // Which recipe is it? // # of dice is 75% primary skill, 25% secondary (unless secondary is null) int skill_dice = u.sklevel[making->sk_primary] * 3; if (making->sk_secondary == sk_null) skill_dice += u.sklevel[making->sk_primary]; else skill_dice += u.sklevel[making->sk_secondary]; // Sides on dice is 16 plus your current intelligence int skill_sides = 16 + u.int_cur; int diff_dice = making->difficulty * 4; // Since skill level is * 4 also int diff_sides = 24; // 16 + 8 (default intelligence) int skill_roll = dice(skill_dice, skill_sides); int diff_roll = dice(diff_dice, diff_sides); if (making->sk_primary != sk_null) u.practice(making->sk_primary, making->difficulty * 5 + 20); if (making->sk_secondary != sk_null) u.practice(making->sk_secondary, 5); // Messed up badly; waste some components. if (making->difficulty != 0 && diff_roll > skill_roll * (1 + 0.1 * rng(1, 5))) { add_msg("You fail to make the %s, and waste some materials.", itypes[making->result]->name.c_str()); for (int i = 0; i < 5; i++) { if (making->components[i].size() > 0) { std::vector<component> copy = making->components[i]; for (int j = 0; j < copy.size(); j++) copy[j].count = rng(0, copy[j].count); consume_items(this, copy); } if (making->tools[i].size() > 0) consume_tools(this, making->tools[i]); } u.activity.type = ACT_NULL; return; // Messed up slightly; no components wasted. } else if (diff_roll > skill_roll) { add_msg("You fail to make the %s, but don't waste any materials.", itypes[making->result]->name.c_str()); u.activity.type = ACT_NULL; return; } // If we're here, the craft was a success! // Use up the components and tools for (int i = 0; i < 5; i++) { if (making->components[i].size() > 0) consume_items(this, making->components[i]); if (making->tools[i].size() > 0) consume_tools(this, making->tools[i]); } // Set up the new item, and pick an inventory letter int iter = 0; item newit(itypes[making->result], turn, nextinv); if (!newit.craft_has_charges()) newit.charges = 0; do { newit.invlet = nextinv; advance_nextinv(); iter++; } while (u.has_item(newit.invlet) && iter < 52); //newit = newit.in_its_container(&itypes); if (newit.made_of(LIQUID)) handle_liquid(newit, false, false); else { // We might not have space for the item if (iter == 52 || u.volume_carried()+newit.volume() > u.volume_capacity()) { add_msg("There's no room in your inventory for the %s, so you drop it.", newit.tname().c_str()); m.add_item(u.posx, u.posy, newit); } else if (u.weight_carried() + newit.volume() > u.weight_capacity()) { add_msg("The %s is too heavy to carry, so you drop it.", newit.tname().c_str()); m.add_item(u.posx, u.posy, newit); } else { u.i_add(newit); add_msg("%c - %s", newit.invlet, newit.tname().c_str()); } } }
void game::wish() { int a = 0, shift = 0; int line; char ch = '.'; bool search = false, found = false; std::string pattern; std::string info; item tmp; tmp.corpse = mtypes[0]; do { erase(); mvprintw(0, 0, "Wish for a: "); if (search) { found = false; if (ch == '\n') { search = false; found = true; pattern = ""; ch = '.'; } else if (ch == KEY_BACKSPACE && pattern.length() > 0) pattern.erase(pattern.end() - 1); else pattern += ch; for (int i = 0; i < itypes.size() && !found; i++) { if (itypes[i]->name.find(pattern) != std::string::npos) { shift = i; a = 0; if (shift + 23 > itypes.size()) { a = shift + 23 - itypes.size(); shift = itypes.size() - 23; } found = true; } } if (found) mvprintw(1, 0, "%s ", pattern.c_str()); else if (search) mvprintz(1, 0, c_red, "%s not found! ", pattern.c_str()); else mvprintw(1, 0, " "); } else { // Not searching; scroll by keys if (ch == 'j') a++; if (ch == 'k') a--; if (ch == '/') { search = true; pattern = ""; } } if (a < 0) { a = 0; shift--; if (shift < 0) shift = 0; } if (a > 22) { a = 22; shift++; if (shift + 23 > itypes.size()) shift = itypes.size() - 23; } for (int i = 1; i < LESS(24, itypes.size()); i++) { mvprintz(i, 40, c_white, itypes[i-1+shift]->name.c_str()); printz(itypes[i-1+shift]->color, "%c%", itypes[i-1+shift]->sym); } tmp.make(itypes[a + shift]); if (tmp.is_tool()) tmp.charges = dynamic_cast<it_tool*>(tmp.type)->max_charges; else if (tmp.is_ammo()) tmp.charges = 100; info = tmp.info(); line = 2; mvprintw(line, 1, info.c_str()); ch = getch(); } while (ch != '\n'); clear(); mvprintw(0, 0, "\nWish granted."); tmp.invlet = nextinv; u.i_add(tmp); advance_nextinv(); getch(); }