From 599425c0380630197005c9ecc86604396d612f81 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 12 Jan 2016 08:49:12 -0500 Subject: inside? --- include/common.h | 2 ++ include/entities.h | 4 +-- include/world.h | 4 +-- src/common.cpp | 3 ++- src/entities.cpp | 4 --- src/gameplay.cpp | 54 +++++++++++++++++++++++++++++++++----- src/ui.cpp | 5 ++-- src/world.cpp | 30 ++++++++++++--------- xml/playerSpawnHill1.xml | 4 +-- xml/playerSpawnHill1_Building1.xml | 9 +++++++ 10 files changed, 87 insertions(+), 32 deletions(-) create mode 100644 xml/playerSpawnHill1_Building1.xml diff --git a/include/common.h b/include/common.h index 22ecb22..be32019 100644 --- a/include/common.h +++ b/include/common.h @@ -203,4 +203,6 @@ unsigned int millis(void); int getdir(const char *dir, std::vector &files); void strVectorSortAlpha(std::vector *v); +extern void *NULLPTR; + #endif // COMMON_H diff --git a/include/entities.h b/include/entities.h index d7ad2c0..1e6d316 100644 --- a/include/entities.h +++ b/include/entities.h @@ -198,15 +198,13 @@ public: typedef struct { EntitySavePacket esp; - World *inWorld; - World *inside; BUILD_SUB bsubtype; } __attribute__ ((packed)) StructuresSavePacket; class Structures : public Entity{ public: World *inWorld; - World *inside; + World **inside; BUILD_SUB bsubtype; Structures(); diff --git a/include/world.h b/include/world.h index ef37365..27936f7 100644 --- a/include/world.h +++ b/include/world.h @@ -176,8 +176,8 @@ public: std::vector particles; std::vector light; - void addStructure(BUILD_SUB sub,float x,float y,World *inside); - void addVillage(int bCount, int npcMin, int npcMax,World *inside); + void addStructure(BUILD_SUB sub,float x,float y,World **inside);//,World **outside); + void addVillage(int bCount, int npcMin, int npcMax,World **inside); void addMob(int t,float x,float y); void addMob(int t,float x,float y,void (*hey)(Mob *)); void addNPC(float x,float y); diff --git a/src/common.cpp b/src/common.cpp index 6307790..84515c3 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -10,6 +10,8 @@ #include #endif // __WIN32__ +void *NULLPTR = NULL; + #ifndef __WIN32__ unsigned int millis(void){ @@ -84,7 +86,6 @@ void strVectorSortAlpha(std::vector *v){ change = false; for(unsigned int i=0;isize()-1;i++){ if(v[0][i] > v[0][i+1]){ - std::cout<<"swap "< "<esp,esp,sizeof(EntitySavePacket)); delete[] esp; - ssp->inWorld = inWorld; - ssp->inside = inside; ssp->bsubtype = bsubtype; return (char *)ssp; } @@ -682,8 +680,6 @@ char *Structures::save(void){ void Structures::load(char *s){ StructuresSavePacket *ssp = (StructuresSavePacket *)s; baseLoad((char *)&ssp->esp); - inWorld = ssp->inWorld; - inside = ssp->inside; bsubtype = ssp->bsubtype; } diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 55161f9..d647270 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -153,8 +153,12 @@ void initEverything(void){ const char *name; std::vector xmlFiles; static char *file; + + static bool Indoor = false; bool dialog; float spawnx; + World **yoyo;//,**yoyo2; + XMLDocument xml; XMLElement *wxml; @@ -181,9 +185,17 @@ void initEverything(void){ std::cout<FirstChildElement(); + wxml = xml.FirstChildElement("World");//->FirstChildElement(); - earth.push_back(new World()); + if(wxml){ + wxml = wxml->FirstChildElement(); + earth.push_back(new World()); + Indoor = false; + }else if((wxml = xml.FirstChildElement("IndoorWorld"))){ + wxml = wxml->FirstChildElement(); + earth.push_back(new IndoorWorld()); + Indoor = true; + } for(auto &l : earthlnk){ if(!strcmp(file+4,l.name)){ @@ -209,12 +221,28 @@ void initEverything(void){ break; } } + }else if(Indoor && !strcmp(name,"link") && wxml->Attribute("outside")){ + for(auto &l : earthlnk){ + if(!strcmp(l.name,wxml->Attribute("outside"))){ + for(auto &b : l.ptr->build){ + if(*b->inside == earth.back()){ + ((IndoorWorld *)*b->inside)->outside = 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")){ if(!strcmp(wxml->Attribute("type"),"Random")){ - earth.back()->generate(wxml->UnsignedAttribute("width")); + if(Indoor) + ((IndoorWorld *)earth.back())->generate(wxml->UnsignedAttribute("width")); + else + earth.back()->generate(wxml->UnsignedAttribute("width")); + }else if(Indoor){ + abort(); } }else if(!strcmp(name,"mob")){ if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR) @@ -245,10 +273,24 @@ SKIP: 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); + if(wxml->Attribute("inside")){ + for(auto &l : earthlnk){ + if(!strcmp(l.name,wxml->Attribute("inside"))){ + yoyo = &l.ptr; + break; + } + } + } + /*for(auto &l : earthlnk){ + if(!strcmp(file+4,l.name)){ + yoyo2 = &l.ptr; + break; + } + }*/ + if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR) + earth.back()->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),getRand() % earth.back()->getTheWidth() / 2.0f,100,yoyo);//,yoyo2); else - earth.back()->addNPC(wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));*/ + earth.back()->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),spawnx,wxml->FloatAttribute("y"),yoyo);//,yoyo2); } wxml = wxml->NextSiblingElement(); diff --git a/src/ui.cpp b/src/ui.cpp index 0d01033..616eb82 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -718,8 +718,9 @@ DONE: //delete &tmp; toggleBlackFast(); } - }else + }else{ currentWorld=currentWorld->goInsideStructure(player); + } break; case SDLK_i: currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible @@ -823,7 +824,7 @@ DONE: currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); break; case SDLK_g: - currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, currentWorld); + //currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, currentWorld); break; default: break; diff --git a/src/world.cpp b/src/world.cpp index 451a022..19e9fbc 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -185,8 +185,6 @@ void World::load(std::ifstream *i){ } } -void *NULLPTR = NULL; - World::World(void){ bgm = NULL; @@ -1057,21 +1055,28 @@ LOOOOP: goto LOOOOP; } } -void World::addStructure(BUILD_SUB sub, float x,float y,World *inside){ +void World::addStructure(BUILD_SUB sub, float x,float y,World **inside){//,World **outside){ build.push_back(new Structures()); build.back()->spawn(sub,x,y,this); build.back()->inWorld=this; - build.back()->inside = (World *)inside; - ((IndoorWorld *)inside)->outside = this; + build.back()->inside = inside; + //std::cout<<"yo"<outside = outside; + + + //std::cout<<"yo"<loc.x > b->loc.x && - p->loc.x + p->width < b->loc.x + b->width ){ + p->loc.x + p->width < b->loc.x + b->width && + *b->inside != this ){ thing.push_back(this); ui::toggleBlackFast(); ui::waitForCover(); ui::toggleBlackFast(); - return (World *)b->inside; + return (World *)*b->inside; } } }else{ for(auto &b : ((World *)thing.back())->build){ - if(b->inside == this){ - World *tmp = (World *)thing.back(); + if(*b->inside == this){ + //World *tmp = (World *)thing.back(); p->loc.x = b->loc.x + (b->width / 2) - (p->width / 2); thing.erase(thing.end()-1); ui::toggleBlackFast(); ui::waitForCover(); ui::toggleBlackFast(); - return tmp; + return ((IndoorWorld *)(*b->inside))->outside; } } } diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 5ad31b0..12d55fc 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -3,13 +3,13 @@