Skip to content

Commit 6ffd547

Browse files
committed
fix AI_Flee
1 parent 9314256 commit 6ffd547

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

game/world/objects/npc.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,7 @@ bool Npc::implAiFlee(uint64_t dt) {
16011601

16021602
const WayPoint* wp = nullptr;
16031603
const float maxDist = 5*100; // 5 meters
1604+
16041605
owner.findWayPoint(position(),[&](const WayPoint& p) {
16051606
if(p.useCounter()>0 || qDistTo(&p)>maxDist*maxDist)
16061607
return false;
@@ -1611,16 +1612,21 @@ bool Npc::implAiFlee(uint64_t dt) {
16111612
return false;
16121613
});
16131614

1615+
if(go2.flag!=GT_Flee && go2.flag!=GT_No) {
1616+
go2.clear();
1617+
setAnim(Anim::Idle);
1618+
}
1619+
16141620
if(wp==nullptr || oth.qDistTo(wp)<oth.qDistTo(*this)) {
16151621
auto dx = oth.x-x;
16161622
auto dz = oth.z-z;
16171623
if(implTurnTo(-dx,-dz,false,dt))
1618-
return false;
1624+
return (go2.flag==GT_Flee);
16191625
} else {
16201626
auto dx = wp->x-x;
16211627
auto dz = wp->z-z;
16221628
if(implTurnTo(dx,dz,false,dt))
1623-
return false;
1629+
return (go2.flag==GT_Flee);
16241630
}
16251631

16261632
go2.setFlee();
@@ -1949,8 +1955,11 @@ void Npc::tick(uint64_t dt) {
19491955
if(implAtack(dt))
19501956
return;
19511957

1952-
if(implGoTo(dt))
1958+
if(implGoTo(dt)) {
1959+
if(go2.flag==GT_Flee)
1960+
implAiTick(dt);
19531961
return;
1962+
}
19541963
}
19551964

19561965
mvAlgo.tick(dt);

0 commit comments

Comments
 (0)