1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 12:42:11 +00:00
OpenMW/apps/openmw/mwlua/actions.hpp

85 lines
2.2 KiB
C++
Raw Normal View History

2021-03-28 15:44:08 +00:00
#ifndef MWLUA_ACTIONS_H
#define MWLUA_ACTIONS_H
#include <variant>
#include "object.hpp"
#include "worldview.hpp"
2021-11-14 23:54:01 +00:00
namespace LuaUtil
{
class LuaState;
}
2021-03-28 15:44:08 +00:00
namespace MWLua
{
// Some changes to the game world can not be done from the scripting thread (because it runs in parallel with OSG Cull),
// so we need to queue it and apply from the main thread. All such changes should be implemented as classes inherited
// from MWLua::Action.
class Action
{
public:
2021-11-14 23:54:01 +00:00
Action(LuaUtil::LuaState* state);
2021-03-28 15:44:08 +00:00
virtual ~Action() {}
2021-11-14 23:54:01 +00:00
void safeApply(WorldView&) const;
2021-03-28 15:44:08 +00:00
virtual void apply(WorldView&) const = 0;
2021-11-14 23:54:01 +00:00
virtual std::string toString() const = 0;
private:
std::string mCallerTraceback;
2021-03-28 15:44:08 +00:00
};
class TeleportAction final : public Action
{
public:
2021-11-14 23:54:01 +00:00
TeleportAction(LuaUtil::LuaState* state, ObjectId object, std::string cell, const osg::Vec3f& pos, const osg::Vec3f& rot)
: Action(state), mObject(object), mCell(std::move(cell)), mPos(pos), mRot(rot) {}
2021-03-28 15:44:08 +00:00
void apply(WorldView&) const override;
2021-11-14 23:54:01 +00:00
std::string toString() const override { return "TeleportAction"; }
2021-03-28 15:44:08 +00:00
private:
ObjectId mObject;
std::string mCell;
osg::Vec3f mPos;
osg::Vec3f mRot;
};
class SetEquipmentAction final : public Action
{
public:
using Item = std::variant<std::string, ObjectId>; // recordId or ObjectId
using Equipment = std::map<int, Item>; // slot to item
2021-11-14 23:54:01 +00:00
SetEquipmentAction(LuaUtil::LuaState* state, ObjectId actor, Equipment equipment)
: Action(state), mActor(actor), mEquipment(std::move(equipment)) {}
2021-03-28 15:44:08 +00:00
void apply(WorldView&) const override;
2021-11-14 23:54:01 +00:00
std::string toString() const override { return "SetEquipmentAction"; }
2021-03-28 15:44:08 +00:00
private:
ObjectId mActor;
Equipment mEquipment;
};
class ActivateAction final : public Action
{
public:
ActivateAction(LuaUtil::LuaState* state, ObjectId object, ObjectId actor)
: Action(state), mObject(object), mActor(actor) {}
void apply(WorldView&) const override;
std::string toString() const override;
private:
ObjectId mObject;
ObjectId mActor;
};
2021-03-28 15:44:08 +00:00
}
#endif // MWLUA_ACTIONS_H