]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
xml: more npc functionality
authorClyne Sullivan <tullivan99@gmail.com>
Sun, 10 Jan 2016 19:53:08 +0000 (14:53 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Sun, 10 Jan 2016 19:53:08 +0000 (14:53 -0500)
src/gameplay.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index 9cae698fd5df855220cd158cd81256c3dbe90961..aede91a1f290d0a8682893129e7f3ff77aeb0f44 100644 (file)
@@ -46,6 +46,7 @@ int commonAIFunc(NPC *speaker){
        XMLDocument xml;
        XMLElement *exml,*oxml;
        unsigned int idx;
+       bool stop = false;
        
        for(auto &n : npcd){
                if(n.npc == speaker){
@@ -102,6 +103,22 @@ int commonAIFunc(NPC *speaker){
                                                        ui::dialogBox(speaker->name,"",false,exml->GetText());
                                                        ui::waitForDialog();
                                                }
+                                               if(exml->Attribute("call")){
+                                                       for(auto &n : currentWorld->npc){
+                                                               if(!strcmp(n->name,exml->Attribute("call"))){
+                                                                       if(exml->QueryUnsignedAttribute("callid",&idx) == XML_NO_ERROR){
+                                                                               for(auto &n2 : npcd){
+                                                                                       if(n2.npc == n){
+                                                                                               n2.index = idx;
+                                                                                               break;
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                                       n->addAIFunc(commonAIFunc,false);
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
                                                if(exml->QueryUnsignedAttribute("nextid",&idx) == XML_NO_ERROR){
                                                        for(auto &n : npcd){
                                                                if(n.npc == speaker){
@@ -109,7 +126,11 @@ int commonAIFunc(NPC *speaker){
                                                                        break;
                                                                }
                                                        }
-                                                       return 1;
+                                                       if(exml->QueryBoolAttribute("stop",&stop) == XML_NO_ERROR && stop)
+                                                               return 0;
+                                                       else if(exml->QueryBoolAttribute("pause",&stop) == XML_NO_ERROR && stop)
+                                                               return 1;
+                                                       else return commonAIFunc(speaker);
                                                }
                                                return 0;
                                        }
@@ -127,6 +148,7 @@ void initEverything(void){
        std::vector<std::string> xmlFiles;
        static char *file;
        bool dialog;
+       float spawnx;
        XMLDocument xml;
        XMLElement *wxml;
        
@@ -158,9 +180,16 @@ void initEverything(void){
                                                earth.back()->generate(wxml->UnsignedAttribute("width"));
                                        }
                                }else if(!strcmp(name,"mob")){
-                                       earth.back()->addMob(wxml->UnsignedAttribute("type"),wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));
+                                       if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
+                                               earth.back()->addMob(wxml->UnsignedAttribute("type"),getRand() % earth.back()->getTheWidth() / 2,100);
+                                       else
+                                               earth.back()->addMob(wxml->UnsignedAttribute("type"),wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));
                                }else if(!strcmp(name,"npc")){
-                                       earth.back()->addNPC(wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));
+                                       if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
+                                               earth.back()->addNPC(getRand() % earth.back()->getTheWidth() / 2.0f,100);
+                                       else
+                                               earth.back()->addNPC(wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));
+                                       
                                        if(wxml->Attribute("name")){
                                                delete[] earth.back()->npc.back()->name;
                                                earth.back()->npc.back()->name = new char[strlen(wxml->Attribute("name"))+1];
index e97ec5635517e1543a0301dd5f655ff46b4e2f87..68d5d2f83c0a12d936a5465cf7d01cb46c747810 100644 (file)
@@ -770,11 +770,9 @@ LOOP2:
                cline[i].y-=(yoff-DRAW_Y_OFFSET);
        }
        //glEnd();
-       //glUseProgram(0);
+       glUseProgram(0);
        glDisable(GL_TEXTURE_2D);
 
-       //glUseProgram(0);
-
        /*
         *      Draw non-structure entities.
        */
index 94292ab54432f7376cc34e54dc0dee3977ba2b94..f3036a5f0503e0c0fa5babf12d7502607aac1db9 100644 (file)
@@ -3,9 +3,10 @@
        <style background="0" bgm="assets/music/embark.wav" />
        <generation type="Random" width="500" />
        
-       <!--<mob type="1" x="250" y="100" />-->
+       <mob type="1" />
        
-       <npc name="Ralph" x="0" y="100" hasDialog="true"/>
+       <npc name="Ralph" hasDialog="true" />
+       <npc name="Johnny" hasDialog="true" />
 
 </World>
 
                gg.
        </text>
        
-       <text id="2">
-               Frrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
+       <text id="2" call="Johnny" callid="1">
+               what you have done it to trick Microsoft
        </text>
        
 </Dialog>
+
+<Dialog name="Johnny">
+       <text id="0" nextid="1" stop="true">
+               Sup bro!
+       </text>
+       
+       <text id="1" >
+               My name's Johnny.
+       </text>
+</Dialog>