diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-01-07 08:33:54 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-01-07 08:33:54 -0500 |
commit | e043a2432c4dacce56a308948188482fb230ff33 (patch) | |
tree | b8809e54bc3c516dabfa8eace3b51a92d5c8fbcd /src/world.cpp | |
parent | c7e3d72f0ef08cb9463cd8960bc29dad40e3bdcb (diff) | |
parent | 45edad31559852d306d59b50f380cb79c9f27dcc (diff) |
Hey, that's pretty good lighting!
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 86 |
1 files changed, 78 insertions, 8 deletions
diff --git a/src/world.cpp b/src/world.cpp index b539a87..c6ab6e1 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -52,6 +52,7 @@ float worldGetYBase(World *w){ } void World::setBackground(WORLD_BG_TYPE bgt){ + bgType = bgt; switch(bgt){ case BG_FOREST: bgTex = new Texturec(7,bgPaths[0]); @@ -62,12 +63,69 @@ void World::setBackground(WORLD_BG_TYPE bgt){ } } -void World::save(FILE *s){ - fclose(s); +void World::save(std::ofstream *o){ + static unsigned int size2; + unsigned int size,i; + size_t bgms = strlen(bgm) + 1; + char *bufptr; + + o->write((char *)&lineCount, sizeof(unsigned int)); + o->write((char *)line ,lineCount * sizeof(struct line_t)); + o->write("GG" ,2 * sizeof(char)); + o->write((char *)star ,100 * sizeof(vec2)); + o->write((char *)&bgType , sizeof(WORLD_BG_TYPE)); + o->write((char *)&bgms , sizeof(size_t)); + o->write(bgm ,strlen(bgm)+1); + o->write("NO" ,2 * sizeof(char)); + + /*std::vector<NPC *> npc; + std::vector<Structures *> build; + std::vector<Mob *> mob; + std::vector<Entity *> entity; + std::vector<Object *> object;*/ + + size = npc.size(); + for(i=0;i<size;i++){ + bufptr = npc[i]->save(&size2); + o->write((char *)&size2,sizeof(unsigned int)); + o->write(bufptr,size2); + } } -void World::load(FILE *s){ - fclose(s); +void World::load(std::ifstream *i){ + //unsigned int size; + size_t bgms; + char sig[2]; + + i->read((char *)&lineCount,sizeof(unsigned int)); + + line = new struct line_t[lineCount]; + i->read((char *)line,lineCount * sizeof(struct line_t)); + + i->read(sig,2 * sizeof(char)); + if(strncmp(sig,"GG",2)){ + std::cout<<"world.dat corrupt"<<std::endl; + exit(EXIT_FAILURE); + } + + x_start = 0 - getWidth(this) / 2; + + i->read((char *)star,100 * sizeof(vec2)); + i->read((char *)&bgType,sizeof(WORLD_BG_TYPE)); + + i->read((char *)&bgms,sizeof(size_t)); + bgm = new char[bgms]; + i->read(bgm,bgms); + setBGM(bgm); + + + i->read(sig,2 * sizeof(char)); + if(strncmp(sig,"NO",2)){ + std::cout<<"world.dat corrupt"<<std::endl; + exit(EXIT_FAILURE); + } + + } World::World(void){ @@ -942,16 +1000,20 @@ void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){ entity.push_back(build.back()); } -void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside){ +void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside){ std::cout << npcMin << ", " << npcMax << std::endl; - int xwasd; + //int xwasd; for(int i = 0; i < bCount; i++){ - xwasd = (rand()%(int)x+1000*HLINE); + addStructure(t,HOUSE,x_start + (i * 300),100,inside); + /*std::cout<<"1\n"; HERE: + xwasd = (rand()%(int)x+1000*HLINE); for(auto &bu : build){ if(xwasd > bu->loc.x && xwasd < bu->loc.x+bu->width)goto HERE; } - addStructure(t,HOUSE,xwasd,y,outside); + std::cout<<"2\n"; + addStructure(t,HOUSE,xwasd,y,inside); + std::cout<<"3\n";*/ } } void World::addMob(int t,float x,float y){ @@ -1015,6 +1077,14 @@ void World::addLayer(unsigned int width){ behind->bgTex=bgTex; } +NPC *World::getAvailableNPC(void){ + for(auto &n : npc){ + if(n->aiFunc.empty()) + return n; + } + return (NPC *)NULL; +} + World *World::goWorldLeft(Player *p){ if(toLeft&&p->loc.x<x_start+HLINE*15){ p->loc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10; |