10 Inventory::Inventory()
15 bool Inventory::Add(const Item *item, int count) {
16 if (count > 99) return false;
18 Entry *entry(FindItem(item));
20 if (entry->count + count > 99) {
23 entry->count += count;
27 for (int i(0); i < MaxItems(); ++i) {
29 entries[i].item = item;
30 entries[i].count = count;
38 void Inventory::Remove(const Item *item, int count) {
39 Entry *entry(FindItem(item));
42 if (entry->count <= count) {
46 entry->count -= count;
50 void Inventory::RemoveAll(const Item *item) {
54 Inventory::Entry *Inventory::FindItem(const Item *item) {
55 for (int i(0); i < MaxItems(); ++i) {
56 if (item == ItemAt(i)) {
63 bool Inventory::SloteFree(int offset) const {
64 return !ItemAt(offset);
68 bool Inventory::AddScenarioItem(const Item *i) {
69 if (scenarioEnd < MaxScenarioItems()) {
70 scenario[scenarioEnd] = i;
79 void Inventory::Sort() {
80 std::stable_sort(entries, entries + 96, Entry::Less);
83 bool Inventory::Entry::Less(const Entry &lhs, const Entry &rhs) {
86 return Item::Less(*lhs.item, *rhs.item);
95 void Inventory::SwapEntriesAt(int lhs, int rhs) {
96 std::swap(entries[lhs], entries[rhs]);