void inventory::add_item(item newit, bool keep_invlet) { if (keep_invlet && !newit.invlet_is_okay()) assign_empty_invlet(newit); // Keep invlet is true, but invlet is invalid! if (newit.is_style()) return; // Styles never belong in our inventory. for (int i = 0; i < items.size(); i++) { if (items[i][0].stacks_with(newit)) { /* if (keep_invlet) items[i][0].invlet = newit.invlet; else */ newit.invlet = items[i][0].invlet; items[i].push_back(newit); return; } else if (keep_invlet && items[i][0].invlet == newit.invlet) assign_empty_invlet(items[i][0]); } if (!newit.invlet_is_okay() || index_by_letter(newit.invlet) != -1) assign_empty_invlet(newit); std::vector<item> newstack; newstack.push_back(newit); items.push_back(newstack); }
void inventory::add_item(item newit) { for (int i = 0; i < items.size(); i++) { if (items[i][0].stacks_with(newit)) { newit.invlet = items[i][0].invlet; items[i].push_back(newit); return; } } if (!newit.invlet_is_okay() || index_by_letter(newit.invlet) != -1) { int ch; for (ch = 'a'; ch <= 'z' && ch > 0; ch++) { if (index_by_letter(ch) == -1) { newit.invlet = ch; ch = -1; } } if (ch > 0) { for (ch = 'A'; ch <= 'Z' && ch > 0; ch++) { if (index_by_letter(ch) == -1) { newit.invlet = ch; ch = -1; } } } if (ch > 0) newit.invlet = '`'; } std::vector<item> newstack; newstack.push_back(newit); items.push_back(newstack); }