diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 5b4f43ad34..b789bd28fb 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -11,9 +11,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "idtable.hpp" #include "idtree.hpp" @@ -27,15 +27,21 @@ namespace { - class SpellStore : public GamePlay::CommonStore + class CSStore : public AutoCalc::StoreCommon { + const CSMWorld::IdCollection& mGmstTable; + const CSMWorld::IdCollection& mSkillTable; + const CSMWorld::IdCollection& mMagicEffectTable; const CSMWorld::NestedIdCollection& mSpells; std::vector mLocal; public: - SpellStore(const CSMWorld::NestedIdCollection& spells) - : mSpells(spells) + CSStore(const CSMWorld::IdCollection& gmst, + const CSMWorld::IdCollection& skills, + const CSMWorld::IdCollection& magicEffects, + const CSMWorld::NestedIdCollection& spells) + : mGmstTable(gmst), mSkillTable(skills), mMagicEffectTable(magicEffects), mSpells(spells) { // prepare data in a format used by OpenMW store for (int index = 0; index < mSpells.getSize(); ++index) @@ -44,53 +50,6 @@ namespace mLocal.push_back(spell); } } - - ~SpellStore() {} - - typedef GamePlay::SharedIterator iterator; - - virtual iterator begin() const - { - return mLocal.begin(); - } - - virtual iterator end() const - { - return mLocal.end(); - } - - virtual const ESM::Spell *find(const std::string &id) const - { - return &mSpells.getRecord(id).get(); - } - - virtual size_t getSize() const - { - return mSpells.getSize(); - } - - private: - // not used in OpenCS - virtual void load(ESM::ESMReader &esm, const std::string &id) - { - } - }; - - class CSStore : public GamePlay::StoreWrap - { - const CSMWorld::IdCollection& mGmstTable; - const CSMWorld::IdCollection& mSkillTable; - const CSMWorld::IdCollection& mMagicEffectTable; - const SpellStore mSpellStore; - - public: - - CSStore(const CSMWorld::IdCollection& gmst, - const CSMWorld::IdCollection& skills, - const CSMWorld::IdCollection& magicEffects, - const CSMWorld::NestedIdCollection& spells) - : mGmstTable(gmst), mSkillTable(skills), mMagicEffectTable(magicEffects), mSpellStore(spells) - { } ~CSStore() {} virtual int findGmstInt(const std::string& name) const @@ -115,18 +74,18 @@ namespace return &mMagicEffectTable.getRecord(ESM::MagicEffect::indexToId((short)id)).get(); } - virtual const GamePlay::CommonStore& getSpells() const + virtual const std::vector& getSpells() const { - return mSpellStore; + return mLocal; } }; - unsigned short autoCalculateMana(GamePlay::StatsBase& stats) + unsigned short autoCalculateMana(AutoCalc::StatsBase& stats) { return stats.getBaseAttribute(ESM::Attribute::Intelligence) * 2; } - unsigned short autoCalculateFatigue(GamePlay::StatsBase& stats) + unsigned short autoCalculateFatigue(AutoCalc::StatsBase& stats) { return stats.getBaseAttribute(ESM::Attribute::Strength) + stats.getBaseAttribute(ESM::Attribute::Willpower) @@ -1579,15 +1538,15 @@ CSMWorld::NpcStats* CSMWorld::Data::npcAutoCalculate(const ESM::NPC& npc) const if (autoCalc) { - GamePlay::autoCalcAttributesImpl (&npc, race, class_, level, *stats, &store); + AutoCalc::autoCalcAttributesImpl (&npc, race, class_, level, *stats, &store); stats->setHealth(autoCalculateHealth(level, class_, *stats)); stats->setMana(autoCalculateMana(*stats)); stats->setFatigue(autoCalculateFatigue(*stats)); - GamePlay::autoCalcSkillsImpl(&npc, race, class_, level, *stats, &store); + AutoCalc::autoCalcSkillsImpl(&npc, race, class_, level, *stats, &store); - GamePlay::autoCalculateSpells(race, *stats, &store); + AutoCalc::autoCalculateSpells(race, *stats, &store); } else { @@ -1645,7 +1604,7 @@ CSMWorld::NpcStats* CSMWorld::Data::npcAutoCalculate(const ESM::NPC& npc) const int school; float skillTerm; - GamePlay::calcWeakestSchool(spell, skills, school, skillTerm, &store); + AutoCalc::calcWeakestSchool(spell, skills, school, skillTerm, &store); float chance = calcAutoCastChance(spell, skills, attributes, school, &store); stats->addCostAndChance((*it).mName, cost, (int)ceil(chance)); // percent diff --git a/apps/opencs/model/world/npcstats.hpp b/apps/opencs/model/world/npcstats.hpp index a5287d2b47..4d9be149fb 100644 --- a/apps/opencs/model/world/npcstats.hpp +++ b/apps/opencs/model/world/npcstats.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace CSMWorld { @@ -20,7 +20,7 @@ namespace CSMWorld int mChance; }; - class NpcStats : public GamePlay::StatsBase + class NpcStats : public AutoCalc::StatsBase { int mAttr[ESM::Attribute::Length]; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 4f419c6359..64ed868a13 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -11,9 +11,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -62,28 +62,26 @@ namespace return new NpcCustomData (*this); } - class Stats : public GamePlay::StatsBase + class Stats : public AutoCalc::StatsBase { - MWMechanics::CreatureStats& mCreatureStats; MWMechanics::NpcStats& mNpcStats; public: - Stats(MWMechanics::CreatureStats& creatureStats, MWMechanics::NpcStats& npcStats) - : mCreatureStats(creatureStats), mNpcStats(npcStats) {} + Stats(MWMechanics::NpcStats& npcStats) : mNpcStats(npcStats) {} - virtual unsigned char getBaseAttribute(int index) const { return mCreatureStats.getAttribute(index).getBase(); } + virtual unsigned char getBaseAttribute(int index) const { return mNpcStats.getAttribute(index).getBase(); } - virtual void setAttribute(int index, unsigned char value) { mCreatureStats.setAttribute(index, value); } + virtual void setAttribute(int index, unsigned char value) { mNpcStats.setAttribute(index, value); } - virtual void addSpells(std::string id) { mCreatureStats.getSpells().add(id); } + virtual void addSpells(std::string id) { mNpcStats.getSpells().add(id); } virtual unsigned char getBaseSkill(int index) const { return mNpcStats.getSkill(index).getBase(); } virtual void setBaseSkill(int index, unsigned char value) { mNpcStats.getSkill(index).setBase(value); } }; - void autoCalculateAttributes (const ESM::NPC* npc, MWMechanics::CreatureStats& creatureStats) + void autoCalculateAttributes (const ESM::NPC* npc, MWMechanics::NpcStats& npcStats) { const ESM::Race *race = MWBase::Environment::get().getWorld()->getStore().get().find(npc->mRace); @@ -91,16 +89,15 @@ namespace const ESM::Class *class_ = MWBase::Environment::get().getWorld()->getStore().get().find(npc->mClass); - int level = creatureStats.getLevel(); + int level = npcStats.getLevel(); - MWMechanics::NpcStats dummy; // npc stats are needed for skills, which is not calculated here - Stats stats(creatureStats, dummy); + Stats stats(npcStats); MWWorld::MWStore store; - GamePlay::autoCalcAttributesImpl (npc, race, class_, level, stats, &store); + AutoCalc::autoCalcAttributesImpl (npc, race, class_, level, stats, &store); - creatureStats.setHealth(GamePlay::autoCalculateHealth(level, class_, stats)); + npcStats.setHealth(AutoCalc::autoCalculateHealth(level, class_, stats)); } void autoCalculateSkills(const ESM::NPC* npc, MWMechanics::NpcStats& npcStats, const MWWorld::Ptr& ptr) @@ -112,13 +109,13 @@ namespace const ESM::Race *race = MWBase::Environment::get().getWorld()->getStore().get().find(npc->mRace); - Stats stats(npcStats, npcStats); + Stats stats(npcStats); MWWorld::MWStore store; - GamePlay::autoCalcSkillsImpl(npc, race, class_, level, stats, &store); + AutoCalc::autoCalcSkillsImpl(npc, race, class_, level, stats, &store); - GamePlay::autoCalculateSpells(race, stats, &store); + AutoCalc::autoCalculateSpells(race, stats, &store); } } diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index c6954d91d7..c392372ff3 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -4,8 +4,6 @@ #include #include -#include - #include "../mwbase/windowmanager.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -142,7 +140,7 @@ namespace MWGui if(world->getStore().get().isDynamic(cls->mId)) { // Choosing Stealth specialization and Speed/Agility as attributes, if possible. Otherwise fall back to first class found. - GamePlay::SharedIterator it = world->getStore().get().begin(); + MWWorld::SharedIterator it = world->getStore().get().begin(); for(; it != world->getStore().get().end(); ++it) { if(it->mData.mIsPlayable && it->mData.mSpecialization == 2 && it->mData.mAttribute[0] == 4 && it->mData.mAttribute[1] == 3) diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 5d61bc1d29..dc388555ed 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -6,7 +6,7 @@ #include -#include +#include #include "../mwworld/esmstore.hpp" #include "../mwworld/inventorystore.hpp" @@ -256,10 +256,10 @@ namespace MWMechanics static const float fAutoPCSpellChance = esmStore.get().find("fAutoPCSpellChance")->getFloat(); MWWorld::MWStore store; - if (GamePlay::calcAutoCastChance(spell, skills, attributes, -1, &store) < fAutoPCSpellChance) + if (AutoCalc::calcAutoCastChance(spell, skills, attributes, -1, &store) < fAutoPCSpellChance) continue; - if (!GamePlay::attrSkillCheck(spell, skills, attributes, &store)) + if (!AutoCalc::attrSkillCheck(spell, skills, attributes, &store)) continue; selectedSpells.push_back(spell->mId); diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 61518548bc..5d9beecb65 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -66,7 +66,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) esm.getRecHeader(); // Look up the record type. - std::map::iterator it = mStores.find(n.val); + std::map::iterator it = mStores.find(n.val); if (it == mStores.end()) { if (n.val == ESM::REC_INFO) { @@ -130,7 +130,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) void ESMStore::setUp() { - std::map::iterator it = mStores.begin(); + std::map::iterator it = mStores.begin(); for (; it != mStores.end(); ++it) { it->second->setUp(); } diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 61d361b3e5..05b6339566 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -67,7 +67,7 @@ namespace MWWorld // Lookup of all IDs. Makes looking up references faster. Just // maps the id name to the record type. std::map mIds; - std::map mStores; + std::map mStores; ESM::NPC mPlayerTemplate; @@ -75,7 +75,7 @@ namespace MWWorld public: /// \todo replace with SharedIterator - typedef std::map::const_iterator iterator; + typedef std::map::const_iterator iterator; iterator begin() const { return mStores.begin(); @@ -144,7 +144,7 @@ namespace MWWorld void clearDynamic () { - for (std::map::iterator it = mStores.begin(); it != mStores.end(); ++it) + for (std::map::iterator it = mStores.begin(); it != mStores.end(); ++it) it->second->clearDynamic(); mNpcs.insert(mPlayerTemplate); diff --git a/apps/openmw/mwworld/mwstore.cpp b/apps/openmw/mwworld/mwstore.cpp index 02c7106b63..8ebe91cd97 100644 --- a/apps/openmw/mwworld/mwstore.cpp +++ b/apps/openmw/mwworld/mwstore.cpp @@ -29,8 +29,8 @@ namespace MWWorld return MWBase::Environment::get().getWorld()->getStore().get().find(id); } - const GamePlay::CommonStore& MWStore::getSpells() const + const std::vector& MWStore::getSpells() const { - return MWBase::Environment::get().getWorld()->getStore().get(); + return MWBase::Environment::get().getWorld()->getStore().get().getShared(); } } diff --git a/apps/openmw/mwworld/mwstore.hpp b/apps/openmw/mwworld/mwstore.hpp index c616e4e1d0..c43c589316 100644 --- a/apps/openmw/mwworld/mwstore.hpp +++ b/apps/openmw/mwworld/mwstore.hpp @@ -3,13 +3,13 @@ #include -#include +#include #include "store.hpp" namespace MWWorld { - class MWStore : public GamePlay::StoreWrap + class MWStore : public AutoCalc::StoreCommon { const MWWorld::Store& mGmst; const MWWorld::Store &mSpells; @@ -27,7 +27,7 @@ namespace MWWorld virtual const ESM::MagicEffect* findMagicEffect(int id) const; - virtual const GamePlay::CommonStore& getSpells() const; + virtual const std::vector& getSpells() const; }; } diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 852092a9a9..c86a92f7a3 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -10,7 +10,6 @@ #include #include -#include #include @@ -18,10 +17,89 @@ namespace MWWorld { + struct StoreBase + { + virtual ~StoreBase() {} + + virtual void setUp() {} + virtual void listIdentifier(std::vector &list) const {} + + virtual size_t getSize() const = 0; + virtual int getDynamicSize() const { return 0; } + virtual void load(ESM::ESMReader &esm, const std::string &id) = 0; + + virtual bool eraseStatic(const std::string &id) {return false;} + virtual void clearDynamic() {} + + virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) const {} + + virtual void read (ESM::ESMReader& reader, const std::string& id) {} + ///< Read into dynamic storage + }; + + template + class SharedIterator + { + typedef typename std::vector::const_iterator Iter; + + Iter mIter; + + public: + SharedIterator() {} + + SharedIterator(const SharedIterator &orig) + : mIter(orig.mIter) + {} + + SharedIterator(const Iter &iter) + : mIter(iter) + {} + + SharedIterator &operator++() { + ++mIter; + return *this; + } + + SharedIterator operator++(int) { + SharedIterator iter = *this; + ++mIter; + + return iter; + } + + SharedIterator &operator--() { + --mIter; + return *this; + } + + SharedIterator operator--(int) { + SharedIterator iter = *this; + --mIter; + + return iter; + } + + bool operator==(const SharedIterator &x) const { + return mIter == x.mIter; + } + + bool operator!=(const SharedIterator &x) const { + return !(*this == x); + } + + const T &operator*() const { + return **mIter; + } + + const T *operator->() const { + return &(**mIter); + } + }; + class ESMStore; template - class Store : public GamePlay::CommonStore + class Store : public StoreBase { std::map mStatic; std::vector mShared; // Preserves the record order as it came from the content files (this @@ -59,7 +137,7 @@ namespace MWWorld : mStatic(orig.mData) {} - typedef GamePlay::SharedIterator iterator; + typedef SharedIterator iterator; // setUp needs to be called again after virtual void clearDynamic() @@ -156,6 +234,10 @@ namespace MWWorld return mShared.size(); } + const std::vector& getShared() const { + return mShared; + } + int getDynamicSize() const { return static_cast (mDynamic.size()); // truncated from unsigned __int64 if _MSC_VER && _WIN64 @@ -302,7 +384,7 @@ namespace MWWorld } template <> - class Store : public GamePlay::StoreBase + class Store : public StoreBase { // For multiple ESM/ESP files we need one list per file. typedef std::vector LandTextureList; @@ -379,7 +461,7 @@ namespace MWWorld }; template <> - class Store : public GamePlay::StoreBase + class Store : public StoreBase { std::vector mStatic; @@ -394,7 +476,7 @@ namespace MWWorld }; public: - typedef GamePlay::SharedIterator iterator; + typedef SharedIterator iterator; virtual ~Store() { @@ -468,7 +550,7 @@ namespace MWWorld }; template <> - class Store : public GamePlay::StoreBase + class Store : public StoreBase { struct DynamicExtCmp { @@ -508,7 +590,7 @@ namespace MWWorld void handleMovedCellRefs(ESM::ESMReader& esm, ESM::Cell* cell); public: - typedef GamePlay::SharedIterator iterator; + typedef SharedIterator iterator; const ESM::Cell *search(const std::string &id) const { ESM::Cell cell; @@ -756,7 +838,7 @@ namespace MWWorld }; template <> - class Store : public GamePlay::StoreBase + class Store : public StoreBase { private: typedef std::map Interior; diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 8c37c8ef3a..2938dcd81f 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -6,16 +6,16 @@ set (VERSION_HPP ${CMAKE_CURRENT_SOURCE_DIR}/version/version.hpp) if (GIT_CHECKOUT) add_custom_target (git-version COMMAND ${CMAKE_COMMAND} - -DGIT_EXECUTABLE=${GIT_EXECUTABLE} + -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} - -DVERSION_HPP_IN=${VERSION_HPP_IN} - -DVERSION_HPP=${VERSION_HPP} - -DOPENMW_VERSION_MAJOR=${OPENMW_VERSION_MAJOR} - -DOPENMW_VERSION_MINOR=${OPENMW_VERSION_MINOR} - -DOPENMW_VERSION_RELEASE=${OPENMW_VERSION_RELEASE} - -DOPENMW_VERSION=${OPENMW_VERSION} + -DVERSION_HPP_IN=${VERSION_HPP_IN} + -DVERSION_HPP=${VERSION_HPP} + -DOPENMW_VERSION_MAJOR=${OPENMW_VERSION_MAJOR} + -DOPENMW_VERSION_MINOR=${OPENMW_VERSION_MINOR} + -DOPENMW_VERSION_RELEASE=${OPENMW_VERSION_RELEASE} + -DOPENMW_VERSION=${OPENMW_VERSION} -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/GitVersion.cmake - VERBATIM) + VERBATIM) else (GIT_CHECKOUT) configure_file(${VERSION_HPP_IN} ${VERSION_HPP}) endif (GIT_CHECKOUT) @@ -119,7 +119,7 @@ add_component_dir (fontloader fontloader ) -add_component_dir (gameplay +add_component_dir (autocalc autocalc autocalcspell ) @@ -165,14 +165,14 @@ include_directories(${BULLET_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR}) -target_link_libraries(components +target_link_libraries(components ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_WAVE_LIBRARY} ${OGRE_LIBRARIES} - ${OENGINE_LIBRARY} + ${OENGINE_LIBRARY} ${BULLET_LIBRARIES} ) diff --git a/components/gameplay/autocalc.cpp b/components/autocalc/autocalc.cpp similarity index 98% rename from components/gameplay/autocalc.cpp rename to components/autocalc/autocalc.cpp index fbfc4a0204..78cd549ca4 100644 --- a/components/gameplay/autocalc.cpp +++ b/components/autocalc/autocalc.cpp @@ -37,10 +37,10 @@ namespace } } -namespace GamePlay +namespace AutoCalc { void autoCalcAttributesImpl (const ESM::NPC* npc, - const ESM::Race *race, const ESM::Class *class_, int level, StatsBase& stats, StoreWrap *store) + const ESM::Race *race, const ESM::Class *class_, int level, StatsBase& stats, StoreCommon *store) { // race bonus bool male = (npc->mFlags & ESM::NPC::Female) == 0; @@ -106,7 +106,7 @@ namespace GamePlay * and by adding class, race, specialization bonus. */ void autoCalcSkillsImpl (const ESM::NPC* npc, - const ESM::Race *race, const ESM::Class *class_, int level, StatsBase& stats, StoreWrap *store) + const ESM::Race *race, const ESM::Class *class_, int level, StatsBase& stats, StoreCommon *store) { for (int i = 0; i < 2; ++i) { @@ -188,7 +188,7 @@ namespace GamePlay return static_cast(floor(0.5f * (strength + endurance)) + multiplier * (level-1)); } - void autoCalculateSpells(const ESM::Race *race, StatsBase& stats, StoreWrap *store) + void autoCalculateSpells(const ESM::Race *race, StatsBase& stats, StoreCommon *store) { int skills[ESM::Skill::Length]; for (int i=0; i @@ -12,7 +12,7 @@ namespace ESM struct Class; } -namespace GamePlay +namespace AutoCalc { // wrapper class for sharing the autocalc code between OpenMW and OpenCS class StatsBase @@ -35,13 +35,13 @@ namespace GamePlay }; void autoCalcAttributesImpl (const ESM::NPC* npc, - const ESM::Race *race, const ESM::Class *class_, int level, StatsBase& stats, StoreWrap *store); + const ESM::Race *race, const ESM::Class *class_, int level, StatsBase& stats, StoreCommon *store); void autoCalcSkillsImpl (const ESM::NPC* npc, - const ESM::Race *race, const ESM::Class *class_, int level, StatsBase& stats, StoreWrap *store); + const ESM::Race *race, const ESM::Class *class_, int level, StatsBase& stats, StoreCommon *store); unsigned short autoCalculateHealth(int level, const ESM::Class *class_, StatsBase& stats); - void autoCalculateSpells(const ESM::Race *race, StatsBase& stats, StoreWrap *store); + void autoCalculateSpells(const ESM::Race *race, StatsBase& stats, StoreCommon *store); } -#endif // COMPONENTS_GAMEPLAY_AUTOCALC_H +#endif // COMPONENTS_AUTOCALC_AUTOCALC_H diff --git a/components/gameplay/autocalcspell.cpp b/components/autocalc/autocalcspell.cpp similarity index 92% rename from components/gameplay/autocalcspell.cpp rename to components/autocalc/autocalcspell.cpp index 8f28433676..8f2883e1b4 100644 --- a/components/gameplay/autocalcspell.cpp +++ b/components/autocalc/autocalcspell.cpp @@ -14,7 +14,7 @@ #include "autocalc.hpp" // Most of the code in this file was moved from apps/openmw/mwmechanics/autocalcspell.cpp -namespace GamePlay +namespace AutoCalc { struct SchoolCaps @@ -27,7 +27,7 @@ namespace GamePlay }; std::vector autoCalcNpcSpells(const int *actorSkills, - const int *actorAttributes, const ESM::Race* race, StoreWrap *store) + const int *actorAttributes, const ESM::Race* race, StoreCommon *store) { static const float fNPCbaseMagickaMult = store->findGmstFloat("fNPCbaseMagickaMult"); float baseMagicka = fNPCbaseMagickaMult * actorAttributes[ESM::Attribute::Intelligence]; @@ -61,13 +61,13 @@ namespace GamePlay std::vector selectedSpells; - const CommonStore &spells = store->getSpells(); + const std::vector& spells = store->getSpells(); // Note: the algorithm heavily depends on the traversal order of the spells. For vanilla-compatible results the // Store must preserve the record ordering as it was in the content files. - for (CommonStore::iterator iter = spells.begin(); iter != spells.end(); ++iter) + for (std::vector::const_iterator iter = spells.begin(); iter != spells.end(); ++iter) { - const ESM::Spell* spell = &*iter; + ESM::Spell* spell = *iter; if (spell->mData.mType != ESM::Spell::ST_Spell) continue; @@ -107,7 +107,17 @@ namespace GamePlay cap.mMinCost = INT_MAX; for (std::vector::iterator weakIt = selectedSpells.begin(); weakIt != selectedSpells.end(); ++weakIt) { - const ESM::Spell* testSpell = spells.find(*weakIt); + std::vector::const_iterator it = spells.begin(); + for (; it != spells.end(); ++it) + { + if ((*it)->mId == *weakIt) + break; + } + + if (it == spells.end()) + continue; + + const ESM::Spell* testSpell = *it; //int testSchool; //float dummySkillTerm; @@ -146,7 +156,7 @@ namespace GamePlay } bool attrSkillCheck (const ESM::Spell* spell, - const int* actorSkills, const int* actorAttributes, StoreWrap *store) + const int* actorSkills, const int* actorAttributes, StoreCommon *store) { const std::vector& effects = spell->mEffects.mList; for (std::vector::const_iterator effectIt = effects.begin(); effectIt != effects.end(); ++effectIt) @@ -186,7 +196,7 @@ namespace GamePlay } void calcWeakestSchool (const ESM::Spell* spell, - const int* actorSkills, int& effectiveSchool, float& skillTerm, StoreWrap *store) + const int* actorSkills, int& effectiveSchool, float& skillTerm, StoreCommon *store) { float minChance = FLT_MAX; @@ -220,7 +230,7 @@ namespace GamePlay } float calcAutoCastChance(const ESM::Spell *spell, - const int *actorSkills, const int *actorAttributes, int effectiveSchool, StoreWrap *store) + const int *actorSkills, const int *actorAttributes, int effectiveSchool, StoreCommon *store) { if (spell->mData.mType != ESM::Spell::ST_Spell) return 100.f; diff --git a/components/gameplay/autocalcspell.hpp b/components/autocalc/autocalcspell.hpp similarity index 61% rename from components/gameplay/autocalcspell.hpp rename to components/autocalc/autocalcspell.hpp index ceb9f197b9..769e602485 100644 --- a/components/gameplay/autocalcspell.hpp +++ b/components/autocalc/autocalcspell.hpp @@ -1,5 +1,5 @@ -#ifndef COMPONENTS_GAMEPLAY_AUTOCALCSPELL_H -#define COMPONENTS_GAMEPLAY_AUTOCALCSPELL_H +#ifndef COMPONENTS_AUTOCALC_AUTOCALCSPELL_H +#define COMPONENTS_AUTOCALC_AUTOCALCSPELL_H #include @@ -11,28 +11,29 @@ namespace ESM struct Race; } -namespace GamePlay +namespace AutoCalc { -class StoreWrap; +class StoreCommon; /// Contains algorithm for calculating an NPC's spells based on stats std::vector autoCalcNpcSpells(const int* actorSkills, - const int* actorAttributes, const ESM::Race* race, StoreWrap *store); + const int* actorAttributes, const ESM::Race* race, StoreCommon *store); // Helpers -bool attrSkillCheck (const ESM::Spell* spell, const int* actorSkills, const int* actorAttributes, StoreWrap *store); +bool attrSkillCheck (const ESM::Spell* spell, + const int* actorSkills, const int* actorAttributes, StoreCommon *store); ESM::Skill::SkillEnum mapSchoolToSkill(int school); void calcWeakestSchool(const ESM::Spell* spell, - const int* actorSkills, int& effectiveSchool, float& skillTerm, StoreWrap *store); + const int* actorSkills, int& effectiveSchool, float& skillTerm, StoreCommon *store); float calcAutoCastChance(const ESM::Spell* spell, - const int* actorSkills, const int* actorAttributes, int effectiveSchool, StoreWrap *store); + const int* actorSkills, const int* actorAttributes, int effectiveSchool, StoreCommon *store); } -#endif +#endif // COMPONENTS_AUTOCALC_AUTOCALCSPELL_H diff --git a/components/autocalc/store.hpp b/components/autocalc/store.hpp new file mode 100644 index 0000000000..65a29def73 --- /dev/null +++ b/components/autocalc/store.hpp @@ -0,0 +1,42 @@ +#ifndef COMPONENTS_AUTOCALC_STORE_H +#define COMPONENTS_AUTOCALC_STORE_H + +#include +#include + +namespace Loading +{ + class Listener; +} + +namespace ESM +{ + class ESMWriter; + class ESMReader; + struct Spell; + struct Skill; + struct MagicEffect; +} + +namespace AutoCalc +{ + // interface class for sharing the autocalc component between OpenMW and OpenCS + class StoreCommon + { + + public: + StoreCommon() {} + virtual ~StoreCommon() {} + + virtual int findGmstInt(const std::string& gmst) const = 0; + + virtual float findGmstFloat(const std::string& gmst) const = 0; + + virtual const ESM::Skill *findSkill(int index) const = 0; + + virtual const ESM::MagicEffect* findMagicEffect(int id) const = 0; + + virtual const std::vector& getSpells() const = 0; + }; +} +#endif // COMPONENTS_AUTOCALC_STORE_H diff --git a/components/gameplay/store.hpp b/components/gameplay/store.hpp deleted file mode 100644 index c4d7cba179..0000000000 --- a/components/gameplay/store.hpp +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef COMPONENTS_GAMEPLAY_STORE_H -#define COMPONENTS_GAMEPLAY_STORE_H - -#include -#include - -namespace Loading -{ - class Listener; -} - -namespace ESM -{ - class ESMWriter; - class ESMReader; - struct Spell; - struct Skill; - struct MagicEffect; -} - -namespace GamePlay -{ - // moved from apps/openmw/mwworld/store.hpp - struct StoreBase - { - virtual ~StoreBase() {} - - virtual void setUp() {} - virtual void listIdentifier(std::vector &list) const {} - - virtual size_t getSize() const = 0; - virtual int getDynamicSize() const { return 0; } - virtual void load(ESM::ESMReader &esm, const std::string &id) = 0; - - virtual bool eraseStatic(const std::string &id) {return false;} - virtual void clearDynamic() {} - - virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) const {} - - virtual void read (ESM::ESMReader& reader, const std::string& id) {} - ///< Read into dynamic storage - }; - - // moved from apps/openmw/mwworld/store.hpp - template - class SharedIterator - { - typedef typename std::vector::const_iterator Iter; - - Iter mIter; - - public: - SharedIterator() {} - - SharedIterator(const SharedIterator &orig) - : mIter(orig.mIter) - {} - - SharedIterator(const Iter &iter) - : mIter(iter) - {} - - SharedIterator &operator++() { - ++mIter; - return *this; - } - - SharedIterator operator++(int) { - SharedIterator iter = *this; - ++mIter; - - return iter; - } - - SharedIterator &operator--() { - --mIter; - return *this; - } - - SharedIterator operator--(int) { - SharedIterator iter = *this; - --mIter; - - return iter; - } - - bool operator==(const SharedIterator &x) const { - return mIter == x.mIter; - } - - bool operator!=(const SharedIterator &x) const { - return !(*this == x); - } - - const T &operator*() const { - return **mIter; - } - - const T *operator->() const { - return &(**mIter); - } - }; - - // interface class for sharing the autocalc component between OpenMW and OpenCS - template - class CommonStore : public StoreBase - { - - public: - typedef SharedIterator iterator; - - virtual iterator begin() const = 0; - - virtual iterator end() const = 0; - - virtual const T *find(const std::string &id) const = 0; - }; - - // interface class for sharing the autocalc component between OpenMW and OpenCS - class StoreWrap - { - - public: - StoreWrap() {} - virtual ~StoreWrap() {} - - virtual int findGmstInt(const std::string& gmst) const = 0; - - virtual float findGmstFloat(const std::string& gmst) const = 0; - - virtual const ESM::Skill *findSkill(int index) const = 0; - - virtual const ESM::MagicEffect* findMagicEffect(int id) const = 0; - - virtual const CommonStore& getSpells() const = 0; - }; -} -#endif // COMPONENTS_GAMEPLAY_STORE_H