diff --git a/game/game/movealgo.cpp b/game/game/movealgo.cpp index 3c2c17d6d..8ecd327d5 100644 --- a/game/game/movealgo.cpp +++ b/game/game/movealgo.cpp @@ -897,6 +897,9 @@ void MoveAlgo::onMoveFailed(const Tempest::Vec3& dp, const DynamicWorld::Collisi case Npc::GT_Point: npc.setDirection(npc.rotation()+stp); break; + case Npc::GT_Flee: + npc.setDirection(npc.rotation()+stp); + break; } } diff --git a/game/world/objects/npc.cpp b/game/world/objects/npc.cpp index ab45dfaab..c12f4685e 100644 --- a/game/world/objects/npc.cpp +++ b/game/world/objects/npc.cpp @@ -71,6 +71,10 @@ void Npc::GoTo::set(const Vec3& to) { flag = GT_Point; } +void Npc::GoTo::setFlee() { + flag = GT_Flee; + } + struct Npc::TransformBack { TransformBack(Npc& self) { @@ -1388,7 +1392,10 @@ bool Npc::implGoTo(uint64_t dt, float destDist) { auto dpos = go2.target()-position(); - if(mvAlgo.isClose(go2.target(),destDist)) { + if(go2.flag==GT_Flee) { + // nop + } + else if(mvAlgo.isClose(go2.target(),destDist)) { bool finished = true; if(go2.flag==GT_Way) { go2.wp = wayPath.pop(); @@ -1652,7 +1659,7 @@ void Npc::implSetFightMode(const Animation::EvCount& ev) { } bool Npc::implAiFlee(uint64_t dt) { - if(currentTarget==nullptr || currentTarget==this) + if(currentTarget==nullptr) return true; auto& oth = *currentTarget; @@ -1681,6 +1688,7 @@ bool Npc::implAiFlee(uint64_t dt) { return false; } + go2.setFlee(); setAnim(Anim::Move); return true; } diff --git a/game/world/objects/npc.h b/game/world/objects/npc.h index 083a2af13..d0440032e 100644 --- a/game/world/objects/npc.h +++ b/game/world/objects/npc.h @@ -43,6 +43,7 @@ class Npc final { GT_Item, GT_Point, GT_EnemyG, + GT_Flee, }; enum HitSound : uint8_t { @@ -419,6 +420,7 @@ class Npc final { void set(const WayPoint* to, GoToHint hnt = GoToHint::GT_Way); void set(const Item* to); void set(const Tempest::Vec3& to); + void setFlee(); }; void updateWeaponSkeleton();