diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-30 08:51:10 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-30 08:51:10 -0400 |
commit | 8deee144293102d4498424c38161d13c877250b2 (patch) | |
tree | e55cd9352fdd8534425b469ff428b3ca23d2729d | |
parent | b3e21d31304efd793c58e904765bf298da6c5c20 (diff) |
quest stuff
-rw-r--r-- | Changelog | 3 | ||||
-rw-r--r-- | include/Quest.h | 13 | ||||
-rw-r--r-- | include/common.h | 1 | ||||
-rw-r--r-- | include/entities.h | 1 | ||||
-rw-r--r-- | src/Quest.cpp | 52 | ||||
-rw-r--r-- | src/entities.cpp | 3 | ||||
-rw-r--r-- | src/main.cpp | 4 |
7 files changed, 39 insertions, 38 deletions
@@ -50,3 +50,6 @@ - improved left/right movement - added framework work NPC dialog n' stuff + - added quest stuff between NPCs and player + - began work on giving names to NPCs + - began working on config file diff --git a/include/Quest.h b/include/Quest.h index c73bf79..076b800 100644 --- a/include/Quest.h +++ b/include/Quest.h @@ -1,26 +1,23 @@ #ifndef QUEST_H
#define QUEST_H
-#include <common.h>
+#include <vector>
+#include <cstdlib>
#include <cstring>
-#define QUEST_LIMIT 5
#define TOTAL_QUESTS 1
class Quest {
public:
char *title,*desc;
- unsigned int xp;
- Quest(const char *t,const char *d,unsigned int x);
+ unsigned int reward;
+ Quest(const char *t,const char *d,unsigned int r);
~Quest();
};
class QuestHandler {
-private:
- unsigned char ccnt;
- const Quest *current[QUEST_LIMIT];
public:
- QuestHandler();
+ std::vector<const Quest *>current;
int assign(const char *t);
int drop(const char *t);
int finish(const char *t);
diff --git a/include/common.h b/include/common.h index 8410f58..5dfbb78 100644 --- a/include/common.h +++ b/include/common.h @@ -20,6 +20,7 @@ enum _TYPE { //these are the main types of entities NPCT = 1 }; +#include <Quest.h> #include <entities.h> #define SCREEN_WIDTH 1280 diff --git a/include/entities.h b/include/entities.h index 9e0257f..aa7eff9 100644 --- a/include/entities.h +++ b/include/entities.h @@ -37,6 +37,7 @@ private: class Player : public Entity{ public: + QuestHandler qh; Player(); void interact(); }; diff --git a/src/Quest.cpp b/src/Quest.cpp index a42e42c..c9175b1 100644 --- a/src/Quest.cpp +++ b/src/Quest.cpp @@ -4,58 +4,56 @@ const Quest QuestList[TOTAL_QUESTS]={ Quest("Test","A test quest",0)
};
-Quest::Quest(const char *t,const char *d,unsigned int x){
+Quest::Quest(const char *t,const char *d,unsigned int r){
size_t len;
title=(char *)malloc((len=strlen(t)));
strncpy(title,t,len);
desc=(char *)malloc((len=strlen(d)));
strncpy(desc,d,len);
- xp=x;
+ reward=r;
}
+
Quest::~Quest(){
free(title);
free(desc);
- xp=0;
+ reward=0;
}
-QuestHandler::QuestHandler(){
- ccnt=0;
-}
int QuestHandler::assign(const char *t){
- unsigned int i=0;
- if(ccnt==QUEST_LIMIT)
- return -1;
- for(;i<TOTAL_QUESTS;i++){
+ unsigned char i;
+ for(i=0;i<current.size();i++){
+ if(!strcmp(current[i]->title,t)){
+ return -2;
+ }
+ }
+ for(i=0;i<TOTAL_QUESTS;i++){
if(!strcmp(QuestList[i].title,t)){
- current[ccnt++]=&QuestList[i];
- return ccnt;
+ current.push_back(&QuestList[i]);
+ return current.size();
}
}
return -1;
}
+
int QuestHandler::drop(const char *t){
- unsigned char i=0;
- for(;i<ccnt;i++){
+ unsigned char i;
+ for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
- for(i++;i<ccnt;i++){
- current[i-1]=current[i];
- }
- return (--ccnt);
+ current.erase(current.begin()+i);
+ return current.size();
}
}
return -1;
}
+
int QuestHandler::finish(const char *t){
- unsigned char i=0;
- unsigned int j;
- for(;i<ccnt;i++){
+ unsigned char i;
+ unsigned int r;
+ for(;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
- j=current[i]->xp;
- for(i++;i<ccnt;i++){
- current[i-1]=current[i];
- }
- ccnt--;
- return j;
+ r=current[i]->reward;
+ current.erase(current.begin()+i);
+ return r;
}
}
return -1;
diff --git a/src/entities.cpp b/src/entities.cpp index cff971f..8689b00 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -94,14 +94,13 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure 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(); } } diff --git a/src/main.cpp b/src/main.cpp index 77d22bc..afc34b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +34,7 @@ void logic(); void render(); int entityInteractTest(NPC *speaker){ - ui::dialogBox("NPC: Hello there!"); + player->qh.assign("Test"); return 1; } @@ -213,6 +213,8 @@ void render(){ 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 } |