Skip to content

Commit ad18f1c

Browse files
committed
+ mapHeadBone
1 parent 0c138fd commit ad18f1c

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

game/graphics/mdlvisual.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ Vec3 MdlVisual::mapWeaponBone() const {
522522
}
523523

524524
Vec3 MdlVisual::mapHeadBone() const {
525+
if(skeleton->BIP01_HEAD==size_t(-1))
526+
return {pos.at(3,0), pos.at(3,1)+180, pos.at(3,2)};
525527
return mapBone(skeleton->BIP01_HEAD);
526528
}
527529

game/world/objects/npc.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,9 @@ float Npc::rotationYRad() const {
656656
}
657657

658658
Bounds Npc::bounds() const {
659-
return visual.bounds();
659+
auto b = visual.bounds();
660+
b.setObjMatrix(transform());
661+
return b;
660662
}
661663

662664
float 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+
28442850
Vec3 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

37743780
bool 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

37783785
bool 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

37833790
SensesBit 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

37883796
SensesBit 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);

game/world/objects/npc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ class Npc final {
337337
Item* currentMeleWeapon();
338338
Item* currentRangeWeapon();
339339
auto mapWeaponBone() const -> Tempest::Vec3;
340+
auto mapHeadBone() const -> Tempest::Vec3;
340341
auto mapBone(std::string_view bone) const -> Tempest::Vec3;
341342

342343
bool turnTo (float dx, float dz, bool anim, uint64_t dt);

game/world/worldobjects.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -898,10 +898,12 @@ static bool canSee(const Npc& pl,const Item& n){
898898
auto p0 = pl.position();
899899
auto p1 = n.position();
900900
const float plY = p0.y;
901-
const float itY = p1.y;
902-
if(plY<=itY && itY<=plY+180)
903-
return pl.canSeeNpc(p1.x,plY+180,p1.z,true);
904-
return pl.canSeeNpc(p1.x,itY+20,p1.z,true);
901+
if(plY<=p1.y && p1.y<=plY+180) {
902+
//auto head = pl.mapHeadBone();
903+
if(pl.canSeeNpc(p0.x,p1.y,p0.z,true))
904+
return true;
905+
}
906+
return pl.canSeeNpc(p1.x,p1.y+20,p1.z,true);
905907
}
906908

907909
template<class T>

0 commit comments

Comments
 (0)