From 5227bcfa382b914fff3f01e856a433a7f841b943 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 9 Jan 2016 10:06:35 -0500 Subject: xml: dialog options --- src/gameplay.cpp | 58 ++++++++++++++++++++++++++++++++++++++++-------- src/ui.cpp | 5 +++-- xml/playerSpawnHill1.xml | 14 ++++++++---- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 6637d23..9cae698 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -37,13 +37,14 @@ typedef struct { unsigned int index; } NPCDialog; -std::vector npcd; -std::vector earthxml; -std::vector earth; +std::vector npcd; +std::vector earthxml; +std::vector earth; +std::vector dopt; int commonAIFunc(NPC *speaker){ XMLDocument xml; - XMLElement *exml; + XMLElement *exml,*oxml; unsigned int idx; for(auto &n : npcd){ @@ -56,13 +57,51 @@ int commonAIFunc(NPC *speaker){ for(auto &e : earthxml){ if(e.ptr == currentWorld){ xml.LoadFile(e.file); - exml = xml.FirstChildElement("Dialog")->FirstChildElement(); + + exml = xml.FirstChildElement("Dialog"); + while(strcmp(exml->Attribute("name"),speaker->name)) + exml = exml->NextSiblingElement(); + + exml = exml->FirstChildElement(); do{ if(!strcmp(exml->Name(),"text")){ - if(!strcmp(exml->Attribute("name"),speaker->name) && exml->UnsignedAttribute("id") == idx){ - ui::dialogBox(speaker->name,"",false,exml->GetText()); - ui::waitForDialog(); + if(/*!strcmp(exml->Attribute("name"),speaker->name) &&*/ exml->UnsignedAttribute("id") == idx){ + + if((oxml = exml->FirstChildElement("option"))){ + const char *op; + char *bp1 = new char[1],*bp2,*tmp; + unsigned int idx = 0; + bp1[0] = '\0'; + while(oxml){ + op = oxml->Attribute("text"); + + bp2 = new char[strlen(bp1) + strlen(op) + 2]; + strcpy(bp2,bp1); + + bp2[idx++] = ':'; + strcpy(bp2+idx,op); + idx += strlen(op); + + tmp = bp1; + bp1 = bp2; + delete[] tmp; + + dopt.push_back(oxml); + + oxml = oxml->NextSiblingElement(); + } + ui::dialogBox(speaker->name,bp1,false,exml->GetText()); + ui::waitForDialog(); + if(ui::dialogOptChosen){ + exml = dopt[ui::dialogOptChosen-1]; + } + while(!dopt.empty()) + dopt.pop_back(); + }else{ + ui::dialogBox(speaker->name,"",false,exml->GetText()); + ui::waitForDialog(); + } if(exml->QueryUnsignedAttribute("nextid",&idx) == XML_NO_ERROR){ for(auto &n : npcd){ if(n.npc == speaker){ @@ -98,7 +137,8 @@ void initEverything(void){ for(auto x : xmlFiles){ if(strncmp(x.c_str(),".",1) && strncmp(x.c_str(),"..",2)){ - file = new char[4 + x.size()]; + file = new char[5 + x.size()]; + memset(file,0,5 + x.size()); strncpy(file,"xml/",4); strcpy(file+4,x.c_str()); xml.LoadFile(file); diff --git a/src/ui.cpp b/src/ui.cpp index ead9d8c..6e33692 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -437,10 +437,11 @@ namespace ui { dialogOptCount--; }; - dialogOptChosen=0; + dialogOptCount = 0; + dialogOptChosen = 0; memset(&dialogOptLoc,0,sizeof(float)*12); - if(opt){ + if(opt != NULL){ soptbuf = new char[strlen(opt)+1]; strcpy(soptbuf,opt); diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index c924d7e..94292ab 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -9,14 +9,20 @@ - + - + Hello there! + - - Lol + + gg. + + + + Frrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr -- cgit v1.2.3 From 66c99350e63ab6b32ec7fcda45e2e6b8c9f658da Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 10 Jan 2016 14:53:08 -0500 Subject: xml: more npc functionality --- src/gameplay.cpp | 35 ++++++++++++++++++++++++++++++++--- src/world.cpp | 4 +--- xml/playerSpawnHill1.xml | 19 +++++++++++++++---- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 9cae698..aede91a 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -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 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]; diff --git a/src/world.cpp b/src/world.cpp index e97ec56..68d5d2f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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. */ diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 94292ab..f3036a5 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -3,9 +3,10 @@