2010-07-02 16:08:00 +00:00
|
|
|
#include "interpretercontext.hpp"
|
|
|
|
|
2010-07-05 10:30:45 +00:00
|
|
|
#include <cmath>
|
2010-07-02 16:08:00 +00:00
|
|
|
#include <stdexcept>
|
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>
|
|
|
|
|
2017-04-24 16:46:12 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Include additional headers for multiplayer purposes
|
|
|
|
*/
|
2019-08-19 18:39:33 +00:00
|
|
|
#include <components/openmw-mp/TimedLog.hpp>
|
2016-10-26 09:29:32 +00:00
|
|
|
#include "../mwmp/Main.hpp"
|
2016-12-16 08:59:15 +00:00
|
|
|
#include "../mwmp/Networking.hpp"
|
2017-07-13 06:46:30 +00:00
|
|
|
#include "../mwmp/LocalPlayer.hpp"
|
2018-05-12 21:42:24 +00:00
|
|
|
#include "../mwmp/ObjectList.hpp"
|
2018-07-22 22:39:43 +00:00
|
|
|
#include "../mwmp/ScriptController.hpp"
|
2017-04-24 16:46:12 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2016-10-26 09:29:32 +00:00
|
|
|
|
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
|
|
|
MWWorld::Ptr InterpreterContext::getReferenceImp (
|
2014-01-09 01:14:08 +00:00
|
|
|
const std::string& id, bool activeOnly, bool doThrow)
|
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
|
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
if (mReference.isEmpty() && !mTargetId.empty())
|
|
|
|
mReference =
|
|
|
|
MWBase::Environment::get().getWorld()->searchPtr (mTargetId, false);
|
|
|
|
|
2014-01-09 01:14:08 +00:00
|
|
|
if (mReference.isEmpty() && doThrow)
|
2010-07-09 17:32:17 +00:00
|
|
|
throw std::runtime_error ("no implicit reference");
|
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
|
|
|
}
|
|
|
|
|
2018-07-22 21:46:07 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Used for setting and checking the type of this InterpreterContext
|
|
|
|
*/
|
|
|
|
unsigned short InterpreterContext::getContextType() const
|
|
|
|
{
|
|
|
|
return mContextType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterpreterContext::setContextType(unsigned short contextType)
|
|
|
|
{
|
|
|
|
mContextType = contextType;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
if (mReference.isEmpty() && !mTargetId.empty())
|
|
|
|
mReference =
|
|
|
|
MWBase::Environment::get().getWorld()->searchPtr (mTargetId, false);
|
|
|
|
|
2014-01-09 01:14:08 +00:00
|
|
|
if (mReference.isEmpty() && doThrow)
|
2010-07-09 17:32:17 +00:00
|
|
|
throw std::runtime_error ("no implicit reference");
|
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
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
InterpreterContext::InterpreterContext (
|
2017-04-20 11:36:14 +00:00
|
|
|
MWScript::Locals *locals, const MWWorld::Ptr& reference, const std::string& targetId)
|
2016-02-26 11:59:35 +00:00
|
|
|
: mLocals (locals), mReference (reference), mTargetId (targetId)
|
2014-07-18 07:57:47 +00:00
|
|
|
{
|
|
|
|
// If we run on a reference (local script, dialogue script or console with object
|
|
|
|
// selected), store the ID of that reference store it so it can be inherited by
|
|
|
|
// targeted scripts started from this one.
|
|
|
|
if (targetId.empty() && !reference.isEmpty())
|
2015-12-18 15:58:08 +00:00
|
|
|
mTargetId = reference.getCellRef().getRefId();
|
2017-01-27 14:01:53 +00:00
|
|
|
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Boolean used to check whether value change packets should be sent for the
|
|
|
|
script being processed by the InterpreterContext
|
|
|
|
*/
|
2017-01-27 14:01:53 +00:00
|
|
|
sendPackets = false;
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
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;
|
2016-10-25 19:44:15 +00:00
|
|
|
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_SCRIPT_LOCAL_SHORT packet every time a local short changes its value
|
|
|
|
in a script approved for packet sending
|
|
|
|
*/
|
2016-10-25 19:44:15 +00:00
|
|
|
if (sendPackets)
|
2016-10-26 09:29:32 +00:00
|
|
|
{
|
2018-05-12 21:42:24 +00:00
|
|
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
|
|
|
objectList->reset();
|
2018-07-22 22:39:43 +00:00
|
|
|
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
|
2018-05-12 21:42:24 +00:00
|
|
|
objectList->addScriptLocalShort(mReference, index, value);
|
|
|
|
objectList->sendScriptLocalShort();
|
2016-10-26 09:29:32 +00:00
|
|
|
}
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2010-07-02 16:08:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2016-10-26 09:29:32 +00:00
|
|
|
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_SCRIPT_LOCAL_FLOAT packet every time a local float changes its value
|
|
|
|
to one without decimals (to avoid packet spam for timers) in a script approved
|
|
|
|
for packet sending
|
|
|
|
*/
|
2016-10-26 09:29:32 +00:00
|
|
|
if (sendPackets && value == (int) value)
|
|
|
|
{
|
2018-05-12 21:42:24 +00:00
|
|
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
|
|
|
objectList->reset();
|
2018-07-22 22:39:43 +00:00
|
|
|
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
|
2018-05-12 21:42:24 +00:00
|
|
|
objectList->addScriptLocalFloat(mReference, index, value);
|
|
|
|
objectList->sendScriptLocalFloat();
|
2016-10-26 09:29:32 +00:00
|
|
|
}
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
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
|
|
|
bool InterpreterContext::menuMode()
|
|
|
|
{
|
2018-05-26 02:11:41 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp change (major)
|
2016-10-25 14:48:00 +00:00
|
|
|
|
2018-05-26 02:11:41 +00:00
|
|
|
Being in a menu should not pause scripts in multiplayer, so always return false
|
2016-10-25 14:48:00 +00:00
|
|
|
*/
|
2018-05-26 02:11:41 +00:00
|
|
|
//return MWBase::Environment::get().getWindowManager()->isGuiMode();
|
2017-02-14 17:31:56 +00:00
|
|
|
return false;
|
2018-05-26 02:11:41 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp change (major)
|
|
|
|
*/
|
2010-07-04 10:29:28 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2019-09-15 13:10:09 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Avoid setting a global to a value it already is, preventing packet spam
|
|
|
|
*/
|
2019-09-23 04:55:16 +00:00
|
|
|
if (getGlobalShort(name) == value) return;
|
2019-09-15 13:10:09 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
2020-01-04 07:56:37 +00:00
|
|
|
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global short changes its value as long as
|
2019-09-14 06:37:19 +00:00
|
|
|
it is being set in a script that has been approved for packet sending or the global itself
|
|
|
|
has been set to always be synchronized
|
2017-02-26 14:59:53 +00:00
|
|
|
*/
|
2019-09-14 06:37:19 +00:00
|
|
|
if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
|
2016-10-26 09:29:32 +00:00
|
|
|
{
|
2020-01-04 07:56:37 +00:00
|
|
|
mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value);
|
2016-10-26 09:29:32 +00:00
|
|
|
}
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2016-10-26 09:29:32 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2020-01-04 07:56:37 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Avoid setting a global to a value it already is, preventing packet spam
|
|
|
|
*/
|
|
|
|
if (getGlobalLong(name) == value) return;
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global short changes its value as long as
|
|
|
|
it is being set in a script that has been approved for packet sending or the global itself
|
|
|
|
has been set to always be synchronized
|
|
|
|
*/
|
|
|
|
if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
|
|
|
|
{
|
|
|
|
mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
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)
|
|
|
|
{
|
2020-01-04 07:56:37 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Avoid setting a global to a value it already is, preventing packet spam
|
|
|
|
*/
|
|
|
|
if (getGlobalFloat(name) == value) return;
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global short changes its value as long as
|
|
|
|
it is being set in a script that has been approved for packet sending or the global itself
|
|
|
|
has been set to always be synchronized
|
|
|
|
*/
|
|
|
|
if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
|
|
|
|
{
|
|
|
|
mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
std::vector<std::string> ids;
|
|
|
|
|
|
|
|
const MWWorld::Store<ESM::Global>& globals =
|
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Global>();
|
|
|
|
|
|
|
|
for (MWWorld::Store<ESM::Global>::iterator iter = globals.begin(); iter!=globals.end();
|
|
|
|
++iter)
|
|
|
|
{
|
|
|
|
ids.push_back (iter->mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-12-21 18:09:31 +00:00
|
|
|
std::string InterpreterContext::getActionBinding(const std::string& action) const
|
|
|
|
{
|
2014-12-20 20:46:11 +00:00
|
|
|
MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
|
|
|
|
std::vector<int> actions = input->getActionKeySorting ();
|
2012-12-21 18:09:31 +00:00
|
|
|
for (std::vector<int>::const_iterator it = actions.begin(); it != actions.end(); ++it)
|
|
|
|
{
|
2014-12-20 20:46:11 +00:00
|
|
|
std::string desc = input->getActionDescription (*it);
|
2012-12-21 18:09:31 +00:00
|
|
|
if(desc == "")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(desc == action)
|
2014-12-20 20:46:11 +00:00
|
|
|
{
|
|
|
|
if(input->joystickLastUsed())
|
|
|
|
return input->getActionControllerBindingName(*it);
|
|
|
|
else
|
|
|
|
return input->getActionKeyBindingName (*it);
|
|
|
|
}
|
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
|
|
|
|
2010-07-07 18:14:50 +00:00
|
|
|
bool InterpreterContext::isScriptRunning (const std::string& name) const
|
2010-07-04 14:00:32 +00:00
|
|
|
{
|
2012-04-23 13:27:03 +00:00
|
|
|
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning (name);
|
2010-07-04 14:00:32 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2014-07-15 11:26:04 +00:00
|
|
|
void InterpreterContext::startScript (const std::string& name, const std::string& targetId)
|
2010-07-04 14:00:32 +00:00
|
|
|
{
|
2014-07-15 11:26:04 +00:00
|
|
|
MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript (name, targetId);
|
2010-07-04 14:00:32 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-04 14:00:32 +00:00
|
|
|
void InterpreterContext::stopScript (const std::string& name)
|
|
|
|
{
|
2012-04-23 13:27:03 +00:00
|
|
|
MWBase::Environment::get().getScriptManager()->getGlobalScripts().removeScript (name);
|
2010-07-04 14:00:32 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-09 18:55:39 +00:00
|
|
|
float InterpreterContext::getDistance (const std::string& name, const std::string& id) const
|
2010-07-05 10:30:45 +00:00
|
|
|
{
|
2014-06-16 14:34:00 +00:00
|
|
|
// NOTE: id may be empty, indicating an implicit reference
|
|
|
|
|
|
|
|
MWWorld::Ptr ref2;
|
|
|
|
|
|
|
|
if (id.empty())
|
2014-07-17 11:36:55 +00:00
|
|
|
ref2 = getReferenceImp();
|
2014-06-16 14:34:00 +00:00
|
|
|
else
|
2014-09-09 23:40:33 +00:00
|
|
|
ref2 = MWBase::Environment::get().getWorld()->getPtr(id, false);
|
2014-06-16 14:34:00 +00:00
|
|
|
|
2014-10-24 16:49:38 +00:00
|
|
|
if (ref2.getContainerStore()) // is the object contained?
|
|
|
|
{
|
|
|
|
MWWorld::Ptr container = MWBase::Environment::get().getWorld()->findContainer(ref2);
|
|
|
|
|
|
|
|
if (!container.isEmpty())
|
|
|
|
ref2 = container;
|
|
|
|
else
|
|
|
|
throw std::runtime_error("failed to find container ptr");
|
|
|
|
}
|
|
|
|
|
2014-09-09 23:40:33 +00:00
|
|
|
const MWWorld::Ptr ref = MWBase::Environment::get().getWorld()->getPtr(name, false);
|
2014-04-28 17:23:25 +00:00
|
|
|
|
2014-09-09 23:40:33 +00:00
|
|
|
// If the objects are in different worldspaces, return a large value (just like vanilla)
|
2018-01-11 01:48:05 +00:00
|
|
|
if (!ref.isInCell() || !ref2.isInCell() || ref.getCell()->getCell()->getCellId().mWorldspace != ref2.getCell()->getCell()->getCellId().mWorldspace)
|
2014-10-12 21:26:03 +00:00
|
|
|
return std::numeric_limits<float>::max();
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-05 10:30:45 +00:00
|
|
|
double diff[3];
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2011-11-08 00:08:00 +00:00
|
|
|
const float* const pos1 = ref.getRefData().getPosition().pos;
|
|
|
|
const float* const pos2 = ref2.getRefData().getPosition().pos;
|
2010-08-03 20:43:53 +00:00
|
|
|
for (int i=0; i<3; ++i)
|
2011-11-08 00:08:00 +00:00
|
|
|
diff[i] = pos1[i] - pos2[i];
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2015-03-08 00:07:29 +00:00
|
|
|
return static_cast<float>(std::sqrt(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]));
|
2010-07-05 10:30:45 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +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
|
|
|
}
|
|
|
|
|
2010-07-06 10:06:50 +00:00
|
|
|
float InterpreterContext::getSecondsPassed() const
|
|
|
|
{
|
2012-04-23 13:27:03 +00:00
|
|
|
return MWBase::Environment::get().getFrameDuration();
|
2010-07-06 10:06:50 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-09 17:32:17 +00:00
|
|
|
bool InterpreterContext::isDisabled (const std::string& id) const
|
2010-07-09 14:07:03 +00:00
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
const MWWorld::Ptr ref = getReferenceImp (id, false);
|
2010-07-10 11:19:04 +00:00
|
|
|
return !ref.getRefData().isEnabled();
|
2010-07-09 14:07:03 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-09 17:32:17 +00:00
|
|
|
void InterpreterContext::enable (const std::string& id)
|
2010-07-09 14:07:03 +00:00
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
MWWorld::Ptr ref = getReferenceImp (id, false);
|
2017-07-13 06:46:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_OBJECT_STATE packet whenever an object is enabled, as long as
|
2019-01-15 12:26:00 +00:00
|
|
|
the player is logged in on the server, the object is still disabled, and our last
|
|
|
|
packet regarding its state did not already attempt to enable it (to prevent
|
|
|
|
packet spam)
|
2017-07-13 06:46:30 +00:00
|
|
|
*/
|
2018-10-13 12:36:13 +00:00
|
|
|
if (mwmp::Main::get().getLocalPlayer()->isLoggedIn())
|
2017-07-13 06:46:30 +00:00
|
|
|
{
|
2019-01-15 12:26:00 +00:00
|
|
|
if (ref.isInCell() && !ref.getRefData().isEnabled() &&
|
|
|
|
ref.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Enabled)
|
2017-07-20 14:01:04 +00:00
|
|
|
{
|
2019-01-15 12:26:00 +00:00
|
|
|
ref.getRefData().setLastCommunicatedState(MWWorld::RefData::StateCommunication::Enabled);
|
|
|
|
|
2018-05-12 21:42:24 +00:00
|
|
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
|
|
|
objectList->reset();
|
2018-07-22 22:39:43 +00:00
|
|
|
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
|
2018-05-12 21:42:24 +00:00
|
|
|
objectList->addObjectState(ref, true);
|
|
|
|
objectList->sendObjectState();
|
2017-07-20 14:01:04 +00:00
|
|
|
}
|
2017-07-13 06:46:30 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2017-07-20 14:01:04 +00:00
|
|
|
|
2018-07-08 00:31:48 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp change (major)
|
|
|
|
|
|
|
|
Disable unilateral state enabling on this client and expect the server's reply to our
|
|
|
|
packet to do it instead
|
|
|
|
*/
|
|
|
|
//MWBase::Environment::get().getWorld()->enable (ref);
|
|
|
|
/*
|
|
|
|
End of tes3mp change (major)
|
|
|
|
*/
|
2010-07-09 14:07:03 +00:00
|
|
|
}
|
2010-08-03 20:43:53 +00:00
|
|
|
|
2010-07-09 17:32:17 +00:00
|
|
|
void InterpreterContext::disable (const std::string& id)
|
2010-07-09 14:07:03 +00:00
|
|
|
{
|
2014-07-17 11:36:55 +00:00
|
|
|
MWWorld::Ptr ref = getReferenceImp (id, false);
|
2017-07-13 06:46:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
2019-01-15 12:26:00 +00:00
|
|
|
Send an ID_OBJECT_STATE packet whenever an object should be disabled, as long as
|
|
|
|
the player is logged in on the server, the object is still enabled, and our last
|
|
|
|
packet regarding its state did not already attempt to disable it (to prevent
|
|
|
|
packet spam)
|
2017-07-13 06:46:30 +00:00
|
|
|
*/
|
2018-10-13 12:36:13 +00:00
|
|
|
if (mwmp::Main::get().getLocalPlayer()->isLoggedIn())
|
2017-07-13 06:46:30 +00:00
|
|
|
{
|
2019-01-15 12:26:00 +00:00
|
|
|
if (ref.isInCell() && ref.getRefData().isEnabled() &&
|
|
|
|
ref.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Disabled)
|
2017-07-20 14:01:04 +00:00
|
|
|
{
|
2019-01-15 12:26:00 +00:00
|
|
|
ref.getRefData().setLastCommunicatedState(MWWorld::RefData::StateCommunication::Disabled);
|
|
|
|
|
2018-05-12 21:42:24 +00:00
|
|
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
|
|
|
objectList->reset();
|
2018-07-22 22:39:43 +00:00
|
|
|
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
|
2018-05-12 21:42:24 +00:00
|
|
|
objectList->addObjectState(ref, false);
|
|
|
|
objectList->sendObjectState();
|
2017-07-20 14:01:04 +00:00
|
|
|
}
|
2017-07-13 06:46:30 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2017-07-20 14:01:04 +00:00
|
|
|
|
2018-07-08 00:31:48 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp change (major)
|
|
|
|
|
|
|
|
Disable unilateral state disabling on this client and expect the server's reply to our
|
|
|
|
packet to do it instead
|
|
|
|
*/
|
|
|
|
//MWBase::Environment::get().getWorld()->disable (ref);
|
|
|
|
/*
|
|
|
|
End of tes3mp change (major)
|
|
|
|
*/
|
2010-07-03 13:17:02 +00:00
|
|
|
}
|
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
|
|
|
|
2018-05-26 02:11:41 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp change (minor)
|
|
|
|
|
|
|
|
Declare an integer so it can be reused below for multiplayer script sync purposes
|
|
|
|
*/
|
2016-10-26 23:18:27 +00:00
|
|
|
int index = findLocalVariableIndex(scriptId, name, 's');
|
|
|
|
|
|
|
|
locals.mShorts[index] = value;
|
2018-05-26 02:11:41 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp change (minor)
|
|
|
|
*/
|
2016-10-26 23:18:27 +00:00
|
|
|
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_SCRIPT_MEMBER_SHORT packet every time a member short changes its value
|
|
|
|
in a script approved for packet sending
|
|
|
|
*/
|
2016-10-26 23:18:27 +00:00
|
|
|
if (sendPackets && !global)
|
|
|
|
{
|
2018-05-12 21:42:24 +00:00
|
|
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
|
|
|
objectList->reset();
|
2018-07-22 22:39:43 +00:00
|
|
|
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
|
2018-05-12 21:42:24 +00:00
|
|
|
objectList->addScriptMemberShort(id, index, value);
|
|
|
|
objectList->sendScriptMemberShort();
|
2016-10-26 23:18:27 +00:00
|
|
|
}
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InterpreterContext::getTargetId() const
|
|
|
|
{
|
|
|
|
return mTargetId;
|
2010-07-03 15:59:30 +00:00
|
|
|
}
|
2014-12-11 18:27:13 +00:00
|
|
|
|
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
|
|
|
}
|