1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 22:19:54 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/aiactivate.cpp

71 lines
2.2 KiB
C++
Raw Normal View History

2012-11-15 21:22:44 +00:00
#include "aiactivate.hpp"
2014-02-05 15:12:50 +00:00
2014-06-12 21:27:04 +00:00
#include <components/esm/aisequence.hpp>
2014-02-05 15:12:50 +00:00
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
2014-02-23 19:11:05 +00:00
2014-02-05 15:12:50 +00:00
#include "../mwworld/class.hpp"
2016-06-17 14:07:16 +00:00
#include "creaturestats.hpp"
2014-02-17 09:50:10 +00:00
#include "steering.hpp"
2014-02-23 19:11:05 +00:00
#include "movement.hpp"
2014-02-05 15:12:50 +00:00
2016-06-17 11:50:46 +00:00
namespace MWMechanics
{
2016-06-17 11:50:46 +00:00
AiActivate::AiActivate(const std::string &objectId)
: mObjectId(objectId)
{
}
2014-06-12 21:27:04 +00:00
2016-06-17 11:50:46 +00:00
AiActivate *MWMechanics::AiActivate::clone() const
{
return new AiActivate(*this);
}
bool AiActivate::execute(const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration)
2016-06-17 11:50:46 +00:00
{
const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(mObjectId, false); //The target to follow
2016-06-17 11:50:46 +00:00
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Nothing);
2014-06-12 21:27:04 +00:00
2018-11-02 11:24:43 +00:00
// Stop if the target doesn't exist
// Really we should be checking whether the target is currently registered with the MechanicsManager
if (target == MWWorld::Ptr() || !target.getRefData().getCount() || !target.getRefData().isEnabled())
return true;
2014-06-12 21:27:04 +00:00
//Set the target destination for the actor
2018-11-02 11:24:43 +00:00
const osg::Vec3f dest = target.getRefData().getPosition().asVec3();
if (pathTo(actor, dest, duration, MWBase::Environment::get().getWorld()->getMaxActivationDistance())) //Stop when you get in activation range
{
// activate when reached
2016-06-17 11:50:46 +00:00
MWBase::Environment::get().getWorld()->activate(target, actor);
return true;
}
2016-06-17 11:50:46 +00:00
return false;
}
2014-06-12 21:27:04 +00:00
2016-06-17 11:50:46 +00:00
int AiActivate::getTypeId() const
{
return TypeIdActivate;
}
2014-06-12 21:27:04 +00:00
2016-06-17 11:50:46 +00:00
void AiActivate::writeState(ESM::AiSequence::AiSequence &sequence) const
{
std::unique_ptr<ESM::AiSequence::AiActivate> activate(new ESM::AiSequence::AiActivate());
2016-06-17 11:50:46 +00:00
activate->mTargetId = mObjectId;
2014-06-12 21:27:04 +00:00
2016-06-17 11:50:46 +00:00
ESM::AiSequence::AiPackageContainer package;
package.mType = ESM::AiSequence::Ai_Activate;
package.mPackage = activate.release();
sequence.mPackages.push_back(package);
}
2014-06-12 21:27:04 +00:00
2016-06-17 11:50:46 +00:00
AiActivate::AiActivate(const ESM::AiSequence::AiActivate *activate)
: mObjectId(activate->mTargetId)
{
}
2014-06-12 21:27:04 +00:00
}