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