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/savegame.cc
parent8ecbe636dd7e4930265614152914be6cb7b42583 (diff)
Moved server-side savegame functions into a separate class.
Diffstat (limited to 'src/game/base/savegame.cc')
-rw-r--r--src/game/base/savegame.cc83
1 files changed, 83 insertions, 0 deletions
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