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
|
|
|
|
2011-01-08 14:11:37 +00:00
|
|
|
#include "../mwrender/player.hpp"
|
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
#include "world.hpp"
|
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
|
|
|
{
|
2011-01-08 14:11:37 +00:00
|
|
|
Player::Player (MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world) :
|
2011-03-13 21:37:54 +00:00
|
|
|
mCellStore (0), mRenderer (renderer), mWorld (world), 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;
|
|
|
|
mName = player->name;
|
|
|
|
mMale = !(player->flags & ESM::NPC::Female);
|
|
|
|
mRace = player->race;
|
|
|
|
mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0;
|
2011-02-10 11:56:19 +00:00
|
|
|
mPlayer.mData.setHandle (renderer->getHandle());
|
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-01-04 14:58:22 +00:00
|
|
|
void Player::setPos(float x, float y, float z, bool updateCamera)
|
2010-08-21 10:41:59 +00:00
|
|
|
{
|
|
|
|
mWorld.moveObject (getPlayer(), x, y, z);
|
|
|
|
|
|
|
|
if (updateCamera)
|
2011-01-08 14:11:37 +00:00
|
|
|
mRenderer->getCamera()->setPosition (Ogre::Vector3 (
|
2010-08-21 10:41:59 +00:00
|
|
|
mPlayer.ref.pos.pos[0],
|
|
|
|
mPlayer.ref.pos.pos[2],
|
|
|
|
-mPlayer.ref.pos.pos[1]));
|
|
|
|
}
|
2010-09-15 12:33:02 +00:00
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2010-08-21 10:41:59 +00:00
|
|
|
}
|