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/savegame.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/game/base/savegame.cc (limited to 'src/game/base/savegame.cc') diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc new file mode 100644 index 0000000..d9a7c4f --- /dev/null +++ b/src/game/base/savegame.cc @@ -0,0 +1,83 @@ +/* + base/savegame.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "base/savegame.h" +#include "base/ship.h" + +namespace game { + +void SaveGame::player_to_stream(core::Player *player, std::ostream & os) +{ + if (!os.good()) + return; + + os << "[player]" << std::endl; + // player name + os << "name=" << player->name() << std::endl; + // credit + os << "credits=" << player->credits() << std::endl; + os << std::endl; +} + +void SaveGame::ship_to_stream(Ship *ship, std::ostream & os) +{ + if (!os.good()) + return; + + os << "[ship]" << std::endl; + os << "model=" << ship->shipmodel()->label() << std::endl; + // ship zone + os << "zone=" << ship->zone()->label()<< std::endl; + // ship location + os << "location=" << ship->location() << std::endl; + // ship orientation + os << "forward=" << ship->axis().forward() << std::endl; + os << "left=" << ship->axis().left() << std::endl; + os << "up=" << ship->axis().up() << std::endl; + // ship is docked at spawn on load + os << "docked="; + if (ship->dock() && (ship->dock() == ship->spawn())) { + os << "yes"; + } else if (ship->state() == core::Entity::Destroyed) { + os << "yes"; + } else { + os << "no"; + } + os << std::endl; + // ship spawn + os << "spawn="; + if (ship->spawn()) { + os << ship->spawn()->zone()->label() << ":" << ship->spawn()->label(); + } + os << std::endl; +} + +void SaveGame::inventory_to_stream(core::Inventory *inventory, std::ostream & os) +{ + if (!os.good()) + return; + + if(!inventory) + return; + + for (core::Inventory::Items::iterator it = inventory->items().begin(); + it != inventory->items().end(); ++it) + { + const core::Item *item = (*it); + + os << std::endl; + os << "[item]" << std::endl; + // item InfoType label + os << "type=" << item->info()->type()->label() << std::endl; + // item Info label + os << "label=" << item->info()->label() << std::endl; + os << "amount=" << item->amount() << std::endl; + os << "price=" << item->price() << std::endl; + os << "tradeable=" << (item->flag_is_set(core::Item::Tradeable) ? "yes" : "no") << std::endl; + } +} + +} // namespace game -- cgit v1.2.3