From d3792c499ce9e33f314e06d102d2a0119108e8d3 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 12 Jan 2016 07:38:57 -0500 Subject: world linking xml'd --- src/common.cpp | 14 ++++++++++++ src/gameplay.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++------------ src/world.cpp | 22 ++++++++++-------- 3 files changed, 81 insertions(+), 24 deletions(-) (limited to 'src') 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 &files){ closedir(dp); return 0; } + +void strVectorSortAlpha(std::vector *v){ + static bool change; + do{ + change = false; + for(unsigned int i=0;isize()-1;i++){ + if(v[0][i] > v[0][i+1]){ + std::cout<<"swap "< "< npcd; -std::vector earthxml; -std::vector earth; -std::vector dopt; +std::vector npcd; +std::vector earthxml; +static std::vector earthlnk; +std::vector earth; +std::vector 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;iFirstChildElement(); 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.xloc.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.xloc.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; } -- cgit v1.2.3