4 * Created on: Aug 9, 2012
17 Inventory::Inventory()
22 bool Inventory::Add(const Item *item, int count) {
23 if (count > 99) return false;
25 Entry *entry(FindItem(item));
27 if (entry->count + count > 99) {
30 entry->count += count;
34 for (int i(0); i < MaxItems(); ++i) {
36 entries[i].item = item;
37 entries[i].count = count;
45 void Inventory::Remove(const Item *item, int count) {
46 Entry *entry(FindItem(item));
49 if (entry->count <= count) {
53 entry->count -= count;
57 void Inventory::RemoveAll(const Item *item) {
61 Inventory::Entry *Inventory::FindItem(const Item *item) {
62 for (int i(0); i < MaxItems(); ++i) {
63 if (item == ItemAt(i)) {
70 bool Inventory::SloteFree(int offset) const {
71 return !ItemAt(offset);
75 bool Inventory::AddScenarioItem(const Item *i) {
76 if (scenarioEnd < MaxScenarioItems()) {
77 scenario[scenarioEnd] = i;
86 void Inventory::Sort() {
87 std::sort(entries, entries + 96, Entry::Less);
90 bool Inventory::Entry::Less(const Entry &lhs, const Entry &rhs) {
93 return Item::Less(*lhs.item, *rhs.item);
102 void Inventory::SwapEntriesAt(int lhs, int rhs) {
103 std::swap(entries[lhs], entries[rhs]);