aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.cpp
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2016-03-01 08:00:55 -0500
committerdrumsetmonkey <abelleisle@roadrunner.com>2016-03-01 08:00:55 -0500
commit97c701f329bf3da154c23b0529f194d4d8823287 (patch)
treee003610fa009b82eff3580a6b72407f282b19510 /src/world.cpp
parent4df411931dd63f22258be76911e0648c3cdc3936 (diff)
parent26d71799f37bc325b6db0214268f4e72eb970ee9 (diff)
Work on merchants and yer mum
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp55
1 files changed, 37 insertions, 18 deletions
diff --git a/src/world.cpp b/src/world.cpp
index 306933d..9e891fb 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -118,14 +118,13 @@ void World::deleteEntities(void){
delete mob.back();
mob.pop_back();
}
+ while(!merchant.empty()){
+ merchant.pop_back();
+ }
while(!npc.empty()){
delete npc.back();
npc.pop_back();
}
- while(!merchant.empty()){
- delete merchant.back();
- merchant.pop_back();
- }
while(!build.empty()){
delete build.back();
build.pop_back();
@@ -144,6 +143,10 @@ void World::deleteEntities(void){
while(!light.empty()){
light.pop_back();
}
+ while(!village.empty()){
+ delete village.back();
+ village.pop_back();
+ }
}
World::~World(void){
@@ -1004,13 +1007,13 @@ void World::detect(Player *p){
}
for(auto &v : village){
- if(p->loc.x > v.start.x && p->loc.x < v.end.x){
- if(!v.in){
- ui::passiveImportantText(5000,"Welcome to %s",v.name.c_str());
- v.in = true;
+ if(p->loc.x > v->start.x && p->loc.x < v->end.x){
+ if(!v->in){
+ ui::passiveImportantText(5000,"Welcome to %s",v->name.c_str());
+ v->in = true;
}
}else{
- v.in = false;
+ v->in = false;
}
}
@@ -1545,14 +1548,15 @@ World *loadWorldFromXMLNoSave(const char *path){
xml.LoadFile(currentXML);
wxml = xml.FirstChildElement("World");
- vil = xml.FirstChildElement("World")->FirstChildElement("village");
if(wxml){
wxml = wxml->FirstChildElement();
+ vil = xml.FirstChildElement("World")->FirstChildElement("village");
Indoor = false;
tmp = new World();
}else if((wxml = xml.FirstChildElement("IndoorWorld"))){
wxml = wxml->FirstChildElement();
+ vil = NULL;
Indoor = true;
tmp = new IndoorWorld();
}
@@ -1627,8 +1631,11 @@ World *loadWorldFromXMLNoSave(const char *path){
wxml = wxml->NextSiblingElement();
}
+ Village *vptr;
+
if(vil){
- tmp->village.push_back(vil->Attribute("name"));
+ tmp->village.push_back(new Village(vil->Attribute("name"), tmp));
+ vptr = tmp->village.back();
vil = vil->FirstChildElement();
}
@@ -1640,11 +1647,11 @@ World *loadWorldFromXMLNoSave(const char *path){
/**
* READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE
*/
+
if(!strcmp(name,"structure")){
ptr = vil->Attribute("inside");
tmp->addStructure((BUILD_SUB)vil->UnsignedAttribute("type"),
- vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ?
- randx : spawnx,
+ vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ? randx : spawnx,
100,
(char*)vil->Attribute("texture"),
ptr);
@@ -1659,6 +1666,11 @@ World *loadWorldFromXMLNoSave(const char *path){
(char*)vil->Attribute("texture"),
ptr);
tmp->addMerchant(0,100);
+ if(!strcmp(name,"buy")){
+ std::cout << "Buying";
+ }else if(!strcmp(name,"sell")){
+ std::cout << "Selling";
+ }
strcpy(tmp->merchant.back()->name,"meme");
}else if(!strcmp(vil->Attribute("type"),"trader")){
@@ -1671,12 +1683,12 @@ World *loadWorldFromXMLNoSave(const char *path){
ptr);
}
}
- tmp->village.back().build.push_back(tmp->build.back());
- if(tmp->village.back().build.back()->loc.x < tmp->village.back().start.x){
- tmp->village.back().start.x = tmp->village.back().build.back()->loc.x;
+ vptr->build.push_back(tmp->build.back());
+ if(vptr->build.back()->loc.x < vptr->start.x){
+ vptr->start.x = vptr->build.back()->loc.x;
}
- if(tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width > tmp->village.back().end.x){
- tmp->village.back().end.x = tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width;
+ if(vptr->build.back()->loc.x + vptr->build.back()->width > vptr->end.x){
+ vptr->end.x = vptr->build.back()->loc.x + vptr->build.back()->width;
}
//go to the next element in the village block
@@ -1691,3 +1703,10 @@ World *loadWorldFromXMLNoSave(const char *path){
return tmp;
}
+
+Village::Village(const char *meme, World *w){
+ name = meme;
+ start.x = w->getTheWidth() / 2.0f;
+ end.x = -start.x;
+ in = false;
+}