mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 13:53:55 +00:00
Associate a character controller with each MWWorld::Ptr
This commit is contained in:
parent
97f8c73d91
commit
35d17fdaf6
3 changed files with 64 additions and 65 deletions
|
@ -166,30 +166,28 @@ namespace MWMechanics
|
||||||
void Actors::addActor (const MWWorld::Ptr& ptr)
|
void Actors::addActor (const MWWorld::Ptr& ptr)
|
||||||
{
|
{
|
||||||
if (!MWWorld::Class::get (ptr).getCreatureStats (ptr).isDead())
|
if (!MWWorld::Class::get (ptr).getCreatureStats (ptr).isDead())
|
||||||
mActors.insert (ptr);
|
mActors[ptr] = CharacterController();
|
||||||
else
|
else
|
||||||
MWBase::Environment::get().getWorld()->playAnimationGroup (ptr, "death1", 2);
|
MWBase::Environment::get().getWorld()->playAnimationGroup (ptr, "death1", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actors::removeActor (const MWWorld::Ptr& ptr)
|
void Actors::removeActor (const MWWorld::Ptr& ptr)
|
||||||
{
|
{
|
||||||
std::set<MWWorld::Ptr>::iterator iter = mActors.find (ptr);
|
PtrControllerMap::iterator iter = mActors.find(ptr);
|
||||||
|
if(iter != mActors.end())
|
||||||
if (iter!=mActors.end())
|
mActors.erase(iter);
|
||||||
mActors.erase (iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actors::dropActors (const MWWorld::Ptr::CellStore *cellStore)
|
void Actors::dropActors (const MWWorld::Ptr::CellStore *cellStore)
|
||||||
{
|
{
|
||||||
std::set<MWWorld::Ptr>::iterator iter = mActors.begin();
|
PtrControllerMap::iterator iter = mActors.begin();
|
||||||
|
while(iter != mActors.end())
|
||||||
while (iter!=mActors.end())
|
{
|
||||||
if (iter->getCell()==cellStore)
|
if(iter->first.getCell()==cellStore)
|
||||||
{
|
mActors.erase(iter++);
|
||||||
mActors.erase (iter++);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
++iter;
|
++iter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actors::update (std::vector<std::pair<std::string, Ogre::Vector3> >& movement, float duration,
|
void Actors::update (std::vector<std::pair<std::string, Ogre::Vector3> >& movement, float duration,
|
||||||
|
@ -202,78 +200,71 @@ namespace MWMechanics
|
||||||
float totalDuration = mDuration;
|
float totalDuration = mDuration;
|
||||||
mDuration = 0;
|
mDuration = 0;
|
||||||
|
|
||||||
std::set<MWWorld::Ptr>::iterator iter (mActors.begin());
|
PtrControllerMap::iterator iter(mActors.begin());
|
||||||
|
while(iter != mActors.end())
|
||||||
while (iter!=mActors.end())
|
|
||||||
{
|
{
|
||||||
if (!MWWorld::Class::get (*iter).getCreatureStats (*iter).isDead())
|
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
||||||
{
|
{
|
||||||
updateActor (*iter, totalDuration);
|
updateActor(iter->first, totalDuration);
|
||||||
|
if(iter->first.getTypeName() == typeid(ESM::NPC).name())
|
||||||
|
updateNpc(iter->first, totalDuration, paused);
|
||||||
|
|
||||||
if (iter->getTypeName()==typeid (ESM::NPC).name())
|
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
||||||
updateNpc (*iter, totalDuration, paused);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MWWorld::Class::get (*iter).getCreatureStats (*iter).isDead())
|
|
||||||
{
|
|
||||||
// workaround: always keep player alive for now
|
|
||||||
// \todo remove workaround, once player death can be handled
|
|
||||||
if (iter->getRefData().getHandle()=="player")
|
|
||||||
{
|
{
|
||||||
MWMechanics::DynamicStat<float> stat (
|
iter++;
|
||||||
MWWorld::Class::get (*iter).getCreatureStats (*iter).getHealth());
|
|
||||||
|
|
||||||
if (stat.getModified()<1)
|
|
||||||
{
|
|
||||||
stat.setModified (1, 0);
|
|
||||||
MWWorld::Class::get (*iter).getCreatureStats (*iter).setHealth (stat);
|
|
||||||
}
|
|
||||||
|
|
||||||
MWWorld::Class::get (*iter).getCreatureStats (*iter).resurrect();
|
|
||||||
++iter;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
++mDeathCount[MWWorld::Class::get (*iter).getId (*iter)];
|
|
||||||
|
|
||||||
MWBase::Environment::get().getWorld()->playAnimationGroup (*iter, "death1", 0);
|
|
||||||
|
|
||||||
if (MWWorld::Class::get (*iter).isEssential (*iter))
|
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox (
|
|
||||||
"#{sKilledEssential}", std::vector<std::string>());
|
|
||||||
|
|
||||||
mActors.erase (iter++);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// workaround: always keep player alive for now
|
||||||
|
// \todo remove workaround, once player death can be handled
|
||||||
|
if(iter->first.getRefData().getHandle()=="player")
|
||||||
|
{
|
||||||
|
MWMechanics::DynamicStat<float> stat (
|
||||||
|
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).getHealth());
|
||||||
|
|
||||||
|
if (stat.getModified()<1)
|
||||||
|
{
|
||||||
|
stat.setModified (1, 0);
|
||||||
|
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).setHealth(stat);
|
||||||
|
}
|
||||||
|
|
||||||
|
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).resurrect();
|
||||||
++iter;
|
++iter;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];
|
||||||
|
|
||||||
|
MWBase::Environment::get().getWorld()->playAnimationGroup(iter->first, "death1", 0);
|
||||||
|
|
||||||
|
if(MWWorld::Class::get(iter->first).isEssential(iter->first))
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox(
|
||||||
|
"#{sKilledEssential}", std::vector<std::string>());
|
||||||
|
|
||||||
|
mActors.erase(iter++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<MWWorld::Ptr>::iterator iter (mActors.begin()); iter!=mActors.end();
|
for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();++iter)
|
||||||
++iter)
|
|
||||||
{
|
{
|
||||||
Ogre::Vector3 vector = MWWorld::Class::get (*iter).getMovementVector (*iter);
|
Ogre::Vector3 vector = MWWorld::Class::get(iter->first).getMovementVector(iter->first);
|
||||||
|
if(vector!=Ogre::Vector3::ZERO)
|
||||||
if (vector!=Ogre::Vector3::ZERO)
|
movement.push_back(std::make_pair(iter->first.getRefData().getHandle(), vector));
|
||||||
movement.push_back (std::make_pair (iter->getRefData().getHandle(), vector));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actors::restoreDynamicStats()
|
void Actors::restoreDynamicStats()
|
||||||
{
|
{
|
||||||
for (std::set<MWWorld::Ptr>::iterator iter (mActors.begin()); iter!=mActors.end(); ++iter)
|
for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();++iter)
|
||||||
{
|
calculateRestoration(iter->first, 3600);
|
||||||
calculateRestoration (*iter, 3600);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Actors::countDeaths (const std::string& id) const
|
int Actors::countDeaths (const std::string& id) const
|
||||||
{
|
{
|
||||||
std::map<std::string, int>::const_iterator iter = mDeathCount.find (id);
|
std::map<std::string, int>::const_iterator iter = mDeathCount.find(id);
|
||||||
|
if(iter != mDeathCount.end())
|
||||||
if (iter!=mDeathCount.end())
|
|
||||||
return iter->second;
|
return iter->second;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "character.hpp"
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
class Vector3;
|
class Vector3;
|
||||||
|
@ -21,9 +23,10 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
class Actors
|
class Actors
|
||||||
{
|
{
|
||||||
std::set<MWWorld::Ptr> mActors;
|
typedef std::map<MWWorld::Ptr,CharacterController> PtrControllerMap;
|
||||||
float mDuration;
|
PtrControllerMap mActors;
|
||||||
std::map<std::string, int> mDeathCount;
|
float mDuration;
|
||||||
|
std::map<std::string, int> mDeathCount;
|
||||||
|
|
||||||
void updateNpc (const MWWorld::Ptr& ptr, float duration, bool paused);
|
void updateNpc (const MWWorld::Ptr& ptr, float duration, bool paused);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class CharacterController
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GAME_MWMECHANICS_CHARACTER_HPP */
|
#endif /* GAME_MWMECHANICS_CHARACTER_HPP */
|
||||||
|
|
Loading…
Reference in a new issue