aboutsummaryrefslogtreecommitdiffstats
path: root/src/gameplay.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-01-08 08:47:04 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-01-08 08:47:04 -0500
commitcde980d06325f37d70c1354d1d3b5cc1f3736938 (patch)
tree857f81fe41e57ab6b77d540f8317642dd6cec81f /src/gameplay.cpp
parent0c89c034ffe5fdf79e57c8bdbe9ca07eaf79b382 (diff)
xml improvements
Diffstat (limited to 'src/gameplay.cpp')
-rw-r--r--src/gameplay.cpp111
1 files changed, 99 insertions, 12 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 52ce729..6637d23 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -27,36 +27,123 @@ extern Player *player;
* initEverything() start
*/
+typedef struct {
+ World *ptr;
+ char *file;
+} WorldXML;
+
+typedef struct {
+ NPC *npc;
+ unsigned int index;
+} NPCDialog;
+
+std::vector<NPCDialog> npcd;
+std::vector<WorldXML> earthxml;
std::vector<World *> earth;
+int commonAIFunc(NPC *speaker){
+ XMLDocument xml;
+ XMLElement *exml;
+ unsigned int idx;
+
+ for(auto &n : npcd){
+ if(n.npc == speaker){
+ idx = n.index;
+ break;
+ }
+ }
+
+ for(auto &e : earthxml){
+ if(e.ptr == currentWorld){
+ xml.LoadFile(e.file);
+ exml = xml.FirstChildElement("Dialog")->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(exml->QueryUnsignedAttribute("nextid",&idx) == XML_NO_ERROR){
+ for(auto &n : npcd){
+ if(n.npc == speaker){
+ n.index = idx;
+ break;
+ }
+ }
+ return 1;
+ }
+ return 0;
+ }
+ }
+ exml = exml->NextSiblingElement();
+ }while(exml);
+ }
+ }
+ return 0;
+}
+
void destroyEverything(void);
void initEverything(void){
- const char *gentype;
+ const char *name;
std::vector<std::string> xmlFiles;
- char *file;
+ static char *file;
+ bool dialog;
XMLDocument xml;
+ XMLElement *wxml;
+
if(getdir("./xml/",xmlFiles)){
std::cout<<"Error reading XML files!!!1"<<std::endl;
abort();
}
+
for(auto x : xmlFiles){
if(strncmp(x.c_str(),".",1) && strncmp(x.c_str(),"..",2)){
file = new char[4 + x.size()];
strncpy(file,"xml/",4);
strcpy(file+4,x.c_str());
xml.LoadFile(file);
- delete[] file;
+
+ wxml = xml.FirstChildElement("World")->FirstChildElement();
earth.push_back(new World());
- earth.back()->setBackground((WORLD_BG_TYPE)atoi(xml.FirstChildElement("World")->FirstChildElement("Background")->GetText()));
- earth.back()->setBGM(xml.FirstChildElement("World")->FirstChildElement("BGM")->GetText());
- gentype = xml.FirstChildElement("World")->FirstChildElement("GenerationType")->GetText();
- if(!strcmp(gentype,"Random")){
- std::cout<<"rand\n";
- earth.back()->generate(atoi(xml.FirstChildElement("World")->FirstChildElement("GenerationWidth")->GetText()));
- }else{
- abort();
- }
+
+ do{
+ name = wxml->Name();
+
+ if(!strcmp(name,"style")){
+ earth.back()->setBackground((WORLD_BG_TYPE)wxml->UnsignedAttribute("background"));
+ earth.back()->setBGM(wxml->Attribute("bgm"));
+ }else if(!strcmp(name,"generation")){
+ if(!strcmp(wxml->Attribute("type"),"Random")){
+ earth.back()->generate(wxml->UnsignedAttribute("width"));
+ }
+ }else if(!strcmp(name,"mob")){
+ 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->Attribute("name")){
+ delete[] earth.back()->npc.back()->name;
+ earth.back()->npc.back()->name = new char[strlen(wxml->Attribute("name"))+1];
+ strcpy(earth.back()->npc.back()->name,wxml->Attribute("name"));
+ }
+ dialog = false;
+ if(wxml->QueryBoolAttribute("hasDialog",&dialog) == XML_NO_ERROR && dialog){
+ for(auto &ex : earthxml){
+ if(ex.ptr == earth.back())
+ goto SKIP;
+ }
+ earthxml.push_back((WorldXML){earth.back(),new char[64]});
+ strcpy(earthxml.back().file,file);
+SKIP:
+ earth.back()->npc.back()->addAIFunc(commonAIFunc,false);
+ npcd.push_back((NPCDialog){earth.back()->npc.back(),0});
+ }
+ }
+
+ wxml = wxml->NextSiblingElement();
+ }while(wxml);
+
+ delete[] file;
}
}