diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index ecb230f58c..856b00e909 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -130,7 +130,7 @@ int CSMWorld::Data::count (RecordBase::State state, const CollectionBase& collec } CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourcesManager) -: mEncoder (encoding), mPathgrids (mCells), mRefs (mCells), mReferenceables(self()), +: mEncoder (encoding), mPathgrids (mCells), mReferenceables(self()), mRefs (mCells), mResourcesManager (resourcesManager), mReader (0), mDialogue (0), mReaderIndex(0) { int index = 0; @@ -1526,7 +1526,7 @@ CSMWorld::NpcStats* CSMWorld::Data::npcAutoCalculate(const ESM::NPC& npc) const if (autoCalc) level = npc.mNpdt12.mLevel; - CSMWorld::NpcStats *stats = new CSMWorld::NpcStats(); + std::auto_ptr stats (new CSMWorld::NpcStats()); CSStore store(mGmsts, mSkills, mMagicEffects, mSpells); @@ -1547,7 +1547,7 @@ CSMWorld::NpcStats* CSMWorld::Data::npcAutoCalculate(const ESM::NPC& npc) const for (std::vector::const_iterator it = npc.mSpells.mList.begin(); it != npc.mSpells.mList.end(); ++it) { - stats->addSpells(*it); + stats->addSpell(*it); } } @@ -1605,8 +1605,11 @@ CSMWorld::NpcStats* CSMWorld::Data::npcAutoCalculate(const ESM::NPC& npc) const } } - emit cacheNpcStats (npc.mId, stats); - return stats; + if (stats.get() == 0) + return 0; + + emit cacheNpcStats (npc.mId, stats.release()); + return stats.release(); } void CSMWorld::Data::cacheNpcStatsEvent (const std::string& id, CSMWorld::NpcStats *stats) diff --git a/apps/opencs/model/world/npcstats.cpp b/apps/opencs/model/world/npcstats.cpp index da14b473e1..5b84849348 100644 --- a/apps/opencs/model/world/npcstats.cpp +++ b/apps/opencs/model/world/npcstats.cpp @@ -45,7 +45,7 @@ namespace CSMWorld mAttr[index] = value; } - void NpcStats::addSpells(std::string id) + void NpcStats::addSpell(const std::string& id) { struct SpellInfo info; info.mName = id; diff --git a/apps/opencs/model/world/npcstats.hpp b/apps/opencs/model/world/npcstats.hpp index 4d9be149fb..8cefe586fc 100644 --- a/apps/opencs/model/world/npcstats.hpp +++ b/apps/opencs/model/world/npcstats.hpp @@ -43,7 +43,7 @@ namespace CSMWorld virtual void setAttribute(int index, unsigned char value); - virtual void addSpells(std::string id); + virtual void addSpell(const std::string& id); void addPowers(const std::string& id, int type); diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 64ed868a13..3b0234a252 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -74,7 +74,7 @@ namespace virtual void setAttribute(int index, unsigned char value) { mNpcStats.setAttribute(index, value); } - virtual void addSpells(std::string id) { mNpcStats.getSpells().add(id); } + virtual void addSpell(const std::string& id) { mNpcStats.getSpells().add(id); } virtual unsigned char getBaseSkill(int index) const { return mNpcStats.getSkill(index).getBase(); } diff --git a/components/autocalc/autocalc.cpp b/components/autocalc/autocalc.cpp index 78cd549ca4..122d19763e 100644 --- a/components/autocalc/autocalc.cpp +++ b/components/autocalc/autocalc.cpp @@ -11,7 +11,6 @@ #include "autocalcspell.hpp" -// Most of the code in this file was moved from apps/openmw/mwclass/npc.cpp namespace { int is_even(double d) @@ -117,7 +116,7 @@ namespace AutoCalc int index = class_->mData.mSkills[i2][i]; if (index >= 0 && index < ESM::Skill::Length) { - stats.setBaseSkill (index, stats.getBaseSkill(index) + bonus); + stats.setBaseSkill (index, bonus); } } } @@ -168,7 +167,7 @@ namespace AutoCalc } } - unsigned short autoCalculateHealth(int level, const ESM::Class *class_, StatsBase& stats) + unsigned short autoCalculateHealth(int level, const ESM::Class *class_, const StatsBase& stats) { // initial health int strength = stats.getBaseAttribute(ESM::Attribute::Strength); @@ -200,7 +199,7 @@ namespace AutoCalc std::vector spells = autoCalcNpcSpells(skills, attributes, race, store); for (std::vector::iterator it = spells.begin(); it != spells.end(); ++it) - stats.addSpells(*it); + stats.addSpell(*it); } StatsBase::StatsBase() {} diff --git a/components/autocalc/autocalc.hpp b/components/autocalc/autocalc.hpp index 3f4b6bae16..5cfe06b426 100644 --- a/components/autocalc/autocalc.hpp +++ b/components/autocalc/autocalc.hpp @@ -27,7 +27,7 @@ namespace AutoCalc virtual void setAttribute(int index, unsigned char value) = 0; - virtual void addSpells(std::string id) = 0; + virtual void addSpell(const std::string& id) = 0; virtual unsigned char getBaseSkill(int index) const = 0; @@ -40,7 +40,7 @@ namespace AutoCalc void autoCalcSkillsImpl (const ESM::NPC* npc, 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); + unsigned short autoCalculateHealth(int level, const ESM::Class *class_, const StatsBase& stats); void autoCalculateSpells(const ESM::Race *race, StatsBase& stats, StoreCommon *store); } diff --git a/components/autocalc/autocalcspell.cpp b/components/autocalc/autocalcspell.cpp index 01c25a6952..78499a0927 100644 --- a/components/autocalc/autocalcspell.cpp +++ b/components/autocalc/autocalcspell.cpp @@ -13,7 +13,6 @@ #include "autocalc.hpp" -// Most of the code in this file was moved from apps/openmw/mwmechanics/autocalcspell.cpp namespace AutoCalc { diff --git a/components/autocalc/store.hpp b/components/autocalc/store.hpp index 67061eef9c..9a798a5ce8 100644 --- a/components/autocalc/store.hpp +++ b/components/autocalc/store.hpp @@ -4,15 +4,8 @@ #include #include -namespace Loading -{ - class Listener; -} - namespace ESM { - class ESMWriter; - class ESMReader; struct Spell; struct Skill; struct MagicEffect;