From 85bbfb39bdc272614a2a1526c96f757cb58335d9 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 30 Nov 2012 21:20:08 +0000 Subject: Save weapon slot positions. --- src/game/base/savegame.cc | 31 +++++++++++++++++++++++++++---- src/game/base/savegame.h | 2 +- 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'src/game') diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc index 85388f0..9bfe7b6 100644 --- a/src/game/base/savegame.cc +++ b/src/game/base/savegame.cc @@ -182,6 +182,17 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) item->unset_flag(core::Item::Tradeable); } } + } else if (inifile.got_key_long("slot", l)) { + if ((l > 0) && ((size_t) l <= ship->slots()->size())) { + core::Slot *slot = ship->slots()->operator[]((size_t) (l - 1)); + + if (slot) { + slot->set_item(item); + slot->set_flag(core::Slot::Active); + slot->set_flag(core::Slot::Mounted); + item->set_flag(core::Item::Mounted); + } + } } else { inifile.unknown_key(); } @@ -254,7 +265,7 @@ void SaveGame::player_to_stream(core::Player *player, std::ostream & os) if (player->control()) { ship_to_stream(static_cast(player->control()), os); assert(player->control()->inventory()); - inventory_to_stream(player->control()->inventory(), os); + ship_inventory_to_stream(static_cast(player->control()), os); } } @@ -292,16 +303,17 @@ void SaveGame::ship_to_stream(Ship *ship, std::ostream & os) os << "armor=" << ship->armor() << std::endl; } -void SaveGame::inventory_to_stream(core::Inventory *inventory, std::ostream & os) +void SaveGame::ship_inventory_to_stream(Ship *ship, std::ostream & os) { + core::Inventory *inventory = ship->inventory(); + if (!os.good()) return; if(!inventory) return; - for (core::Inventory::Items::const_iterator it = inventory->items().begin(); - it != inventory->items().end(); ++it) + for (core::Inventory::Items::const_iterator it = inventory->items().begin(); it != inventory->items().end(); ++it) { const core::Item *item = (*it); @@ -316,6 +328,17 @@ void SaveGame::inventory_to_stream(core::Inventory *inventory, std::ostream & os if (item->has_flag(core::Item::Tradeable)) { os << "tradeable=" << (item->has_flag(core::Item::Tradeable) ? "yes" : "no") << std::endl; } + + if (item->has_flag(core::Item::Mounted)) { + + size_t slot_number = 0; + for (core::Slots::iterator slot_it = ship->slots()->begin(); slot_it != ship->slots()->end(); ++slot_it) { + slot_number++; + if ((*slot_it)->item() == item) { + os << "slot=" << slot_number << std::endl; + } + } + } } } diff --git a/src/game/base/savegame.h b/src/game/base/savegame.h index 06e4ee3..c6aa333 100644 --- a/src/game/base/savegame.h +++ b/src/game/base/savegame.h @@ -36,7 +36,7 @@ public: /** * @brief write inventory data to output stream, in .ini format */ - static void inventory_to_stream(core::Inventory *inventory, std::ostream & os); + static void ship_inventory_to_stream(Ship *ship, std::ostream & os); /** * @brief load a savegame from .ini file -- cgit v1.2.3