2010-07-02 18:08:00 +02:00
|
|
|
#ifndef GAME_SCRIPT_INTERPRETERCONTEXT_H
|
|
|
|
#define GAME_SCRIPT_INTERPRETERCONTEXT_H
|
|
|
|
|
2020-05-10 14:57:06 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2010-07-02 18:08:00 +02:00
|
|
|
#include <components/interpreter/context.hpp>
|
|
|
|
|
2020-05-10 14:57:06 +02:00
|
|
|
#include "globalscripts.hpp"
|
|
|
|
|
2010-07-03 17:46:55 +02:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2010-07-02 18:08:00 +02:00
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
2015-03-06 21:36:42 +13:00
|
|
|
class Locals;
|
2010-07-02 18:08:00 +02:00
|
|
|
|
2020-05-10 14:57:06 +02:00
|
|
|
class MissingImplicitRefError : public std::runtime_error
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MissingImplicitRefError();
|
|
|
|
};
|
|
|
|
|
2010-07-02 18:08:00 +02:00
|
|
|
class InterpreterContext : public Interpreter::Context
|
2010-08-03 22:43:53 +02:00
|
|
|
{
|
2010-07-02 18:08:00 +02:00
|
|
|
Locals *mLocals;
|
2014-07-17 13:36:55 +02:00
|
|
|
mutable MWWorld::Ptr mReference;
|
2020-05-10 14:57:06 +02:00
|
|
|
std::shared_ptr<GlobalScriptDesc> mGlobalScriptDesc;
|
2014-07-17 13:36:55 +02:00
|
|
|
|
|
|
|
/// If \a id is empty, a reference the script is run from is returned or in case
|
|
|
|
/// of a non-local script the reference derived from the target ID.
|
2022-08-12 19:42:35 +02:00
|
|
|
const MWWorld::Ptr getReferenceImp(std::string_view id = {}, bool activeOnly = false, bool doThrow = true) const;
|
2010-07-09 19:32:17 +02:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
const Locals& getMemberLocals(std::string_view& id, bool global) const;
|
2014-02-10 14:45:55 +01:00
|
|
|
///< \a id is changed to the respective script ID, if \a id wasn't a script ID before
|
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
Locals& getMemberLocals(std::string_view& id, bool global);
|
2014-02-10 14:45:55 +01:00
|
|
|
///< \a id is changed to the respective script ID, if \a id wasn't a script ID before
|
|
|
|
|
2014-07-25 07:59:50 +02:00
|
|
|
/// Throws an exception if local variable can't be found.
|
2022-08-12 19:42:35 +02:00
|
|
|
int findLocalVariableIndex(std::string_view scriptId, std::string_view name, char type) const;
|
2014-07-25 07:59:50 +02:00
|
|
|
|
2010-07-02 18:08:00 +02:00
|
|
|
public:
|
2020-05-10 14:57:06 +02:00
|
|
|
InterpreterContext (std::shared_ptr<GlobalScriptDesc> globalScriptDesc);
|
2010-08-03 22:43:53 +02:00
|
|
|
|
2020-05-10 14:57:06 +02:00
|
|
|
InterpreterContext (MWScript::Locals *locals, const MWWorld::Ptr& reference);
|
2010-07-02 18:08:00 +02:00
|
|
|
///< The ownership of \a locals is not transferred. 0-pointer allowed.
|
2010-08-03 22:43:53 +02:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getTarget() const override;
|
2021-02-14 16:25:38 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
int getLocalShort (int index) const override;
|
2010-07-02 18:08:00 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
int getLocalLong (int index) const override;
|
2010-07-02 18:08:00 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
float getLocalFloat (int index) const override;
|
2010-07-02 18:08:00 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void setLocalShort (int index, int value) override;
|
2010-07-02 18:08:00 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void setLocalLong (int index, int value) override;
|
2010-07-02 18:08:00 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void setLocalFloat (int index, float value) override;
|
2010-08-03 22:43:53 +02:00
|
|
|
|
2010-08-12 16:29:22 +02:00
|
|
|
using Interpreter::Context::messageBox;
|
2011-04-26 21:48:13 +02:00
|
|
|
|
2022-08-23 22:14:27 +02:00
|
|
|
void messageBox(std::string_view message,
|
2020-10-16 22:18:54 +04:00
|
|
|
const std::vector<std::string>& buttons) override;
|
2010-07-03 15:04:00 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void report (const std::string& message) override;
|
2014-12-11 20:51:02 +01:00
|
|
|
///< By default, do nothing.
|
2011-04-26 21:48:13 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
int getGlobalShort(std::string_view name) const override;
|
2010-07-04 12:29:28 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
int getGlobalLong(std::string_view name) const override;
|
2010-07-04 12:29:28 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
float getGlobalFloat(std::string_view name) const override;
|
2010-07-04 12:29:28 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
void setGlobalShort(std::string_view name, int value) override;
|
2010-07-04 12:29:28 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
void setGlobalLong(std::string_view name, int value) override;
|
2010-07-04 12:29:28 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
void setGlobalFloat(std::string_view name, float value) override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
std::vector<std::string> getGlobals () const override;
|
2012-12-20 23:16:34 +00:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
char getGlobalType(std::string_view name) const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string getActionBinding(std::string_view action) const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getActorName() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getNPCRace() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getNPCClass() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getNPCFaction() const override;
|
2013-03-17 04:20:30 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getNPCRank() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getPCName() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getPCRace() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getPCClass() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getPCRank() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getPCNextRank() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
int getPCBounty() const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
|
2022-08-12 19:42:35 +02:00
|
|
|
std::string_view getCurrentCellName() const override;
|
2010-08-03 22:43:53 +02:00
|
|
|
|
2021-06-23 23:13:59 +02:00
|
|
|
void executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor);
|
2014-05-28 19:23:50 +02:00
|
|
|
///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled.
|
2010-08-03 22:43:53 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
int getMemberShort(std::string_view id, std::string_view name, bool global) const override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
int getMemberLong(std::string_view id, std::string_view name, bool global) const override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
float getMemberFloat(std::string_view id, std::string_view name, bool global) const override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
void setMemberShort(std::string_view id, std::string_view name, int value, bool global) override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
void setMemberLong(std::string_view id, std::string_view name, int value, bool global) override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2022-05-21 01:21:55 +02:00
|
|
|
void setMemberFloat(std::string_view id, std::string_view name, float value, bool global) override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2021-02-14 16:25:38 +01:00
|
|
|
MWWorld::Ptr getReference(bool required=true) const;
|
2010-07-03 17:59:30 +02:00
|
|
|
///< Reference, that the script is running from (can be empty)
|
2014-07-17 13:36:55 +02:00
|
|
|
|
2015-09-30 10:30:50 +02:00
|
|
|
void updatePtr(const MWWorld::Ptr& base, const MWWorld::Ptr& updated);
|
2014-12-11 19:27:13 +01:00
|
|
|
///< Update the Ptr stored in mReference, if there is one stored there. Should be called after the reference has been moved to a new cell.
|
2010-07-02 18:08:00 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|