Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/slots.h24
-rw-r--r--src/game/base/savegame.cc31
-rw-r--r--src/game/base/savegame.h2
3 files changed, 49 insertions, 8 deletions
diff --git a/src/core/slots.h b/src/core/slots.h
index aefffb7..6ac9eb8 100644
--- a/src/core/slots.h
+++ b/src/core/slots.h
@@ -38,16 +38,34 @@ public:
void clear();
/**
- * @brief found a mounted item
+ * @brief find a mounted item
* */
Slot *find(Item *item);
+ /**
+ * @brief return the slot at the specified index
+ * */
+ inline Slot *operator[](size_t index)
+ {
+ if (index < slots_container.size()) {
+ return slots_container[index];
+ } else {
+ return 0;
+ }
+ }
+
+ inline size_t size() const
+ {
+ return slots_container.size();
+ }
- inline iterator begin() {
+ inline iterator begin()
+ {
return slots_container.begin();
}
- inline iterator end() {
+ inline iterator end()
+ {
return slots_container.end();
}
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<Ship *>(player->control()), os);
assert(player->control()->inventory());
- inventory_to_stream(player->control()->inventory(), os);
+ ship_inventory_to_stream(static_cast<Ship *>(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