From ee6298f520b05967bd395ac7351e8b5648190981 Mon Sep 17 00:00:00 2001 From: Ragora Date: Thu, 11 Sep 2014 19:33:45 -0400 Subject: [PATCH] Added Flag_Bound flag for ItemStack to check against but the system behind it is probably not the best --- apps/openmw/mwbase/world.hpp | 3 +++ apps/openmw/mwgui/itemmodel.cpp | 7 +++++++ apps/openmw/mwgui/itemmodel.hpp | 3 ++- apps/openmw/mwworld/worldimp.cpp | 35 +++++++++++++++++++++++++++++++- apps/openmw/mwworld/worldimp.hpp | 5 +++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index f07bb3eb9..85f2116e6 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -220,6 +220,9 @@ namespace MWBase virtual int getMonth() const = 0; virtual int getYear() const = 0; + virtual bool isBoundItemID(const std::string &id) = 0; + /// \return Returns whether or not the id refers to a bound item. + virtual std::string getMonthName (int month = -1) const = 0; ///< Return name of month (-1: current month) diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 59b54e171..96ec308ec 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -2,6 +2,10 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/esmstore.hpp" + +#include "../mwbase/world.hpp" +#include "../mwbase/environment.hpp" namespace MWGui { @@ -15,6 +19,9 @@ namespace MWGui { if (base.getClass().getEnchantment(base) != "") mFlags |= Flag_Enchanted; + + if (MWBase::Environment::get().getWorld()->isBoundItemID(base.getCellRef().getRefId())) + mFlags |= Flag_Bound; } ItemStack::ItemStack() diff --git a/apps/openmw/mwgui/itemmodel.hpp b/apps/openmw/mwgui/itemmodel.hpp index 21c5477d0..c1b243a76 100644 --- a/apps/openmw/mwgui/itemmodel.hpp +++ b/apps/openmw/mwgui/itemmodel.hpp @@ -26,7 +26,8 @@ namespace MWGui enum Flags { - Flag_Enchanted = (1<<0) + Flag_Enchanted = (1<<0), + Flag_Bound = (1<<1) }; int mFlags; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 6a8322d4d..bc8c314ca 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -191,6 +191,29 @@ namespace MWWorld mGlobalVariables.fill (mStore); mWorldScene = new Scene(*mRendering, mPhysics); + + // Build a list of known bound item ID's + const MWWorld::Store &gameSettings = mStore.get(); + + for (MWWorld::Store::iterator currentIteration = gameSettings.begin(); currentIteration != gameSettings.end(); ++currentIteration) + { + const ESM::GameSetting ¤tSetting = *currentIteration; + try + { + std::string currentGMSTID = currentSetting.mId; + std::transform(currentGMSTID.begin(), currentGMSTID.end(), currentGMSTID.begin(), ::tolower); + + // Don't bother checking this GMST if it's not a sMagicBound* one. + if (currentGMSTID.find("smagicbound") != 0) + continue; + + std::string currentGMSTValue = currentSetting.getString(); + std::transform(currentGMSTValue.begin(), currentGMSTValue.end(), currentGMSTValue.begin(), ::tolower); + + mBoundID[currentGMSTValue] = true; + } + catch(...){} + } } void World::startNewGame (bool bypass) @@ -879,6 +902,16 @@ namespace MWWorld return mGlobalVariables["timescale"].getFloat(); } + bool World::isBoundItemID(const std::string &id) + { + std::string id_temp = id; + std::transform(id_temp.begin(), id_temp.end(), id_temp.begin(), ::tolower); + + if (mBoundID.count(id_temp) != 0) + return true; + return false; + } + void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { mPhysics->clearQueuedMovement(); @@ -2501,7 +2534,7 @@ namespace MWWorld if (!selectedSpell.empty()) { const ESM::Spell* spell = getStore().get().search(selectedSpell); - + // A power can be used once per 24h if (spell->mData.mType == ESM::Spell::ST_Power) stats.getSpells().usePower(spell->mId); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 54827d042..bc85ab199 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -99,6 +99,8 @@ namespace MWWorld std::string mStartCell; + std::map mBoundID; + void updateWeather(float duration); int getDaysPerMonth (int month) const; @@ -308,6 +310,9 @@ namespace MWWorld virtual float getTimeScaleFactor() const; + virtual bool isBoundItemID(const std::string &id); + ///< \return Whether or not the specified id refers to a bound item. + virtual void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); ///< Move to interior cell.