]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
quest completion
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 9 Feb 2016 13:44:41 +0000 (08:44 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 9 Feb 2016 13:44:41 +0000 (08:44 -0500)
Changelog
config/items.xml
include/Quest.h
src/Quest.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
xml/playerSpawnHill1.xml
xml/playerSpawnHill1_Building1.xml

index 5a94cac3bbf5187836ac7275e88760fb97fc25d9..e8a0605ff9841d4c5708fae1dc8a1377588ab8e3 100644 (file)
--- a/Changelog
+++ b/Changelog
        - partially fixed text drawing
        - XML'd quest checking, working on quest requirements
        - worked on XML'ing villages
+       
+2/9/2016:
+=========
+
+       - quests can require one item for completion
+       - better-er text drawing
+       - can set world themes through XML
index 02d199e0b6e2eaa157de64b3040fbe5bbb2e43fa..02382d6ff29d339cf6386284f9ef62ac05c2e4c9 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 
 <item name="Debug"       type="Tool"  maxStackSize="1"   width="1"  height="1"  sprite="assets/items/ITEM_TEST.png" />
-<item name="Dank Maymay" type="Tool"  maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
+<item name="Dank MayMay" type="Tool"  maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
 <item name="Your Bag"    type="Equip" maxStackSize="1"   width="5"  height="5"  sprite="assets/items/ITEM_TEST.png" />
 <item name="Flashlight"  type="Tool"  maxStackSize="1"   width="4"  height="8"  sprite="assets/items/flashlight_off.png" />
 <item name="Wood Sword"  type="Sword" maxStackSize="1"   width="4"  height="10" sprite="assets/items/SWORD_WOOD.png" />
index 7ba77c85aec8bc217905d64bf4a50f211418b96f..388b14dde47e7e801995494cabd0ab30cef35fc1 100644 (file)
@@ -55,13 +55,13 @@ public:
         * that gave the quest originally.\r
         */\r
        \r
-       int finish(const char *t,void *completer);\r
+       int finish(std::string t);\r
        \r
        /**\r
         * Returns true if this handler is currently taking the quest.\r
         */\r
        \r
-       bool hasQuest(const char *t);\r
+       bool hasQuest(std::string t);\r
 };\r
 \r
 #endif // QUEST_H\r
index 015170610d0a329d181ea20626c2e199ebae9ea1..ac1802171a6c58e687fbf88ae82575138c387bad 100644 (file)
@@ -1,5 +1,9 @@
 #include <Quest.h>\r
 \r
+#include <entities.h>\r
+\r
+extern Player *player;\r
+\r
 int QuestHandler::assign(const char *t){\r
        return strcmp(t,"h");\r
 }\r
@@ -8,16 +12,22 @@ int QuestHandler::drop(const char *t){
        return strcmp(t,"h");\r
 }\r
 \r
