From 77e03f0f31d1bb6705a1fe56090eb4517b2f65c2 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 21 Jul 2010 15:01:35 +0200 Subject: [PATCH] fixed global variable search to properly handle injected variables (DaysPassed) --- apps/openmw/mwscript/compilercontext.cpp | 14 +------------- apps/openmw/mwworld/globals.cpp | 10 ++++++++++ apps/openmw/mwworld/globals.hpp | 3 +++ apps/openmw/mwworld/world.cpp | 5 +++++ apps/openmw/mwworld/world.hpp | 3 +++ 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwscript/compilercontext.cpp b/apps/openmw/mwscript/compilercontext.cpp index 5e4882f259..de00353caf 100644 --- a/apps/openmw/mwscript/compilercontext.cpp +++ b/apps/openmw/mwscript/compilercontext.cpp @@ -17,19 +17,7 @@ namespace MWScript char CompilerContext::getGlobalType (const std::string& name) const { - if (const ESM::Global *global = mEnvironment.mWorld->getStore().globals.find (name)) - { - switch (global->type) - { - case ESM::VT_Short: return 's'; - case ESM::VT_Int: return 'l'; - case ESM::VT_Float: return 'f'; - - default: return ' '; - } - } - - return ' '; + return mEnvironment.mWorld->getGlobalVariableType (name); } bool CompilerContext::isId (const std::string& name) const diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index acaa4243d9..b20a678bcb 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -145,5 +145,15 @@ namespace MWWorld default: throw std::runtime_error ("unsupported global variable type"); } } + + char Globals::getType (const std::string& name) const + { + Collection::const_iterator iter = mVariables.find (name); + + if (iter==mVariables.end()) + return ' '; + + return iter->second.first; + } } diff --git a/apps/openmw/mwworld/globals.hpp b/apps/openmw/mwworld/globals.hpp index f946b8d14e..6aa54ade29 100644 --- a/apps/openmw/mwworld/globals.hpp +++ b/apps/openmw/mwworld/globals.hpp @@ -53,6 +53,9 @@ namespace MWWorld float getFloat (const std::string& name) const; ///< Get value independently from real type. + + char getType (const std::string& name) const; + ///< If there is no global variable with this name, ' ' is returned. }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 301111d060..7c806230a5 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -228,6 +228,11 @@ namespace MWWorld return (*mGlobalVariables)[name]; } + char World::getGlobalVariableType (const std::string& name) const + { + return mGlobalVariables->getType (name); + } + Ptr World::getPtr (const std::string& name, bool activeOnly) { // the player is always in an active cell. diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index d94e9d766d..dda80054a1 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -82,6 +82,9 @@ namespace MWWorld Globals::Data& getGlobalVariable (const std::string& name); + char getGlobalVariableType (const std::string& name) const; + ///< Return ' ', if there is no global variable with this name. + Ptr getPtr (const std::string& name, bool activeOnly); ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do non search inactive cells.