Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-01-14 13:11:57 +0000
committerStijn Buys <ingar@osirion.org>2012-01-14 13:11:57 +0000
commit9a0b0432cbdb0bfc2578b74d305a091d56152839 (patch)
treee81b00cf0b8b34f5644b989903398ab0a0dd8b06 /src/game/base/game.cc
parent8ecbe636dd7e4930265614152914be6cb7b42583 (diff)
Moved server-side savegame functions into a separate class.
Diffstat (limited to 'src/game/base/game.cc')
-rw-r--r--src/game/base/game.cc68
1 files changed, 15 insertions, 53 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index a91ba1d..1c68d11 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -22,6 +22,7 @@
#include "base/navpoint.h"
#include "base/jumppoint.h"
#include "base/planet.h"
+#include "base/savegame.h"
#include "base/station.h"
#include "base/racetrack.h"
#include "base/ship.h"
@@ -1964,19 +1965,21 @@ void Game::player_save(core::Player *player)
std::string guid(player->guid().str());
std::string directory(guid.substr(0,4));
- std::string filename(filesystem::writedir());
// create players/ directory
+ std::string filename(filesystem::writedir());
filename.append("players");
if (!sys::directory_exists(filename)) {
sys::mkdir(filename);
}
filename += '/';
+
// second level directory
filename.append(directory);
if (!sys::directory_exists(filename)) {
sys::mkdir(filename);
}
filename += '/';
+
// guid.ini
filename.append(guid);
filename.append(".ini");
@@ -1987,65 +1990,24 @@ void Game::player_save(core::Player *player)
return;
}
- /* ---- HEADER ----------------------------------------------- */
+ // save header
ofs << "; " << guid << ".ini" << std::endl;
ofs << "; Project::OSiRiON player data" << std::endl;
-
- /* ---- PLAYER ----------------------------------------------- */
ofs << std::endl;
- ofs << "[player]" << std::endl;
- // player name
- ofs << "name=" << player->name() << std::endl;
- // credit
- ofs << "credits=" << player->credits() << std::endl;
- /* ---- SHIP ------------------------------------------------- */
- Ship * ship = static_cast<Ship *>(player->control());
- ofs << std::endl;
- ofs << "[ship]" << std::endl;
- ofs << "model=" << ship->shipmodel()->label() << std::endl;
- // ship zone
- ofs << "zone=" << ship->zone()->label()<< std::endl;
- // ship location
- ofs << "location=" << ship->location() << std::endl;
- // ship orientation
- ofs << "forward=" << ship->axis().forward() << std::endl;
- ofs << "left=" << ship->axis().left() << std::endl;
- ofs << "up=" << ship->axis().up() << std::endl;
- // ship is docked at spawn on load
- ofs << "docked=";
- if (ship->dock() && (ship->dock() == ship->spawn())) {
- ofs << "yes";
- } else if (ship->state() == core::Entity::Destroyed) {
- ofs << "yes";
- } else {
- ofs << "no";
- }
- ofs << std::endl;
- // ship spawn
- ofs << "spawn=";
- if (ship->spawn()) {
- ofs << ship->spawn()->zone()->label() << ":" << ship->spawn()->label();
- }
- ofs << std::endl;
+ // save player data
+ SaveGame::player_to_stream(player, ofs);
- /* ---- INVENTORY -------------------------------------------- */
- assert (ship->inventory());
- for (core::Inventory::Items::iterator it = ship->inventory()->items().begin();
- it != ship->inventory()->items().end(); ++it)
- {
- core::Item *item = (*it);
+ // save ship
+ // TODO iterate assets and save all ships
+ if (player->control()) {
+ SaveGame::ship_to_stream(static_cast<Ship *>(player->control()), ofs);
- ofs << std::endl;
- ofs << "[item]" << std::endl;
- // item InfoType label
- ofs << "type=" << item->info()->type()->label() << std::endl;
- // item Info label
- ofs << "label=" << item->info()->label() << std::endl;
- ofs << "amount=" << item->amount() << std::endl;
- ofs << "price=" << item->price() << std::endl;
- ofs << "tradeable=" << (item->flag_is_set(core::Item::Tradeable) ? "yes" : "no") << std::endl;
+ assert(player->control()->inventory());
+ SaveGame::inventory_to_stream(player->control()->inventory(), ofs);
}
+
+ // close output stream
ofs.close();
}
}