]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
inside?
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 12 Jan 2016 13:49:12 +0000 (08:49 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 12 Jan 2016 13:49:12 +0000 (08:49 -0500)
include/common.h
include/entities.h
include/world.h
src/common.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp
src/world.cpp
xml/playerSpawnHill1.xml
xml/playerSpawnHill1_Building1.xml [new file with mode: 0644]

index 22ecb22f227eadb3cc97c26ea4b6c899c844de88..be3201973a40da44541b72e53a416c1be49c13d5 100644 (file)
@@ -203,4 +203,6 @@ unsigned int millis(void);
 int getdir(const char *dir, std::vector<std::string> &files);
 void strVectorSortAlpha(std::vector<std::string> *v);
 
+extern void *NULLPTR;
+
 #endif // COMMON_H
index d7ad2c0a16bc6a2ecc63033616fd98e300719551..1e6d31649c6e30f813ae23c13db41e302a7da92e 100644 (file)
@@ -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();
index ef373652402708dcffee0b1f4df8989dc5104e68..27936f7c67b3c3af7c65e34dd00e7cca3a53634b 100644 (file)
@@ -176,8 +176,8 @@ public:
        std::vector<Particles   *>      particles;
        std::vector<Light        >  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);
index 63077908dbef255cb81eb4bec7c77de88b09d089..84515c3626058394b263f21d0ced0f5bd8bbf0f6 100644 (file)
@@ -10,6 +10,8 @@
 #include <vector>
 #endif // __WIN32__
 
+void *NULLPTR = NULL;
+
 #ifndef __WIN32__
 
 unsigned int millis(void){
@@ -84,7 +86,6 @@ void strVectorSortAlpha(std::vector<std::string> *v){
                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;
                        }
index 627946be0d74fa163085f5478e1d6dc84f81fd30..b4c34d958d9441f635aef2c55cccfb550c0b23d6 100644 (file)
@@ -673,8 +673,6 @@ char *Structures::save(void){
        esp = baseSave();
        memcpy(&ssp->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;
 }
 
index 55161f9dfbcc15a73fdf20d82e79a1ad2e656eda..d6472707ea95b811cc8f4001ce524801a8ce740b 100644 (file)
@@ -153,8 +153,12 @@ void initEverything(void){
        const char *name;
        std::vector<std::string> 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<<std::endl<<"Loading "<<file<<" ..."<<std::endl<<std::endl;
                        xml.LoadFile(file);
 
-                       wxml = xml.FirstChildElement("World")->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();
index 0d01033d0f6a2da55724c4ff6bb049a2146fe321..616eb82aa6c02afd4bfe2a798fcd69927933b45c 100644 (file)
@@ -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;
index 451a0223f7ee4b5b93290c4115c28990bf85d65b..19e9fbc3e07ab8f6d8bc97347d16bfb71de5a466 100644 (file)
@@ -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"<<std::endl;
+       
+               
+//       void *       |void ** - *|void ** | void **
+       //((IndoorWorld *)inside[0])->outside = outside;
+       
+       
        
+       //std::cout<<"yo"<<std::endl;
        entity.push_back(build.back());
 }
        
-void World::addVillage(int bCount, int npcMin, int npcMax,World *inside){
+void World::addVillage(int bCount, int npcMin, int npcMax,World **inside){
        std::cout << npcMin << ", " << npcMax << std::endl;
        //int xwasd;
        for(int i = 0; i < bCount; i++){
-               addStructure(HOUSE,x_start + (i * 300),100,inside);
+               addStructure(HOUSE,x_start + (i * 300),100,inside);//,(World **)&NULLPTR);
                /*std::cout<<"1\n";
                HERE:
                xwasd = (rand()%(int)x+1000*HLINE);
@@ -1197,24 +1202,25 @@ World *World::goInsideStructure(Player *p){
        if(!thing.size()){
                for(auto &b : build){
                        if(p->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;
                        }
                }
        }
index 5ad31b0e1cdb70d958a2d4d8e64a2f1a10c05bfc..12d55fc6b14c56ce00c0212a87c94f94b28a8f4c 100644 (file)
@@ -3,13 +3,13 @@
        <style background="0" bgm="assets/music/embark.wav" />
        <generation type="Random" width="800" />
        
-       <link right="playerSpawnHill2.xml" />
+       <!--<link right="playerSpawnHill2.xml" />-->
        
        <mob type="1" />
        
        <npc name="Ralph" hasDialog="true" />
        <npc name="Johnny" hasDialog="true" />
-       <structure type="6"/>
+       <structure type="5" inside="playerSpawnHill1_Building1.xml" />
 
 </World>
 
diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml
new file mode 100644 (file)
index 0000000..a9245e7
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<IndoorWorld>
+       <style background="1" bgm="assets/music/theme_jazz.wav" />
+       <generation type="Random" width="400" />
+
+       <link outside="playerSpawnHill1.xml" />
+
+</IndoorWorld>
+