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 | |
parent | 36ef7e42fb1b151c64d69d96df7e33a9f4c47b83 (diff) |
quest completion
Diffstat (limited to 'src')
-rw-r--r-- | src/Quest.cpp | 24 | ||||
-rw-r--r-- | src/gameplay.cpp | 17 | ||||
-rw-r--r-- | src/inventory.cpp | 22 | ||||
-rw-r--r-- | src/ui.cpp | 29 |
4 files changed, 59 insertions, 33 deletions
diff --git a/src/Quest.cpp b/src/Quest.cpp index 0151706..ac18021 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -1,5 +1,9 @@ #include <Quest.h>
+#include <entities.h>
+
+extern Player *player;
+
int QuestHandler::assign(const char *t){
return strcmp(t,"h");
}
@@ -8,16 +12,22 @@ int QuestHandler::drop(const char *t){ return strcmp(t,"h");
}
-int QuestHandler::finish(const char *t,void *completer){
- return strncmp(t,(char *)completer,1);
+int QuestHandler::finish(std::string t){
+ for(unsigned int i=0;i<current.size();i++){
+ if(current[i].title == t){
+ if(!player->inv->takeItem(current[i].need.back(),1)){
+ current.erase(current.begin()+i);
+ return 1;
+ }else return 0;
+ }
+ }
+ return 0;
}
-bool QuestHandler::hasQuest(const char *t){
- unsigned int i;
- for(i=0;i<current.size();i++){
- if(!strcmp(current[i].title.c_str(),t)){
+bool QuestHandler::hasQuest(std::string t){
+ for(unsigned int i=0;i<current.size();i++){
+ if(current[i].title == t)
return true;
- }
}
return false;
}
diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 5633eb8..bceb811 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -82,10 +82,9 @@ int commonAIFunc(NPC *speaker){ player->qh.current.push_back(tmp); }else if((qname = oxml->Attribute("check"))){ - if(player->qh.hasQuest(qname)){ - ui::dialogBox(speaker->name,NULL,false,"Nice meme"); - ui::waitForDialog(); - return 0; + if(player->qh.hasQuest(qname) && player->qh.finish(qname)){ + player->qh.finish(qname); + goto CONT; }else{ oldidx = speaker->dialogIndex; speaker->dialogIndex = oxml->UnsignedAttribute("fail"); @@ -96,7 +95,9 @@ int commonAIFunc(NPC *speaker){ oxml = oxml->NextSiblingElement(); } } - + +CONT: + /* * Handle any 'give' requests. */ @@ -152,7 +153,7 @@ int commonAIFunc(NPC *speaker){ * Get the player's choice, then set the XMLElement to the option's block. */ - ui::dialogBox(speaker->name,optstr.c_str(),false,exml->GetText()); + ui::dialogBox(speaker->name,optstr.c_str(),false,exml->GetText()+1); ui::waitForDialog(); if(ui::dialogOptChosen) @@ -161,12 +162,12 @@ int commonAIFunc(NPC *speaker){ while(!dopt.empty()) dopt.pop_back(); }else{ - + /* * No options - simply print the text. */ - ui::dialogBox(speaker->name,"",false,exml->GetText()); + ui::dialogBox(speaker->name,NULL,false,exml->GetText()); ui::waitForDialog(); } 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; @@ -258,17 +258,15 @@ namespace ui { * Draws a character at the specified coordinates, aborting if the character is unknown. */ - vec2 putChar(float xx,float yy,char c){ + vec2 putChar(float x,float y,char c){ vec2 c1,c2; - int x = xx, y = yy; - /* * Get the width and height of the rendered character. */ - c1={x+ftexbl[c-33].x, - y+ftexbl[c-33].y}; + c1={(float)floor(x)+ftexbl[c-33].x, + (float)floor(y)+ftexbl[c-33].y}; c2=ftexwh[c-33]; /* @@ -316,7 +314,10 @@ namespace ui { if(s[i] == ' ') i++; } - if(s[i] == '\n' || s[i] == '\r' || s[i] == '\t'){ + if(s[i] == '\n'){ + yo-=fontSize*1.05; + xo=x; + }else if(s[i] == '\r' || s[i] == '\t'){ /*if(s[i] == '\n'){ yo-=fontSize*1.05; xo=x; @@ -325,7 +326,7 @@ namespace ui { }else if(s[i]=='\b'){ // Handle backspaces? xo-=add.x; }else{ - add=putChar(xo,yo,s[i]); + add=putChar(floor(xo),floor(yo),s[i]); xo+=add.x; yo+=add.y; } @@ -334,12 +335,10 @@ namespace ui { return xo; // i.e. the string width } - float putStringCentered(const float xx,const float yy,const char *s){ + float putStringCentered(const float x,const float y,const char *s){ unsigned int i = 0; float width = 0; - int x = xx,y = yy; - do{ if(s[i]=='\n'){ // Handle newlines // TODO @@ -353,7 +352,7 @@ namespace ui { } }while(s[++i]); - putString(x-width/2,y,s); + putString(floor(x-width/2),y,s); return width; } @@ -530,15 +529,15 @@ namespace ui { } void importantText(const char *text,...){ va_list textArgs; - + //if(!player->ground)return; - + memset(dialogBoxText,0,512); - + va_start(textArgs,text); vsnprintf(dialogBoxText,512,text,textArgs); va_end(textArgs); - + dialogBoxExists = true; dialogImportant = true; //toggleBlack(); |