2011-01-04 15:58:22 +01:00
|
|
|
#include "player.hpp"
|
2010-08-21 12:41:59 +02:00
|
|
|
|
2014-01-16 12:03:23 +01:00
|
|
|
#include <stdexcept>
|
2018-08-14 23:05:43 +04:00
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
2014-01-16 12:03:23 +01:00
|
|
|
|
|
|
|
#include <components/esm/defs.hpp>
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/esmreader.hpp>
|
|
|
|
#include <components/esm3/esmwriter.hpp>
|
|
|
|
#include <components/esm3/loadbsgn.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadmgef.hpp>
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/player.hpp>
|
2022-05-05 00:57:15 +03:00
|
|
|
#include <components/fallback/fallback.hpp>
|
2014-01-16 12:03:23 +01:00
|
|
|
|
2022-11-06 21:06:32 +01:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2020-01-09 13:55:14 +03:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2021-11-23 15:26:43 +01:00
|
|
|
#include "../mwworld/magiceffects.hpp"
|
2022-12-06 00:11:19 +01:00
|
|
|
#include "../mwworld/worldmodel.hpp"
|
2014-04-24 20:40:17 -04:00
|
|
|
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2014-04-24 22:47:45 -04:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2013-05-19 18:40:37 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2013-04-04 11:23:17 +02:00
|
|
|
|
2012-01-27 13:17:30 +01:00
|
|
|
#include "../mwmechanics/movement.hpp"
|
2012-04-08 19:43:04 +02:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2020-04-26 20:46:51 +03:00
|
|
|
#include "../mwmechanics/spellutil.hpp"
|
2012-01-27 13:17:30 +01:00
|
|
|
|
2022-05-05 00:57:15 +03:00
|
|
|
#include "../mwrender/camera.hpp"
|
|
|
|
#include "../mwrender/renderingmanager.hpp"
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
#include "cellstore.hpp"
|
2011-02-03 12:16:59 +01:00
|
|
|
#include "class.hpp"
|
2014-02-23 20:11:05 +01:00
|
|
|
#include "ptr.hpp"
|
2010-08-21 12:41:59 +02:00
|
|
|
|
2011-01-04 15:58:22 +01:00
|
|
|
namespace MWWorld
|
2010-08-21 12:41:59 +02:00
|
|
|
{
|
2015-07-02 18:11:24 +02:00
|
|
|
Player::Player(const ESM::NPC* player)
|
2020-11-13 11:39:47 +04:00
|
|
|
: mCellStore(nullptr)
|
2014-01-01 00:12:31 +01:00
|
|
|
, mLastKnownExteriorPosition(0, 0, 0)
|
2019-02-17 11:56:24 +04:00
|
|
|
, mMarkedPosition(ESM::Position())
|
2018-10-09 10:21:12 +04:00
|
|
|
, mMarkedCell(nullptr)
|
2014-01-01 17:06:21 +01:00
|
|
|
, mTeleported(false)
|
2014-04-05 10:26:14 -04:00
|
|
|
, mCurrentCrimeId(-1)
|
2015-07-02 19:14:28 +02:00
|
|
|
, mPaidCrimeId(-1)
|
2018-09-15 19:38:21 +04:00
|
|
|
, mJumping(false)
|
2010-09-15 14:33:02 +02:00
|
|
|
{
|
2014-05-25 14:13:07 +02:00
|
|
|
ESM::CellRef cellRef;
|
|
|
|
cellRef.blank();
|
2022-10-18 09:26:55 +02:00
|
|
|
cellRef.mRefID = ESM::RefId::stringRefId("Player");
|
2014-05-25 14:13:07 +02:00
|
|
|
mPlayer = LiveCellRef<ESM::NPC>(cellRef, player);
|
2011-11-08 00:08:00 +00:00
|
|
|
|
2014-06-14 17:56:41 +02:00
|
|
|
ESM::Position playerPos = mPlayer.mData.getPosition();
|
|
|
|
playerPos.pos[0] = playerPos.pos[1] = playerPos.pos[2] = 0;
|
|
|
|
mPlayer.mData.setPosition(playerPos);
|
2010-09-15 14:33:02 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 14:05:36 +03:00
|
|
|
void Player::saveStats()
|
2015-06-21 17:27:52 +02:00
|
|
|
{
|
|
|
|
MWMechanics::NpcStats& stats = getPlayer().getClass().getNpcStats(getPlayer());
|
2018-03-30 14:05:36 +03:00
|
|
|
|
2023-06-05 21:21:30 +02:00
|
|
|
for (size_t i = 0; i < mSaveSkills.size(); ++i)
|
|
|
|
mSaveSkills[i] = stats.getSkill(ESM::Skill::indexToRefId(i)).getModified();
|
2015-06-21 17:27:52 +02:00
|
|
|
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
2021-12-27 00:47:33 +01:00
|
|
|
mSaveAttributes[i] = stats.getAttribute(i).getModified();
|
2015-06-21 17:27:52 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 14:05:36 +03:00
|
|
|
void Player::restoreStats()
|
2015-06-21 17:27:52 +02:00
|
|
|
{
|
2023-06-05 21:21:30 +02:00
|
|
|
const auto& store = MWBase::Environment::get().getESMStore();
|
|
|
|
const MWWorld::Store<ESM::GameSetting>& gmst = store->get<ESM::GameSetting>();
|
2018-03-30 14:05:36 +03:00
|
|
|
MWMechanics::CreatureStats& creatureStats = getPlayer().getClass().getCreatureStats(getPlayer());
|
|
|
|
MWMechanics::NpcStats& npcStats = getPlayer().getClass().getNpcStats(getPlayer());
|
|
|
|
MWMechanics::DynamicStat<float> health = creatureStats.getDynamic(0);
|
2021-12-27 00:47:33 +01:00
|
|
|
creatureStats.setHealth(health.getBase() / gmst.find("fWereWolfHealth")->mValue.getFloat());
|
2023-06-05 21:21:30 +02:00
|
|
|
for (size_t i = 0; i < mSaveSkills.size(); ++i)
|
2021-12-27 00:47:33 +01:00
|
|
|
{
|
2023-06-05 21:21:30 +02:00
|
|
|
auto& skill = npcStats.getSkill(ESM::Skill::indexToRefId(i));
|
2021-12-27 00:47:33 +01:00
|
|
|
skill.restore(skill.getDamage());
|
|
|
|
skill.setModifier(mSaveSkills[i] - skill.getBase());
|
|
|
|
}
|
2015-06-21 17:27:52 +02:00
|
|
|
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
2021-12-27 00:47:33 +01:00
|
|
|
{
|
|
|
|
auto attribute = npcStats.getAttribute(i);
|
|
|
|
attribute.restore(attribute.getDamage());
|
|
|
|
attribute.setModifier(mSaveAttributes[i] - attribute.getBase());
|
|
|
|
npcStats.setAttribute(i, attribute);
|
|
|
|
}
|
2015-06-21 17:27:52 +02:00
|
|
|
}
|
|
|
|
|
2018-03-30 14:05:36 +03:00
|
|
|
void Player::setWerewolfStats()
|
2015-06-21 17:27:52 +02:00
|
|
|
{
|
2023-05-28 15:28:34 +02:00
|
|
|
const auto& store = MWBase::Environment::get().getESMStore();
|
|
|
|
const MWWorld::Store<ESM::GameSetting>& gmst = store->get<ESM::GameSetting>();
|
2018-03-30 14:05:36 +03:00
|
|
|
MWMechanics::CreatureStats& creatureStats = getPlayer().getClass().getCreatureStats(getPlayer());
|
|
|
|
MWMechanics::NpcStats& npcStats = getPlayer().getClass().getNpcStats(getPlayer());
|
|
|
|
MWMechanics::DynamicStat<float> health = creatureStats.getDynamic(0);
|
2021-12-27 00:47:33 +01:00
|
|
|
creatureStats.setHealth(health.getBase() * gmst.find("fWereWolfHealth")->mValue.getFloat());
|
2023-05-28 15:28:34 +02:00
|
|
|
for (const auto& attribute : store->get<ESM::Attribute>())
|
2015-06-21 17:27:52 +02:00
|
|
|
{
|
2023-05-28 15:28:34 +02:00
|
|
|
MWMechanics::AttributeValue value = npcStats.getAttribute(attribute.mId);
|
2023-05-31 17:02:18 +02:00
|
|
|
value.setModifier(attribute.mWerewolfValue - value.getModified());
|
2023-05-28 15:28:34 +02:00
|
|
|
npcStats.setAttribute(attribute.mId, value);
|
2015-06-21 17:27:52 +02:00
|
|
|
}
|
|
|
|
|
2023-06-05 12:41:01 +02:00
|
|
|
for (const auto& skill : store->get<ESM::Skill>())
|
2015-06-21 17:27:52 +02:00
|
|
|
{
|
|
|
|
// Acrobatics is set separately for some reason.
|
2023-06-06 17:24:22 +02:00
|
|
|
if (skill.mId == ESM::Skill::Acrobatics)
|
2015-06-21 17:27:52 +02:00
|
|
|
continue;
|
|
|
|
|
2023-06-05 21:21:30 +02:00
|
|
|
MWMechanics::SkillValue& value = npcStats.getSkill(skill.mId);
|
2023-05-31 17:45:20 +02:00
|
|
|
value.setModifier(skill.mWerewolfValue - value.getModified());
|
2015-06-21 17:27:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-15 17:54:18 +02:00
|
|
|
void Player::set(const ESM::NPC* player)
|
|
|
|
{
|
|
|
|
mPlayer.mBase = player;
|
|
|
|
}
|
|
|
|
|
2013-04-04 11:23:17 +02:00
|
|
|
void Player::setCell(MWWorld::CellStore* cellStore)
|
|
|
|
{
|
|
|
|
mCellStore = cellStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWWorld::Ptr Player::getPlayer()
|
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr(&mPlayer, mCellStore);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2019-03-03 14:58:03 +03:00
|
|
|
MWWorld::ConstPtr Player::getConstPlayer() const
|
|
|
|
{
|
|
|
|
MWWorld::ConstPtr ptr(&mPlayer, mCellStore);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void Player::setBirthSign(const ESM::RefId& sign)
|
2013-04-04 11:23:17 +02:00
|
|
|
{
|
|
|
|
mSign = sign;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
const ESM::RefId& Player::getBirthSign() const
|
2013-04-04 11:23:17 +02:00
|
|
|
{
|
|
|
|
return mSign;
|
|
|
|
}
|
|
|
|
|
2022-07-17 19:36:48 +03:00
|
|
|
void Player::setDrawState(MWMechanics::DrawState state)
|
2012-04-08 12:25:33 +02:00
|
|
|
{
|
2012-04-08 19:43:04 +02:00
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
2014-05-22 20:37:22 +02:00
|
|
|
ptr.getClass().getNpcStats(ptr).setDrawState(state);
|
2012-04-08 12:25:33 +02:00
|
|
|
}
|
2012-04-08 13:17:16 +02:00
|
|
|
|
2013-06-12 16:07:46 +02:00
|
|
|
void Player::yaw(float yaw)
|
2013-03-31 02:57:22 -07:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
2014-05-22 20:37:22 +02:00
|
|
|
ptr.getClass().getMovementSettings(ptr).mRotation[2] += yaw;
|
2013-03-31 02:57:22 -07:00
|
|
|
}
|
2013-06-12 16:07:46 +02:00
|
|
|
void Player::pitch(float pitch)
|
2013-03-31 02:57:22 -07:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
2014-05-22 20:37:22 +02:00
|
|
|
ptr.getClass().getMovementSettings(ptr).mRotation[0] += pitch;
|
2013-03-31 02:57:22 -07:00
|
|
|
}
|
2013-06-12 16:07:46 +02:00
|
|
|
void Player::roll(float roll)
|
2013-03-31 02:57:22 -07:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
2014-05-22 20:37:22 +02:00
|
|
|
ptr.getClass().getMovementSettings(ptr).mRotation[1] += roll;
|
2013-03-31 02:57:22 -07:00
|
|
|
}
|
|
|
|
|
2022-07-17 19:36:48 +03:00
|
|
|
MWMechanics::DrawState Player::getDrawState()
|
2012-04-08 19:43:04 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
2014-05-22 20:37:22 +02:00
|
|
|
return ptr.getClass().getNpcStats(ptr).getDrawState();
|
2012-04-08 19:43:04 +02:00
|
|
|
}
|
2013-12-31 20:40:23 +01:00
|
|
|
|
2015-11-14 02:43:24 +01:00
|
|
|
void Player::activate()
|
|
|
|
{
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MWWorld::Ptr player = getPlayer();
|
|
|
|
const MWMechanics::NpcStats& playerStats = player.getClass().getNpcStats(player);
|
2020-10-09 20:34:36 +03:00
|
|
|
bool godmode = MWBase::Environment::get().getWorld()->getGodModeState();
|
|
|
|
if ((!godmode && playerStats.isParalyzed()) || playerStats.getKnockedDown() || playerStats.isDead())
|
2015-11-14 02:43:24 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
MWWorld::Ptr toActivate = MWBase::Environment::get().getWorld()->getFacedObject();
|
|
|
|
|
|
|
|
if (toActivate.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2019-09-10 21:56:10 +03:00
|
|
|
if (!toActivate.getClass().hasToolTip(toActivate))
|
2015-11-14 02:43:24 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->activate(toActivate, player);
|
|
|
|
}
|
|
|
|
|
2013-12-31 20:40:23 +01:00
|
|
|
bool Player::wasTeleported() const
|
|
|
|
{
|
|
|
|
return mTeleported;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::setTeleported(bool teleported)
|
|
|
|
{
|
|
|
|
mTeleported = teleported;
|
|
|
|
}
|
2014-01-01 17:06:21 +01:00
|
|
|
|
2018-09-15 19:38:21 +04:00
|
|
|
void Player::setJumping(bool jumping)
|
|
|
|
{
|
|
|
|
mJumping = jumping;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Player::getJumping() const
|
|
|
|
{
|
|
|
|
return mJumping;
|
|
|
|
}
|
|
|
|
|
2014-04-24 22:47:45 -04:00
|
|
|
bool Player::isInCombat()
|
|
|
|
{
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->getActorsFighting(getPlayer()).size() != 0;
|
|
|
|
}
|
|
|
|
|
2016-06-07 01:53:16 +02:00
|
|
|
bool Player::enemiesNearby()
|
|
|
|
{
|
|
|
|
return MWBase::Environment::get().getMechanicsManager()->getEnemiesNearby(getPlayer()).size() != 0;
|
|
|
|
}
|
|
|
|
|
2017-04-20 20:36:14 +09:00
|
|
|
void Player::markPosition(CellStore* markedCell, const ESM::Position& markedPosition)
|
2014-01-01 17:06:21 +01:00
|
|
|
{
|
|
|
|
mMarkedCell = markedCell;
|
|
|
|
mMarkedPosition = markedPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::getMarkedPosition(CellStore*& markedCell, ESM::Position& markedPosition) const
|
|
|
|
{
|
|
|
|
markedCell = mMarkedCell;
|
|
|
|
if (mMarkedCell)
|
|
|
|
markedPosition = mMarkedPosition;
|
|
|
|
}
|
2014-01-11 15:34:32 +01:00
|
|
|
|
|
|
|
void Player::clear()
|
|
|
|
{
|
2020-11-13 11:39:47 +04:00
|
|
|
mCellStore = nullptr;
|
2023-02-17 19:20:29 +01:00
|
|
|
mSign = ESM::RefId();
|
2020-11-13 11:39:47 +04:00
|
|
|
mMarkedCell = nullptr;
|
2014-01-11 15:34:32 +01:00
|
|
|
mTeleported = false;
|
2018-09-15 19:38:21 +04:00
|
|
|
mJumping = false;
|
2017-09-11 20:49:22 +04:00
|
|
|
mCurrentCrimeId = -1;
|
|
|
|
mPaidCrimeId = -1;
|
2018-03-09 08:56:04 +04:00
|
|
|
mPreviousItems.clear();
|
2017-09-11 20:49:22 +04:00
|
|
|
mLastKnownExteriorPosition = osg::Vec3f(0, 0, 0);
|
|
|
|
|
2023-06-05 21:21:30 +02:00
|
|
|
mSaveSkills.fill(0.f);
|
2017-09-11 20:49:22 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
|
|
|
{
|
2021-12-27 00:47:33 +01:00
|
|
|
mSaveAttributes[i] = 0.f;
|
2017-09-11 20:49:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mMarkedPosition.pos[0] = 0;
|
|
|
|
mMarkedPosition.pos[1] = 0;
|
|
|
|
mMarkedPosition.pos[2] = 0;
|
|
|
|
mMarkedPosition.rot[0] = 0;
|
|
|
|
mMarkedPosition.rot[1] = 0;
|
|
|
|
mMarkedPosition.rot[2] = 0;
|
2014-01-11 15:34:32 +01:00
|
|
|
}
|
2014-01-16 12:03:23 +01:00
|
|
|
|
2014-04-28 11:29:57 +02:00
|
|
|
void Player::write(ESM::ESMWriter& writer, Loading::Listener& progress) const
|
2014-01-16 12:03:23 +01:00
|
|
|
{
|
|
|
|
ESM::Player player;
|
|
|
|
|
|
|
|
mPlayer.save(player.mObject);
|
2023-02-21 23:26:40 +01:00
|
|
|
player.mCellId = mCellStore->getCell()->getId();
|
2014-01-16 12:03:23 +01:00
|
|
|
|
2014-04-14 18:11:04 -04:00
|
|
|
player.mCurrentCrimeId = mCurrentCrimeId;
|
2014-05-03 12:23:22 +02:00
|
|
|
player.mPaidCrimeId = mPaidCrimeId;
|
2014-04-14 18:11:04 -04:00
|
|
|
|
2014-01-17 13:07:57 +01:00
|
|
|
player.mBirthsign = mSign;
|
|
|
|
|
2015-06-03 19:41:19 +02:00
|
|
|
player.mLastKnownExteriorPosition[0] = mLastKnownExteriorPosition.x();
|
|
|
|
player.mLastKnownExteriorPosition[1] = mLastKnownExteriorPosition.y();
|
|
|
|
player.mLastKnownExteriorPosition[2] = mLastKnownExteriorPosition.z();
|
2014-01-17 13:07:57 +01:00
|
|
|
|
|
|
|
if (mMarkedCell)
|
|
|
|
{
|
|
|
|
player.mHasMark = true;
|
|
|
|
player.mMarkedPosition = mMarkedPosition;
|
2023-02-21 23:26:40 +01:00
|
|
|
player.mMarkedCell = mMarkedCell->getCell()->getId();
|
2014-01-17 13:07:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
player.mHasMark = false;
|
2014-01-16 12:03:23 +01:00
|
|
|
|
2015-06-21 17:36:11 +02:00
|
|
|
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
2021-12-27 00:47:33 +01:00
|
|
|
player.mSaveAttributes[i] = mSaveAttributes[i];
|
2023-06-05 21:21:30 +02:00
|
|
|
for (size_t i = 0; i < mSaveSkills.size(); ++i)
|
2021-12-27 00:47:33 +01:00
|
|
|
player.mSaveSkills[i] = mSaveSkills[i];
|
2015-06-21 17:36:11 +02:00
|
|
|
|
2018-03-09 10:20:17 +04:00
|
|
|
player.mPreviousItems = mPreviousItems;
|
|
|
|
|
2014-01-16 12:03:23 +01:00
|
|
|
writer.startRecord(ESM::REC_PLAY);
|
|
|
|
player.save(writer);
|
|
|
|
writer.endRecord(ESM::REC_PLAY);
|
|
|
|
}
|
|
|
|
|
2015-01-22 19:04:59 +01:00
|
|
|
bool Player::readRecord(ESM::ESMReader& reader, uint32_t type)
|
2014-01-16 12:03:23 +01:00
|
|
|
{
|
|
|
|
if (type == ESM::REC_PLAY)
|
|
|
|
{
|
|
|
|
ESM::Player player;
|
|
|
|
player.load(reader);
|
|
|
|
|
|
|
|
if (!mPlayer.checkState(player.mObject))
|
|
|
|
{
|
|
|
|
// this is the one object we can not silently drop.
|
2014-01-17 13:07:57 +01:00
|
|
|
throw std::runtime_error("invalid player state record (object state)");
|
2014-01-16 12:03:23 +01:00
|
|
|
}
|
2023-02-10 13:16:52 +01:00
|
|
|
if (reader.getFormatVersion() <= ESM::MaxClearModifiersFormatVersion)
|
2021-08-27 20:07:50 +02:00
|
|
|
convertMagicEffects(
|
|
|
|
player.mObject.mCreatureStats, player.mObject.mInventory, &player.mObject.mNpcStats);
|
2023-02-10 13:16:52 +01:00
|
|
|
else if (reader.getFormatVersion() <= ESM::MaxOldCreatureStatsFormatVersion)
|
2022-02-14 18:38:37 +01:00
|
|
|
convertStats(player.mObject.mCreatureStats);
|
2014-01-16 12:03:23 +01:00
|
|
|
|
2017-01-21 03:39:51 +01:00
|
|
|
if (!player.mObject.mEnabled)
|
|
|
|
{
|
2018-08-14 23:05:43 +04:00
|
|
|
Log(Debug::Warning) << "Warning: Savegame attempted to disable the player.";
|
2017-01-21 03:39:51 +01:00
|
|
|
player.mObject.mEnabled = true;
|
|
|
|
}
|
|
|
|
|
2014-01-16 12:03:23 +01:00
|
|
|
mPlayer.load(player.mObject);
|
|
|
|
|
2015-06-21 17:36:11 +02:00
|
|
|
for (int i = 0; i < ESM::Attribute::Length; ++i)
|
2021-12-27 00:47:33 +01:00
|
|
|
mSaveAttributes[i] = player.mSaveAttributes[i];
|
2023-06-05 21:21:30 +02:00
|
|
|
for (size_t i = 0; i < mSaveSkills.size(); ++i)
|
2021-12-27 00:47:33 +01:00
|
|
|
mSaveSkills[i] = player.mSaveSkills[i];
|
2015-06-21 17:36:11 +02:00
|
|
|
|
2021-12-27 00:47:33 +01:00
|
|
|
if (player.mObject.mNpcStats.mIsWerewolf)
|
2015-06-21 18:18:24 +02:00
|
|
|
{
|
2021-12-27 00:47:33 +01:00
|
|
|
if (player.mObject.mNpcStats.mWerewolfDeprecatedData)
|
|
|
|
{
|
|
|
|
saveStats();
|
|
|
|
setWerewolfStats();
|
|
|
|
}
|
2023-02-10 13:16:52 +01:00
|
|
|
else if (reader.getFormatVersion() <= ESM::MaxOldSkillsAndAttributesFormatVersion)
|
2021-12-27 00:47:33 +01:00
|
|
|
{
|
|
|
|
setWerewolfStats();
|
|
|
|
if (player.mSetWerewolfAcrobatics)
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->applyWerewolfAcrobatics(getPlayer());
|
|
|
|
}
|
2015-06-21 18:18:24 +02:00
|
|
|
}
|
|
|
|
|
2014-08-03 22:29:50 +02:00
|
|
|
getPlayer().getClass().getCreatureStats(getPlayer()).getAiSequence().clear();
|
|
|
|
|
2014-01-17 13:07:57 +01:00
|
|
|
MWBase::World& world = *MWBase::Environment::get().getWorld();
|
|
|
|
|
2023-05-27 01:17:20 +02:00
|
|
|
mCellStore = MWBase::Environment::get().getWorldModel()->findCell(player.mCellId);
|
|
|
|
if (mCellStore == nullptr)
|
|
|
|
Log(Debug::Warning) << "Player cell " << player.mCellId << " no longer exists";
|
2014-01-17 13:07:57 +01:00
|
|
|
|
2015-02-05 04:29:52 +01:00
|
|
|
if (!player.mBirthsign.empty())
|
|
|
|
{
|
|
|
|
const ESM::BirthSign* sign = world.getStore().get<ESM::BirthSign>().search(player.mBirthsign);
|
|
|
|
if (!sign)
|
|
|
|
throw std::runtime_error("invalid player state record (birthsign does not exist)");
|
|
|
|
}
|
2014-01-17 13:07:57 +01:00
|
|
|
|
2014-04-14 18:11:04 -04:00
|
|
|
mCurrentCrimeId = player.mCurrentCrimeId;
|
2014-05-03 12:23:22 +02:00
|
|
|
mPaidCrimeId = player.mPaidCrimeId;
|
2014-04-14 18:11:04 -04:00
|
|
|
|
2014-01-17 13:07:57 +01:00
|
|
|
mSign = player.mBirthsign;
|
|
|
|
|
2015-06-03 19:41:19 +02:00
|
|
|
mLastKnownExteriorPosition.x() = player.mLastKnownExteriorPosition[0];
|
|
|
|
mLastKnownExteriorPosition.y() = player.mLastKnownExteriorPosition[1];
|
|
|
|
mLastKnownExteriorPosition.z() = player.mLastKnownExteriorPosition[2];
|
2014-01-16 12:03:23 +01:00
|
|
|
|
2023-02-22 23:20:15 +01:00
|
|
|
if (player.mHasMark)
|
2014-01-17 13:07:57 +01:00
|
|
|
{
|
2023-02-21 23:26:40 +01:00
|
|
|
if (!world.getStore().get<ESM::Cell>().search(player.mMarkedCell))
|
2014-01-17 13:07:57 +01:00
|
|
|
player.mHasMark = false; // drop mark silently
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player.mHasMark)
|
|
|
|
{
|
|
|
|
mMarkedPosition = player.mMarkedPosition;
|
2023-04-20 15:55:40 +02:00
|
|
|
mMarkedCell = &MWBase::Environment::get().getWorldModel()->getCell(player.mMarkedCell);
|
2014-01-17 13:07:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 11:39:47 +04:00
|
|
|
mMarkedCell = nullptr;
|
2014-01-17 13:07:57 +01:00
|
|
|
}
|
2014-01-16 12:03:23 +01:00
|
|
|
|
|
|
|
mTeleported = false;
|
|
|
|
|
2018-03-09 10:20:17 +04:00
|
|
|
mPreviousItems = player.mPreviousItems;
|
|
|
|
|
2014-01-16 12:03:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-05 10:26:14 -04:00
|
|
|
|
|
|
|
int Player::getNewCrimeId()
|
|
|
|
{
|
2014-04-05 22:45:40 -04:00
|
|
|
return ++mCurrentCrimeId;
|
2014-04-05 10:26:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::recordCrimeId()
|
|
|
|
{
|
2014-05-03 12:23:22 +02:00
|
|
|
mPaidCrimeId = mCurrentCrimeId;
|
2014-04-05 10:26:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int Player::getCrimeId() const
|
|
|
|
{
|
2014-05-03 12:23:22 +02:00
|
|
|
return mPaidCrimeId;
|
2014-04-05 10:26:14 -04:00
|
|
|
}
|
2018-03-09 08:56:04 +04:00
|
|
|
|
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
|
|
|
void Player::setPreviousItem(const ESM::RefId& boundItemId, const ESM::RefId& previousItemId)
|
2018-03-09 08:56:04 +04:00
|
|
|
{
|
|
|
|
mPreviousItems[boundItemId] = previousItemId;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ESM::RefId Player::getPreviousItem(const ESM::RefId& boundItemId)
|
2018-03-09 08:56:04 +04:00
|
|
|
{
|
|
|
|
return mPreviousItems[boundItemId];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void Player::erasePreviousItem(const ESM::RefId& boundItemId)
|
2018-03-09 08:56:04 +04:00
|
|
|
{
|
|
|
|
mPreviousItems.erase(boundItemId);
|
|
|
|
}
|
2020-01-09 13:55:14 +03:00
|
|
|
|
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
|
|
|
void Player::setSelectedSpell(const ESM::RefId& spellId)
|
2020-01-09 13:55:14 +03:00
|
|
|
{
|
|
|
|
Ptr player = getPlayer();
|
|
|
|
InventoryStore& store = player.getClass().getInventoryStore(player);
|
|
|
|
store.setSelectedEnchantItem(store.end());
|
|
|
|
int castChance = int(MWMechanics::getSpellSuccessChance(spellId, player));
|
|
|
|
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, castChance);
|
|
|
|
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
|
|
|
|
}
|
2022-05-05 00:57:15 +03:00
|
|
|
|
|
|
|
void Player::update()
|
|
|
|
{
|
|
|
|
auto player = getPlayer();
|
2022-05-06 17:46:50 +02:00
|
|
|
const auto world = MWBase::Environment::get().getWorld();
|
|
|
|
const auto rendering = world->getRenderingManager();
|
2022-05-05 00:57:15 +03:00
|
|
|
auto& store = world->getStore();
|
|
|
|
auto& playerClass = player.getClass();
|
2022-05-06 17:46:50 +02:00
|
|
|
const auto windowMgr = MWBase::Environment::get().getWindowManager();
|
2022-05-05 00:57:15 +03:00
|
|
|
|
|
|
|
if (player.getCell()->isExterior())
|
|
|
|
{
|
|
|
|
ESM::Position pos = player.getRefData().getPosition();
|
|
|
|
setLastKnownExteriorPosition(pos.asVec3());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isWerewolf = playerClass.getNpcStats(player).isWerewolf();
|
|
|
|
bool isFirstPerson = world->isFirstPerson();
|
|
|
|
if (isWerewolf && isFirstPerson)
|
|
|
|
{
|
|
|
|
float werewolfFov = Fallback::Map::getFloat("General_Werewolf_FOV");
|
|
|
|
if (werewolfFov != 0)
|
|
|
|
rendering->overrideFieldOfView(werewolfFov);
|
|
|
|
windowMgr->setWerewolfOverlay(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rendering->resetFieldOfView();
|
|
|
|
windowMgr->setWerewolfOverlay(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sink the camera while sneaking
|
|
|
|
bool sneaking = playerClass.getCreatureStats(player).getStance(MWMechanics::CreatureStats::Stance_Sneak);
|
|
|
|
bool swimming = world->isSwimming(player);
|
|
|
|
bool flying = world->isFlying(player);
|
|
|
|
|
|
|
|
static const float i1stPersonSneakDelta
|
|
|
|
= store.get<ESM::GameSetting>().find("i1stPersonSneakDelta")->mValue.getFloat();
|
|
|
|
if (sneaking && !swimming && !flying)
|
|
|
|
rendering->getCamera()->setSneakOffset(i1stPersonSneakDelta);
|
|
|
|
else
|
|
|
|
rendering->getCamera()->setSneakOffset(0.f);
|
|
|
|
|
|
|
|
int blind = 0;
|
|
|
|
const auto& magicEffects = playerClass.getCreatureStats(player).getMagicEffects();
|
|
|
|
if (!world->getGodModeState())
|
2023-05-23 19:06:08 +02:00
|
|
|
blind = static_cast<int>(magicEffects.getOrDefault(ESM::MagicEffect::Blind).getModifier());
|
2022-05-05 00:57:15 +03:00
|
|
|
windowMgr->setBlindness(std::clamp(blind, 0, 100));
|
|
|
|
|
2023-05-23 19:06:08 +02:00
|
|
|
int nightEye = static_cast<int>(magicEffects.getOrDefault(ESM::MagicEffect::NightEye).getMagnitude());
|
2022-05-05 00:57:15 +03:00
|
|
|
rendering->setNightEyeFactor(std::min(1.f, (nightEye / 100.f)));
|
|
|
|
}
|
|
|
|
|
2010-08-21 12:41:59 +02:00
|
|
|
}
|