]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
quest fixes
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 15 Oct 2015 13:07:06 +0000 (09:07 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 15 Oct 2015 13:07:06 +0000 (09:07 -0400)
Changelog
config/quest_list.txt [new file with mode: 0644]
include/entities.h
main.cpp
src/Quest.cpp
src/common.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp

index 27384e07f485b9987eb3848e85cfb9187181dfdd..752d92cc71eb36085b34e5bf1e453f17b8614760 100644 (file)
--- a/Changelog
+++ b/Changelog
        - 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 (file)
index 0000000..3014ede
--- /dev/null
@@ -0,0 +1 @@
+TITLE "Test" DESC "A test quest" REWARD 1 x TEST_ITEM END
index fc2f35ca06bf2b8084a3d4359c86b0dbe08c4560..1f2b2498cb4c2fbbed95b02fefd6ec939aedf8d7 100644 (file)
@@ -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
index 5595c7ecfbe382b982d1018d9b0152633d9c0fb5..68979023b201f58dfceb16e69907031ac4d40df3 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -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)){
index 5d197950bd04db31ed313e524552b7a88681fa1e..8aea00641293f796cd215edf4ebb3188df7d93fd 100644 (file)
@@ -1,17 +1,22 @@
 #include <common.h>\r
-//#include <Quest.h>\r
-//#include <entities.h>\r
+\r
+#define TITLE  Quest(\r
+#define DESC   ,\r
+#define REWARD ,(struct item_t){\r
+#define x              ,\r
+#define END            }),\r
 \r
 const Quest QuestList[TOTAL_QUESTS]={\r
-       Quest("Test","A test quest",(struct item_t){1,TEST_ITEM})\r
+//     Quest("Test","A test quest",(struct item_t){1,TEST_ITEM}),\r
+\r
+// Get quest list\r
+#include "../config/quest_list.txt"\r
+\r
 };\r
 \r
 Quest::Quest(const char *t,const char *d,struct item_t 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
+       strcpy((title=(char *)malloc(strlen(t))),t);\r
+       strcpy((desc =(char *)malloc(strlen(d))),d);\r
        memcpy(&reward,&r,sizeof(struct item_t));\r
 }\r
 \r
@@ -39,6 +44,9 @@ int QuestHandler::assign(const char *t){
 #endif // DEBUG\r
                        return current.size();\r
                }\r
+#ifdef DEBUG\r
+               DEBUG_printf("Finding quest: %s != %s\n",t,QuestList[i].title);\r
+#endif // DEBUG\r
        }\r
 #ifdef DEBUG\r
        DEBUG_printf("Quest %s does not exist.\n",t);\r
index 8dcbd1181ab4ce5181dc87646bb8f863b34609ed..182b5b85887bb93e0a99c22ce5e1c39a6f6fb248 100644 (file)
@@ -31,3 +31,4 @@ void DEBUG_prints(const char* file, int line, const char *s,...){
        vprintf(s,args);
        va_end(args);
 }
+
index 0457ba17f09bc66f988de680edcb46f2a3b5816e..080da3eecb22a33f1614dd62404e8d9dc174aef7 100644 (file)
@@ -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
+}
index 17a7bedbdd58d68a746b2000f56c69bc7331c2da..3b9b8192ac69762f99850da61256275fe9a242d1 100644 (file)
@@ -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;
        }
index 83c40f6bfc74e39311155a82c9e01f280e28d9f7..3690de53eeaf630f5d9a5f4d53e64e4961cb1a70 100644 (file)
@@ -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;
                }
index fe5414cdb14ba26e65ca2b574c0b0835f6a2cd5d..8e80341db8403b4fb0c38bb6d10913ae1bc20db8 100644 (file)
@@ -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;
        }
 }