-int QuestHandler::finish(const char *t,void *completer){\r
-       return strncmp(t,(char *)completer,1);\r
+int QuestHandler::finish(std::string t){\r
+       for(unsigned int i=0;i<current.size();i++){\r
+               if(current[i].title == t){\r
+                       if(!player->inv->takeItem(current[i].need.back(),1)){\r
+                               current.erase(current.begin()+i);\r
+                               return 1;\r
+                       }else return 0;\r
+               }\r
+       }\r
+       return 0;\r
 }\r
 \r
-bool QuestHandler::hasQuest(const char *t){\r
-       unsigned int i;\r
-       for(i=0;i<current.size();i++){\r
-               if(!strcmp(current[i].title.c_str(),t)){\r
+bool QuestHandler::hasQuest(std::string t){\r
+       for(unsigned int i=0;i<current.size();i++){\r
+               if(current[i].title == t)\r
                        return true;\r
-               }\r
        }\r
        return false;\r
 }\r
index 5633eb86916bc12f061ebbb8be63f3ff7594ed75..bceb81163a26aa536e99a5dff711f49bb432de74 100644 (file)
@@ -82,10 +82,9 @@ int commonAIFunc(NPC *speaker){
                                                        
                                                        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;
+                                                       if(player->qh.hasQuest(qname) && player->qh.finish(qname)){
+                                                               player->qh.finish(qname);
+                                                               goto CONT;
                                                        }else{
                                                                oldidx = speaker->dialogIndex;
                                                                speaker->dialogIndex = oxml->UnsignedAttribute("fail");
@@ -96,7 +95,9 @@ int commonAIFunc(NPC *speaker){
                                                oxml = oxml->NextSiblingElement();
                                        }
                                }
-                               
+
+CONT:
+
                                /*
                                 * Handle any 'give' requests.
                                 */
@@ -152,7 +153,7 @@ int commonAIFunc(NPC *speaker){
                                         * Get the player's choice, then set the XMLElement to the option's block.
                                         */
                                        
-                                       ui::dialogBox(speaker->name,optstr.c_str(),false,exml->GetText());
+                                       ui::dialogBox(speaker->name,optstr.c_str(),false,exml->GetText()+1);
                                        ui::waitForDialog();
                                        
                                        if(ui::dialogOptChosen)
@@ -161,12 +162,12 @@ int commonAIFunc(NPC *speaker){
                                        while(!dopt.empty())
                                                dopt.pop_back();
                                }else{
-                                       
+                                                                               
                                        /*
                                         * No options - simply print the text.
                                         */
 
-                                       ui::dialogBox(speaker->name,"",false,exml->GetText());
+                                       ui::dialogBox(speaker->name,NULL,false,exml->GetText());
                                        ui::waitForDialog();
                                }
                                
index 93bdeb6cb250ae616e0675ddf94d258c3a9a4403..d52dbe8040c36c8e2d97bed8d2ca90f823f89928 100644 (file)
@@ -53,22 +53,38 @@ int Inventory::addItem(std::string name,uint count){
 
 int Inventory::takeItem(std::string name,uint count){
        unsigned int id = 999999;
+       
+       /*
+        * Name to ID lookup
+        */
+       
        for(unsigned int i=0;i<itemMap.size();i++){
                if(itemMap[i]->name == name){
                        id = i;
                        break;
                }
        }
+       
+       if(id == 999999)
+               return -1;
+       
+       /*
+        * Inventory lookup
+        */
+       
        for(unsigned int i=0;i<items.size();i++){
                if(items[i].id == id){
                        if(count > items[i].count)
-                               items.erase(items.begin()+i);
-                       else 
+                               return -(items[i].count - count);
+                       else{
                                items[i].count -= count;
+                               if(!items[i].count)
+                                       items.erase(items.begin()+i);
+                       }
                        return 0;
                }
        }
-       return -1;
+       return -2;
 }
 
 static GLuint *itemtex;
index 5adb7b59aa6bf73f0fe6895374a883ed69fb08c8..7c7319294f4d98ca7036388d14b76ed58badb6c8 100644 (file)
@@ -258,17 +258,15 @@ namespace ui {
         *      Draws a character at the specified coordinates, aborting if the character is unknown.
        */
        
-       vec2 putChar(float xx,float yy,char c){
+       vec2 putChar(float x,float y,char c){
                vec2 c1,c2;
                
-               int x = xx, y = yy;
-               
                /*
                 *      Get the width and height of the rendered character.
                */
                
-               c1={x+ftexbl[c-33].x,
-                   y+ftexbl[c-33].y};
+               c1={(float)floor(x)+ftexbl[c-33].x,
+                   (float)floor(y)+ftexbl[c-33].y};
                c2=ftexwh[c-33];
                
                /*
@@ -316,7 +314,10 @@ namespace ui {
                                if(s[i] == ' ')
                                        i++;
                        }
-                       if(s[i] == '\n' || s[i] == '\r' || s[i] == '\t'){
+                       if(s[i] == '\n'){
+                               yo-=fontSize*1.05;
+                               xo=x;
+                       }else if(s[i] == '\r' || s[i] == '\t'){
                        /*if(s[i] == '\n'){
                                yo-=fontSize*1.05;
                                xo=x;
@@ -325,7 +326,7 @@ namespace ui {
                        }else if(s[i]=='\b'){   //      Handle backspaces?
                                xo-=add.x;
                        }else{
-                               add=putChar(xo,yo,s[i]);
+                               add=putChar(floor(xo),floor(yo),s[i]);
                                xo+=add.x;
                                yo+=add.y;
                        }
@@ -334,12 +335,10 @@ namespace ui {
                return xo;      // i.e. the string width
        }
        
-       float putStringCentered(const float xx,const float yy,const char *s){
+       float putStringCentered(const float x,const float y,const char *s){
                unsigned int i = 0;
                float width = 0;
                
-               int x = xx,y = yy;
-               
                do{
                        if(s[i]=='\n'){                 //      Handle newlines
                                // TODO
@@ -353,7 +352,7 @@ namespace ui {
                        }
                }while(s[++i]);
                
-               putString(x-width/2,y,s);
+               putString(floor(x-width/2),y,s);
                return width;
        }
        
@@ -530,15 +529,15 @@ namespace ui {
        }
        void importantText(const char *text,...){
                va_list textArgs;
-               
+
                //if(!player->ground)return;
-               
+
                memset(dialogBoxText,0,512);
-                               
+
                va_start(textArgs,text);
                vsnprintf(dialogBoxText,512,text,textArgs);
                va_end(textArgs);
-                                 
+
                dialogBoxExists = true;
                dialogImportant = true;
                //toggleBlack();
index cf42cdaa740515104a6cad734ca716a84c680035..387e1a9f937dbe5b1d6964bf0e457e1d5bdb87bf 100644 (file)
@@ -31,8 +31,8 @@ And it wasn't stormy.
        </text>
        
        <text id="2" >
-               <quest check="Your First Quest" fail="3" />
                Niice.
+               <quest check="Your First Quest" fail="3" />
        </text>
        
        <text id="3">
@@ -43,9 +43,7 @@ And it wasn't stormy.
 <Dialog name="Johnny">
        <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>
+               <quest assign="Your First Quest" >Dank MayMay</quest>
        </text>
        
        <text id="1" nextid="1" pause="true" >
index 54d217ba4bc7fe342521066fc6dea0b97c919923..5c2b723a8aa0b92f0b9801cbfb436635c382432b 100644 (file)
@@ -3,6 +3,13 @@
        <style background="1" bgm="assets/music/theme_jazz.wav" />
        <generation type="Random" width="300" />
        
-       <npc name="Bob" />
+       <npc name="Bob" hasDialog="true" />
 
 </IndoorWorld>
+
+<Dialog name="Bob">
+       <text id="0">
+               Hey. Have a Dank Maymay :)
+               <give id="Dank MayMay" count="1" />
+       </text>
+</Dialog>