]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
quests?
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 8 Feb 2016 13:48:33 +0000 (08:48 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 8 Feb 2016 13:48:33 +0000 (08:48 -0500)
Changelog
include/Quest.h
src/Quest.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
xml/playerSpawnHill1.xml

index 2077ac0fb59a4b2b9ce00f8099991a9ec9ad1f64..5a94cac3bbf5187836ac7275e88760fb97fc25d9 100644 (file)
--- a/Changelog
+++ b/Changelog
        - improved font rendering codes
        - added font selection to settings.xml
        - XML'd important text
+
+2/8/2016:
+=========
+
+       - partially fixed text drawing
+       - XML'd quest checking, working on quest requirements
+       - worked on XML'ing villages
index cc01d274a396427c5c18da20c25b58f6168f3241..7ba77c85aec8bc217905d64bf4a50f211418b96f 100644 (file)
@@ -24,17 +24,9 @@ typedef struct {
        std::string title;\r
        std::string desc;\r
        struct item_t reward;\r
+       std::vector<std::string> need;\r
 } Quest;\r
 \r
-/*class Quest {\r
-public:\r
-       char *title;\r
-       char *desc;\r
-       struct item_t reward;\r
-       Quest(const char *t,const char *d,struct item_t r);\r
-       ~Quest();\r
-};*/\r
-\r
 /**\r
  * The Quest Handler class.\r
  * \r
index f0be63ca635c24960d9ed69f4810dac4489298a9..015170610d0a329d181ea20626c2e199ebae9ea1 100644 (file)
@@ -1,81 +1,14 @@
 #include <Quest.h>\r
 \r
-/*const Quest QuestList[1] = {\r
-       Quest("Not a quest","Stop",(struct item_t){0,0})\r
-};*/\r
-\r
-\r
-/*Quest::Quest(const char *t,const char *d,struct item_t r){\r
-       title = new char[strlen(t)+1];\r
-       desc = new char[strlen(d)+1];\r
-       strcpy(title,t);\r
-       strcpy(desc,d);\r
-       memcpy(&reward,&r,sizeof(struct item_t));\r
-}\r
-\r
-Quest::~Quest(){\r
-       delete[] title;\r
-       delete[] desc;\r
-       memset(&reward,0,sizeof(struct item_t));\r
-}*/\r
-\r
 int QuestHandler::assign(const char *t){\r
-       /*unsigned char i;\r
-       for(i=0;i<current.size();i++){                          // Make sure we don't already have this quest\r
-               if(!strcmp(current[i]->title,t)){\r
-#ifdef DEBUG\r
-                       DEBUG_printf("The QuestHandler already has this quest: %s\n",t);\r
-#endif // DEBUG\r
-                       return -2;\r
-               }\r
-       }\r
-       for(i=0;i<0;i++){                               // Add the quest (if it really exists)\r
-               if(!strcmp(QuestList[i].title,t)){\r
-                       current.push_back(&QuestList[i]);\r
-#ifdef DEBUG\r
-                       DEBUG_printf("Added quest %s, now have %u active quests.\n",t,current.size());\r
-#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
-#endif // DEBUG*/\r
        return strcmp(t,"h");\r
 }\r
 \r
 int QuestHandler::drop(const char *t){\r
-       /*unsigned char i;\r
-       for(i=0;i<current.size();i++){\r
-               if(!strcmp(current[i]->title,t)){\r
-                       current.erase(current.begin()+i);\r
-                       return current.size();\r
-               }\r
-       }*/\r
        return strcmp(t,"h");\r
 }\r
 \r
 int QuestHandler::finish(const char *t,void *completer){\r
-       /*unsigned char i;\r
-       for(i=0;i<current.size();i++){\r
-               if(!strcmp(current[i]->title,t)){\r
-#ifdef DEBUG\r
-                       DEBUG_printf("Completing quest %s.\n",t);\r
-#endif // DEBUG\r
-                       ((Entity *)completer)->inv->addItem(current[i]->reward.id,current[i]->reward.count);\r
-                       current.erase(current.begin()+i);\r
-#ifdef DEBUG\r
-                       DEBUG_printf("QuestHandler now has %u active quests.\n",current.size());\r
-#endif // DEBUG\r
-                       return 0;\r
-               }\r
-       }\r
-#ifdef DEBUG\r
-       DEBUG_printf("QuestHandler never had quest %s.\n",t);\r
-#endif // DEBUG*/\r
        return strncmp(t,(char *)completer,1);\r
 }\r
 \r
index 5a9c42a5721ef879d26512a7ddf4bd31e4411eb1..f079b034ec159e78b113ca036d8b2662f368d708 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <istream>
 
+#define RAND_DIALOG_COUNT 13
+
 extern std::istream *names;
 extern unsigned int loops;
 
@@ -126,7 +128,7 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
        tex = new Texturec(1,"assets/NPC.png");
        inv = new Inventory(NPC_INV_SIZE);
        
-       randDialog = 6;//rand() % 12 - 1;
+       randDialog = rand() % RAND_DIALOG_COUNT - 1;
        dialogIndex = 0;
 }
 NPC::~NPC(){
@@ -392,7 +394,7 @@ void NPC::clearAIFunc(void){
        aiFunc.clear();
 }
 
-const char *randomDialog[] = {
+const char *randomDialog[RAND_DIALOG_COUNT] = {
        "What a beautiful day it is.",
        "Have you ever went fast? I have.",
        "I heard if you complete a quest, you'll get a special reward.",
index 00faf70d88308a52656fa3094042596e4b373d78..5633eb86916bc12f061ebbb8be63f3ff7594ed75 100644 (file)
@@ -33,6 +33,8 @@ int commonAIFunc(NPC *speaker){
        XMLDocument xml;
        XMLElement *exml,*oxml;
        
+       static unsigned int oldidx = 9999;
+       
        const char *name;
        unsigned int idx = 0;
        bool stop = false;
@@ -67,9 +69,30 @@ int commonAIFunc(NPC *speaker){
        
                                if((oxml = exml->FirstChildElement("quest"))){
                                        const char *qname;
+                                       Quest tmp;
                                        while(oxml){
-                                               if((qname = oxml->Attribute("assign")))
-                                                       player->qh.current.push_back((Quest){qname,"None",(struct item_t){0,0}});
+                                               if((qname = oxml->Attribute("assign"))){
+                                                       tmp.title = qname;
+                                                       tmp.desc = "None";
+                                                       tmp.reward = (struct item_t){0,0};
+                                                       
+                                                       if(oxml->GetText()){
+                                                               tmp.need.push_back(oxml->GetText());
+                                                       }
+                                                       
+                                                       player->qh.current.push_back(tmp);
+                                               }else if((qname = oxml->Attribute("check"))){
+                                                       if(player->qh.hasQuest(qname)){
+                                                               ui::dialogBox(speaker->name,NULL,false,"Nice meme");
+                                                               ui::waitForDialog();
+                                                               return 0;
+                                                       }else{
+                                                               oldidx = speaker->dialogIndex;
+                                                               speaker->dialogIndex = oxml->UnsignedAttribute("fail");
+                                                               return commonAIFunc(speaker);
+                                                       }
+                                               }       
+                                               
                                                oxml = oxml->NextSiblingElement();
                                        }
                                }
@@ -177,10 +200,16 @@ int commonAIFunc(NPC *speaker){
                                                return 1;
                                        }else return commonAIFunc(speaker);
                                }else{
-                                       speaker->dialogIndex = 9999;
-                                       return 0;
+                                       if(oldidx != 9999){
+                                               speaker->dialogIndex = oldidx;
+                                               oldidx = 9999;
+                                               return 1;
+                                       }else{
+                                               speaker->dialogIndex = 9999;
+                                               return 0;
+                                       }
                                }
-                               return 1;
+                               //return 1;
                        }
                }
                
index 56a88a33376cde51f9b3e55f83b80a2b622b472b..5adb7b59aa6bf73f0fe6895374a883ed69fb08c8 100644 (file)
@@ -224,9 +224,9 @@ namespace ui {
                        buf = new char[ftf->glyph->bitmap.width * ftf->glyph->bitmap.rows * 4];
                
                        for(j=0;j<ftf->glyph->bitmap.width*ftf->glyph->bitmap.rows;j++){
-                               buf[j*4  ]=fontColor[0];
-                               buf[j*4+1]=fontColor[1];
-                               buf[j*4+2]=fontColor[2];
+                               buf[j*4  ]=255;//fontColor[0];
+                               buf[j*4+1]=255;//fontColor[1];
+                               buf[j*4+2]=255;//fontColor[2];
                                buf[j*4+3]=ftf->glyph->bitmap.buffer[j] ? 255 : 0;
                                //buf[j*4+3]=ftf->glyph->bitmap.buffer[j];
                        }
@@ -258,9 +258,11 @@ namespace ui {
         *      Draws a character at the specified coordinates, aborting if the character is unknown.
        */
        
-       vec2 putChar(float x,float y,char c){
+       vec2 putChar(float xx,float yy,char c){
                vec2 c1,c2;
                
+               int x = xx, y = yy;
+               
                /*
                 *      Get the width and height of the rendered character.
                */
@@ -332,10 +334,12 @@ namespace ui {
                return xo;      // i.e. the string width
        }
        
-       float putStringCentered(const float x,const float y,const char *s){
+       float putStringCentered(const float xx,const float yy,const char *s){
                unsigned int i = 0;
                float width = 0;
                
+               int x = xx,y = yy;
+               
                do{
                        if(s[i]=='\n'){                 //      Handle newlines
                                // TODO
@@ -626,13 +630,13 @@ namespace ui {
                        
                        if(player->inv->invOpen){
                                hub.y = player->loc.y + fontSize * 8;
-                               hub.x = player->loc.x;
+                               hub.x = player->loc.x;// + player->width / 2;
                                
                                putStringCentered(hub.x,hub.y,"Current Quests:");
                                
                                for(auto &c : player->qh.current){
                                        hub.y -= fontSize * 1.15;
-                                       putString(hub.x,hub.y,c.title.c_str());
+                                       putStringCentered(hub.x,hub.y,c.title.c_str());
                                }       
                        }
                }
@@ -726,7 +730,7 @@ namespace ui {
 
        void drawMenu(Menu *menu){
 
-               setFontSize(20);
+               setFontSize(24);
                SDL_Event e;
                        
                mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
index 55612d3a3c5f84153734005f19a4ce80e1eb60d7..cf42cdaa740515104a6cad734ca716a84c680035 100644 (file)
@@ -10,7 +10,7 @@
        <trigger x="-300" id="Test" />
        
        <npc name="Ralph" hasDialog="true" />
-       <npc name="Johnny" hasDialog="true" />
+       <npc name="Johnny" hasDialog="false" />
        <structure type="5" inside="playerSpawnHill1_Building1.xml" />
 
 </World>
@@ -22,30 +22,33 @@ And it wasn't stormy.
 
 <Dialog name="Ralph">
        
-       <text id="0">
-               Hello there!
-               <option text="Hello" nextid="1" />
-               <option text="Frig" nextid="2" />
+       <text id="0" nextid="1" >
+               Hello there! My name is Ralph.
        </text>
        
-       <text id="1">
-               gg.
+       <text id="1" nextid="2" call="Johnny" callid="0" pause="true" >
+               You should go talk to my friend Johnny. He's a pretty chill dude.
        </text>
        
-       <text id="2" call="Johnny" callid="1">
-               what you have done it to trick Microsoft
+       <text id="2" >
+               <quest check="Your First Quest" fail="3" />
+               Niice.
        </text>
        
+       <text id="3">
+               Go check out Johnny. He's cool.
+       </text>
 </Dialog>
 
 <Dialog name="Johnny">
-       <text id="0" nextid="1" pause="true">
-               Sup bro!
-               <quest assign="Quest #1" />
+       <text id="0" nextid="1" pause="true" >
+               Sup bro! Have a quest. To complete it, just go talk to Ralph again.
+               <quest assign="Your First Quest" >
+                       Dank Maymay
+               </quest>
        </text>
        
-       <text id="1" stop="true">
-               My name's Johnny.
-               <give id="Dank Maymay" count="1" />
+       <text id="1" nextid="1" pause="true" >
+               Broooooooooooooo...
        </text>
 </Dialog>