mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-04 18:45:33 +00:00
added NPC stances
This commit is contained in:
parent
a724de2429
commit
b48a5084be
5 changed files with 150 additions and 19 deletions
|
@ -311,7 +311,6 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
if (!ptr.getRefData().getNpcStats().get())
|
if (!ptr.getRefData().getNpcStats().get())
|
||||||
{
|
{
|
||||||
// xxx
|
|
||||||
boost::shared_ptr<MWMechanics::NpcStats> stats (
|
boost::shared_ptr<MWMechanics::NpcStats> stats (
|
||||||
new MWMechanics::NpcStats);
|
new MWMechanics::NpcStats);
|
||||||
|
|
||||||
|
@ -363,6 +362,80 @@ namespace MWClass
|
||||||
return ref->base->script;
|
return ref->base->script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Npc::setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const
|
||||||
|
{
|
||||||
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
||||||
|
|
||||||
|
switch (stance)
|
||||||
|
{
|
||||||
|
case Run:
|
||||||
|
|
||||||
|
stats.mForceRun = force;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Sneak:
|
||||||
|
|
||||||
|
stats.mForceSneak = force;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Combat:
|
||||||
|
|
||||||
|
throw std::runtime_error ("combat stance not enforcable for NPCs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Npc::setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const
|
||||||
|
{
|
||||||
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
||||||
|
|
||||||
|
switch (stance)
|
||||||
|
{
|
||||||
|
case Run:
|
||||||
|
|
||||||
|
throw std::runtime_error ("run stance not manually setable for NPCs");
|
||||||
|
|
||||||
|
case Sneak:
|
||||||
|
|
||||||
|
stats.mSneak = set;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Combat:
|
||||||
|
|
||||||
|
stats.mCombat = set;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Npc::getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce) const
|
||||||
|
{
|
||||||
|
MWMechanics::NpcStats& stats = getNpcStats (ptr);
|
||||||
|
|
||||||
|
switch (stance)
|
||||||
|
{
|
||||||
|
case Run:
|
||||||
|
|
||||||
|
return ignoreForce ? false : stats.mForceRun;
|
||||||
|
|
||||||
|
case Sneak:
|
||||||
|
|
||||||
|
if (!ignoreForce && stats.mForceSneak)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return stats.mSneak;
|
||||||
|
|
||||||
|
case Combat:
|
||||||
|
|
||||||
|
return stats.mCombat;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Npc::getSpeed (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
return getStance (ptr, Run) ? 600 : 300; // TODO calculate these values from stats
|
||||||
|
}
|
||||||
|
|
||||||
void Npc::registerSelf()
|
void Npc::registerSelf()
|
||||||
{
|
{
|
||||||
boost::shared_ptr<Class> instance (new Npc);
|
boost::shared_ptr<Class> instance (new Npc);
|
||||||
|
|
|
@ -43,6 +43,19 @@ namespace MWClass
|
||||||
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
|
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
|
||||||
///< Return name of the script attached to ptr
|
///< Return name of the script attached to ptr
|
||||||
|
|
||||||
|
virtual void setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const;
|
||||||
|
///< Force or unforce a stance.
|
||||||
|
|
||||||
|
virtual void setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const;
|
||||||
|
///< Set or unset a stance.
|
||||||
|
|
||||||
|
virtual bool getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce = false)
|
||||||
|
const;
|
||||||
|
////< Check if a stance is active or not.
|
||||||
|
|
||||||
|
virtual float getSpeed (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< Return movement speed.
|
||||||
|
|
||||||
static void registerSelf();
|
static void registerSelf();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,13 @@ namespace MWMechanics
|
||||||
std::map<std::string, int> mFactionRank;
|
std::map<std::string, int> mFactionRank;
|
||||||
|
|
||||||
Stat<float> mSkill[27];
|
Stat<float> mSkill[27];
|
||||||
|
|
||||||
|
bool mForceRun;
|
||||||
|
bool mForceSneak;
|
||||||
|
bool mSneak;
|
||||||
|
bool mCombat;
|
||||||
|
|
||||||
|
NpcStats() : mForceRun (false), mForceSneak (false), mSneak (false), mCombat (false) {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,26 @@ namespace MWWorld
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Class::setForceStance (const Ptr& ptr, Stance stance, bool force) const
|
||||||
|
{
|
||||||
|
throw std::runtime_error ("stance not supported by class");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Class::setStance (const Ptr& ptr, Stance stance, bool set) const
|
||||||
|
{
|
||||||
|
throw std::runtime_error ("stance not supported by class");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Class::getStance (const Ptr& ptr, Stance stance, bool ignoreForce) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Class::getSpeed (const Ptr& ptr) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const Class& Class::get (const std::string& key)
|
const Class& Class::get (const std::string& key)
|
||||||
{
|
{
|
||||||
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);
|
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);
|
||||||
|
|
|
@ -41,6 +41,12 @@ namespace MWWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/// NPC-stances.
|
||||||
|
enum Stance
|
||||||
|
{
|
||||||
|
Run, Sneak, Combat
|
||||||
|
};
|
||||||
|
|
||||||
virtual ~Class();
|
virtual ~Class();
|
||||||
|
|
||||||
virtual std::string getId (const Ptr& ptr) const;
|
virtual std::string getId (const Ptr& ptr) const;
|
||||||
|
@ -108,6 +114,18 @@ namespace MWWorld
|
||||||
///< Return name of the script attached to ptr (default implementation: return an empty
|
///< Return name of the script attached to ptr (default implementation: return an empty
|
||||||
/// string).
|
/// string).
|
||||||
|
|
||||||
|
virtual void setForceStance (const Ptr& ptr, Stance stance, bool force) const;
|
||||||
|
///< Force or unforce a stance.
|
||||||
|
|
||||||
|
virtual void setStance (const Ptr& ptr, Stance stance, bool set) const;
|
||||||
|
///< Set or unset a stance.
|
||||||
|
|
||||||
|
virtual bool getStance (const Ptr& ptr, Stance stance, bool ignoreForce = false) const;
|
||||||
|
////< Check if a stance is active or not.
|
||||||
|
|
||||||
|
virtual float getSpeed (const Ptr& ptr) const;
|
||||||
|
///< Return movement speed.
|
||||||
|
|
||||||
static const Class& get (const std::string& key);
|
static const Class& get (const std::string& key);
|
||||||
///< If there is no class for this \a key, an exception is thrown.
|
///< If there is no class for this \a key, an exception is thrown.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue