Merge pull request #1043 from DarkflameUniverse/update-change-orientation-behavior

Fix and fully implement ChangeOrientation behavior
This commit is contained in:
Gie "Max" Vanommeslaeghe 2023-04-03 20:51:39 +02:00 committed by GitHub
commit d25b7729b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 49 deletions

View File

@ -2,43 +2,35 @@
#include "BehaviorBranchContext.h" #include "BehaviorBranchContext.h"
#include "BehaviorContext.h" #include "BehaviorContext.h"
#include "EntityManager.h" #include "EntityManager.h"
#include "BaseCombatAIComponent.h"
void ChangeOrientationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
}
void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
if (!m_ToTarget) return; // TODO: Add the other arguments to this behavior Entity* sourceEntity;
if (this->m_orientCaster) sourceEntity = EntityManager::Instance()->GetEntity(context->originator);
else sourceEntity = EntityManager::Instance()->GetEntity(branch.target);
if (!sourceEntity) return;
auto* self = EntityManager::Instance()->GetEntity(context->originator); if (this->m_toTarget) {
auto* other = EntityManager::Instance()->GetEntity(branch.target); Entity* destinationEntity;
if (this->m_orientCaster) destinationEntity = EntityManager::Instance()->GetEntity(branch.target);
else destinationEntity = EntityManager::Instance()->GetEntity(context->originator);
if (!destinationEntity) return;
if (self == nullptr || other == nullptr) return; sourceEntity->SetRotation(
NiQuaternion::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition())
const auto source = self->GetPosition(); );
const auto destination = self->GetPosition(); } else if (this->m_toAngle){
auto baseAngle = NiPoint3(0, 0, this->m_angle);
if (m_OrientCaster) { if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetForwardVector();
auto* baseCombatAIComponent = self->GetComponent<BaseCombatAIComponent>(); sourceEntity->SetRotation(NiQuaternion::FromEulerAngles(baseAngle));
} else return;
/*if (baseCombatAIComponent != nullptr) EntityManager::Instance()->SerializeEntity(sourceEntity);
{ return;
baseCombatAIComponent->LookAt(destination);
}
else*/
{
self->SetRotation(NiQuaternion::LookAt(source, destination));
}
EntityManager::Instance()->SerializeEntity(self);
} else {
other->SetRotation(NiQuaternion::LookAt(destination, source));
EntityManager::Instance()->SerializeEntity(other);
}
} }
void ChangeOrientationBehavior::Load() { void ChangeOrientationBehavior::Load() {
m_OrientCaster = GetBoolean("orient_caster"); this->m_orientCaster = GetBoolean("orient_caster", true);
m_ToTarget = GetBoolean("to_target"); this->m_toTarget = GetBoolean("to_target", false);
this->m_toAngle = GetBoolean("to_angle", false);
this->m_angle = GetFloat("angle", 0.0f);
this->m_relative = GetBoolean("relative", false);
} }

View File

@ -2,24 +2,15 @@
#include "Behavior.h" #include "Behavior.h"
#include <vector> class ChangeOrientationBehavior final : public Behavior {
class ChangeOrientationBehavior final : public Behavior
{
public: public:
bool m_OrientCaster; explicit ChangeOrientationBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {}
bool m_ToTarget;
/*
* Inherited
*/
explicit ChangeOrientationBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
}
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Load() override; void Load() override;
private:
bool m_orientCaster;
bool m_toTarget;
bool m_toAngle;
float m_angle;
bool m_relative;
}; };