2014-05-03 10:23:22 +00:00
|
|
|
#include "aipursue.hpp"
|
2014-04-02 04:18:22 +00:00
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
#include <components/esm/aisequence.hpp>
|
|
|
|
|
2014-04-02 04:18:22 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2020-05-09 18:14:58 +00:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2019-11-18 08:41:11 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2019-02-18 22:10:55 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2014-04-02 04:18:22 +00:00
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
2017-04-16 17:26:06 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Include additional headers for multiplayer purposes
|
|
|
|
*/
|
2019-08-19 18:39:33 +00:00
|
|
|
#include <components/openmw-mp/TimedLog.hpp>
|
2017-04-16 17:26:06 +00:00
|
|
|
#include "../mwgui/windowmanagerimp.hpp"
|
2017-09-04 12:13:05 +00:00
|
|
|
#include "../mwmp/Main.hpp"
|
|
|
|
#include "../mwmp/LocalPlayer.hpp"
|
2017-04-16 17:26:06 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
2014-04-02 04:18:22 +00:00
|
|
|
#include "movement.hpp"
|
|
|
|
#include "creaturestats.hpp"
|
2019-04-28 12:41:10 +00:00
|
|
|
#include "combat.hpp"
|
2014-04-02 04:18:22 +00:00
|
|
|
|
2014-05-17 15:20:57 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
|
|
|
|
AiPursue::AiPursue(const MWWorld::Ptr& actor)
|
2014-04-02 04:18:22 +00:00
|
|
|
{
|
2017-11-21 16:00:51 +00:00
|
|
|
mTargetActorId = actor.getClass().getCreatureStats(actor).getActorId();
|
2014-04-02 04:18:22 +00:00
|
|
|
}
|
2014-06-12 21:27:04 +00:00
|
|
|
|
|
|
|
AiPursue::AiPursue(const ESM::AiSequence::AiPursue *pursue)
|
|
|
|
{
|
2017-11-21 16:00:51 +00:00
|
|
|
mTargetActorId = pursue->mTargetActorId;
|
2014-06-12 21:27:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 15:47:04 +00:00
|
|
|
bool AiPursue::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration)
|
2014-04-02 04:18:22 +00:00
|
|
|
{
|
2014-08-23 20:55:32 +00:00
|
|
|
if(actor.getClass().getCreatureStats(actor).isDead())
|
|
|
|
return true;
|
|
|
|
|
2014-05-17 15:20:57 +00:00
|
|
|
const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId); //The target to follow
|
2014-04-02 04:18:22 +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-05-03 15:14:59 +00:00
|
|
|
|
2020-08-09 09:48:59 +00:00
|
|
|
if (isTargetMagicallyHidden(target) && !MWBase::Environment::get().getMechanicsManager()->awarenessCheck(target, actor))
|
2020-05-09 18:14:58 +00:00
|
|
|
return false;
|
2014-12-21 16:34:34 +00:00
|
|
|
|
2018-11-02 11:24:43 +00:00
|
|
|
if (target.getClass().getCreatureStats(target).isDead())
|
2014-08-23 20:55:32 +00:00
|
|
|
return true;
|
|
|
|
|
2017-04-16 17:26:06 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Because multiplayer does not pause the game, prevent infinite arrest loops by ignoring
|
2020-07-26 09:06:11 +00:00
|
|
|
players already engaged in dialogue while retaining the AiPursue package
|
2018-02-25 19:33:04 +00:00
|
|
|
|
|
|
|
Additionally, do not arrest players who are currently jailed
|
2017-04-16 17:26:06 +00:00
|
|
|
*/
|
|
|
|
if (target == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
|
|
|
{
|
2018-02-25 19:33:04 +00:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_Dialogue) ||
|
|
|
|
MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_Jail))
|
2017-04-16 17:26:06 +00:00
|
|
|
{
|
2020-07-26 09:06:11 +00:00
|
|
|
return false;
|
2017-04-16 17:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
2014-07-28 15:28:00 +00:00
|
|
|
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Nothing);
|
|
|
|
|
2018-11-02 11:24:43 +00:00
|
|
|
//Set the target destination
|
|
|
|
const osg::Vec3f dest = target.getRefData().getPosition().asVec3();
|
|
|
|
const osg::Vec3f actorPos = actor.getRefData().getPosition().asVec3();
|
2014-04-02 04:18:22 +00:00
|
|
|
|
2018-11-02 11:24:43 +00:00
|
|
|
const float pathTolerance = 100.f;
|
2017-04-16 17:26:06 +00:00
|
|
|
|
2021-03-03 19:04:10 +00:00
|
|
|
// check the true distance in case the target is far away in Z-direction
|
|
|
|
bool reached = pathTo(actor, dest, duration, pathTolerance) &&
|
|
|
|
std::abs(dest.z() - actorPos.z()) < pathTolerance;
|
|
|
|
|
|
|
|
if (reached)
|
2017-11-02 19:01:22 +00:00
|
|
|
{
|
2021-03-03 19:04:10 +00:00
|
|
|
if (!MWBase::Environment::get().getWorld()->getLOS(target, actor))
|
|
|
|
return false;
|
2021-03-20 14:44:11 +00:00
|
|
|
|
2017-09-04 12:13:05 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Record that the player has not died since the last attempt to arrest them
|
2017-12-16 05:21:02 +00:00
|
|
|
|
|
|
|
Close the player's inventory or open container and cancel any drag and drops
|
2017-09-04 12:13:05 +00:00
|
|
|
*/
|
2019-08-19 18:39:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "After being pursued by %s, diedSinceArrestAttempt is now false", actor.getCellRef().getRefId().c_str());
|
2017-09-04 12:13:05 +00:00
|
|
|
mwmp::Main::get().getLocalPlayer()->diedSinceArrestAttempt = false;
|
2017-12-16 05:21:02 +00:00
|
|
|
mwmp::Main::get().getLocalPlayer()->closeInventoryWindows();
|
2017-09-04 12:13:05 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2021-03-20 14:44:11 +00:00
|
|
|
|
2019-11-18 08:41:11 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Dialogue, actor); //Arrest player when reached
|
2014-04-02 04:18:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-13 01:05:32 +00:00
|
|
|
actor.getClass().getCreatureStats(actor).setMovementFlag(MWMechanics::CreatureStats::Flag_Run, true); //Make NPC run
|
2014-04-02 04:18:22 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-17 15:20:57 +00:00
|
|
|
MWWorld::Ptr AiPursue::getTarget() const
|
2014-05-12 20:05:30 +00:00
|
|
|
{
|
2014-05-17 15:20:57 +00:00
|
|
|
return MWBase::Environment::get().getWorld()->searchPtrViaActorId(mTargetActorId);
|
2014-05-12 20:05:30 +00:00
|
|
|
}
|
2014-05-17 15:20:57 +00:00
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
void AiPursue::writeState(ESM::AiSequence::AiSequence &sequence) const
|
|
|
|
{
|
2017-04-28 15:30:26 +00:00
|
|
|
std::unique_ptr<ESM::AiSequence::AiPursue> pursue(new ESM::AiSequence::AiPursue());
|
2014-06-12 21:27:04 +00:00
|
|
|
pursue->mTargetActorId = mTargetActorId;
|
|
|
|
|
|
|
|
ESM::AiSequence::AiPackageContainer package;
|
|
|
|
package.mType = ESM::AiSequence::Ai_Pursue;
|
|
|
|
package.mPackage = pursue.release();
|
|
|
|
sequence.mPackages.push_back(package);
|
|
|
|
}
|
|
|
|
|
2014-05-17 15:20:57 +00:00
|
|
|
} // namespace MWMechanics
|