1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 10:53:54 +00:00

Associate a character controller with each MWWorld::Ptr

This commit is contained in:
Chris Robinson 2013-01-12 07:12:12 -08:00
parent 97f8c73d91
commit 35d17fdaf6
3 changed files with 64 additions and 65 deletions

View file

@ -166,31 +166,29 @@ namespace MWMechanics
void Actors::addActor (const MWWorld::Ptr& ptr)
{
if (!MWWorld::Class::get (ptr).getCreatureStats (ptr).isDead())
mActors.insert (ptr);
mActors[ptr] = CharacterController();
else
MWBase::Environment::get().getWorld()->playAnimationGroup (ptr, "death1", 2);
}
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())
mActors.erase(iter);
}
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())
if (iter->getCell()==cellStore)
{
if(iter->first.getCell()==cellStore)
mActors.erase(iter++);
}
else
++iter;
}
}
void Actors::update (std::vector<std::pair<std::string, Ogre::Vector3> >& movement, float duration,
bool paused)
@ -202,78 +200,71 @@ namespace MWMechanics
float totalDuration = mDuration;
mDuration = 0;
std::set<MWWorld::Ptr>::iterator iter (mActors.begin());
PtrControllerMap::iterator iter(mActors.begin());
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())
updateNpc (*iter, totalDuration, paused);
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
{
iter++;
continue;
}
}
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")
if(iter->first.getRefData().getHandle()=="player")
{
MWMechanics::DynamicStat<float> stat (
MWWorld::Class::get (*iter).getCreatureStats (*iter).getHealth());
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).getHealth());
if (stat.getModified()<1)
{
stat.setModified (1, 0);
MWWorld::Class::get (*iter).getCreatureStats (*iter).setHealth (stat);
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).setHealth(stat);
}
MWWorld::Class::get (*iter).getCreatureStats (*iter).resurrect();
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).resurrect();
++iter;
continue;
}
++mDeathCount[MWWorld::Class::get (*iter).getId (*iter)];
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];
MWBase::Environment::get().getWorld()->playAnimationGroup (*iter, "death1", 0);
MWBase::Environment::get().getWorld()->playAnimationGroup(iter->first, "death1", 0);
if (MWWorld::Class::get (*iter).isEssential (*iter))
if(MWWorld::Class::get(iter->first).isEssential(iter->first))
MWBase::Environment::get().getWindowManager()->messageBox(
"#{sKilledEssential}", std::vector<std::string>());
mActors.erase(iter++);
}
else
++iter;
}
}
for (std::set<MWWorld::Ptr>::iterator iter (mActors.begin()); iter!=mActors.end();
++iter)
for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();++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)
movement.push_back (std::make_pair (iter->getRefData().getHandle(), vector));
movement.push_back(std::make_pair(iter->first.getRefData().getHandle(), vector));
}
}
void Actors::restoreDynamicStats()
{
for (std::set<MWWorld::Ptr>::iterator iter (mActors.begin()); iter!=mActors.end(); ++iter)
{
calculateRestoration (*iter, 3600);
}
for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();++iter)
calculateRestoration(iter->first, 3600);
}
int Actors::countDeaths (const std::string& id) const
{
std::map<std::string, int>::const_iterator iter = mDeathCount.find(id);
if(iter != mDeathCount.end())
return iter->second;
return 0;
}
}

View file

@ -6,6 +6,8 @@
#include <string>
#include <map>
#include "character.hpp"
namespace Ogre
{
class Vector3;
@ -21,7 +23,8 @@ namespace MWMechanics
{
class Actors
{
std::set<MWWorld::Ptr> mActors;
typedef std::map<MWWorld::Ptr,CharacterController> PtrControllerMap;
PtrControllerMap mActors;
float mDuration;
std::map<std::string, int> mDeathCount;

View file

@ -4,6 +4,11 @@
namespace MWMechanics
{
class CharacterController
{
};
}
#endif /* GAME_MWMECHANICS_CHARACTER_HPP */