1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-02 03:45:34 +00:00

Issue #324: Started turning NpcStats into a proper class; fixed a cmake script bug; fixed a namespace issue

This commit is contained in:
Marc Zinnschlag 2012-07-06 15:50:26 +02:00
parent 1a5203749f
commit 771863e73b
8 changed files with 57 additions and 30 deletions

View file

@ -60,7 +60,7 @@ add_openmw_dir (mwclass
add_openmw_dir (mwmechanics
mechanicsmanager stat creaturestats magiceffects movement actors drawstate spells
activespells
activespells npcstats
)
add_openmw_dir (mwbase

View file

@ -233,7 +233,8 @@ namespace MWClass
case Combat:
stats.mCombat = set;
// Combat stance ignored for now; need to be determined based on draw state instead of
// being maunally set.
break;
}
}
@ -260,7 +261,7 @@ namespace MWClass
case Combat:
return stats.mCombat;
return false;
}
return false;

View file

@ -102,15 +102,15 @@ private:
{
if (windows.isGuiMode()) return;
DrawState state = player.getDrawState();
if (state == DrawState_Weapon || state == DrawState_Nothing)
MWMechanics::DrawState state = player.getDrawState();
if (state == MWMechanics::DrawState_Weapon || state == MWMechanics::DrawState_Nothing)
{
player.setDrawState(DrawState_Spell);
player.setDrawState(MWMechanics::DrawState_Spell);
std::cout << "Player has now readied his hands for spellcasting!\n";
}
else
{
player.setDrawState(DrawState_Nothing);
player.setDrawState(MWMechanics::DrawState_Nothing);
std::cout << "Player does not have any kind of attack ready now.\n";
}
}
@ -119,15 +119,15 @@ private:
{
if (windows.isGuiMode()) return;
DrawState state = player.getDrawState();
if (state == DrawState_Spell || state == DrawState_Nothing)
MWMechanics::DrawState state = player.getDrawState();
if (state == MWMechanics::DrawState_Spell || state == MWMechanics::DrawState_Nothing)
{
player.setDrawState(DrawState_Weapon);
player.setDrawState(MWMechanics::DrawState_Weapon);
std::cout << "Player is now drawing his weapon.\n";
}
else
{
player.setDrawState(DrawState_Nothing);
player.setDrawState(MWMechanics::DrawState_Nothing);
std::cout << "Player does not have any kind of attack ready now.\n";
}
}
@ -336,7 +336,7 @@ private:
poller.bind(A_MoveRight, KC_D);
poller.bind(A_MoveForward, KC_W);
poller.bind(A_MoveBackward, KC_S);
poller.bind(A_Jump, KC_E);
poller.bind(A_Crouch, KC_LCONTROL);
}

View file

@ -3,11 +3,14 @@
#undef DrawState
enum DrawState
namespace MWMechanics
{
DrawState_Weapon = 0,
DrawState_Spell = 1,
DrawState_Nothing = 2,
};
enum DrawState
{
DrawState_Weapon = 0,
DrawState_Spell = 1,
DrawState_Nothing = 2,
};
}
#endif

View file

@ -0,0 +1,17 @@
#include "npcstats.hpp"
MWMechanics::NpcStats::NpcStats()
: mForceRun (false), mForceSneak (false), mRun (false), mSneak (false),
mDrawState (DrawState_Nothing)
{}
MWMechanics::DrawState MWMechanics::NpcStats::getDrawState() const
{
return mDrawState;
}
void MWMechanics::NpcStats::setDrawState (DrawState state)
{
mDrawState = state;
}

View file

@ -3,6 +3,7 @@
#include <map>
#include <set>
#include <string>
#include "stat.hpp"
#include "drawstate.hpp"
@ -16,10 +17,14 @@ namespace MWMechanics
/// \note For technical reasons the spell list and the currently selected spell is also handled by
/// CreatureStats, even though they are actually NPC stats.
struct NpcStats
class NpcStats
{
// NPCs other than the player can only have one faction. But for the sake of consistency
// we use the same data structure for the PC and the NPCs.
DrawState mDrawState;
public:
/// NPCs other than the player can only have one faction. But for the sake of consistency
/// we use the same data structure for the PC and the NPCs.
/// \note the faction key must be in lowercase
std::map<std::string, int> mFactionRank;
@ -29,11 +34,12 @@ namespace MWMechanics
bool mForceSneak;
bool mRun;
bool mSneak;
bool mCombat;
DrawState mDrawState;
NpcStats() : mForceRun (false), mForceSneak (false), mRun (false), mSneak (false),
mCombat (false) , mDrawState(DrawState_Nothing) {}
NpcStats();
DrawState getDrawState() const;
void setDrawState (DrawState state);
};
}

View file

@ -56,10 +56,10 @@ namespace MWWorld
mClass = new_class;
}
void Player::setDrawState(const DrawState& value)
void Player::setDrawState (MWMechanics::DrawState state)
{
MWWorld::Ptr ptr = getPlayer();
MWWorld::Class::get(ptr).getNpcStats(ptr).mDrawState = value;
MWWorld::Class::get(ptr).getNpcStats(ptr).setDrawState (state);
}
void Player::setAutoMove (bool enable)
@ -111,10 +111,10 @@ namespace MWWorld
MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Run, !running);
}
DrawState Player::getDrawState()
MWMechanics::DrawState Player::getDrawState()
{
MWWorld::Ptr ptr = getPlayer();
return MWWorld::Class::get(ptr).getNpcStats(ptr).mDrawState;
return MWWorld::Class::get(ptr).getNpcStats(ptr).getDrawState();
}
}

View file

@ -83,7 +83,7 @@ namespace MWWorld
void setClass (const ESM::Class& class_);
void setDrawState(const DrawState& state);
void setDrawState (MWMechanics::DrawState state);
std::string getName() const
{
@ -115,7 +115,7 @@ namespace MWWorld
return mAutoMove;
}
DrawState getDrawState();
MWMechanics::DrawState getDrawState(); /// \todo constness
void setAutoMove (bool enable);