@@ -656,7 +656,9 @@ float Npc::rotationYRad() const {
656656 }
657657
658658Bounds Npc::bounds () const {
659- return visual.bounds ();
659+ auto b = visual.bounds ();
660+ b.setObjMatrix (transform ());
661+ return b;
660662 }
661663
662664float Npc::translateY () const {
@@ -2841,6 +2843,10 @@ Vec3 Npc::mapWeaponBone() const {
28412843 return visual.mapWeaponBone ();
28422844 }
28432845
2846+ Vec3 Npc::mapHeadBone () const {
2847+ return visual.mapHeadBone ();
2848+ }
2849+
28442850Vec3 Npc::mapBone (std::string_view bone) const {
28452851 if (auto sk = visual.visualSkeleton ()) {
28462852 size_t id = sk->findNode (bone);
@@ -3772,7 +3778,8 @@ void Npc::stopWalking() {
37723778 }
37733779
37743780bool Npc::canSeeNpc (const Npc &oth, bool freeLos) const {
3775- return canSeeNpc (oth.x ,oth.y +180 ,oth.z ,freeLos);
3781+ const auto mid = oth.bounds ().midTr ;
3782+ return canSeeNpc (mid.x ,mid.y ,mid.z ,freeLos);
37763783 }
37773784
37783785bool Npc::canSeeNpc (float tx, float ty, float tz, bool freeLos) const {
@@ -3781,8 +3788,9 @@ bool Npc::canSeeNpc(float tx, float ty, float tz, bool freeLos) const {
37813788 }
37823789
37833790SensesBit Npc::canSenseNpc (const Npc &oth, bool freeLos, float extRange) const {
3791+ const auto mid = oth.bounds ().midTr ;
37843792 const bool isNoisy = (oth.bodyState ()&BodyState::BS_SNEAK)==0 ;
3785- return canSenseNpc (oth .x ,oth. y + 180 ,oth .z ,freeLos,isNoisy,extRange);
3793+ return canSenseNpc (mid .x ,mid. y ,mid .z ,freeLos,isNoisy,extRange);
37863794 }
37873795
37883796SensesBit Npc::canSenseNpc (float tx, float ty, float tz, bool freeLos, bool isNoisy, float extRange) const {
@@ -3800,16 +3808,17 @@ SensesBit Npc::canSenseNpc(float tx, float ty, float tz, bool freeLos, bool isNo
38003808 ret = ret | SensesBit::SENSE_HEAR;
38013809 }
38023810
3803- if (!freeLos){
3811+ // npc eyesight height
3812+ auto head = visual.mapHeadBone ();
3813+ if (!freeLos) {
38043814 float dx = x-tx, dz=z-tz;
38053815 float dir = angleDir (dx,dz);
38063816 float da = float (M_PI)*(visual.viewDirection ()-dir)/180 .f ;
38073817 if (double (std::cos (da))<=ref)
3808- if (!w->ray (Vec3 (x,y+ 180 ,z) , Vec3 (tx,ty,tz)).hasCol )
3818+ if (!w->ray (head , Vec3 (tx,ty,tz)).hasCol )
38093819 ret = ret | SensesBit::SENSE_SEE;
38103820 } else {
3811- // TODO: npc eyesight height
3812- if (!w->ray (Vec3 (x,y+180 ,z), Vec3 (tx,ty,tz)).hasCol )
3821+ if (!w->ray (head, Vec3 (tx,ty,tz)).hasCol )
38133822 ret = ret | SensesBit::SENSE_SEE;
38143823 }
38153824 return ret & SensesBit (hnpc.senses );
0 commit comments