Skip to content

Commit

Permalink
improve ai_flee
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Aug 1, 2021
1 parent 068fa6c commit f4cf3ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions game/game/movealgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
12 changes: 10 additions & 2 deletions game/world/objects/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1681,6 +1688,7 @@ bool Npc::implAiFlee(uint64_t dt) {
return false;
}

go2.setFlee();
setAnim(Anim::Move);
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions game/world/objects/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Npc final {
GT_Item,
GT_Point,
GT_EnemyG,
GT_Flee,
};

enum HitSound : uint8_t {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f4cf3ee

Please sign in to comment.