Ashlar checks / tooling (push) Successful in 5s
New [Game] mantling setting, on by default, with mantle max height (1.1 times the actor's height above its feet) and mantle duration (0.4 s). When the player jumps or falls into a wall while moving towards it (within 60 degrees), the movement solver casts the player's collision shape up, across the edge and down. If it finds a surface flat enough to stand on, above the feet and within reach, with headroom and room on top, the player moves up, across and onto it along that checked path. Movement and jump input are ignored meanwhile, and the climb ends any fall without fall damage. No animation is needed. A script move or teleport, noclip or paralysis cancels a climb. Lua: self.controls.mantle (true by default) vetoes climbs while false, and the actor's scripts get an AshlarMantle event with the ledge height when one starts. The engine logs "Ashlar mantle:" lines at verbose level. Player only; with the setting off nothing changes. The geometry rules (reach, headroom, room on top, slope, too high, too low) and the climb path are in mwphysics/mantle.cpp, apart from the physics calls, with unit tests. The new mantle scenario uses a CC0 box mesh written for it: the player climbs an 80 unit ledge, doesn't climb it with the Lua veto, and doesn't climb a 240 unit wall. Closes #28 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
204 lines
8.0 KiB
C++
204 lines
8.0 KiB
C++
#ifndef GAME_MWBASE_LUAMANAGER_H
|
|
#define GAME_MWBASE_LUAMANAGER_H
|
|
|
|
#include <filesystem>
|
|
#include <map>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
#include <SDL_events.h>
|
|
#include <osg/Quat>
|
|
#include <osg/Vec3f>
|
|
|
|
#include <components/esm3/refnum.hpp>
|
|
#include <components/sdlutil/events.hpp>
|
|
|
|
#include "../mwmechanics/attacktype.hpp"
|
|
#include "../mwmechanics/damagesourcetype.hpp"
|
|
#include "../mwrender/animationpriority.hpp"
|
|
|
|
namespace MWWorld
|
|
{
|
|
class CellStore;
|
|
class Ptr;
|
|
}
|
|
|
|
namespace Loading
|
|
{
|
|
class Listener;
|
|
}
|
|
|
|
namespace ESM
|
|
{
|
|
class ESMReader;
|
|
class ESMWriter;
|
|
class RefId;
|
|
struct LuaScripts;
|
|
struct DialInfo;
|
|
struct Dialogue;
|
|
struct IndexedENAMstruct;
|
|
}
|
|
|
|
namespace LuaUtil
|
|
{
|
|
namespace InputAction
|
|
{
|
|
class Registry;
|
|
}
|
|
}
|
|
|
|
namespace osg
|
|
{
|
|
class Vec3f;
|
|
}
|
|
|
|
namespace MWBase
|
|
{
|
|
// \brief LuaManager is the central interface through which the engine invokes lua scripts.
|
|
//
|
|
// The native side invokes functions on this interface, which queues events to be handled by the
|
|
// scripts in the lua thread. Synchronous calls are not possible.
|
|
//
|
|
// The main implementation is in apps/openmw/mwlua/luamanagerimp.cpp.
|
|
// Lua logic in general lives under apps/openmw/mwlua and this interface is
|
|
// the main way for the rest of the engine to interact with the logic there.
|
|
class LuaManager
|
|
{
|
|
public:
|
|
virtual ~LuaManager() = default;
|
|
|
|
virtual void contentFilesLoaded() = 0;
|
|
virtual void newGameStarted() = 0;
|
|
virtual void gameLoaded() = 0;
|
|
virtual void gameEnded() = 0;
|
|
virtual void noGame() = 0;
|
|
virtual void objectAddedToScene(const MWWorld::Ptr& ptr) = 0;
|
|
virtual void objectRemovedFromScene(const MWWorld::Ptr& ptr) = 0;
|
|
virtual void objectTeleported(const MWWorld::Ptr& ptr) = 0;
|
|
virtual void itemConsumed(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) = 0;
|
|
virtual void objectDropped(const MWWorld::Ptr& object, const MWWorld::Ptr& actor, const osg::Vec3f& position,
|
|
const osg::Quat& rotation)
|
|
= 0;
|
|
virtual void objectPlaced(const MWWorld::Ptr& object, const MWWorld::Ptr& actor, const osg::Vec3f& position,
|
|
const osg::Quat& rotation)
|
|
= 0;
|
|
virtual void objectActivated(const MWWorld::Ptr& object, const MWWorld::Ptr& actor) = 0;
|
|
virtual void useItem(const MWWorld::Ptr& object, const MWWorld::Ptr& actor, bool force) = 0;
|
|
virtual void animationTextKey(const MWWorld::Ptr& actor, const std::string& key) = 0;
|
|
virtual void playAnimation(const MWWorld::Ptr& object, const std::string& groupname,
|
|
const MWRender::AnimPriority& priority, int blendMask, bool autodisable, float speedmult,
|
|
std::string_view start, std::string_view stop, float startpoint, uint32_t loops, bool loopfallback)
|
|
= 0;
|
|
virtual void animationEnded(const MWWorld::Ptr& actor, std::string_view groupname, float time, float completion,
|
|
std::string_view startKey, std::string_view stopKey)
|
|
= 0;
|
|
virtual void jailTimeServed(const MWWorld::Ptr& actor, int days) = 0;
|
|
virtual void skillLevelUp(const MWWorld::Ptr& actor, ESM::RefId skillId, std::string_view source) = 0;
|
|
virtual void skillUse(const MWWorld::Ptr& actor, ESM::RefId skillId, int useType, float scale) = 0;
|
|
virtual void onHit(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, const MWWorld::Ptr& weapon,
|
|
const MWWorld::Ptr& ammo, int attackType, float attackStrength, float attackWindUp, float damage,
|
|
bool isHealth, const osg::Vec3f& hitPos, bool successful, MWMechanics::DamageSourceType)
|
|
= 0;
|
|
virtual void exteriorCreated(MWWorld::CellStore& cell) = 0;
|
|
virtual void actorDied(const MWWorld::Ptr& actor) = 0;
|
|
// Ashlar mantling: the actor started climbing a ledge this high above its feet.
|
|
virtual void actorMantled(const MWWorld::Ptr& actor, float height) = 0;
|
|
virtual void onDialogueResponse(
|
|
const MWWorld::Ptr& actor, const ESM::DialInfo& info, const ESM::Dialogue& record)
|
|
= 0;
|
|
virtual void questUpdated(const ESM::RefId& questId, int stage) = 0;
|
|
// `arg` is either forwarded from MWGui::pushGuiMode or empty
|
|
virtual void uiModeChanged(const MWWorld::Ptr& arg) = 0;
|
|
virtual void viewportResized(int width, int height) = 0;
|
|
virtual void savePermanentStorage(const std::filesystem::path& userConfigPath) = 0;
|
|
virtual void applyMagicEffects(ESM::RefId id, const MWWorld::Ptr& caster, ESM::RefNum item,
|
|
const MWWorld::Ptr& target, const std::vector<ESM::IndexedENAMstruct>& effects, bool ignoreReflect,
|
|
bool ignoreSpellAbsorption, bool stackable, bool isReflect)
|
|
= 0;
|
|
virtual void magicProjectileHit(ESM::RefId spellId, const MWWorld::Ptr& caster, ESM::RefNum item,
|
|
const MWWorld::Ptr& victim, const osg::Vec3f& position, const osg::Vec3f& normal)
|
|
= 0;
|
|
// TODO: notify LuaManager about other events
|
|
// virtual void objectOnHit(const MWWorld::Ptr &ptr, float damage, bool ishealth, const MWWorld::Ptr &object,
|
|
// const MWWorld::Ptr &attacker, const osg::Vec3f &hitPosition, bool successful,
|
|
// DamageSourceType sourceType) = 0;
|
|
|
|
struct InputEvent
|
|
{
|
|
struct WheelChange
|
|
{
|
|
int x;
|
|
int y;
|
|
};
|
|
|
|
enum
|
|
{
|
|
KeyPressed,
|
|
KeyReleased,
|
|
ControllerPressed,
|
|
ControllerReleased,
|
|
Action,
|
|
TouchPressed,
|
|
TouchReleased,
|
|
TouchMoved,
|
|
MouseButtonPressed,
|
|
MouseButtonReleased,
|
|
MouseWheel,
|
|
} mType;
|
|
std::variant<SDL_Keysym, int, SDLUtil::TouchEvent, WheelChange> mValue;
|
|
};
|
|
virtual void inputEvent(const InputEvent& event) = 0;
|
|
|
|
struct ActorControls
|
|
{
|
|
bool mDisableAI = false;
|
|
bool mChanged = false;
|
|
|
|
bool mJump = false;
|
|
bool mRun = false;
|
|
bool mSneak = false;
|
|
bool mBlock = false; // Ashlar active blocking
|
|
bool mSprint = false; // Ashlar sprint
|
|
bool mMantle = true; // Ashlar mantling: false vetoes mantles
|
|
float mMovement = 0;
|
|
float mSideMovement = 0;
|
|
float mPitchChange = 0;
|
|
float mYawChange = 0;
|
|
MWMechanics::AttackType mUse = MWMechanics::AttackType::NoAttack;
|
|
};
|
|
|
|
virtual ActorControls* getActorControls(const MWWorld::Ptr&) const = 0;
|
|
|
|
virtual void clear() = 0;
|
|
virtual void setupPlayer(const MWWorld::Ptr&) = 0;
|
|
|
|
// Saving
|
|
size_t countSavedGameRecords() const { return 1; }
|
|
virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress) = 0;
|
|
virtual void saveLocalScripts(const MWWorld::Ptr& ptr, ESM::LuaScripts& data) = 0;
|
|
|
|
// Must be called before save, otherwise the world can be saved in an inconsistent state.
|
|
virtual void applyDelayedActions() = 0;
|
|
|
|
// Loading from a save
|
|
virtual void readRecord(ESM::ESMReader& reader, uint32_t type) = 0;
|
|
virtual void loadLocalScripts(const MWWorld::Ptr& ptr, const ESM::LuaScripts& data) = 0;
|
|
|
|
// Should be called before loading. The map is used to fix refnums if the order of content files was changed.
|
|
virtual void setContentFileMapping(const std::map<int, int>&) = 0;
|
|
|
|
// Drops script cache and reloads all scripts. Calls `onSave` and `onLoad` for every script.
|
|
virtual void reloadAllScripts() = 0;
|
|
|
|
virtual void handleConsoleCommand(
|
|
const std::string& consoleMode, const std::string& command, const MWWorld::Ptr& selectedPtr)
|
|
= 0;
|
|
|
|
virtual std::string formatResourceUsageStats() const = 0;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // GAME_MWBASE_LUAMANAGER_H
|