From 810ba6190921572d3ac01cfb5d82bbe4b7fb171d Mon Sep 17 00:00:00 2001
From: cc9cii <cc9c@iinet.net.au>
Date: Sat, 27 Sep 2014 17:46:48 +1000
Subject: [PATCH 1/7] While loading overwrite records with the same id.  Should
 resolve bug #1750.

---
 apps/opencs/model/world/collection.hpp | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp
index 1fb3e1f1db..387b33cf36 100644
--- a/apps/opencs/model/world/collection.hpp
+++ b/apps/opencs/model/world/collection.hpp
@@ -7,6 +7,7 @@
 #include <cctype>
 #include <stdexcept>
 #include <functional>
+#include <iostream>
 
 #include <QVariant>
 
@@ -431,18 +432,27 @@ namespace CSMWorld
 
         const Record<ESXRecordT>& record2 = dynamic_cast<const Record<ESXRecordT>&> (record);
 
-        mRecords.insert (mRecords.begin()+index, record2);
+        std::pair<std::map<std::string, int>::iterator, bool> insertResult =
+            mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (record2.get())),
+                                           index));
 
+        if(!insertResult.second) // duplicate index found, replace the current record
+        {
+            std::cerr << "Duplicate record found, using new: " + IdAccessorT().getId(record2.get()) << std::endl;
+            replace(insertResult.first->second, record2);
+            return;
+        }
+
+        // else update the index except for the record to be inserted
         if (index<static_cast<int> (mRecords.size())-1)
         {
-            for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end();
-                ++iter)
-                 if (iter->second>=index)
+            std::string id = IdAccessorT().getId(record2.get());
+            for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end(); ++iter)
+                 if (iter->second > index || (iter->second == index && iter->first != id))
                      ++(iter->second);
         }
 
-        mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (
-            record2.get())), index));
+        mRecords.insert (mRecords.begin()+index, record2);
     }
 
     template<typename ESXRecordT, typename IdAccessorT>

From a2d043f43a31195acd357f937a9cc8d9c5534b26 Mon Sep 17 00:00:00 2001
From: cc9cii <cc9c@iinet.net.au>
Date: Sat, 27 Sep 2014 23:36:27 +1000
Subject: [PATCH 2/7] Re-check unknown record id after loading.

---
 apps/opencs/model/world/idcollection.hpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp
index 7e7756ff3e..940181c24b 100644
--- a/apps/opencs/model/world/idcollection.hpp
+++ b/apps/opencs/model/world/idcollection.hpp
@@ -71,6 +71,14 @@ namespace CSMWorld
 
             record.load (reader);
 
+            if (index==-1)
+            {
+                std::string newId = IdAccessorT().getId(record);
+                int newIndex = this->searchId(newId);
+                if (newIndex != -1 && id != newId)
+                    index = newIndex;
+            }
+
             load (record, base, index);
         }
     }

From d790b8edfa5d41107fb5f55e3eecf0455679f660 Mon Sep 17 00:00:00 2001
From: cc9cii <cc9c@iinet.net.au>
Date: Sat, 27 Sep 2014 23:39:22 +1000
Subject: [PATCH 3/7] Revert old fix.

---
 apps/opencs/model/world/collection.hpp | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp
index 387b33cf36..1fb3e1f1db 100644
--- a/apps/opencs/model/world/collection.hpp
+++ b/apps/opencs/model/world/collection.hpp
@@ -7,7 +7,6 @@
 #include <cctype>
 #include <stdexcept>
 #include <functional>
-#include <iostream>
 
 #include <QVariant>
 
@@ -432,27 +431,18 @@ namespace CSMWorld
 
         const Record<ESXRecordT>& record2 = dynamic_cast<const Record<ESXRecordT>&> (record);
 
-        std::pair<std::map<std::string, int>::iterator, bool> insertResult =
-            mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (record2.get())),
-                                           index));
+        mRecords.insert (mRecords.begin()+index, record2);
 
