From a67ef6336ff7ea04f4601a4a3ac8d2059ca6a172 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Fri, 26 Jan 2024 02:20:00 -0800 Subject: [PATCH] fix faction change issue fixes an issue where enemies who would have their faction changed would not change aggro targets. Tested that stromling mechs and ronin/horsemen in forbidden valley still aggro on spawn as expected. --- dGame/Entity.cpp | 34 ++++++++++++++-------------------- dGame/Entity.h | 2 +- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 8b72a80c..dafa732e 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1357,17 +1357,11 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) { } if (!other->GetIsDead()) { - auto* combat = GetComponent(); - - if (combat != nullptr) { + if (GetComponent() != nullptr) { const auto index = std::find(m_TargetsInPhantom.begin(), m_TargetsInPhantom.end(), otherEntity); if (index != m_TargetsInPhantom.end()) return; - const auto valid = combat->IsEnemy(otherEntity); - - if (!valid) return; - m_TargetsInPhantom.push_back(otherEntity); } } @@ -1992,25 +1986,25 @@ void Entity::SetNetworkId(const uint16_t id) { m_NetworkID = id; } -std::vector& Entity::GetTargetsInPhantom() { - std::vector valid; - +std::vector Entity::GetTargetsInPhantom() { // Clean up invalid targets, like disconnected players - for (auto i = 0u; i < m_TargetsInPhantom.size(); ++i) { - const auto id = m_TargetsInPhantom.at(i); - - auto* entity = Game::entityManager->GetEntity(id); - - if (entity == nullptr) { + for (auto i = 0u; i < m_TargetsInPhantom.size(); ) { + if (Game::entityManager->GetEntity(m_TargetsInPhantom.at(i))) { + i++; continue; } - - valid.push_back(id); + m_TargetsInPhantom.erase(m_TargetsInPhantom.begin() + i); } - m_TargetsInPhantom = valid; + std::vector enemies; + for (const auto id : m_TargetsInPhantom) { + auto* combat = GetComponent(); + if (!combat || !combat->IsEnemy(id)) continue; - return m_TargetsInPhantom; + enemies.push_back(id); + } + + return enemies; } void Entity::SendNetworkVar(const std::string& data, const SystemAddress& sysAddr) { diff --git a/dGame/Entity.h b/dGame/Entity.h index 36621d5c..c0a546d3 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -293,7 +293,7 @@ public: /* * Collision */ - std::vector& GetTargetsInPhantom(); + std::vector GetTargetsInPhantom(); Entity* GetScheduledKiller() { return m_ScheduleKiller; }