2010-07-02 16:08:00 +00:00
|
|
|
#include "interpretercontext.hpp"
|
|
|
|
|
2010-07-05 10:30:45 +00:00
|
|
|
#include <cmath>
|
2014-07-25 05:59:50 +00:00
|
|
|
#include <sstream>
|
2010-07-02 16:08:00 +00:00
|
|
|
|
2014-07-25 05:59:50 +00:00
|
|
|
#include <components/compiler/locals.hpp>
|
|
|
|
|
2014-09-10 00:49:57 +00:00
|
|
|
#include <components/esm/cellid.hpp>
|
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2010-07-04 11:33:33 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-08 13:18:55 +00:00
|
|
|
#include "../mwbase/scriptmanager.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-12-21 18:09:31 +00:00
|
|
|
#include "../mwbase/inputmanager.hpp"
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2019-02-22 19:16:47 +00:00
|
|
|
#include "../mwworld/action.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2014-09-09 23:40:33 +00:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2014-10-24 16:49:38 +00:00
|
|
|
#include "../mwworld/containerstore.hpp"
|
2010-07-02 16:08:00 +00:00
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
|
2010-07-04 14:00:32 +00:00
|
|
|
#include "locals.hpp"
|
|
|
|
#include "globalscripts.hpp"
|
|
|
|
|
2010-07-02 16:08:00 +00:00
|
|
|
namespace MWScript
|
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
const MWWorld::Ptr InterpreterContext::getReferenceImp (
|
2014-01-09 01:14:08 +00:00
|
|
|
const std::string& id, bool activeOnly, bool doThrow) const
|
2010-07-09 17:32:17 +00:00
|
|
|
{
|
|
|
|
if (!id.empty())
|
|
|
|
{
|
2012-04-23 13:27:03 +00:00
|
|
|
return MWBase::Environment::get().getWorld()->getPtr (id, activeOnly);
|
2010-07-09 17:32:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-10 12:57:06 +00:00
|
|
|
if (mReference.isEmpty() && mGlobalScriptDesc)
|
|
|
|
mReference = mGlobalScriptDesc->getPtr();
|
2014-07-17 11:36:55 +00:00
|
|
|
|
2014-01-09 01:14:08 +00:00
|
|
|
if (mReference.isEmpty() && doThrow)
|
2020-05-10 12:57:06 +00:00
|
|
|
throw MissingImplicitRefError();
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-10 11:19:04 +00:00
|
|
|
return mReference;
|
2010-08-03 20:43:53 +00:00
|
|
|
}
|
2010-07-09 17:32:17 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
const Locals& InterpreterContext::getMemberLocals (std::string& id, bool global)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
if (global)
|
|
|
|
{
|
|
|
|
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().
|
|
|
|
getLocals (id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
const MWWorld::Ptr ptr = getReferenceImp (id, false);
|
2014-02-10 13:45:55 +00:00
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
id = ptr.getClass().getScript (ptr);
|
2014-02-10 13:45:55 +00:00
|
|
|
|
|
|
|
ptr.getRefData().setLocals (
|
|
|
|
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (id));
|
|
|
|
|
|
|
|
return ptr.getRefData().getLocals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Locals& InterpreterContext::getMemberLocals (std::string& id, bool global)
|
|
|
|
{
|
|
|
|
if (global)
|
|
|
|
{
|
|
|
|
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().
|
|
|
|
getLocals (id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
const MWWorld::Ptr ptr = getReferenceImp (id, false);
|
2014-02-10 13:45:55 +00:00
|
|
|
|
2014-05-22 18:37:22 +00:00
|
|
|
id = ptr.getClass().getScript (ptr);
|
2014-02-10 13:45:55 +00:00
|
|
|
|
|
|
|
ptr.getRefData().setLocals (
|
|
|
|
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (id));
|
|
|
|
|
|
|
|
return ptr.getRefData().getLocals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
MissingImplicitRefError::MissingImplicitRefError() : std::runtime_error("no implicit reference") {}
|
|
|
|
|
2014-07-25 05:59:50 +00:00
|
|
|
int InterpreterContext::findLocalVariableIndex (const std::string& scriptId,
|
|
|
|
const std::string& name, char type) const
|
|
|
|
{
|
|
|
|
int index = MWBase::Environment::get().getScriptManager()->getLocals (scriptId).
|
2014-08-24 09:58:08 +00:00
|
|
|
searchIndex (type, name);
|
2014-07-25 05:59:50 +00:00
|
|
|
|
|
|
|
if (index!=-1)
|
|
|
|
return index;
|
|
|
|
|
|
|
|
std::ostringstream stream;
|
|
|
|
|
|
|
|
stream << "Failed to access ";
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 's': stream << "short"; break;
|
|
|
|
case 'l': stream << "long"; break;
|
|
|
|
case 'f': stream << "float"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream << " member variable " << name << " in script " << scriptId;
|
|
|
|
|
|
|
|
throw std::runtime_error (stream.str().c_str());
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
InterpreterContext::InterpreterContext (MWScript::Locals *locals, const MWWorld::Ptr& reference)
|
|
|
|
: mLocals (locals), mReference (reference)
|
|
|
|
{}
|
2014-07-25 05:59:50 +00:00
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
InterpreterContext::InterpreterContext (std::shared_ptr<GlobalScriptDesc> globalScriptDesc)
|
|
|
|
: mLocals (&(globalScriptDesc->mLocals))
|
2014-07-18 07:57:47 +00:00
|
|
|
{
|
2020-05-10 12:57:06 +00:00
|
|
|
const MWWorld::Ptr* ptr = globalScriptDesc->getPtrIfPresent();
|
|
|
|
// A nullptr here signifies that the script's target has not yet been resolved after loading the game.
|
|
|
|
// Script targets are lazily resolved to MWWorld::Ptrs (which can, upon resolution, be empty)
|
|
|
|
// because scripts started through dialogue often don't use their implicit target.
|
|
|
|
if (ptr)
|
|
|
|
mReference = *ptr;
|
|
|
|
else
|
|
|
|
mGlobalScriptDesc = globalScriptDesc;
|
2014-07-18 07:57:47 +00:00
|
|
|
}
|
2010-07-02 16:08:00 +00:00
|
|
|
|
|
|
|
int InterpreterContext::getLocalShort (int index) const
|
|
|
|
{
|
|
|
|
if (!mLocals)
|
|
|
|
throw std::runtime_error ("local variables not available in this context");
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-02 16:08:00 +00:00
|
|
|
return mLocals->mShorts.at (index);
|
|
|
|
}
|
|
|
|
|
|
|
|
int InterpreterContext::getLocalLong (int index) const
|
|
|
|
{
|
|
|
|
if (!mLocals)
|
|
|
|
throw std::runtime_error ("local variables not available in this context");
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-02 16:08:00 +00:00
|
|
|
return mLocals->mLongs.at (index);
|
|
|
|
}
|
|
|
|
|
|
|
|
float InterpreterContext::getLocalFloat (int index) const
|
|
|
|
{
|
|
|
|
if (!mLocals)
|
|
|
|
throw std::runtime_error ("local variables not available in this context");
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-02 16:08:00 +00:00
|
|
|
return mLocals->mFloats.at (index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterpreterContext::setLocalShort (int index, int value)
|
|
|
|
{
|
|
|
|
if (!mLocals)
|
|
|
|
throw std::runtime_error ("local variables not available in this context");
|
|
|
|
|
|
|
|
mLocals->mShorts.at (index) = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterpreterContext::setLocalLong (int index, int value)
|
|
|
|
{
|
|
|
|
if (!mLocals)
|
|
|
|
throw std::runtime_error ("local variables not available in this context");
|
|
|
|
|
2010-08-03 20:43:53 +00:00
|
|
|
mLocals->mLongs.at (index) = value;
|
2010-07-02 16:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterpreterContext::setLocalFloat (int index, float value)
|
|
|
|
{
|
|
|
|
if (!mLocals)
|
|
|
|
throw std::runtime_error ("local variables not available in this context");
|
2010-08-03 20:43:53 +00:00
|
|
|
|
|
|
|
mLocals->mFloats.at (index) = value;
|
2010-07-02 16:08:00 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-02 16:08:00 +00:00
|
|
|
void InterpreterContext::messageBox (const std::string& message,
|
|
|
|
const std::vector<std::string>& buttons)
|
|
|
|
{
|
2015-01-10 22:21:39 +00:00
|
|
|
if (buttons.empty())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox (message);
|
|
|
|
else
|
|
|
|
MWBase::Environment::get().getWindowManager()->interactiveMessageBox(message, buttons);
|
2010-07-02 16:08:00 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2011-04-26 19:48:13 +00:00
|
|
|
void InterpreterContext::report (const std::string& message)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-04 10:29:28 +00:00
|
|
|
int InterpreterContext::getGlobalShort (const std::string& name) const
|
|
|
|
{
|
2013-11-28 08:10:38 +00:00
|
|
|
return MWBase::Environment::get().getWorld()->getGlobalInt (name);
|
2010-07-04 10:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int InterpreterContext::getGlobalLong (const std::string& name) const
|
|
|
|
{
|
2010-07-04 11:33:33 +00:00
|
|
|
// a global long is internally a float.
|
2013-11-28 08:10:38 +00:00
|
|
|
return MWBase::Environment::get().getWorld()->getGlobalInt (name);
|
2010-07-04 10:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float InterpreterContext::getGlobalFloat (const std::string& name) const
|
|
|
|
{
|
2013-11-28 08:10:38 +00:00
|
|
|
return MWBase::Environment::get().getWorld()->getGlobalFloat (name);
|
2010-07-04 10:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterpreterContext::setGlobalShort (const std::string& name, int value)
|
|
|
|
{
|
2013-11-28 08:13:54 +00:00
|
|
|
MWBase::Environment::get().getWorld()->setGlobalInt (name, value);
|
2010-07-04 10:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterpreterContext::setGlobalLong (const std::string& name, int value)
|
|
|
|
{
|
2013-11-28 08:13:54 +00:00
|
|
|
MWBase::Environment::get().getWorld()->setGlobalInt (name, value);
|
2010-07-04 10:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterpreterContext::setGlobalFloat (const std::string& name, float value)
|
|
|
|
{
|
2013-11-28 08:13:54 +00:00
|
|
|
MWBase::Environment::get().getWorld()->setGlobalFloat (name, value);
|
2010-07-04 10:29:28 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2013-12-10 14:22:38 +00:00
|
|
|
std::vector<std::string> InterpreterContext::getGlobals() const
|
2012-12-20 23:16:34 +00:00
|
|
|
{
|
2013-12-10 14:22:38 +00:00
|
|
|
const MWWorld::Store<ESM::Global>& globals =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Global>();
|
|
|
|
|
2020-07-30 16:57:25 +00:00
|
|
|
std::vector<std::string> ids;
|
|
|
|
for (auto& globalVariable : globals)
|
2013-12-10 14:22:38 +00:00
|
|
|
{
|
2020-07-30 16:57:25 +00:00
|
|
|
ids.emplace_back(globalVariable.mId);
|
2013-12-10 14:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
2012-12-20 23:16:34 +00:00
|
|
|
}
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2012-12-20 23:16:34 +00:00
|
|
|
char InterpreterContext::getGlobalType (const std::string& name) const
|
|
|
|
{
|
2013-01-03 08:55:48 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2012-12-20 23:16:34 +00:00
|
|
|
return world->getGlobalVariableType(name);
|
|
|
|
}
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2020-07-30 16:57:25 +00:00
|
|
|
std::string InterpreterContext::getActionBinding(const std::string& targetAction) const
|
2012-12-21 18:09:31 +00:00
|
|
|
{
|
2014-12-20 20:46:11 +00:00
|
|
|
MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
|
|
|
|
std::vector<int> actions = input->getActionKeySorting ();
|
2020-07-30 16:57:25 +00:00
|
|
|
for (const int action : actions)
|
2012-12-21 18:09:31 +00:00
|
|
|
{
|
2020-07-30 16:57:25 +00:00
|
|
|
std::string desc = input->getActionDescription (action);
|
2012-12-21 18:09:31 +00:00
|
|
|
if(desc == "")
|
|
|
|
continue;
|
|
|
|
|
2020-07-30 16:57:25 +00:00
|
|
|
if(desc == targetAction)
|
2014-12-20 20:46:11 +00:00
|
|
|
{
|
|
|
|
if(input->joystickLastUsed())
|
2020-07-30 16:57:25 +00:00
|
|
|
return input->getActionControllerBindingName(action);
|
2014-12-20 20:46:11 +00:00
|
|
|
else
|
2020-07-30 16:57:25 +00:00
|
|
|
return input->getActionKeyBindingName(action);
|
2014-12-20 20:46:11 +00:00
|
|
|
}
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
2012-12-20 23:16:34 +00:00
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
return "None";
|
|
|
|
}
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2018-09-16 16:47:51 +00:00
|
|
|
std::string InterpreterContext::getActorName() const
|
2012-12-21 18:09:31 +00:00
|
|
|
{
|
2018-09-16 16:47:51 +00:00
|
|
|
const MWWorld::Ptr& ptr = getReferenceImp();
|
|
|
|
if (ptr.getClass().isNpc())
|
|
|
|
{
|
|
|
|
const ESM::NPC* npc = ptr.get<ESM::NPC>()->mBase;
|
|
|
|
return npc->mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ESM::Creature* creature = ptr.get<ESM::Creature>()->mBase;
|
|
|
|
return creature->mName;
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
std::string InterpreterContext::getNPCRace() const
|
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
ESM::NPC npc = *getReferenceImp().get<ESM::NPC>()->mBase;
|
2013-03-17 03:20:30 +00:00
|
|
|
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npc.mRace);
|
|
|
|
return race->mName;
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
std::string InterpreterContext::getNPCClass() const
|
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
ESM::NPC npc = *getReferenceImp().get<ESM::NPC>()->mBase;
|
2013-03-17 03:20:30 +00:00
|
|
|
const ESM::Class* class_ = MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find(npc.mClass);
|
|
|
|
return class_->mName;
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string InterpreterContext::getNPCFaction() const
|
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
ESM::NPC npc = *getReferenceImp().get<ESM::NPC>()->mBase;
|
2013-03-17 03:20:30 +00:00
|
|
|
const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(npc.mFaction);
|
|
|
|
return faction->mName;
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string InterpreterContext::getNPCRank() const
|
|
|
|
{
|
2015-01-27 16:32:21 +00:00
|
|
|
const MWWorld::Ptr& ptr = getReferenceImp();
|
|
|
|
std::string faction = ptr.getClass().getPrimaryFaction(ptr);
|
|
|
|
if (faction.empty())
|
2014-10-28 15:07:37 +00:00
|
|
|
throw std::runtime_error("getNPCRank(): NPC is not in a faction");
|
|
|
|
|
2015-01-27 16:32:21 +00:00
|
|
|
int rank = ptr.getClass().getPrimaryFactionRank(ptr);
|
|
|
|
if (rank < 0 || rank > 9)
|
|
|
|
throw std::runtime_error("getNPCRank(): invalid rank");
|
2012-12-21 18:09:31 +00:00
|
|
|
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
const MWWorld::ESMStore &store = world->getStore();
|
2015-01-27 16:32:21 +00:00
|
|
|
const ESM::Faction *fact = store.get<ESM::Faction>().find(faction);
|
|
|
|
return fact->mRanks[rank];
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string InterpreterContext::getPCName() const
|
|
|
|
{
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2014-01-08 17:39:44 +00:00
|
|
|
ESM::NPC player = *world->getPlayerPtr().get<ESM::NPC>()->mBase;
|
2012-12-21 18:09:31 +00:00
|
|
|
return player.mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InterpreterContext::getPCRace() const
|
|
|
|
{
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2014-01-08 17:39:44 +00:00
|
|
|
std::string race = world->getPlayerPtr().get<ESM::NPC>()->mBase->mRace;
|
2013-01-03 08:55:48 +00:00
|
|
|
return world->getStore().get<ESM::Race>().find(race)->mName;
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string InterpreterContext::getPCClass() const
|
|
|
|
{
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2014-01-08 17:39:44 +00:00
|
|
|
std::string class_ = world->getPlayerPtr().get<ESM::NPC>()->mBase->mClass;
|
2013-01-03 08:55:48 +00:00
|
|
|
return world->getStore().get<ESM::Class>().find(class_)->mName;
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
std::string InterpreterContext::getPCRank() const
|
|
|
|
{
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2014-01-08 17:39:44 +00:00
|
|
|
MWWorld::Ptr player = world->getPlayerPtr();
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2015-01-27 16:32:21 +00:00
|
|
|
std::string factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp());
|
|
|
|
if (factionId.empty())
|
2014-10-28 15:07:37 +00:00
|
|
|
throw std::runtime_error("getPCRank(): NPC is not in a faction");
|
|
|
|
|
2014-10-05 14:47:55 +00:00
|
|
|
const std::map<std::string, int>& ranks = player.getClass().getNpcStats (player).getFactionRanks();
|
2015-01-27 16:32:21 +00:00
|
|
|
std::map<std::string, int>::const_iterator it = ranks.find(Misc::StringUtils::lowerCase(factionId));
|
2014-04-28 13:26:40 +00:00
|
|
|
int rank = -1;
|
|
|
|
if (it != ranks.end())
|
|
|
|
rank = it->second;
|
2012-12-21 18:09:31 +00:00
|
|
|
|
2014-04-28 13:30:57 +00:00
|
|
|
// If you are not in the faction, PcRank returns the first rank, for whatever reason.
|
|
|
|
// This is used by the dialogue when joining the Thieves Guild in Balmora.
|
|
|
|
if (rank == -1)
|
|
|
|
rank = 0;
|
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
const MWWorld::ESMStore &store = world->getStore();
|
|
|
|
const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId);
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2014-04-28 13:26:40 +00:00
|
|
|
if(rank < 0 || rank > 9) // there are only 10 ranks
|
2012-12-21 18:09:31 +00:00
|
|
|
return "";
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2014-04-28 13:26:40 +00:00
|
|
|
return faction->mRanks[rank];
|
2013-01-03 08:55:48 +00:00
|
|
|
}
|
2012-12-21 18:09:31 +00:00
|
|
|
|
|
|
|
std::string InterpreterContext::getPCNextRank() const
|
|
|
|
{
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2014-01-08 17:39:44 +00:00
|
|
|
MWWorld::Ptr player = world->getPlayerPtr();
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2015-01-27 16:32:21 +00:00
|
|
|
std::string factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp());
|
|
|
|
if (factionId.empty())
|
2014-10-28 15:07:37 +00:00
|
|
|
throw std::runtime_error("getPCNextRank(): NPC is not in a faction");
|
|
|
|
|
2014-10-05 14:47:55 +00:00
|
|
|
const std::map<std::string, int>& ranks = player.getClass().getNpcStats (player).getFactionRanks();
|
2015-01-27 16:32:21 +00:00
|
|
|
std::map<std::string, int>::const_iterator it = ranks.find(Misc::StringUtils::lowerCase(factionId));
|
2014-04-28 13:26:40 +00:00
|
|
|
int rank = -1;
|
|
|
|
if (it != ranks.end())
|
|
|
|
rank = it->second;
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2014-04-28 13:26:40 +00:00
|
|
|
++rank; // Next rank
|
2013-05-04 10:28:12 +00:00
|
|
|
|
2014-04-28 13:26:40 +00:00
|
|
|
// if we are already at max rank, there is no next rank
|
|
|
|
if (rank > 9)
|
|
|
|
rank = 9;
|
2013-05-04 10:28:12 +00:00
|
|
|
|
2014-04-28 13:26:40 +00:00
|
|
|
const MWWorld::ESMStore &store = world->getStore();
|
|
|
|
const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId);
|
|
|
|
|
Some PVS-Studio and cppcheck fixes
cppcheck:
[apps/esmtool/record.cpp:697]: (performance) Prefer prefix ++/-- operators for non-primitive types.
[apps/esmtool/record.cpp:1126]: (performance) Prefer prefix ++/-- operators for non-primitive types.
[apps/esmtool/record.cpp:1138]: (performance) Prefer prefix ++/-- operators for non-primitive types.
[apps/niftest/niftest.cpp:36]: (performance) Function parameter 'filename' should be passed by reference.
[apps/niftest/niftest.cpp:41]: (performance) Function parameter 'filename' should be passed by reference.
[apps/opencs/model/prefs/boolsetting.cpp:25]: (warning) Possible leak in public function. The pointer 'mWidget' is not deallocated before it is allocated.
[apps/opencs/model/prefs/shortcuteventhandler.cpp:52]: (warning) Return value of std::remove() ignored. Elements remain in container.
[apps/openmw/mwstate/quicksavemanager.cpp:5]: (performance) Variable 'mSaveName' is assigned in constructor body. Consider performing initialization in initialization list.
PVS-Studio:
apps/opencs/model/filter/parser.cpp 582 warn V560 A part of conditional expression is always true: allowPredefined.
apps/opencs/view/world/referencecreator.cpp 67 warn V547 Expression '!errors.empty()' is always false.
apps/opencs/view/world/referencecreator.cpp 74 warn V547 Expression '!errors.empty()' is always false.
apps/opencs/view/doc/loader.cpp 170 warn V560 A part of conditional expression is always true: !completed.
apps/opencs/view/doc/loader.cpp 170 warn V560 A part of conditional expression is always true: !error.empty().
apps/opencs/model/tools/pathgridcheck.cpp 32 err V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 32, 34.
apps/opencs/model/world/refidadapterimp.cpp 1376 err V547 Expression 'subColIndex < 3' is always true.
apps/openmw/mwgui/widgets.hpp 318 warn V703 It is odd that the 'mEnableRepeat' field in derived class 'MWScrollBar' overwrites field in base class 'ScrollBar'. Check lines: widgets.hpp:318, MyGUI_ScrollBar.h:179.
apps/openmw/mwgui/widgets.hpp 319 warn V703 It is odd that the 'mRepeatTriggerTime' field in derived class 'MWScrollBar' overwrites field in base class 'ScrollBar'. Check lines: widgets.hpp:319, MyGUI_ScrollBar.h:180.
apps/openmw/mwgui/widgets.hpp 320 warn V703 It is odd that the 'mRepeatStepTime' field in derived class 'MWScrollBar' overwrites field in base class 'ScrollBar'. Check lines: widgets.hpp:320, MyGUI_ScrollBar.h:181
apps/openmw/mwmechanics/actors.cpp 1425 warn V547 Expression '!detected' is always true.
apps/openmw/mwmechanics/character.cpp 2155 err V547 Expression 'mode == 0' is always true.
apps/openmw/mwmechanics/character.cpp 1192 warn V592 The expression was enclosed by parentheses twice: ((expression)). One pair of parentheses is unnecessary or misprint is present.
apps/openmw/mwmechanics/character.cpp 521 warn V560 A part of conditional expression is always true: (idle == mIdleState).
apps/openmw/mwmechanics/pathfinding.cpp 317 err V547 Expression 'mPath.size() >= 2' is always true.
apps/openmw/mwscript/interpretercontext.cpp 409 warn V560 A part of conditional expression is always false: rank > 9.
apps/openmw/mwgui/windowbase.cpp 28 warn V560 A part of conditional expression is always true: !visible.
apps/openmw/mwgui/journalwindow.cpp 561 warn V547 Expression '!mAllQuests' is always false.
apps/openmw/mwgui/referenceinterface.cpp 18 warn V571 Recurring check. The '!mPtr.isEmpty()' condition was already verified in line 16.
apps/openmw/mwworld/scene.cpp 463 warn V547 Expression 'adjustPlayerPos' is always true.
apps/openmw/mwworld/worldimp.cpp 409 err V766 An item with the same key '"sCompanionShare"' has already been added.
apps/openmw/mwworld/cellstore.cpp 691 warn V519 The 'state.mWaterLevel' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 689, 691.
apps/openmw/mwworld/weather.cpp 1125 warn V519 The 'mResult.mParticleEffect' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1123, 1125.
apps/openmw/mwworld/weather.cpp 1137 warn V519 The 'mResult.mParticleEffect' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1135, 1137.
apps/wizard/unshield/unshieldworker.cpp 475 warn V728 An excessive check can be simplified. The '(A && B) || (!A && !B)' expression is equivalent to the 'bool(A) == bool(B)' expression.
apps/wizard/installationpage.cpp 163 warn V735 Possibly an incorrect HTML. The "</p" closing tag was encountered, while the "</span" tag was expected.
components/fontloader/fontloader.cpp 427 err V547 Expression 'i == 1' is always true.
components/nifosg/nifloader.cpp 282 warn V519 The 'created' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 278, 282.
components/esm/loadregn.cpp 119 err V586 The 'clear' function is called twice for deallocation of the same resource. Check lines: 112, 119.
components/esm/cellref.cpp 178 warn V581 The conditional expressions of the 'if' statements situated alongside each other are identical. Check lines: 175, 178.
components/esmterrain/storage.cpp 235 warn V560 A part of conditional expression is always true: colStart == 0.
components/esmterrain/storage.cpp 237 warn V560 A part of conditional expression is always true: rowStart == 0.
2018-04-09 15:55:16 +00:00
|
|
|
if(rank < 0)
|
2014-04-28 13:26:40 +00:00
|
|
|
return "";
|
|
|
|
|
|
|
|
return faction->mRanks[rank];
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
int InterpreterContext::getPCBounty() const
|
|
|
|
{
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2014-01-08 17:39:44 +00:00
|
|
|
MWWorld::Ptr player = world->getPlayerPtr();
|
2014-05-22 18:37:22 +00:00
|
|
|
return player.getClass().getNpcStats (player).getBounty();
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
2013-01-03 08:55:48 +00:00
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
std::string InterpreterContext::getCurrentCellName() const
|
|
|
|
{
|
2013-11-26 10:39:58 +00:00
|
|
|
return MWBase::Environment::get().getWorld()->getCellName();
|
2012-12-21 18:09:31 +00:00
|
|
|
}
|
2012-12-20 23:16:34 +00:00
|
|
|
|
2014-06-12 22:01:29 +00:00
|
|
|
void InterpreterContext::executeActivation(MWWorld::Ptr ptr, MWWorld::Ptr actor)
|
2010-08-03 20:43:53 +00:00
|
|
|
{
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action = (ptr.getClass().activate(ptr, actor));
|
2014-06-12 22:01:29 +00:00
|
|
|
action->execute (actor);
|
2017-01-18 20:57:50 +00:00
|
|
|
if (action->getTarget() != MWWorld::Ptr() && action->getTarget() != ptr)
|
|
|
|
{
|
|
|
|
updatePtr(ptr, action->getTarget());
|
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
int InterpreterContext::getMemberShort (const std::string& id, const std::string& name,
|
|
|
|
bool global) const
|
2012-06-07 09:59:45 +00:00
|
|
|
{
|
2014-02-10 13:45:55 +00:00
|
|
|
std::string scriptId (id);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
const Locals& locals = getMemberLocals (scriptId, global);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-07-25 05:59:50 +00:00
|
|
|
return locals.mShorts[findLocalVariableIndex (scriptId, name, 's')];
|
2012-06-07 09:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
int InterpreterContext::getMemberLong (const std::string& id, const std::string& name,
|
|
|
|
bool global) const
|
2012-06-07 09:59:45 +00:00
|
|
|
{
|
2014-02-10 13:45:55 +00:00
|
|
|
std::string scriptId (id);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
const Locals& locals = getMemberLocals (scriptId, global);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-07-25 05:59:50 +00:00
|
|
|
return locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')];
|
2012-06-07 09:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
float InterpreterContext::getMemberFloat (const std::string& id, const std::string& name,
|
|
|
|
bool global) const
|
2012-06-07 09:59:45 +00:00
|
|
|
{
|
2014-02-10 13:45:55 +00:00
|
|
|
std::string scriptId (id);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
const Locals& locals = getMemberLocals (scriptId, global);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-07-25 05:59:50 +00:00
|
|
|
return locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')];
|
2012-06-07 09:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
void InterpreterContext::setMemberShort (const std::string& id, const std::string& name,
|
|
|
|
int value, bool global)
|
2012-06-07 09:59:45 +00:00
|
|
|
{
|
2014-02-10 13:45:55 +00:00
|
|
|
std::string scriptId (id);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
Locals& locals = getMemberLocals (scriptId, global);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-07-25 05:59:50 +00:00
|
|
|
locals.mShorts[findLocalVariableIndex (scriptId, name, 's')] = value;
|
2012-06-07 09:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
void InterpreterContext::setMemberLong (const std::string& id, const std::string& name, int value, bool global)
|
2012-06-07 09:59:45 +00:00
|
|
|
{
|
2014-02-10 13:45:55 +00:00
|
|
|
std::string scriptId (id);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
Locals& locals = getMemberLocals (scriptId, global);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-07-25 05:59:50 +00:00
|
|
|
locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')] = value;
|
2012-06-07 09:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
void InterpreterContext::setMemberFloat (const std::string& id, const std::string& name, float value, bool global)
|
2012-06-07 09:59:45 +00:00
|
|
|
{
|
2014-02-10 13:45:55 +00:00
|
|
|
std::string scriptId (id);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
Locals& locals = getMemberLocals (scriptId, global);
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2014-07-25 05:59:50 +00:00
|
|
|
locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')] = value;
|
2012-06-07 09:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 01:14:08 +00:00
|
|
|
MWWorld::Ptr InterpreterContext::getReference(bool required)
|
2010-07-03 15:59:30 +00:00
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
return getReferenceImp ("", true, required);
|
|
|
|
}
|
|
|
|
|
2015-09-30 08:30:50 +00:00
|
|
|
void InterpreterContext::updatePtr(const MWWorld::Ptr& base, const MWWorld::Ptr& updated)
|
2014-12-11 18:27:13 +00:00
|
|
|
{
|
2015-09-30 08:30:50 +00:00
|
|
|
if (!mReference.isEmpty() && base == mReference)
|
2017-01-18 20:55:47 +00:00
|
|
|
{
|
2014-12-11 18:27:13 +00:00
|
|
|
mReference = updated;
|
2017-01-29 12:29:53 +00:00
|
|
|
if (mLocals == &base.getRefData().getLocals())
|
|
|
|
mLocals = &mReference.getRefData().getLocals();
|
2017-01-18 20:55:47 +00:00
|
|
|
}
|
2014-12-11 18:27:13 +00:00
|
|
|
}
|
2010-07-02 16:08:00 +00:00
|
|
|
}
|