diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-02-09 08:44:41 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-02-09 08:44:41 -0500 |
commit | 1382f79d57060dc38f6c45fd4fc865e0e565f90b (patch) | |
tree | 19d57dfa61ce77dc38caae73c0db559e01cb18b3 /src/inventory.cpp | |
parent | 36ef7e42fb1b151c64d69d96df7e33a9f4c47b83 (diff) |
quest completion
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 93bdeb6..d52dbe8 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -53,22 +53,38 @@ int Inventory::addItem(std::string name,uint count){ int Inventory::takeItem(std::string name,uint count){ unsigned int id = 999999; + + /* + * Name to ID lookup + */ + for(unsigned int i=0;i<itemMap.size();i++){ if(itemMap[i]->name == name){ id = i; break; } } + + if(id == 999999) + return -1; + + /* + * Inventory lookup + */ + for(unsigned int i=0;i<items.size();i++){ if(items[i].id == id){ if(count > items[i].count) - items.erase(items.begin()+i); - else + return -(items[i].count - count); + else{ items[i].count -= count; + if(!items[i].count) + items.erase(items.begin()+i); + } return 0; } } - return -1; + return -2; } static GLuint *itemtex; |