diff --git a/CHANGELOG.md b/CHANGELOG.md index 321eb3c0cb..6974fd46c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Bug #3676: NiParticleColorModifier isn't applied properly Bug #3714: Savegame fails to load due to conflict between SpellState and MagicEffects Bug #4021: Attributes and skills are not stored as floats + Bug #4055: Local scripts don't inherit variables from their base record Bug #4623: Corprus implementation is incorrect Bug #4764: Data race in osg ParticleSystem Bug #4774: Guards are ignorant of an invisible player that tries to attack them diff --git a/apps/openmw/mwscript/globalscripts.cpp b/apps/openmw/mwscript/globalscripts.cpp index a7865f0ae8..41f153b280 100644 --- a/apps/openmw/mwscript/globalscripts.cpp +++ b/apps/openmw/mwscript/globalscripts.cpp @@ -299,6 +299,15 @@ namespace MWScript return iter->second->mLocals; } + const Locals* GlobalScripts::getLocalsIfPresent (const std::string& name) const + { + std::string name2 = ::Misc::StringUtils::lowerCase (name); + auto iter = mScripts.find (name2); + if (iter==mScripts.end()) + return nullptr; + return &iter->second->mLocals; + } + void GlobalScripts::updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated) { MatchPtrVisitor visitor(base); diff --git a/apps/openmw/mwscript/globalscripts.hpp b/apps/openmw/mwscript/globalscripts.hpp index 36d89a7eb7..c5c5a9a452 100644 --- a/apps/openmw/mwscript/globalscripts.hpp +++ b/apps/openmw/mwscript/globalscripts.hpp @@ -82,6 +82,8 @@ namespace MWScript ///< If the script \a name has not been added as a global script yet, it is added /// automatically, but is not set to running state. + const Locals* getLocalsIfPresent (const std::string& name) const; + void updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated); ///< Update the Ptrs stored in mTarget. Should be called after the reference has been moved to a new cell. }; diff --git a/apps/openmw/mwscript/locals.cpp b/apps/openmw/mwscript/locals.cpp index 6992005907..381d73ec86 100644 --- a/apps/openmw/mwscript/locals.cpp +++ b/apps/openmw/mwscript/locals.cpp @@ -1,4 +1,5 @@ #include "locals.hpp" +#include "globalscripts.hpp" #include #include @@ -33,15 +34,25 @@ namespace MWScript if (mInitialised) return false; - const Compiler::Locals& locals = - MWBase::Environment::get().getScriptManager()->getLocals (script.mId); + const Locals* global = MWBase::Environment::get().getScriptManager()->getGlobalScripts().getLocalsIfPresent(script.mId); + if(global) + { + mShorts = global->mShorts; + mLongs = global->mLongs; + mFloats = global->mFloats; + } + else + { + const Compiler::Locals& locals = + MWBase::Environment::get().getScriptManager()->getLocals (script.mId); - mShorts.clear(); - mShorts.resize (locals.get ('s').size(), 0); - mLongs.clear(); - mLongs.resize (locals.get ('l').size(), 0); - mFloats.clear(); - mFloats.resize (locals.get ('f').size(), 0); + mShorts.clear(); + mShorts.resize (locals.get ('s').size(), 0); + mLongs.clear(); + mLongs.resize (locals.get ('l').size(), 0); + mFloats.clear(); + mFloats.resize (locals.get ('f').size(), 0); + } mInitialised = true; return true;