-        if(!insertResult.second) // duplicate index found, replace the current record
-        {
-            std::cerr << "Duplicate record found, using new: " + IdAccessorT().getId(record2.get()) << std::endl;
-            replace(insertResult.first->second, record2);
-            return;
-        }
-
-        // else update the index except for the record to be inserted
         if (index<static_cast<int> (mRecords.size())-1)
         {
-            std::string id = IdAccessorT().getId(record2.get());
-            for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end(); ++iter)
-                 if (iter->second > index || (iter->second == index && iter->first != id))
+            for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end();
+                ++iter)
+                 if (iter->second>=index)
                      ++(iter->second);
         }
 
-        mRecords.insert (mRecords.begin()+index, record2);
+        mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (
+            record2.get())), index));
     }
 
     template<typename ESXRecordT, typename IdAccessorT>

From da9d8582017fe358c426831c3567236098e6171f Mon Sep 17 00:00:00 2001
From: Jordan Ayers <jordan.ayers@gmail.com>
Date: Mon, 29 Sep 2014 20:59:10 -0500
Subject: [PATCH 4/7] Add 'const' to a spell helper function.

---
 apps/openmw/mwmechanics/spells.hpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp
index 7caeba6e8c..ab799ffe12 100644
--- a/apps/openmw/mwmechanics/spells.hpp
+++ b/apps/openmw/mwmechanics/spells.hpp
@@ -74,7 +74,7 @@ namespace MWMechanics
 
             TIterator end() const;
 
-            bool hasSpell(const std::string& spell) { return mSpells.find(Misc::StringUtils::lowerCase(spell)) != mSpells.end(); }
+            bool hasSpell(const std::string& spell) const { return mSpells.find(Misc::StringUtils::lowerCase(spell)) != mSpells.end(); }
 
             void add (const std::string& spell);
             ///< Adding a spell that is already listed in *this is a no-op.

From 850a40d4e2fa963e53cf4bface73a702f236084b Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Tue, 30 Sep 2014 13:15:15 +0200
Subject: [PATCH 5/7] fixed resources table drag source problem

---
 apps/opencs/model/world/resourcesmanager.cpp | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/apps/opencs/model/world/resourcesmanager.cpp b/apps/opencs/model/world/resourcesmanager.cpp
index ec67465213..50014f4b5c 100644
--- a/apps/opencs/model/world/resourcesmanager.cpp
+++ b/apps/opencs/model/world/resourcesmanager.cpp
@@ -6,18 +6,20 @@
 void CSMWorld::ResourcesManager::addResources (const Resources& resources)
 {
     mResources.insert (std::make_pair (resources.getType(), resources));
+    mResources.insert (std::make_pair (UniversalId::getParentType (resources.getType()),
+        resources));
 }
 
 void CSMWorld::ResourcesManager::listResources()
 {
     static const char * const sMeshTypes[] = { "nif", 0 };
 
-    addResources (Resources ("meshes", UniversalId::Type_Meshes, sMeshTypes));
-    addResources (Resources ("icons", UniversalId::Type_Icons));
-    addResources (Resources ("music", UniversalId::Type_Musics));
-    addResources (Resources ("sound", UniversalId::Type_SoundsRes));
-    addResources (Resources ("textures", UniversalId::Type_Textures));
-    addResources (Resources ("videos", UniversalId::Type_Videos));
+    addResources (Resources ("meshes", UniversalId::Type_Mesh, sMeshTypes));
+    addResources (Resources ("icons", UniversalId::Type_Icon));
+    addResources (Resources ("music", UniversalId::Type_Music));
+    addResources (Resources ("sound", UniversalId::Type_SoundRes));
+    addResources (Resources ("textures", UniversalId::Type_Texture));
+    addResources (Resources ("videos", UniversalId::Type_Video));
 }
 
 const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const

From a9a0930b855b76ef6af00ce01e3f163c7f880b33 Mon Sep 17 00:00:00 2001
From: Jordan Ayers <jordan.ayers@gmail.com>
Date: Wed, 1 Oct 2014 19:24:54 -0500
Subject: [PATCH 6/7] Disease check:  Reuse corprus check from spells.hpp.

---
 apps/openmw/mwmechanics/disease.hpp | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/apps/openmw/mwmechanics/disease.hpp b/apps/openmw/mwmechanics/disease.hpp
index fa97f15417..21dd820546 100644
--- a/apps/openmw/mwmechanics/disease.hpp
+++ b/apps/openmw/mwmechanics/disease.hpp
@@ -33,18 +33,8 @@ namespace MWMechanics
             if (actor.getClass().getCreatureStats(actor).getSpells().hasSpell(spell->mId))
                 continue;
 
