/* 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