From 655b5fa33e3f0047ec5e23f840a75bf8c1179a4c Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Wed, 18 Jan 2023 19:01:56 -0800 Subject: [PATCH] NSEntity: add method IsFacing() which should make some common sneakish tasks easier. --- src/shared/NSEntity.h | 3 +++ src/shared/NSEntity.qc | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/shared/NSEntity.h b/src/shared/NSEntity.h index 4da538e3..9e903b3d 100644 --- a/src/shared/NSEntity.h +++ b/src/shared/NSEntity.h @@ -351,6 +351,9 @@ public: of any entity class that you want to support think functions in. This saves you the effort of writing your own routines and methods. */ nonvirtual void HandleThink(void); + + /** Returns either true or false depending on if this entity is facing the entity in question. */ + nonvirtual bool IsFacing(entity); }; #ifdef CLIENT diff --git a/src/shared/NSEntity.qc b/src/shared/NSEntity.qc index 1c5ef141..1bc2f231 100644 --- a/src/shared/NSEntity.qc +++ b/src/shared/NSEntity.qc @@ -892,6 +892,13 @@ void NSEntity::HandleThink( void ) { } } +bool NSEntity::IsFacing(entity target) +{ + vector vecDiff = normalize(target.origin - origin); + makevectors(angles); + return ((vecDiff * v_forward) > 0 ) ? true : false; +} + #ifdef CLIENT void NSEntity_ReadEntity(bool new)