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; }