aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-01-12 07:38:57 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-01-12 07:38:57 -0500
commitd3792c499ce9e33f314e06d102d2a0119108e8d3 (patch)
treee613126367773a4077cb74c8e0994870df9db38a /src
parenta2284d1c9be35744cb43a91148c82cff64be7a43 (diff)
world linking xml'd
Diffstat (limited to 'src')
-rw-r--r--src/common.cpp14
-rw-r--r--src/gameplay.cpp69
-rw-r--r--src/world.cpp22
3 files changed, 81 insertions, 24 deletions
diff --git a/src/common.cpp b/src/common.cpp
index 8defd61..6307790 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -77,3 +77,17 @@ int getdir(const char *dir, std::vector<std::string> &files){
closedir(dp);
return 0;
}
+
+void strVectorSortAlpha(std::vector<std::string> *v){
+ static bool change;
+ do{
+ change = false;
+ for(unsigned int i=0;i<v->size()-1;i++){
+ if(v[0][i] > v[0][i+1]){
+ std::cout<<"swap "<<v[0][i]<<" <-> "<<v[0][i+1]<<std::endl;
+ std::swap(v[0][i],v[0][i+1]);
+ change = true;
+ }
+ }
+ }while(change);
+}
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index a257ad3..55161f9 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -32,16 +32,21 @@ typedef struct {
char *file;
} WorldXML;
+typedef struct {
+ char *name;
+ World *ptr;
+} WorldLink;
typedef struct {
NPC *npc;
unsigned int index;
} NPCDialog;
-std::vector<NPCDialog> npcd;
-std::vector<WorldXML> earthxml;
-std::vector<World *> earth;
-std::vector<XMLElement *> dopt;
+std::vector<NPCDialog> npcd;
+std::vector<WorldXML> earthxml;
+static std::vector<WorldLink> earthlnk;
+std::vector<World *> earth;
+std::vector<XMLElement *> dopt;
int commonAIFunc(NPC *speaker){
XMLDocument xml;
@@ -68,7 +73,7 @@ int commonAIFunc(NPC *speaker){
do{
if(!strcmp(exml->Name(),"text")){
- if(/*!strcmp(exml->Attribute("name"),speaker->name) &&*/ exml->UnsignedAttribute("id") == idx){
+ if(exml->UnsignedAttribute("id") == idx){
if((oxml = exml->FirstChildElement("option"))){
const char *op;
@@ -158,22 +163,53 @@ void initEverything(void){
abort();
}
- for(auto x : xmlFiles){
- if(strncmp(x.c_str(),".",1) && strncmp(x.c_str(),"..",2)){
- file = new char[5 + x.size()];
- memset(file,0,5 + x.size());
+ strVectorSortAlpha(&xmlFiles);
+
+ for(unsigned int i=0;i<xmlFiles.size();i++){
+ if(strncmp(xmlFiles[i].c_str(),".",1) && strncmp(xmlFiles[i].c_str(),"..",2)){
+ earthlnk.push_back((WorldLink){new char[strlen(xmlFiles[i].c_str() + 1)],NULL});
+ strcpy(earthlnk.back().name,xmlFiles[i].c_str());
+ }
+ }
+
+ for(unsigned int i=0;i<xmlFiles.size();i++){
+ if(strncmp(xmlFiles[i].c_str(),".",1) && strncmp(xmlFiles[i].c_str(),"..",2)){
+ file = new char[5 + xmlFiles[i].size()];
+ memset(file,0,5 + xmlFiles[i].size());
strncpy(file,"xml/",4);
- strcpy(file+4,x.c_str());
+ strcpy(file+4,xmlFiles[i].c_str());
+ std::cout<<std::endl<<"Loading "<<file<<" ..."<<std::endl<<std::endl;
xml.LoadFile(file);
wxml = xml.FirstChildElement("World")->FirstChildElement();
earth.push_back(new World());
- do{
+ for(auto &l : earthlnk){
+ if(!strcmp(file+4,l.name)){
+ l.ptr = earth.back();
+ break;
+ }
+ }
+
+ while(wxml){
name = wxml->Name();
-
- if(!strcmp(name,"style")){
+
+ if(!strcmp(name,"link") && wxml->Attribute("left")){
+ for(auto &l : earthlnk){
+ if(!strcmp(l.name,wxml->Attribute("left"))){
+ earth.back()->toLeft = &l.ptr;
+ break;
+ }
+ }
+ }else if(!strcmp(name,"link") && wxml->Attribute("right")){
+ for(auto &l : earthlnk){
+ if(!strcmp(l.name,wxml->Attribute("right"))){
+ earth.back()->toRight = &l.ptr;
+ break;
+ }
+ }
+ }else if(!strcmp(name,"style")){
earth.back()->setBackground((WORLD_BG_TYPE)wxml->UnsignedAttribute("background"));
earth.back()->setBGM(wxml->Attribute("bgm"));
}else if(!strcmp(name,"generation")){
@@ -208,10 +244,15 @@ SKIP:
earth.back()->npc.back()->addAIFunc(commonAIFunc,false);
npcd.push_back((NPCDialog){earth.back()->npc.back(),0});
}
+ }else if(!strcmp(name,"structure")){
+ /*if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
+ earth.back()->addStructure((getRand() % earth.back()->getTheWidth() / 2.0f,100);
+ else
+ earth.back()->addNPC(wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));*/
}
wxml = wxml->NextSiblingElement();
- }while(wxml);
+ }
delete[] file;
}
diff --git a/src/world.cpp b/src/world.cpp
index e66fb0d..e2c6aa9 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -185,6 +185,8 @@ void World::load(std::ifstream *i){
}
}
+void *NULLPTR = NULL;
+
World::World(void){
bgm = NULL;
@@ -195,9 +197,9 @@ World::World(void){
*/
behind =
- infront =
+ infront = NULL;
toLeft =
- toRight = NULL;
+ toRight = (World **)&NULLPTR;
/*
* Allocate and clear an array for star coordinates.
@@ -1151,19 +1153,19 @@ NPC *World::getAvailableNPC(void){
}
World *World::goWorldLeft(Player *p){
- if(toLeft&&p->loc.x<x_start+HLINE*15){
- p->loc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10;
- p->loc.y=toLeft->line[toLeft->lineCount-GEN_INC-1].y;
- return toLeft;
+ if(toLeft[0]&&p->loc.x<x_start+HLINE*15){
+ p->loc.x=toLeft[0]->x_start+getWidth(toLeft[0])-HLINE*10;
+ p->loc.y=toLeft[0]->line[toLeft[0]->lineCount-GEN_INC-1].y;
+ return toLeft[0];
}
return this;
}
World *World::goWorldRight(Player *p){
- if(toRight&&p->loc.x+p->width>x_start+getWidth(this)-HLINE*10){
- p->loc.x=toRight->x_start+HLINE*10;
- p->loc.y=toRight->line[0].y;
- return toRight;
+ if(toRight[0]&&p->loc.x+p->width>x_start+getWidth(this)-HLINE*10){
+ p->loc.x=toRight[0]->x_start+HLINE*10;
+ p->loc.y=toRight[0]->line[0].y;
+ return toRight[0];
}
return this;
}