Skip to content

Commit f4cf3ee

Browse files
committed
improve ai_flee
1 parent 068fa6c commit f4cf3ee

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

game/game/movealgo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ void MoveAlgo::onMoveFailed(const Tempest::Vec3& dp, const DynamicWorld::Collisi
897897
case Npc::GT_Point:
898898
npc.setDirection(npc.rotation()+stp);
899899
break;
900+
case Npc::GT_Flee:
901+
npc.setDirection(npc.rotation()+stp);
902+
break;
900903
}
901904
}
902905

game/world/objects/npc.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ void Npc::GoTo::set(const Vec3& to) {
7171
flag = GT_Point;
7272
}
7373

74+
void Npc::GoTo::setFlee() {
75+
flag = GT_Flee;
76+
}
77+
7478

7579
struct Npc::TransformBack {
7680
TransformBack(Npc& self) {
@@ -1388,7 +1392,10 @@ bool Npc::implGoTo(uint64_t dt, float destDist) {
13881392

13891393
auto dpos = go2.target()-position();
13901394

1391-
if(mvAlgo.isClose(go2.target(),destDist)) {
1395+
if(go2.flag==GT_Flee) {
1396+
// nop
1397+
}
1398+
else if(mvAlgo.isClose(go2.target(),destDist)) {
13921399
bool finished = true;
13931400
if(go2.flag==GT_Way) {
13941401
go2.wp = wayPath.pop();
@@ -1652,7 +1659,7 @@ void Npc::implSetFightMode(const Animation::EvCount& ev) {
16521659
}
16531660

16541661
bool Npc::implAiFlee(uint64_t dt) {
1655-
if(currentTarget==nullptr || currentTarget==this)
1662+
if(currentTarget==nullptr)
16561663
return true;
16571664

16581665
auto& oth = *currentTarget;
@@ -1681,6 +1688,7 @@ bool Npc::implAiFlee(uint64_t dt) {
16811688
return false;
16821689
}
16831690

1691+
go2.setFlee();
16841692
setAnim(Anim::Move);
16851693
return true;
16861694
}

game/world/objects/npc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Npc final {
4343
GT_Item,
4444
GT_Point,
4545
GT_EnemyG,
46+
GT_Flee,
4647
};
4748

4849
enum HitSound : uint8_t {
@@ -419,6 +420,7 @@ class Npc final {
419420
void set(const WayPoint* to, GoToHint hnt = GoToHint::GT_Way);
420421
void set(const Item* to);
421422
void set(const Tempest::Vec3& to);
423+
void setFlee();
422424
};
423425

424426
void updateWeaponSkeleton();

0 commit comments

Comments
 (0)