#ifndef QUEST_H\r
#define QUEST_H\r
\r
-#include <common.h>\r
+#include <vector>\r
+#include <cstdlib>\r
#include <cstring>\r
\r
-#define QUEST_LIMIT 5\r
#define TOTAL_QUESTS 1\r
\r
class Quest {\r
public:\r
char *title,*desc;\r
- unsigned int xp;\r
- Quest(const char *t,const char *d,unsigned int x);\r
+ unsigned int reward;\r
+ Quest(const char *t,const char *d,unsigned int r);\r
~Quest();\r
};\r
\r
class QuestHandler {\r
-private:\r
- unsigned char ccnt;\r
- const Quest *current[QUEST_LIMIT];\r
public:\r
- QuestHandler();\r
+ std::vector<const Quest *>current;\r
int assign(const char *t);\r
int drop(const char *t);\r
int finish(const char *t);\r
Quest("Test","A test quest",0)\r
};\r
\r
-Quest::Quest(const char *t,const char *d,unsigned int x){\r
+Quest::Quest(const char *t,const char *d,unsigned int r){\r
size_t len;\r
title=(char *)malloc((len=strlen(t)));\r
strncpy(title,t,len);\r
desc=(char *)malloc((len=strlen(d)));\r
strncpy(desc,d,len);\r
- xp=x;\r
+ reward=r;\r
}\r
+\r
Quest::~Quest(){\r
free(title);\r
free(desc);\r
- xp=0;\r
+ reward=0;\r
}\r
\r
-QuestHandler::QuestHandler(){\r
- ccnt=0;\r
-}\r
int QuestHandler::assign(const char *t){\r
- unsigned int i=0;\r
- if(ccnt==QUEST_LIMIT)\r
- return -1;\r
- for(;i<TOTAL_QUESTS;i++){\r
+ unsigned char i;\r
+ for(i=0;i<current.size();i++){\r
+ if(!strcmp(current[i]->title,t)){\r
+ return -2;\r
+ }\r
+ }\r
+ for(i=0;i<TOTAL_QUESTS;i++){\r
if(!strcmp(QuestList[i].title,t)){\r
- current[ccnt++]=&QuestList[i];\r
- return ccnt;\r
+ current.push_back(&QuestList[i]);\r
+ return current.size();\r
}\r
}\r
return -1;\r
}\r
+\r
int QuestHandler::drop(const char *t){\r
- unsigned char i=0;\r
- for(;i<ccnt;i++){\r
+ unsigned char i;\r
+ for(i=0;i<current.size();i++){\r
if(!strcmp(current[i]->title,t)){\r
- for(i++;i<ccnt;i++){\r
- current[i-1]=current[i];\r
- }\r
- return (--ccnt);\r
+ current.erase(current.begin()+i);\r
+ return current.size();\r
}\r
}\r
return -1;\r
}\r
+\r
int QuestHandler::finish(const char *t){\r
- unsigned char i=0;\r
- unsigned int j;\r
- for(;i<ccnt;i++){\r
+ unsigned char i;\r
+ unsigned int r;\r
+ for(;i<current.size();i++){\r
if(!strcmp(current[i]->title,t)){\r
- j=current[i]->xp;\r
- for(i++;i<ccnt;i++){\r
- current[i-1]=current[i];\r
- }\r
- ccnt--;\r
- return j;\r
+ r=current[i]->reward;\r
+ current.erase(current.begin()+i);\r
+ return r;\r
}\r
}\r
return -1;\r
width = 20 * HLINE;
height = 16 * HLINE;
- int tempN = (getRand() % 5 + 1); //amount of villagers that will spawn
+ int tempN = 2;//(getRand() % 5 + 1); //amount of villagers that will spawn
for(int i=0;i<tempN;i++){
entity.push_back(new NPC()); //create a new entity of NPC type
npc.push_back(NPC()); //create new NPC
entity[entity.size()] = &npc[npc.size()-1]; //set the new entity to have the same traits as an NPC
entity[entity.size()-1]->spawn(loc.x + (float)(i - 5),100); //sets the position of the villager around the village
}
- entity.pop_back();
return entity.size();
}
}
void render();
int entityInteractTest(NPC *speaker){
- ui::dialogBox("NPC: Hello there!");
+ player->qh.assign("Test");
return 1;
}
glVertex2i(mx,my-HLINE*3.5);
glEnd();
+ ui::putText(player->loc.x-SCREEN_WIDTH/2,SCREEN_HEIGHT/2,"Quest count: %d",player->qh.current.size());
+
glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer
SDL_GL_SwapWindow(window); //give the stack to SDL to render it
}