1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00
OpenMW/apps/openmw/mwmechanics/creaturestats.hpp
fteppe 125b21de20 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-12-27 19:15:54 +01:00

295 lines
8.7 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
{
static int sActorId;
DrawState mDrawState;
AttributeValue mAttributes[ESM::Attribute::Length];
DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
Spells mSpells;
ActiveSpells mActiveSpells;
MagicEffects mMagicEffects;
Stat<int> mAiSettings[4];
AiSequence mAiSequence;
bool mDead;
bool mDeathAnimationFinished;
bool mDied; // flag for OnDeath script function
bool mMurdered;
int mFriendlyHits;
bool mTalkedTo;
bool mAlarmed;
bool mAttacked;
bool mKnockdown;
bool mKnockdownOneFrame;
bool mKnockdownOverOneFrame;
bool mHitRecovery;
bool mBlock;
unsigned int mMovementFlags;
float mFallHeight;
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;
int mActorId;
int mHitAttemptActorId; // 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.
// The index of the death animation that was played, or -1 if none played
signed char mDeathAnimation;
MWWorld::TimeStamp mTimeOfDeath;
// The difference between view direction and lower body direction.
float mSideMovementAngle;
private:
std::multimap<int, int> mSummonedCreatures; // <Effect, ActorId>
// Contains ActorIds of summoned creatures with an expired lifetime that have not been deleted yet.
// This may be necessary when the creature is in an inactive cell.
std::vector<int> mSummonGraveyard;
protected:
int mLevel;
bool mAttackingOrSpell;
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(int index) 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; }
int getLevel() const;
Spells& getSpells();
ActiveSpells& getActiveSpells();
MagicEffects& getMagicEffects();
void setAttribute(int index, const AttributeValue& value);
// Shortcut to set only the base
void setAttribute(int index, 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);
/// Set Modifier for each magic effect according to \a effects. Does not touch Base values.
void modifyMagicEffects(const MagicEffects& effects);
void setAttackingOrSpell(bool attackingOrSpell) { mAttackingOrSpell = attackingOrSpell; }
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.
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;
std::multimap<int, int>& getSummonedCreatureMap(); // <Effect, ActorId of summoned creature>
std::vector<int>& getSummonedCreatureGraveyard(); // ActorIds
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 setHitAttemptActorId(const int actorId);
int getHitAttemptActorId() const;
void writeState(ESM::CreatureStats& state) const;
void readState(const ESM::CreatureStats& state);
static void writeActorIdCounter(ESM::ESMWriter& esm);
static void readActorIdCounter(ESM::ESMReader& esm);
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;
int getActorId();
///< Will generate an actor ID, if the actor does not have one yet.
bool matchesActorId(int id) const;
///< Check if \a id matches the actor ID of *this (if the actor does not have an ID
/// assigned this function will return false).
static void cleanup();
float getSideMovementAngle() const { return mSideMovementAngle; }
void setSideMovementAngle(float angle) { mSideMovementAngle = angle; }
};
}
#endif