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 add_openmw_dir (mwmechanics
mechanicsmanager stat creaturestats magiceffects movement actors drawstate spells mechanicsmanager stat creaturestats magiceffects movement actors drawstate spells
activespells activespells npcstats
) )
add_openmw_dir (mwbase add_openmw_dir (mwbase

View file

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

View file

@ -102,15 +102,15 @@ private:
{ {
if (windows.isGuiMode()) return; if (windows.isGuiMode()) return;
DrawState state = player.getDrawState(); MWMechanics::DrawState state = player.getDrawState();
if (state == DrawState_Weapon || state == DrawState_Nothing) 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"; std::cout << "Player has now readied his hands for spellcasting!\n";
} }
else else
{ {
player.setDrawState(DrawState_Nothing); player.setDrawState(MWMechanics::DrawState_Nothing);
std::cout << "Player does not have any kind of attack ready now.\n"; std::cout << "Player does not have any kind of attack ready now.\n";
} }
} }
@ -119,15 +119,15 @@ private:
{ {
if (windows.isGuiMode()) return; if (windows.isGuiMode()) return;
DrawState state = player.getDrawState(); MWMechanics::DrawState state = player.getDrawState();
if (state == DrawState_Spell || state == DrawState_Nothing) 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"; std::cout << "Player is now drawing his weapon.\n";
} }
else else
{ {
player.setDrawState(DrawState_Nothing); player.setDrawState(MWMechanics::DrawState_Nothing);
std::cout << "Player does not have any kind of attack ready now.\n"; std::cout << "Player does not have any kind of attack ready now.\n";
} }
} }

View file

@ -3,11 +3,14 @@
#undef DrawState #undef DrawState
namespace MWMechanics
{
enum DrawState enum DrawState
{ {
DrawState_Weapon = 0, DrawState_Weapon = 0,
DrawState_Spell = 1, DrawState_Spell = 1,
DrawState_Nothing = 2, DrawState_Nothing = 2,
}; };
}
#endif #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 <map>
#include <set> #include <set>
#include <string>
#include "stat.hpp" #include "stat.hpp"
#include "drawstate.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 /// \note For technical reasons the spell list and the currently selected spell is also handled by
/// CreatureStats, even though they are actually NPC stats. /// 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 DrawState mDrawState;
// we use the same data structure for the PC and the NPCs.
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 /// \note the faction key must be in lowercase
std::map<std::string, int> mFactionRank; std::map<std::string, int> mFactionRank;
@ -29,11 +34,12 @@ namespace MWMechanics
bool mForceSneak; bool mForceSneak;
bool mRun; bool mRun;
bool mSneak; bool mSneak;
bool mCombat;
DrawState mDrawState;
NpcStats() : mForceRun (false), mForceSneak (false), mRun (false), mSneak (false), NpcStats();
mCombat (false) , mDrawState(DrawState_Nothing) {}
DrawState getDrawState() const;
void setDrawState (DrawState state);
}; };
} }

View file

@ -56,10 +56,10 @@ namespace MWWorld
mClass = new_class; mClass = new_class;
} }
void Player::setDrawState(const DrawState& value) void Player::setDrawState (MWMechanics::DrawState state)
{ {
MWWorld::Ptr ptr = getPlayer(); 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) void Player::setAutoMove (bool enable)
@ -111,10 +111,10 @@ namespace MWWorld
MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Run, !running); MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Run, !running);
} }
DrawState Player::getDrawState() MWMechanics::DrawState Player::getDrawState()
{ {
MWWorld::Ptr ptr = getPlayer(); 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 setClass (const ESM::Class& class_);
void setDrawState(const DrawState& state); void setDrawState (MWMechanics::DrawState state);
std::string getName() const std::string getName() const
{ {
@ -115,7 +115,7 @@ namespace MWWorld
return mAutoMove; return mAutoMove;
} }
DrawState getDrawState(); MWMechanics::DrawState getDrawState(); /// \todo constness
void setAutoMove (bool enable); void setAutoMove (bool enable);