From a3259b0d7dd9e4444b7dbe1489e1470f29c8dc7c Mon Sep 17 00:00:00 2001
From: Stijn Buys <ingar@osirion.org>
Date: Sun, 21 Oct 2012 10:31:05 +0000
Subject: Corrected loadgame to have the Unique and Unrestricted item
 properties set from actual in-game properties rather than read from the
 savegame file.

---
 src/game/base/savegame.cc | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

(limited to 'src/game')

diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc
index e70e143..90f3a57 100644
--- a/src/game/base/savegame.cc
+++ b/src/game/base/savegame.cc
@@ -7,6 +7,7 @@
 #include "base/game.h"
 #include "base/savegame.h"
 #include "base/ship.h"
+#include "base/weapon.h"
 
 namespace game {
 
@@ -177,14 +178,6 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
 							item->unset_flag(core::Item::Tradeable);
 						}
 					}
-				} else if (inifile.got_key_bool("unique", b)) {
-					if (item) {
-						if (b) {
-							item->set_flag(core::Item::Unique);
-						} else {
-							item->unset_flag(core::Item::Unique);
-						}
-					}
 				} else {
 					inifile.unknown_key();
 				}
@@ -194,6 +187,20 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
 	}
 
 	if (ship) {
+		for (core::Inventory::Items::iterator it = ship->inventory()->items().begin(); it != ship->inventory()->items().end(); ++it) {
+			core::Item *item = (*it);
+			
+			if (item->info()->type() == Weapon::infotype()) {
+				const Weapon *weapon = static_cast<const Weapon *>(item->info());
+				
+				item->set_flag(core::Item::Unrestricted);
+				if (weapon->stackable()) {
+					item->unset_flag(core::Item::Unique);
+				} else {
+					item->set_flag(core::Item::Unique);
+				}
+			}
+		}
 		ship->inventory()->recalculate();
 		ship->inventory()->set_dirty();
 		
@@ -286,7 +293,7 @@ void SaveGame::inventory_to_stream(core::Inventory *inventory, std::ostream & os
 	if(!inventory)
 		return;
 	
-	for (core::Inventory::Items::iterator it = inventory->items().begin(); 
+	for (core::Inventory::Items::const_iterator it = inventory->items().begin(); 
 			it != inventory->items().end(); ++it) 
 	{
 		const core::Item *item = (*it);
@@ -302,9 +309,6 @@ 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::Unique)) {
-			os << "unique=" << (item->has_flag(core::Item::Unique) ? "yes" : "no") << std::endl;
-		}
 	}
 }
 
-- 
cgit v1.2.3