aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Quest.cpp24
-rw-r--r--src/common.cpp1
-rw-r--r--src/entities.cpp36
-rw-r--r--src/gameplay.cpp11
-rw-r--r--src/inventory.cpp4
-rw-r--r--src/ui.cpp12
6 files changed, 62 insertions, 26 deletions
diff --git a/src/Quest.cpp b/src/Quest.cpp
index 5d19795..8aea006 100644
--- a/src/Quest.cpp
+++ b/src/Quest.cpp
@@ -1,17 +1,22 @@
#include <common.h>
-//#include <Quest.h>
-//#include <entities.h>
+
+#define TITLE Quest(
+#define DESC ,
+#define REWARD ,(struct item_t){
+#define x ,
+#define END }),
const Quest QuestList[TOTAL_QUESTS]={
- Quest("Test","A test quest",(struct item_t){1,TEST_ITEM})
+// Quest("Test","A test quest",(struct item_t){1,TEST_ITEM}),
+
+// Get quest list
+#include "../config/quest_list.txt"
+
};
Quest::Quest(const char *t,const char *d,struct item_t r){
- size_t len;
- title=(char *)malloc((len=strlen(t)));
- strncpy(title,t,len);
- desc=(char *)malloc((len=strlen(d)));
- strncpy(desc,d,len);
+ strcpy((title=(char *)malloc(strlen(t))),t);
+ strcpy((desc =(char *)malloc(strlen(d))),d);
memcpy(&reward,&r,sizeof(struct item_t));
}
@@ -39,6 +44,9 @@ int QuestHandler::assign(const char *t){
#endif // DEBUG
return current.size();
}
+#ifdef DEBUG
+ DEBUG_printf("Finding quest: %s != %s\n",t,QuestList[i].title);
+#endif // DEBUG
}
#ifdef DEBUG
DEBUG_printf("Quest %s does not exist.\n",t);
diff --git a/src/common.cpp b/src/common.cpp
index 8dcbd11..182b5b8 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -31,3 +31,4 @@ void DEBUG_prints(const char* file, int line, const char *s,...){
vprintf(s,args);
va_end(args);
}
+
diff --git a/src/entities.cpp b/src/entities.cpp
index 0457ba1..080da3e 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -14,7 +14,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
left = false;
near = false;
ticksToUse = 0;
- canMove = false;
+ canMove = true;
ground = false;
name = (char*)malloc(16);
getName();
@@ -109,7 +109,8 @@ void Entity::draw(void){ //draws the entities
texState-=1;
if(texState==0)up=true;
}
- }if(ground == 0){
+ }
+ if(ground == 0){
glBindTexture(GL_TEXTURE_2D, texture[1]);
}
else if(vel.x != 0){
@@ -124,7 +125,8 @@ void Entity::draw(void){ //draws the entities
glBindTexture(GL_TEXTURE_2D,texture[2]);
break;
}
- }else{
+ }
+ else{
glBindTexture(GL_TEXTURE_2D,texture[0]);
}
}else if(type == MOBT){
@@ -213,9 +215,29 @@ void NPC::wander(int timeRun, vec2 *v){ //this makes the entites wander about
ticksToUse--; //removes one off of the entities timer
}
+static int (*AIpreload)(NPC *);
+
+void NPC::addAIFunc(int (*func)(NPC *),bool preload){
+ if(preload)
+#ifdef DEBUG
+ {
+ DEBUG_printf("Preloading an AI %x.\n",func);
+#endif // DEBUG
+ AIpreload=func;
+#ifdef DEBUG
+ }
+#endif // DEBUG
+ else aiFunc.push_back(func);
+}
-void NPC::addAIFunc(int (*func)(NPC *)){
- aiFunc.push_back(func);
+void NPC::flushAIFunc(void){
+ if(AIpreload){
+#ifdef DEBUG
+ DEBUG_printf("Unloading preloaded AI function %x.\n",AIpreload);
+#endif // DEBUG
+ aiFunc.push_back(AIpreload);
+ AIpreload=NULL;
+ }
}
void NPC::interact(){ //have the npc's interact back to the player
@@ -223,9 +245,11 @@ void NPC::interact(){ //have the npc's interact back to the player
loc.y += 5;
if(aiFunc.size()){
func=aiFunc.front();
+ canMove=false;
if(!func(this)){
aiFunc.erase(aiFunc.begin());
}
+ canMove=true;
}
}
@@ -271,4 +295,4 @@ void Mob::wander(int timeRun, vec2* v){
}
ticksToUse--; //removes one off of the entities timer
}
-} \ No newline at end of file
+}
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 17a7bed..3b9b819 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -22,13 +22,7 @@ int compTestQuest(NPC *speaker){
int giveTestQuest(NPC *speaker){
ui::dialogBox(speaker->name,"Here, have a quest!");
player->qh.assign("Test");
- NPCp(entity[2])->addAIFunc(compTestQuest);
- return 0;
-}
-
-int giveStuff(NPC *speaker){
- ui::dialogBox(speaker->name,"Have a sword :D");
- player->inv->addItem(SWORD_ITEM,1);
+ NPCp(entity[2])->addAIFunc(compTestQuest,true);
return 0;
}
@@ -64,8 +58,7 @@ void initEverything(void){
entity.pop_back();
- NPCp(entity[1])->addAIFunc(giveStuff);
- NPCp(entity[1])->addAIFunc(giveTestQuest);
+ NPCp(entity[1])->addAIFunc(giveTestQuest,false);
for(i=0;i<entity.size()+1;i++){
entity[i]->inWorld=test;
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 83c40f6..3690de5 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -49,14 +49,14 @@ int Inventory::addItem(ITEM_ID id,unsigned char count){
if(item[i].id==id){
item[i].count+=count;
#ifdef DEBUG
- DEBUG_printf("Gave player %u more %s(s).\n",count,itemName[i]);
+ DEBUG_printf("Gave player %u more %s(s).\n",count,itemName[item[i].id]);
#endif // DEBUG
return 0;
}else if(!item[i].count){
item[i].id=id;
item[i].count=count;
#ifdef DEBUG
- DEBUG_printf("Gave player %u %s(s).\n",count,itemName[i]);
+ DEBUG_printf("Gave player %u %s(s).\n",count,itemName[item[i].id]);
#endif // DEBUG
return 0;
}
diff --git a/src/ui.cpp b/src/ui.cpp
index fe5414c..8e80341 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -8,6 +8,8 @@
extern Player *player; // 'player' should be (must be) defined in main.cpp
extern World *currentWorld; // should/must also be defined in main.cpp
+extern std::vector<NPC>npc;
+
static FT_Library ftl; // Variables for the FreeType library and stuff
static FT_Face ftf;
static GLuint ftex;
@@ -84,7 +86,7 @@ namespace ui {
h=ftf->glyph->bitmap.rows;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,ftex);
- switch(c){
+ switch(c){ // Some characters are not properly spaced, make them so here
case '^':
case '*':
case '`':
@@ -242,5 +244,13 @@ namespace ui {
break;
}
}
+ static bool once=false;
+ unsigned int i;
+ if(!dialogBoxExists&&!once){
+ for(i=0;i<npc.size();i++){
+ npc[i].flushAIFunc();
+ }
+ once=true;
+ }else once=false;
}
}