2010-07-04 12:55:55 +02:00
|
|
|
#include "compilercontext.hpp"
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
|
2012-08-08 15:18:55 +02:00
|
|
|
#include <components/compiler/locals.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm/records.hpp>
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/loaddial.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadscpt.hpp>
|
2012-08-08 15:18:55 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-08 15:18:55 +02:00
|
|
|
#include "../mwbase/scriptmanager.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwworld/class.hpp"
|
2015-10-06 14:30:32 +02:00
|
|
|
#include "../mwworld/manualref.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2010-07-04 12:55:55 +02:00
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
CompilerContext::CompilerContext(Type type)
|
|
|
|
: mType(type)
|
2010-07-04 12:55:55 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompilerContext::canDeclareLocals() const
|
|
|
|
{
|
|
|
|
return mType == Type_Full;
|
2012-04-23 15:27:03 +02:00
|
|
|
}
|
|
|
|
|
2010-07-04 12:55:55 +02:00
|
|
|
char CompilerContext::getGlobalType(const std::string& name) const
|
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
return MWBase::Environment::get().getWorld()->getGlobalVariableType(name);
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:45:55 +01:00
|
|
|
std::pair<char, bool> CompilerContext::getMemberType(const std::string& name, const std::string& id) const
|
2012-06-16 13:06:23 +02:00
|
|
|
{
|
2022-08-11 22:51:55 +02:00
|
|
|
std::string_view script;
|
2014-02-10 14:45:55 +01:00
|
|
|
bool reference = false;
|
2012-06-16 13:06:23 +02:00
|
|
|
|
2014-02-10 14:45:55 +01:00
|
|
|
if (const ESM::Script* scriptRecord
|
|
|
|
= MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().search(id))
|
|
|
|
{
|
|
|
|
script = scriptRecord->mId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-06 14:30:32 +02:00
|
|
|
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id);
|
2012-06-16 13:06:23 +02:00
|
|
|
|
2015-10-06 14:30:32 +02:00
|
|
|
script = ref.getPtr().getClass().getScript(ref.getPtr());
|
2014-02-10 14:45:55 +01:00
|
|
|
reference = true;
|
|
|
|
}
|
2012-06-16 13:06:23 +02:00
|
|
|
|
2014-02-10 14:45:55 +01:00
|
|
|
char type = ' ';
|
|
|
|
|
|
|
|
if (!script.empty())
|
2014-02-12 15:22:17 +01:00
|
|
|
type = MWBase::Environment::get().getScriptManager()->getLocals(script).getType(
|
|
|
|
Misc::StringUtils::lowerCase(name));
|
2014-02-10 14:45:55 +01:00
|
|
|
|
|
|
|
return std::make_pair(type, reference);
|
2012-06-16 13:06:23 +02:00
|
|
|
}
|
|
|
|
|
2010-07-09 20:35:34 +02:00
|
|
|
bool CompilerContext::isId(const std::string& name) const
|
|
|
|
{
|
2012-11-05 22:34:08 +04:00
|
|
|
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
|
|
|
return store.get<ESM::Activator>().search(name) || store.get<ESM::Potion>().search(name)
|
|
|
|
|| store.get<ESM::Apparatus>().search(name) || store.get<ESM::Armor>().search(name)
|
2012-11-06 13:43:48 +04:00
|
|
|
|| store.get<ESM::Book>().search(name) || store.get<ESM::Clothing>().search(name)
|
2012-11-05 22:34:08 +04:00
|
|
|
|| store.get<ESM::Container>().search(name) || store.get<ESM::Creature>().search(name)
|
|
|
|
|| store.get<ESM::Door>().search(name) || store.get<ESM::Ingredient>().search(name)
|
|
|
|
|| store.get<ESM::CreatureLevList>().search(name) || store.get<ESM::ItemLevList>().search(name)
|
2013-03-22 05:50:54 +01:00
|
|
|
|| store.get<ESM::Light>().search(name) || store.get<ESM::Lockpick>().search(name)
|
2012-11-05 22:34:08 +04:00
|
|
|
|| store.get<ESM::Miscellaneous>().search(name) || store.get<ESM::NPC>().search(name)
|
|
|
|
|| store.get<ESM::Probe>().search(name) || store.get<ESM::Repair>().search(name)
|
|
|
|
|| store.get<ESM::Static>().search(name) || store.get<ESM::Weapon>().search(name)
|
2015-10-08 14:01:29 +02:00
|
|
|
|| store.get<ESM::Script>().search(name);
|
2010-07-09 20:35:34 +02:00
|
|
|
}
|
2010-07-04 12:55:55 +02:00
|
|
|
}
|