[Client] Clean up parts of LocalPlayer and DedicatedPlayer

pull/199/head
David Cernat 8 years ago
parent a650683bae
commit c05c456b11

@ -181,35 +181,6 @@ MWWorld::ManualRef *DedicatedPlayer::getRef()
return reference;
}
ESM::Position Slerp(ESM::Position start, ESM::Position end, float percent)
{
// dot product - the cosine of the angle between 2 vectors.
float dot = start.asVec3() * end.asVec3();
// clamp it to be in the range of Acos()
// This may be unnecessary, but floating point
// precision can be a fickle mistress.
dot = boost::algorithm::clamp(dot, -1.0f, 1.0f);
// acos(dot) returns the angle between start and end,
// And multiplying that by percent returns the angle between
// start and the final result.
float theta = acos(dot) * percent;
osg::Vec3f relativeVec = end.asVec3() - start.asVec3() * dot;
relativeVec.normalize(); // Orthonormal basis
// result
osg::Vec3f tmp ((start.asVec3() * cos(theta)) + (relativeVec * sin(theta)));
ESM::Position result;
result.pos[0] = tmp.x();
result.pos[1] = tmp.y();
result.pos[2] = tmp.z();
result.rot[0] = start.rot[0];
result.rot[1] = start.rot[1];
result.rot[2] = result.rot[2];
return result;
}
void DedicatedPlayer::move(float dt)
{
if (state != 2) return;
@ -340,74 +311,6 @@ void DedicatedPlayer::updateEquipment()
}
}
const std::string DedicatedPlayer::getAnim()
{
static string anim;
static string animDir;
static string animWeap;
MWMechanics::NpcStats *npcStats = &ptr.getClass().getNpcStats(ptr);
if (movementFlags & MWMechanics::CreatureStats::Flag_Run)
anim = "run";
else if (movementFlags & MWMechanics::CreatureStats::Flag_Sneak)
anim = "sneak";
else
anim = "walk";
if (movementAnim != 0)
{
if (movementAnim == 3)
animDir = "forward";
else if (movementAnim == 4)
animDir = "back";
else if (movementAnim == 2)
animDir = "left";
else if (movementAnim == 1)
animDir = "right";
}
else
{
anim = "idle";
animDir = "";
}
if (npcStats->getDrawState() == MWMechanics::DrawState_Weapon)
{
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore(ptr);
MWWorld::ContainerStoreIterator weaponSlot = invStore.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if (weaponSlot != invStore.end() && weaponSlot->getTypeName() == typeid(ESM::Weapon).name())
{
int type = weaponSlot->get<ESM::Weapon>()->mBase->mData.mType;
if (type == ESM::Weapon::ShortBladeOneHand ||
type == ESM::Weapon::LongBladeOneHand ||
type == ESM::Weapon::BluntOneHand ||
type == ESM::Weapon::AxeOneHand /*||
type == ESM::Weapon::MarksmanThrown ||
type == ESM::Weapon::MarksmanCrossbow ||
type == ESM::Weapon::MarksmanBow*/)
animWeap = "1h";
else if (type == ESM::Weapon::LongBladeTwoHand ||
type == ESM::Weapon::BluntTwoClose ||
type == ESM::Weapon::AxeTwoHand)
animWeap = "2c";
else if (type == ESM::Weapon::BluntTwoWide ||
type == ESM::Weapon::SpearTwoWide)
animWeap = "2w";
}
else
animWeap = "hh";
}
else if (movementAnim == 0 && npcStats->getDrawState() == MWMechanics::DrawState_Spell)
animWeap = "spell";
else
animWeap = "";
return (anim + animDir + animWeap);
}
DedicatedPlayer *Players::getPlayer(const MWWorld::Ptr &ptr)
{
std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin();

@ -2,18 +2,20 @@
// Created by koncord on 02.01.16.
//
#ifndef OPENMW_PLAYER_HPP
#define OPENMW_PLAYER_HPP
#ifndef OPENMW_DEDICATEDPLAYER_HPP
#define OPENMW_DEDICATEDPLAYER_HPP
#include <components/esm/custommarkerstate.hpp>
#include <components/esm/loadnpc.hpp>
#include <components/openmw-mp/Base/BasePlayer.hpp>
#include "../mwmechanics/aisequence.hpp"
#include "../mwworld/manualref.hpp"
#include <map>
#include "../mwmechanics/aisequence.hpp"
#include <RakNetTypes.h>
#include <components/openmw-mp/Base/BasePlayer.hpp>
#include <components/esm/custommarkerstate.hpp>
namespace MWMechanics
{
class Actor;
@ -26,6 +28,7 @@ namespace mwmp
class Players
{
public:
static DedicatedPlayer *newPlayer(RakNet::RakNetGUID guid);
static void createPlayer(RakNet::RakNetGUID guid);
static void disconnectPlayer(RakNet::RakNetGUID guid);
@ -33,13 +36,16 @@ namespace mwmp
static DedicatedPlayer *getPlayer(RakNet::RakNetGUID guid);
static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr);
static void update(float dt);
private:
static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players;
};
class DedicatedPlayer : public BasePlayer
{
friend class Players;
public:
MWWorld::Ptr getPtr();
@ -55,11 +61,13 @@ namespace mwmp
void removeMarker();
void setMarkerState(bool state);
void updateActor(MWMechanics::Actor *actor);
private:
DedicatedPlayer(RakNet::RakNetGUID guid);
virtual ~DedicatedPlayer();
void updatePtr(MWWorld::Ptr newPtr);
const std::string getAnim();
int state;
MWWorld::ManualRef* reference;
@ -69,4 +77,4 @@ namespace mwmp
bool markerEnabled;
};
}
#endif //OPENMW_PLAYER_HPP
#endif //OPENMW_DEDICATEDPLAYER_HPP

