mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
Volumes on the server touched far more than in the client: - An enemy's body in the physics world was a sphere the size of its aggro radius, so trigger and damage volumes caught enemies from far away (Cavalry Hill enemies taking damage on spawn). It is now the enemy's own radius and collision group from its physics component. - Trigger volumes ignored their collision group and caught everything. dpEntity now filters with the client's collision filter (PeCollisionFilter, 1.10.64 0x00fb6940, group table from 0x00fcf9a0): POI walls ignore enemies, threat clearing walls ignore players, and so on. The aggro sensor keeps seeing only players. - Rotated boxes were tested as the axis aligned box around them, which for a turned wall covers a big square (the AG survival boundary). Sphere and point tests now use the box's own axes. Proximity monitors take an optional collision group like live's SetProximityRadius; the AM shield generators use live's (10 finds enemies, 1 finds players). Fixes #1127 Refs #1971 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
3.8 KiB
C++
110 lines
3.8 KiB
C++
#include "ProximityMonitorComponent.h"
|
|
#include "GameMessages.h"
|
|
#include "dZoneManager.h"
|
|
#include "ControllablePhysicsComponent.h"
|
|
#include "EntityManager.h"
|
|
#include "SimplePhysicsComponent.h"
|
|
#include "Amf3.h"
|
|
#include "dpShapeSphere.h"
|
|
|
|
const std::unordered_set<LWOOBJID> ProximityMonitorComponent::m_EmptyObjectSet = {};
|
|
|
|
ProximityMonitorComponent::ProximityMonitorComponent(Entity* parent, const int32_t componentID, int radiusSmall, int radiusLarge) : Component(parent, componentID) {
|
|
if (radiusSmall != -1 && radiusLarge != -1) {
|
|
SetProximityRadius(radiusSmall, "rocketSmall");
|
|
SetProximityRadius(radiusLarge, "rocketLarge");
|
|
}
|
|
RegisterMsg(&ProximityMonitorComponent::OnGetObjectReportInfo);
|
|
}
|
|
|
|
ProximityMonitorComponent::~ProximityMonitorComponent() {
|
|
for (const auto& en : m_ProximitiesData) {
|
|
if (!en.second) continue;
|
|
|
|
dpWorld::RemoveEntity(en.second);
|
|
}
|
|
|
|
m_ProximitiesData.clear();
|
|
}
|
|
|
|
void ProximityMonitorComponent::SetProximityRadius(float proxRadius, const std::string& name, const uint32_t collisionGroup) {
|
|
dpEntity* en = new dpEntity(m_Parent->GetObjectID(), proxRadius);
|
|
en->SetCollisionGroup(collisionGroup);
|
|
en->SetPosition(m_Parent->GetPosition());
|
|
|
|
dpWorld::AddEntity(en);
|
|
m_ProximitiesData.insert(std::make_pair(name, en));
|
|
}
|
|
|
|
void ProximityMonitorComponent::SetProximityRadius(dpEntity* entity, const std::string& name) {
|
|
dpWorld::AddEntity(entity);
|
|
entity->SetPosition(m_Parent->GetPosition());
|
|
m_ProximitiesData.insert(std::make_pair(name, entity));
|
|
}
|
|
|
|
const std::unordered_set<LWOOBJID>& ProximityMonitorComponent::GetProximityObjects(const std::string& name) const {
|
|
const auto iter = m_ProximitiesData.find(name);
|
|
|
|
if (iter == m_ProximitiesData.cend()) {
|
|
return m_EmptyObjectSet;
|
|
}
|
|
|
|
return iter->second->GetCurrentlyCollidingObjects();
|
|
}
|
|
|
|
bool ProximityMonitorComponent::IsInProximity(const std::string& name, LWOOBJID objectID) {
|
|
const auto iter = m_ProximitiesData.find(name);
|
|
|
|
if (iter == m_ProximitiesData.cend()) {
|
|
return false;
|
|
}
|
|
|
|
const auto& collisions = iter->second->GetCurrentlyCollidingObjects();
|
|
|
|
return collisions.contains(objectID);
|
|
}
|
|
|
|
bool ProximityMonitorComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo) {
|
|
auto& proxInfo = reportInfo.info->PushDebug("Proximity Monitor");
|
|
for (const auto& [name, entity] : m_ProximitiesData) {
|
|
if (!entity) continue;
|
|
auto& proxAmf = proxInfo.PushDebug(name);
|
|
const auto* const shape = entity->GetShape();
|
|
if (shape && shape->GetShapeType() == dpShapeType::Sphere) {
|
|
const auto* const sphere = static_cast<const dpShapeSphere*>(shape);
|
|
proxAmf.PushDebug<AMFDoubleValue>("Radius") = sphere->GetRadius();
|
|
}
|
|
proxAmf.PushDebug<AMFBoolValue>("Sleeping") = entity->GetSleeping();
|
|
proxAmf.PushDebug<AMFDoubleValue>("Scale") = entity->GetScale();
|
|
proxAmf.PushDebug<AMFBoolValue>("Gargantuan") = entity->GetIsGargantuan();
|
|
proxAmf.PushDebug<AMFBoolValue>("Static") = entity->GetIsStatic();
|
|
proxAmf.PushDebug("Position").PushDebug(entity->GetPosition());
|
|
proxAmf.PushDebug("Rotation").PushDebug(entity->GetRotation());
|
|
auto& collidingAmf = proxAmf.PushDebug("Colliding Objects");
|
|
int i = 1;
|
|
for (const auto& colliding : entity->GetCurrentlyCollidingObjects()) {
|
|
collidingAmf.PushDebug<AMFStringValue>(std::to_string(i++), "LWOOBJID") = std::to_string(colliding);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void ProximityMonitorComponent::Update(float deltaTime) {
|
|
for (const auto& prox : m_ProximitiesData) {
|
|
if (!prox.second) continue;
|
|
|
|
prox.second->SetPosition(m_Parent->GetPosition());
|
|
//Process enter events
|
|
for (const auto id : prox.second->GetNewObjects()) {
|
|
m_Parent->OnCollisionProximity(id, prox.first, "ENTER");
|
|
}
|
|
|
|
//Process exit events
|
|
for (const auto id : prox.second->GetRemovedObjects()) {
|
|
m_Parent->OnCollisionProximity(id, prox.first, "LEAVE");
|
|
}
|
|
}
|
|
}
|
|
|