Files
claudeandClaude Opus 5.5 9e28969629
Ashlar checks / tooling (push) Successful in 5s
Add ledge mantling
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>
2026-11-15 15:44:40 -05:00

330 lines
11 KiB
C++

#ifndef GAME_MWMECHANICS_CREATURESTATS_H
#define GAME_MWMECHANICS_CREATURESTATS_H
#include <map>
#include <set>
#include <stdexcept>
#include <string>
#include "activespells.hpp"
#include "aisequence.hpp"
#include "aisetting.hpp"
#include "drawstate.hpp"
#include "magiceffects.hpp"
#include "spells.hpp"
#include "stat.hpp"
#include <components/esm/attr.hpp>
#include <components/esm/refid.hpp>
#include <components/esm3/magiceffects.hpp>
namespace ESM
{
struct CreatureStats;
}
namespace MWMechanics
{
struct CorprusStats
{
static constexpr int sWorseningPeriod = 24;
int mWorsenings[ESM::Attribute::Length];
MWWorld::TimeStamp mNextWorsening;
};
/// \brief Common creature stats
///
///
class CreatureStats
{
std::map<ESM::RefId, AttributeValue> mAttributes;
DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
DrawState mDrawState = DrawState::Nothing;
Spells mSpells;
ActiveSpells mActiveSpells;
MagicEffects mMagicEffects;
Stat<int> mAiSettings[4];
AiSequence mAiSequence;
bool mDead = false;
bool mDeathAnimationFinished = false;
bool mDied = false; // flag for OnDeath script function
bool mMurdered = false;
int mFriendlyHits = 0;
bool mTalkedTo = false;
bool mAlarmed = false;
bool mAttacked = false;
bool mKnockdown = false;
bool mKnockdownOneFrame = false;
bool mKnockdownOverOneFrame = false;
bool mHitRecovery = false;
bool mBlock = false;
bool mBlockHeld = false;
bool mAiBlockHeld = false;
bool mSprintHeld = false;
bool mSprinting = false;
bool mSprintCancelled = false;
bool mMantleAllowed = true;
float mPendingFlinch = 0.f;
float mReactionTime = 0.f;
unsigned int mMovementFlags = 0;
float mFallHeight = 0.f;
ESM::RefId mLastHitObject; // The last object to hit this actor
ESM::RefId mLastHitAttemptObject; // The last object to attempt to hit this actor
// For merchants: the last time items were restocked and gold pool refilled.
MWWorld::TimeStamp mLastRestock;
// The pool of merchant gold (not in inventory)
int mGoldPool = 0;
// Stores an actor that attacked this actor. Only one is stored at a time, and it is not changed if a different
// actor attacks. It is cleared when combat ends.
ESM::RefNum mHitAttemptActor;
// The difference between view direction and lower body direction.
float mSideMovementAngle = 0;
MWWorld::TimeStamp mTimeOfDeath;
private:
std::multimap<ESM::RefId, ESM::RefNum> mSummonedCreatures; // <Effect, Actor>
float mAwarenessTimer = 0.f;
int mAwarenessRoll = -1;
protected:
std::string mAttackType;
int mLevel = 0;
bool mAttackingOrSpell = false;
private:
// The index of the death animation that was played, or -1 if none played
signed char mDeathAnimation = -1;
bool mTeleported = false;
public:
CreatureStats();
DrawState getDrawState() const;
void setDrawState(DrawState state);
void recalculateMagicka();
float getFallHeight() const;
void addToFallHeight(float height);
/// Reset the fall height
/// @return total fall height
float land(bool isPlayer = false);
const AttributeValue& getAttribute(ESM::RefId id) const;
const DynamicStat<float>& getHealth() const;
const DynamicStat<float>& getMagicka() const;
const DynamicStat<float>& getFatigue() const;
const DynamicStat<float>& getDynamic(int index) const;
const Spells& getSpells() const;
const ActiveSpells& getActiveSpells() const;
const MagicEffects& getMagicEffects() const;
bool getAttackingOrSpell() const { return mAttackingOrSpell; }
std::string_view getAttackType() const { return mAttackType; }
int getLevel() const;
Spells& getSpells();
ActiveSpells& getActiveSpells();
MagicEffects& getMagicEffects();
void setAttribute(ESM::RefId id, const AttributeValue& value);
// Shortcut to set only the base
void setAttribute(ESM::RefId id, float base);
void setHealth(const DynamicStat<float>& value);
void setMagicka(const DynamicStat<float>& value);
void setFatigue(const DynamicStat<float>& value);
void setDynamic(int index, const DynamicStat<float>& value);
void setAttackingOrSpell(bool attackingOrSpell) { mAttackingOrSpell = attackingOrSpell; }
void setAttackType(std::string_view attackType) { mAttackType = attackType; }
void setLevel(int level);
void setAiSetting(AiSetting index, Stat<int> value);
void setAiSetting(AiSetting index, int base);
Stat<int> getAiSetting(AiSetting index) const;
const AiSequence& getAiSequence() const;
AiSequence& getAiSequence();
float getFatigueTerm() const;
///< Return effective fatigue
bool isParalyzed() const;
bool isDead() const;
bool isDeathAnimationFinished() const;
void setDeathAnimationFinished(bool finished);
void notifyDied();
bool hasDied() const;
void clearHasDied();
bool hasBeenMurdered() const;
void clearHasBeenMurdered();
void notifyMurder();
void resurrect();
bool hasCommonDisease() const;
bool hasBlightDisease() const;
int getFriendlyHits() const;
///< Number of friendly hits received.
void friendlyHit();
///< Increase number of friendly hits by one.
void resetFriendlyHits();
bool hasTalkedToPlayer() const;
///< Has this creature talked with the player before?
void talkedToPlayer();
bool isAlarmed() const;
void setAlarmed(bool alarmed);
bool getAttacked() const;
void setAttacked(bool attacked);
float getEvasion() const;
void setKnockedDown(bool value);
/// Returns true for the entire duration of the actor being knocked down or knocked out,
/// including transition animations (falling down & standing up)
bool getKnockedDown() const;
void setKnockedDownOneFrame(bool value);
/// Returns true only for the first frame of the actor being knocked out; used for "onKnockedOut" command
bool getKnockedDownOneFrame() const;
void setKnockedDownOverOneFrame(bool value);
/// Returns true for all but the first frame of being knocked out; used to know to not reset
/// mKnockedDownOneFrame
bool getKnockedDownOverOneFrame() const;
void setHitRecovery(bool value);
bool getHitRecovery() const;
void setBlock(bool value);
bool getBlock() const;
// Ashlar active blocking: whether the actor is holding the Block control. Not saved.
void setBlockHeld(bool value) { mBlockHeld = value; }
bool getBlockHeld() const { return mBlockHeld; }
// Ashlar: block stance requested by combat AI. Cleared every frame before AI runs. Not saved.
void setAiBlockHeld(bool value) { mAiBlockHeld = value; }
bool getAiBlockHeld() const { return mAiBlockHeld; }
// Ashlar mantling: false while Lua vetoes mantles (self.controls.mantle). Not saved.
void setMantleAllowed(bool value) { mMantleAllowed = value; }
bool getMantleAllowed() const { return mMantleAllowed; }
// Ashlar sprint: the Sprint control, whether the actor sprints this frame, and whether Use cancelled the
// sprint until Sprint is released. Not saved.
void setSprintHeld(bool value) { mSprintHeld = value; }
bool getSprintHeld() const { return mSprintHeld; }
void setSprinting(bool value) { mSprinting = value; }
bool getSprinting() const { return mSprinting; }
void setSprintCancelled(bool value) { mSprintCancelled = value; }
bool getSprintCancelled() const { return mSprintCancelled; }
// Ashlar hit reactions: flinch length queued by the last melee hit, started when its stagger applies. Not saved.
void setPendingFlinch(float value) { mPendingFlinch = value; }
float takePendingFlinch()
{
const float value = mPendingFlinch;
mPendingFlinch = 0.f;
return value;
}
// Ashlar hit reactions: seconds left in a flinch, recoil or stagger. No attacks start meanwhile. Not saved.
void setReactionTime(float value) { mReactionTime = value; }
float getReactionTime() const { return mReactionTime; }
std::multimap<ESM::RefId, ESM::RefNum>& getSummonedCreatureMap(); // <Effect, summoned creature>
enum Flag
{
Flag_ForceRun = 1,
Flag_ForceSneak = 2,
Flag_Run = 4,
Flag_Sneak = 8,
Flag_ForceJump = 16,
Flag_ForceMoveJump = 32
};
enum Stance
{
Stance_Run,
Stance_Sneak
};
bool getMovementFlag(Flag flag) const;
void setMovementFlag(Flag flag, bool state);
/// Like getMovementFlag, but also takes into account if the flag is Forced
bool getStance(Stance flag) const;
void setLastHitObject(const ESM::RefId& objectid);
void clearLastHitObject();
const ESM::RefId& getLastHitObject() const;
void setLastHitAttemptObject(const ESM::RefId& objectid);
void clearLastHitAttemptObject();
const ESM::RefId& getLastHitAttemptObject() const;
void setHitAttemptActor(ESM::RefNum actorId);
ESM::RefNum getHitAttemptActor() const;
void writeState(ESM::CreatureStats& state) const;
void readState(const ESM::CreatureStats& state);
void setLastRestockTime(MWWorld::TimeStamp tradeTime);
MWWorld::TimeStamp getLastRestockTime() const;
void setGoldPool(int pool);
int getGoldPool() const;
signed char getDeathAnimation() const; // -1 means not decided
void setDeathAnimation(signed char index);
MWWorld::TimeStamp getTimeOfDeath() const;
float getSideMovementAngle() const { return mSideMovementAngle; }
void setSideMovementAngle(float angle) { mSideMovementAngle = angle; }
bool wasTeleported() const { return mTeleported; }
void setTeleported(bool v) { mTeleported = v; }
const std::map<ESM::RefId, AttributeValue>& getAttributes() const { return mAttributes; }
void updateAwareness(float duration);
int getAwarenessRoll();
};
}
#endif