From 9a0b0432cbdb0bfc2578b74d305a091d56152839 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 14 Jan 2012 13:11:57 +0000 Subject: Moved server-side savegame functions into a separate class. --- src/game/base/game.cc | 68 ++++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 53 deletions(-) (limited to 'src/game/base/game.cc') 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(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(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(); } } -- cgit v1.2.3