aboutsummaryrefslogtreecommitdiffstats
path: root/src/inventory.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-02-10 08:48:49 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-02-10 08:48:49 -0500
commit3033594b89f23e65b6152daa6610f991307f2f67 (patch)
tree920a7c1b35946210683cdd1146cd0afeb7e24b7d /src/inventory.cpp
parent1382f79d57060dc38f6c45fd4fc865e0e565f90b (diff)
quests, inventory good
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index d52dbe8..b32b56f 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -13,7 +13,7 @@ static bool swing = false;
static vec2 itemLoc;
Mix_Chunk* swordSwing;
-std::vector<Item *> itemMap;
+static std::vector<Item *> itemMap;
void items(void){
XMLDocument xml;
@@ -32,7 +32,7 @@ void items(void){
itemMap.back()->texloc = exml->Attribute("sprite");
exml = exml->NextSiblingElement();
- }
+ }
}
int Inventory::addItem(std::string name,uint count){
@@ -44,7 +44,7 @@ int Inventory::addItem(std::string name,uint count){
return 0;
}
}
- items.push_back((item_t){i,count});
+ items.push_back((item_t){count,i});
return 0;
}
}
@@ -87,6 +87,27 @@ int Inventory::takeItem(std::string name,uint count){
return -2;
}
+int Inventory::hasItem(std::string name){
+ unsigned int id = 999999;
+
+ for(unsigned int i=0;i<itemMap.size();i++){
+ if(itemMap[i]->name == name){
+ id = i;
+ break;
+ }
+ }
+
+ if(id == 999999)
+ return 0;
+
+ for(auto &i : items){
+ if(i.id == id)
+ return i.count;
+ }
+
+ return 0;
+}
+
static GLuint *itemtex;
void itemDraw(Player *p,uint id);
@@ -227,7 +248,7 @@ void Inventory::draw(void){
}
glEnd();
glDisable(GL_TEXTURE_2D);
- ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",itemMap[items[a].id]->name);
+ ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",itemMap[items[a].id]->name.c_str());
ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",items[a].count);
}