2010-08-21 10:41:59 +00:00
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
#include "player.hpp"
|
2010-08-21 10:41:59 +00:00
|
|
|
|
2012-07-03 11:15:20 +00:00
|
|
|
#include <components/esm_store/store.hpp>
|
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2011-01-08 14:11:37 +00:00
|
|
|
#include "../mwrender/player.hpp"
|
|
|
|
|
2012-01-27 12:17:30 +00:00
|
|
|
#include "../mwmechanics/movement.hpp"
|
2012-04-08 17:43:04 +00:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
2012-01-27 12:17:30 +00:00
|
|
|
|
2011-02-03 11:16:59 +00:00
|
|
|
#include "class.hpp"
|
2010-08-21 10:41:59 +00:00
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
namespace MWWorld
|
2010-08-21 10:41:59 +00:00
|
|
|
{
|
2012-07-03 10:30:50 +00:00
|
|
|
Player::Player (MWRender::Player *renderer, const ESM::NPC *player, const MWBase::World& world) :
|
|
|
|
mCellStore (0), mRenderer (renderer), mClass (0),
|
2011-02-03 11:16:59 +00:00
|
|
|
mAutoMove (false), mForwardBackward (0)
|
2010-09-15 12:33:02 +00:00
|
|
|
{
|
|
|
|
mPlayer.base = player;
|
2011-08-27 08:30:38 +00:00
|
|
|
mPlayer.ref.refID = "player";
|
2010-09-15 12:33:02 +00:00
|
|
|
mName = player->name;
|
|
|
|
mMale = !(player->flags & ESM::NPC::Female);
|
|
|
|
mRace = player->race;
|
2011-11-08 00:08:00 +00:00
|
|
|
|
|
|
|
float* playerPos = mPlayer.mData.getPosition().pos;
|
|
|
|
playerPos[0] = playerPos[1] = playerPos[2] = 0;
|
|
|
|
|
2011-11-17 02:15:49 +00:00
|
|
|
mPlayer.mData.setBaseNode(renderer->getNode());
|
2011-08-27 08:30:38 +00:00
|
|
|
/// \todo Do not make a copy of classes defined in esm/p records.
|
2010-09-15 12:33:02 +00:00
|
|
|
mClass = new ESM::Class (*world.getStore().classes.find (player->cls));
|
|
|
|
}
|
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
Player::~Player()
|
2010-09-15 12:33:02 +00:00
|
|
|
{
|
|
|
|
delete mClass;
|
|
|
|
}
|
|
|
|
|
2011-09-04 07:48:50 +00:00
|
|
|
void Player::setPos(float x, float y, float z)
|
2010-08-21 10:41:59 +00:00
|
|
|
{
|
2012-07-03 10:30:50 +00:00
|
|
|
/// \todo This fcuntion should be removed during the mwrender-refactoring.
|
|
|
|
MWBase::Environment::get().getWorld()->moveObject (getPlayer(), x, y, z);
|
2010-08-21 10:41:59 +00:00
|
|
|
}
|
2010-09-15 12:33:02 +00:00
|
|
|
|
2012-05-30 13:52:39 +00:00
|
|
|
void Player::setRot(float x, float y, float z)
|
|
|
|
{
|
|
|
|
mRenderer->setRot(x, y, z);
|
|
|
|
}
|
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
void Player::setClass (const ESM::Class& class_)
|
2010-09-15 12:33:02 +00:00
|
|
|
{
|
|
|
|
ESM::Class *new_class = new ESM::Class (class_);
|
|
|
|
delete mClass;
|
|
|
|
mClass = new_class;
|
|
|
|
}
|
2011-01-17 20:48:12 +00:00
|
|
|
|
2012-07-06 13:50:26 +00:00
|
|
|
void Player::setDrawState (MWMechanics::DrawState state)
|
2012-04-08 10:25:33 +00:00
|
|
|
{
|
2012-04-08 17:43:04 +00:00
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
2012-07-06 13:50:26 +00:00
|
|
|
MWWorld::Class::get(ptr).getNpcStats(ptr).setDrawState (state);
|
2012-04-08 10:25:33 +00:00
|
|
|
}
|
2012-04-08 11:17:16 +00:00
|
|
|
|
2011-02-03 11:16:59 +00:00
|
|
|
void Player::setAutoMove (bool enable)
|
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
|
|
|
|
|
|
|
mAutoMove = enable;
|
|
|
|
|
|
|
|
int value = mForwardBackward;
|
|
|
|
|
|
|
|
if (mAutoMove)
|
|
|
|
value = 1;
|
|
|
|
|
|
|
|
MWWorld::Class::get (ptr).getMovementSettings (ptr).mForwardBackward = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::setLeftRight (int value)
|
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
|
|
|
|
|
|
|
MWWorld::Class::get (ptr).getMovementSettings (ptr).mLeftRight = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::setForwardBackward (int value)
|
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
|
|
|
|
|
|
|
mForwardBackward = value;
|
|
|
|
|
|
|
|
if (mAutoMove)
|
|
|
|
value = 1;
|
|
|
|
|
|
|
|
MWWorld::Class::get (ptr).getMovementSettings (ptr).mForwardBackward = value;
|
|
|
|
}
|
2012-03-25 02:03:08 +00:00
|
|
|
|
2012-07-03 10:30:50 +00:00
|
|
|
void Player::setUpDown(int value)
|
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
2012-03-25 02:03:08 +00:00
|
|
|
|
|
|
|
MWWorld::Class::get (ptr).getMovementSettings (ptr).mUpDown = value;
|
2012-07-03 10:30:50 +00:00
|
|
|
}
|
2011-02-03 11:16:59 +00:00
|
|
|
|
|
|
|
void Player::toggleRunning()
|
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
|
|
|
|
|
|
|
bool running = MWWorld::Class::get (ptr).getStance (ptr, MWWorld::Class::Run, true);
|
|
|
|
|
|
|
|
MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Run, !running);
|
|
|
|
}
|
2012-04-08 17:43:04 +00:00
|
|
|
|
2012-07-06 13:50:26 +00:00
|
|
|
MWMechanics::DrawState Player::getDrawState()
|
2012-04-08 17:43:04 +00:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = getPlayer();
|
2012-07-06 13:50:26 +00:00
|
|
|
return MWWorld::Class::get(ptr).getNpcStats(ptr).getDrawState();
|
2012-04-08 17:43:04 +00:00
|
|
|
}
|
2012-04-17 22:12:05 +00:00
|
|
|
|
2010-08-21 10:41:59 +00:00
|
|
|
}
|