1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 17:39:40 +00:00

Merge pull request #2980 from Assumeru/heritage

Make scripts inherit variables from the base record
This commit is contained in:
Bret Curtis 2020-08-03 13:10:35 +02:00 committed by GitHub
commit 1995e43b46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 8 deletions

View file

@ -7,6 +7,7 @@
Bug #3676: NiParticleColorModifier isn't applied properly Bug #3676: NiParticleColorModifier isn't applied properly
Bug #3714: Savegame fails to load due to conflict between SpellState and MagicEffects Bug #3714: Savegame fails to load due to conflict between SpellState and MagicEffects
Bug #4021: Attributes and skills are not stored as floats 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 #4623: Corprus implementation is incorrect
Bug #4764: Data race in osg ParticleSystem Bug #4764: Data race in osg ParticleSystem
Bug #4774: Guards are ignorant of an invisible player that tries to attack them Bug #4774: Guards are ignorant of an invisible player that tries to attack them

View file

@ -299,6 +299,15 @@ namespace MWScript
return iter->second->mLocals; 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) void GlobalScripts::updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated)
{ {
MatchPtrVisitor visitor(base); MatchPtrVisitor visitor(base);

View file

@ -82,6 +82,8 @@ namespace MWScript
///< If the script \a name has not been added as a global script yet, it is added ///< 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. /// 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); 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. ///< Update the Ptrs stored in mTarget. Should be called after the reference has been moved to a new cell.
}; };

View file

@ -1,4 +1,5 @@
#include "locals.hpp" #include "locals.hpp"
#include "globalscripts.hpp"
#include <components/esm/loadscpt.hpp> #include <components/esm/loadscpt.hpp>
#include <components/esm/variant.hpp> #include <components/esm/variant.hpp>
@ -33,15 +34,25 @@ namespace MWScript
if (mInitialised) if (mInitialised)
return false; return false;
const Compiler::Locals& locals = const Locals* global = MWBase::Environment::get().getScriptManager()->getGlobalScripts().getLocalsIfPresent(script.mId);
MWBase::Environment::get().getScriptManager()->getLocals (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.clear();
mShorts.resize (locals.get ('s').size(), 0); mShorts.resize (locals.get ('s').size(), 0);
mLongs.clear(); mLongs.clear();
mLongs.resize (locals.get ('l').size(), 0); mLongs.resize (locals.get ('l').size(), 0);
mFloats.clear(); mFloats.clear();
mFloats.resize (locals.get ('f').size(), 0); mFloats.resize (locals.get ('f').size(), 0);
}
mInitialised = true; mInitialised = true;
return true; return true;