From 1382f79d57060dc38f6c45fd4fc865e0e565f90b Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 9 Feb 2016 08:44:41 -0500 Subject: quest completion --- config/items.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config') diff --git a/config/items.xml b/config/items.xml index 02d199e..02382d6 100644 --- a/config/items.xml +++ b/config/items.xml @@ -1,7 +1,7 @@ - + -- cgit v1.2.3 From 3033594b89f23e65b6152daa6610f991307f2f67 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 10 Feb 2016 08:48:49 -0500 Subject: quests, inventory good --- Changelog | 8 ++++++ config/settings.xml.example | 26 ++++++++++++++++++ include/Quest.h | 11 +++++--- include/inventory.h | 1 + src/Quest.cpp | 54 ++++++++++++++++++++++++++++++++------ src/gameplay.cpp | 17 +++--------- src/inventory.cpp | 29 +++++++++++++++++--- xml/playerSpawnHill1.xml | 5 +++- xml/playerSpawnHill1_Building1.xml | 23 ++++++++++++++-- 9 files changed, 143 insertions(+), 31 deletions(-) create mode 100644 config/settings.xml.example (limited to 'config') diff --git a/Changelog b/Changelog index e8a0605..582259c 100644 --- a/Changelog +++ b/Changelog @@ -639,3 +639,11 @@ - quests can require one item for completion - better-er text drawing - can set world themes through XML + +2/10/2016: +========== + + - proper quest handling: multiple req's, re-classified, overall good + - began considering unique_ptr's because they're good + - fixed inventory everything + - themes work diff --git a/config/settings.xml.example b/config/settings.xml.example new file mode 100644 index 0000000..d9b8077 --- /dev/null +++ b/config/settings.xml.example @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + diff --git a/include/Quest.h b/include/Quest.h index 388b14d..8b1e142 100644 --- a/include/Quest.h +++ b/include/Quest.h @@ -20,11 +20,16 @@ #define DEBUG +struct need_t { + std::string name; + int n; +}; + typedef struct { std::string title; std::string desc; struct item_t reward; - std::vector need; + std::vector need; } Quest; /** @@ -42,13 +47,13 @@ public: * Adds a quest to the current quest vector by its title. */ - int assign(const char *t); + int assign(std::string title,std::string desc,std::string req); /** * Drops a quest through its title. */ - int drop(const char *t); + int drop(std::string title); /** * Finishes a quest through it's title, also giving a pointer to the Entity diff --git a/include/inventory.h b/include/inventory.h index e5209de..af859a5 100644 --- a/include/inventory.h +++ b/include/inventory.h @@ -48,6 +48,7 @@ public: int addItem(std::string name,uint count); int takeItem(std::string name,uint count); + int hasItem(std::string name); int useItem(void); bool detectCollision(vec2,vec2); diff --git a/src/Quest.cpp b/src/Quest.cpp index ac18021..535afc5 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -4,21 +4,59 @@ extern Player *player; -int QuestHandler::assign(const char *t){ - return strcmp(t,"h"); +int QuestHandler::assign(std::string title,std::string desc,std::string req){ + Quest tmp; + char *tok; + + tmp.title = title; + tmp.desc = desc; + + std::unique_ptr buf (new char[req.size()]); + + strcpy(buf.get(),req.c_str()); + tok = strtok(buf.get(),"\n\r\t,"); + tmp.need.push_back({"\0",0}); + + while(tok){ + if(tmp.need.back().name != "\0"){ + tmp.need.back().n = atoi(tok); + tmp.need.push_back({"\0",0}); + }else + tmp.need.back().name = tok; + + tok = strtok(NULL,"\n\r\t,"); + } + + tmp.need.pop_back(); + current.push_back(tmp); + + return 0; } -int QuestHandler::drop(const char *t){ - return strcmp(t,"h"); +int QuestHandler::drop(std::string title){ + for(unsigned int i=0;iinv->takeItem(current[i].need.back(),1)){ - current.erase(current.begin()+i); - return 1; - }else return 0; + for(auto &n : current[i].need){ + if(player->inv->hasItem(n.name) < n.n) + return 0; + } + + for(auto &n : current[i].need){ + player->inv->takeItem(n.name,n.n); + } + + current.erase(current.begin()+i); + return 1; } } return 0; diff --git a/src/gameplay.cpp b/src/gameplay.cpp index bceb811..e252c26 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -69,21 +69,12 @@ int commonAIFunc(NPC *speaker){ if((oxml = exml->FirstChildElement("quest"))){ const char *qname; - Quest tmp; + while(oxml){ - if((qname = oxml->Attribute("assign"))){ - tmp.title = qname; - tmp.desc = "None"; - tmp.reward = (struct item_t){0,0}; - - if(oxml->GetText()){ - tmp.need.push_back(oxml->GetText()); - } - - player->qh.current.push_back(tmp); - }else if((qname = oxml->Attribute("check"))){ + if((qname = oxml->Attribute("assign"))) + player->qh.assign(qname,"None",(std::string)oxml->GetText()); + else if((qname = oxml->Attribute("check"))){ if(player->qh.hasQuest(qname) && player->qh.finish(qname)){ - player->qh.finish(qname); goto CONT; }else{ oldidx = speaker->dialogIndex; 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 itemMap; +static std::vector 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;iname == 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); } diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 387e1a9..3bd0095 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -43,7 +43,10 @@ And it wasn't stormy. Sup bro! Have a quest. To complete it, just go talk to Ralph again. - Dank MayMay + + Dank MayMay,2 + Wood Sword,1 + diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml index 5c2b723..67695c7 100644 --- a/xml/playerSpawnHill1_Building1.xml +++ b/xml/playerSpawnHill1_Building1.xml @@ -8,8 +8,27 @@ - - Hey. Have a Dank Maymay :) + + Hey. Have a Dank MayMay :) + + + What? You want another Dank MayMay? + + + + K. + + + + + Well... I'm out of Dank MayMays. + + + + Have a sword though. + + + -- cgit v1.2.3