1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 12:42:11 +00:00
OpenMW/apps/openmw/mwscript/compilercontext.cpp
Emanuel Guevel 1e4a854433 Remove static method MWWorld::Class::get(&Ptr)
It was just adding a level of indirection to Ptr.getClass().
All the call were replaced by that instead. The number of lines changed
is important, but the change itself is trivial, so everything should be
fine. :)
2014-05-22 20:50:00 +02:00

99 lines
3.1 KiB
C++

#include "compilercontext.hpp"
#include "../mwworld/esmstore.hpp"
#include <components/esm/loaddial.hpp>
#include <components/compiler/locals.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwworld/class.hpp"
namespace MWScript
{
CompilerContext::CompilerContext (Type type)
: mType (type)
{}
bool CompilerContext::canDeclareLocals() const
{
return mType==Type_Full;
}
char CompilerContext::getGlobalType (const std::string& name) const
{
return MWBase::Environment::get().getWorld()->getGlobalVariableType (name);
}
std::pair<char, bool> CompilerContext::getMemberType (const std::string& name,
const std::string& id) const
{
std::string script;
bool reference = false;
if (const ESM::Script *scriptRecord =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().search (id))
{
script = scriptRecord->mId;
}
else
{
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPtr (id, false);
script = ptr.getClass().getScript (ptr);
reference = true;
}
char type = ' ';
if (!script.empty())
type = MWBase::Environment::get().getScriptManager()->getLocals (script).getType (
Misc::StringUtils::lowerCase (name));
return std::make_pair (type, reference);
}
bool CompilerContext::isId (const std::string& name) const
{
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) ||
store.get<ESM::Book>().search (name) ||
store.get<ESM::Clothing>().search (name) ||
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) ||
store.get<ESM::Light>().search (name) ||
store.get<ESM::Lockpick>().search (name) ||
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);
}
bool CompilerContext::isJournalId (const std::string& name) const
{
const MWWorld::ESMStore &store =
MWBase::Environment::get().getWorld()->getStore();
const ESM::Dialogue *topic = store.get<ESM::Dialogue>().search (name);
return topic && topic->mType==ESM::Dialogue::Journal;
}
}