1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00
OpenMW/apps/openmw/mwworld/player.cpp

195 lines
5.7 KiB
C++
Raw Normal View History

#include "player.hpp"
#include "../mwbase/environment.hpp"
2013-05-19 18:40:37 +02:00
#include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp"
2013-05-19 19:48:51 +02:00
#include "../mwbase/soundmanager.hpp"
2013-04-04 11:23:17 +02:00
#include "../mwworld/ptr.hpp"
2013-05-19 18:40:37 +02:00
#include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/movement.hpp"
#include "../mwmechanics/npcstats.hpp"
2013-05-19 18:40:37 +02:00
#include "../mwmechanics/character.hpp"
#include "../mwmechanics/security.hpp"
#include "../mwrender/animation.hpp"
2011-02-03 12:16:59 +01:00
#include "class.hpp"
namespace MWWorld
{
2012-11-08 01:36:43 +04:00
Player::Player (const ESM::NPC *player, const MWBase::World& world)
: mCellStore(0),
mAutoMove(false),
mForwardBackward (0)
{
2012-11-05 16:07:59 +04:00
mPlayer.mBase = player;
mPlayer.mRef.mRefID = "player";
float* playerPos = mPlayer.mData.getPosition().pos;
playerPos[0] = playerPos[1] = playerPos[2] = 0;
}
2013-05-15 17:54:18 +02:00
void Player::set(const ESM::NPC *player)
{
mPlayer.mBase = player;
float* playerPos = mPlayer.mData.getPosition().pos;
playerPos[0] = playerPos[1] = playerPos[2] = 0;
}
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;
}
void Player::setBirthSign (const std::string &sign)
{
mSign = sign;
}
const std::string& Player::getBirthSign() const
{
return mSign;
}
2012-07-07 20:53:19 +02:00
void Player::setDrawState (MWMechanics::DrawState_ state)
{
MWWorld::Ptr ptr = getPlayer();
MWWorld::Class::get(ptr).getNpcStats(ptr).setDrawState (state);
}
2012-04-08 13:17:16 +02:00
2013-04-04 11:23:17 +02:00
bool Player::getAutoMove() const
{
return mAutoMove;
}
2011-02-03 12:16:59 +01: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).mPosition[1] = value;
2011-02-03 12:16:59 +01:00
}
void Player::setLeftRight (int value)
{
MWWorld::Ptr ptr = getPlayer();
MWWorld::Class::get (ptr).getMovementSettings (ptr).mPosition[0] = value;
2011-02-03 12:16:59 +01:00
}
void Player::setForwardBackward (int value)
{
MWWorld::Ptr ptr = getPlayer();
mForwardBackward = value;
if (mAutoMove)
value = 1;
MWWorld::Class::get (ptr).getMovementSettings (ptr).mPosition[1] = value;
2011-02-03 12:16:59 +01:00
}
2012-03-24 22:03:08 -04:00
void Player::setUpDown(int value)
{
MWWorld::Ptr ptr = getPlayer();
2012-03-24 22:03:08 -04:00
MWWorld::Class::get (ptr).getMovementSettings (ptr).mPosition[2] = value;
}
2011-02-03 12:16:59 +01:00
2013-02-06 17:51:47 -08:00
void Player::setRunState(bool run)
{
MWWorld::Ptr ptr = getPlayer();
MWWorld::Class::get(ptr).setStance(ptr, MWWorld::Class::Run, run);
}
2013-03-06 16:58:56 +01:00
void Player::setSneak(bool sneak)
{
MWWorld::Ptr ptr = getPlayer();
MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Sneak, sneak);
}
void Player::setYaw(float yaw)
{
MWWorld::Ptr ptr = getPlayer();
MWWorld::Class::get(ptr).getMovementSettings(ptr).mRotation[2] = yaw;
}
void Player::setPitch(float pitch)
{
MWWorld::Ptr ptr = getPlayer();
MWWorld::Class::get(ptr).getMovementSettings(ptr).mRotation[0] = pitch;
}
void Player::setRoll(float roll)
{
MWWorld::Ptr ptr = getPlayer();
MWWorld::Class::get(ptr).getMovementSettings(ptr).mRotation[1] = roll;
}
2013-05-19 18:40:37 +02:00
void Player::use()
{
MWWorld::InventoryStore& store = MWWorld::Class::get(getPlayer()).getInventoryStore(getPlayer());
MWWorld::ContainerStoreIterator equipped = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if (getDrawState() == MWMechanics::DrawState_Weapon)
{
if (equipped != store.end())
{
MWWorld::Ptr item = *equipped;
MWRender::Animation* anim = MWBase::Environment::get().getWorld()->getAnimation(getPlayer());
MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getFacedObject();
if (anim->isPriorityActive(MWMechanics::Priority_Weapon))
return;
2013-05-19 19:48:51 +02:00
std::string resultMessage, resultSound;
2013-05-19 18:40:37 +02:00
if (item.getTypeName() == typeid(ESM::Lockpick).name())
{
if (!target.isEmpty())
2013-05-19 23:19:48 +02:00
MWMechanics::Security(getPlayer()).pickLock(target, item, resultMessage, resultSound);
2013-05-19 18:40:37 +02:00
anim->play("pickprobe", MWMechanics::Priority_Weapon, MWRender::Animation::Group_UpperBody, true, "start", "stop", 0.0, 0);
}
else if (item.getTypeName() == typeid(ESM::Probe).name())
{
if (!target.isEmpty())
2013-05-19 23:19:48 +02:00
MWMechanics::Security(getPlayer()).probeTrap(target, item, resultMessage, resultSound);
2013-05-19 18:40:37 +02:00
anim->play("pickprobe", MWMechanics::Priority_Weapon, MWRender::Animation::Group_UpperBody, true, "start", "stop", 0.0, 0);
}
2013-05-19 19:48:51 +02:00
if (!resultMessage.empty())
MWBase::Environment::get().getWindowManager()->messageBox(resultMessage);
if (!resultSound.empty())
MWBase::Environment::get().getSoundManager()->playSound(resultSound,1,1);
2013-05-19 18:40:37 +02:00
// tool used up?
if (!item.getRefData().getCount())
2013-05-20 12:42:11 +02:00
MWBase::Environment::get().getWindowManager()->unsetSelectedWeapon();
else
MWBase::Environment::get().getWindowManager()->setSelectedWeapon(item);
2013-05-19 18:40:37 +02:00
}
}
}
2012-07-07 20:53:19 +02:00
MWMechanics::DrawState_ Player::getDrawState()
{
MWWorld::Ptr ptr = getPlayer();
return MWWorld::Class::get(ptr).getNpcStats(ptr).getDrawState();
}
}