diff options
-rw-r--r-- | Changelog | 6 | ||||
-rw-r--r-- | config/quest_list.txt | 1 | ||||
-rw-r--r-- | include/entities.h | 20 | ||||
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | src/Quest.cpp | 24 | ||||
-rw-r--r-- | src/common.cpp | 1 | ||||
-rw-r--r-- | src/entities.cpp | 36 | ||||
-rw-r--r-- | src/gameplay.cpp | 11 | ||||
-rw-r--r-- | src/inventory.cpp | 4 | ||||
-rw-r--r-- | src/ui.cpp | 12 |
10 files changed, 79 insertions, 38 deletions
@@ -111,3 +111,9 @@ - added DEBUG flags to common.cpp and Quest.cpp - added player health - made textures for rabbit + +10/15/2015: +=========== + + - fixed quest assignment/completion + - entities can't move when interacting now diff --git a/config/quest_list.txt b/config/quest_list.txt new file mode 100644 index 0000000..3014ede --- /dev/null +++ b/config/quest_list.txt @@ -0,0 +1 @@ +TITLE "Test" DESC "A test quest" REWARD 1 x TEST_ITEM END diff --git a/include/entities.h b/include/entities.h index fc2f35c..1f2b249 100644 --- a/include/entities.h +++ b/include/entities.h @@ -4,6 +4,8 @@ #include <common.h> #include <inventory.h> +#define DEBUG + #define NPCp(n) ((NPC *)n) #define PLAYER_INV_SIZE 30 // The size of the player's inventory @@ -16,14 +18,14 @@ public: Inventory *inv; void *inWorld; - + float width; //width and height of the player float height; float speed; //speed of the play int health; int maxHealth; - + int subtype; _TYPE type; //example: @@ -31,10 +33,10 @@ public: // |(subtype) // |-> 0 Base NPC // |-> 1 Merchant - + vec2 loc; //location and velocity of the entity vec2 vel; - + bool near; bool right,left, canMove; //movement variables bool alive; //the flag for whether or not the entity is alive @@ -44,7 +46,7 @@ public: GENDER gender; GLuint texture[3]; //TODO: ADD TEXTURES - + void spawn(float, float); void draw(void); virtual void wander(int, vec2*){} @@ -65,7 +67,8 @@ class NPC : public Entity{ public: std::vector<int (*)(NPC *)>aiFunc; NPC(); - void addAIFunc(int (*func)(NPC *)); + void addAIFunc(int (*func)(NPC *),bool preload); + void flushAIFunc(void); void interact(); void wander(int, vec2*); }; @@ -97,10 +100,5 @@ ENTITY TYPES |->1 Merchant | 2 MOBS -<<<<<<< HEAD -|->1 Rabbit -**/ -======= |->1 Skirl **/ ->>>>>>> 58716d5e4f20eb5a30025c88fe5119a0e40c4187 @@ -235,7 +235,7 @@ void logic(){ switch(entity[i]->type){ case NPCT: // Handle NPCs - entity[i]->wander((rand()%120 + 30), &entity[i]->vel); // Make the NPC wander + if(entity[i]->canMove)entity[i]->wander((rand()%120 + 30), &entity[i]->vel); // Make the NPC wander // Check if the NPC is near the player and handle potential interaction if(pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){ 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; } @@ -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; } } |