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>
|
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
#include <components/esm/refid.hpp>
|
2022-10-18 09:26:55 +02:00
|
|
|
#include <components/interpreter/context.hpp>
|
2010-07-02 18:08:00 +02:00
|
|
|
|
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(
|
2023-02-17 19:20:29 +01:00
|
|
|
const ESM::RefId& id = ESM::RefId(), bool activeOnly = false, bool doThrow = true) const;
|
2010-07-09 19:32:17 +02:00
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
const Locals& getMemberLocals(bool global, ESM::RefId& id) 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
|
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
Locals& getMemberLocals(bool global, ESM::RefId& id);
|
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.
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
int findLocalVariableIndex(const ESM::RefId& 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
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
ESM::RefId 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
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void messageBox(std::string_view message, 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
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
int getMemberShort(ESM::RefId id, std::string_view name, bool global) const override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
int getMemberLong(ESM::RefId id, std::string_view name, bool global) const override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
float getMemberFloat(ESM::RefId id, std::string_view name, bool global) const override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
void setMemberShort(ESM::RefId id, std::string_view name, int value, bool global) override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
void setMemberLong(ESM::RefId id, std::string_view name, int value, bool global) override;
|
2012-06-07 11:59:45 +02:00
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
void setMemberFloat(ESM::RefId 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
|