@ -523,32 +523,22 @@ void LocalPlayer::updateAttackState(bool forceUpdate)
static bool attackPressed = false; // prevent flood
MWMechanics::DrawState_ state = player.getClass().getNpcStats(player).getDrawState();
//player.getClass().hit(player, 1, ESM::Weapon::AT_Chop);
if (world->getPlayer().getAttackingOrSpell() && !attackPressed)
{
MWWorld::Ptr weapon = MWWorld::Ptr(); // hand-to-hand
//player.getClass().onHit(player, 0.5, true, weapon, 0, 1);
if (state == MWMechanics::DrawState_Spell)
{
const string &spell = MWBase::Environment::get().getWindowManager()->getSelectedSpell();
attack.type = Attack::MAGIC;
attack.pressed = true;
attack.spellId = spell;
}
else if (state == MWMechanics::DrawState_Weapon)
{
//PrepareAttack(2);
attack.spellId = MWBase::Environment::get().getWindowManager()->getSelectedSpell();
}
attackPressed = true;
}
else if (!world->getPlayer().getAttackingOrSpell() && attackPressed)
{
if (/*state == MWMechanics::DrawState_Spell ||*/ state == MWMechanics::DrawState_Weapon)
{
//localNetPlayer->getAttack()->success = false;
//SendAttack(0);
}
attackPressed = false;
}
}
@ -1181,10 +1171,9 @@ void LocalPlayer::prepareAttack(Attack::TYPE type, bool state)
if (dstate == MWMechanics::DrawState_Spell)
{
const string &spell = MWBase::Environment::get().getWindowManager()->getSelectedSpell();
attack.success = Misc::Rng::roll0to99() < MWMechanics::getSpellSuccessChance(spell, getPlayerPtr());
attack.spellId = MWBase::Environment::get().getWindowManager()->getSelectedSpell();
attack.success = Misc::Rng::roll0to99() < MWMechanics::getSpellSuccessChance(attack.spellId, getPlayerPtr());
state = true;
attack.spellId = spell;
}
else
{

Loading…
Cancel
Save