diff options
-rw-r--r-- | Changelog | 16 | ||||
-rw-r--r-- | include/entities.h | 1 | ||||
-rw-r--r-- | src/gameplay.cpp | 111 | ||||
-rw-r--r-- | src/ui.cpp | 5 | ||||
-rw-r--r-- | xml/playerSpawnHill1.xml | 23 |
5 files changed, 133 insertions, 23 deletions
@@ -470,28 +470,36 @@ - worked on wrapping text for dialog boxes - did more work on GLSL shaders -1/3/2015: +1/3/2016: ========= - finished wrapping text for dialog boxes - began working on world saving/loading again - got some mad GLSL shaders running -1/4/2015: +1/4/2016: ========= - fixed basic world save/load, working on entity saving - GLSL shaders worked? -1/5/2015: +1/5/2016: ========= - can save NPCs and Structures - more shadering -1/6/2015: +1/6/2016: ========= - flashlight! - XML-scripted worlds!!! - !!!!!!!!!!!!!!!!!!!!!!!! + +1/7/2016: +========= + + - xml'd npc and mob spawning + - xml'd npc dialogs + - drafted page xml + diff --git a/include/entities.h b/include/entities.h index 0fcc662..f26863e 100644 --- a/include/entities.h +++ b/include/entities.h @@ -223,7 +223,6 @@ public: void (*hey)(Mob *callee); Mob(int); - Mob(int,unsigned int); ~Mob(); void wander(int); 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; } } @@ -274,10 +274,11 @@ namespace ui { if(s[i] == ' ') i++; } - if(s[i] == '\n'){ + if(s[i] == '\n' || s[i] == '\r' || s[i] == '\t'){ + /*if(s[i] == '\n'){ yo-=fontSize*1.05; xo=x; - }else if(s[i]==' '){ // Handle spaces + */}else if(s[i]==' '){ // Handle spaces xo+=fontSize/2; }else if(s[i]=='\b'){ // Handle backspaces? xo-=add.x; diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 3544a7e..c924d7e 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -1,7 +1,22 @@ <?xml version="1.0"?> <World> - <Background>0</Background> - <BGM>assets/music/embark.wav</BGM> - <GenerationType>Random</GenerationType> - <GenerationWidth>500</GenerationsWidth> + <style background="0" bgm="assets/music/embark.wav" /> + <generation type="Random" width="500" /> + + <!--<mob type="1" x="250" y="100" />--> + + <npc name="Ralph" x="0" y="100" hasDialog="true"/> + </World> + +<Dialog> + + <text name="Ralph" id="0" nextid="1"> + Hello there! + </text> + + <text name="Ralph" id="1"> + Lol + </text> + +</Dialog> |