aboutsummaryrefslogtreecommitdiffstats
path: root/src/entities.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-02-12 08:47:15 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-02-12 08:47:15 -0500
commitba7df965e73e121820f20e3a0e57631d078c11db (patch)
tree75f09a352be19c369f7bd02e279a275322634d67 /src/entities.cpp
parent3033594b89f23e65b6152daa6610f991307f2f67 (diff)
more saving/loading
Diffstat (limited to 'src/entities.cpp')
-rw-r--r--src/entities.cpp67
1 files changed, 64 insertions, 3 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index f079b03..aa98809 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -341,9 +341,6 @@ NOPE:
if(near)ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-HLINE/2,name);
}
-void Player::interact(){
-}
-
/*
* NPC::wander, this makes the npcs wander around the near area
*
@@ -576,3 +573,67 @@ void Mob::wander(int timeRun){
break;
}
}
+
+void Player::save(void){
+ std::string data;
+ std::ofstream out ("xml/main.dat",std::ios::out | std::ios::binary);
+ std::cout<<"Saving player data..."<<std::endl;
+ data.append(std::to_string((int)loc.x) + "\n");
+ data.append(std::to_string((int)loc.y) + "\n");
+ data.append(std::to_string((int)health) + "\n");
+ data.append(std::to_string((int)maxHealth) + "\n");
+
+ data.append(std::to_string((int)inv->items.size()) + "\n");
+ for(auto &i : inv->items)
+ data.append(std::to_string((int)i.count) + "\n" + std::to_string((int)i.id) + "\n");
+
+ data.append((std::string)(currentXML+4) + "\n");
+
+ data.append("dOnE\0");
+ out.write(data.c_str(),data.size());
+ out.close();
+}
+
+void Player::sspawn(float x,float y){
+ unsigned int i;
+ uint count;
+ std::ifstream in ("xml/main.dat",std::ios::in | std::ios::binary);
+ spawn(x,y);
+
+ if(in.good()){
+ std::istringstream data;
+ std::string ddata;
+ std::streampos len;
+
+ in.seekg(0,std::ios::end);
+ len = in.tellg();
+ in.seekg(0,std::ios::beg);
+
+ std::vector<char> buf (len,'\0');
+ in.read(buf.data(),buf.size());
+
+ data.rdbuf()->pubsetbuf(buf.data(),buf.size());
+
+ std::getline(data,ddata);
+ loc.x = std::stoi(ddata);
+ std::getline(data,ddata);
+ loc.y = std::stoi(ddata);
+ std::getline(data,ddata);
+ health = std::stoi(ddata);
+ std::getline(data,ddata);
+ maxHealth = std::stoi(ddata);
+
+ std::getline(data,ddata);
+ for(i = std::stoi(ddata);i;i--){
+ std::getline(data,ddata);
+ count = std::stoi(ddata);
+ std::getline(data,ddata);
+ inv->items.push_back((item_t){count,(uint)std::stoi(ddata)});
+ }
+
+ std::getline(data,ddata);
+ currentWorld = loadWorldFromXMLNoSave(ddata.c_str());
+
+ in.close();
+ }
+}