-            bool hasCorprusEffect = false;
-            for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = spell->mEffects.mList.begin(); effectIt != spell->mEffects.mList.end(); ++effectIt)
-            {
-                if (effectIt->mEffectID == ESM::MagicEffect::Corprus)
-                {
-                    hasCorprusEffect = true;
-                    break;
-                }
-            }
-
             float resist = 0.f;
-            if (hasCorprusEffect)
+            if (spells.hasCorprusEffect(spell))
                 resist = 1.f - 0.01 * (actor.getClass().getCreatureStats(actor).getMagicEffects().get(ESM::MagicEffect::ResistCorprusDisease).getMagnitude()
                                         - actor.getClass().getCreatureStats(actor).getMagicEffects().get(ESM::MagicEffect::WeaknessToCorprusDisease).getMagnitude());
             else if (spell->mData.mType == ESM::Spell::ST_Disease)

From 3bc91c66e66820a5da0b79614f93090ff94d3623 Mon Sep 17 00:00:00 2001
From: Jordan Ayers <jordan.ayers@gmail.com>
Date: Wed, 1 Oct 2014 19:27:10 -0500
Subject: [PATCH 7/7] Disease Check:  Shorten the resistance calculations.

---
 apps/openmw/mwmechanics/disease.hpp | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/apps/openmw/mwmechanics/disease.hpp b/apps/openmw/mwmechanics/disease.hpp
index 21dd820546..a973c0e353 100644
--- a/apps/openmw/mwmechanics/disease.hpp
+++ b/apps/openmw/mwmechanics/disease.hpp
@@ -25,6 +25,8 @@ namespace MWMechanics
                 MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
                     "fDiseaseXferChance")->getFloat();
 
+        MagicEffects& actorEffects = actor.getClass().getCreatureStats(actor).getMagicEffects();
+
         Spells& spells = carrier.getClass().getCreatureStats(carrier).getSpells();
         for (Spells::TIterator it = spells.begin(); it != spells.end(); ++it)
         {
@@ -35,14 +37,14 @@ namespace MWMechanics
 
             float resist = 0.f;
             if (spells.hasCorprusEffect(spell))
-                resist = 1.f - 0.01 * (actor.getClass().getCreatureStats(actor).getMagicEffects().get(ESM::MagicEffect::ResistCorprusDisease).getMagnitude()
-                                        - actor.getClass().getCreatureStats(actor).getMagicEffects().get(ESM::MagicEffect::WeaknessToCorprusDisease).getMagnitude());
+                resist = 1.f - 0.01 * (actorEffects.get(ESM::MagicEffect::ResistCorprusDisease).getMagnitude()
+                                        - actorEffects.get(ESM::MagicEffect::WeaknessToCorprusDisease).getMagnitude());
             else if (spell->mData.mType == ESM::Spell::ST_Disease)
-                resist = 1.f - 0.01 * (actor.getClass().getCreatureStats(actor).getMagicEffects().get(ESM::MagicEffect::ResistCommonDisease).getMagnitude()
-                                        - actor.getClass().getCreatureStats(actor).getMagicEffects().get(ESM::MagicEffect::WeaknessToCommonDisease).getMagnitude());
+                resist = 1.f - 0.01 * (actorEffects.get(ESM::MagicEffect::ResistCommonDisease).getMagnitude()
+                                        - actorEffects.get(ESM::MagicEffect::WeaknessToCommonDisease).getMagnitude());
             else if (spell->mData.mType == ESM::Spell::ST_Blight)
-                resist = 1.f - 0.01 * (actor.getClass().getCreatureStats(actor).getMagicEffects().get(ESM::MagicEffect::ResistBlightDisease).getMagnitude()
-                                        - actor.getClass().getCreatureStats(actor).getMagicEffects().get(ESM::MagicEffect::WeaknessToBlightDisease).getMagnitude());
+                resist = 1.f - 0.01 * (actorEffects.get(ESM::MagicEffect::ResistBlightDisease).getMagnitude()
+                                        - actorEffects.get(ESM::MagicEffect::WeaknessToBlightDisease).getMagnitude());
             else
                 continue;