1
This commit is contained in:
parent
3cdeace217
commit
a1a027b0c8
@ -148,3 +148,42 @@ behaviac::EBTStatus AndroidAgent::DoAttack()
|
||||
status_ = behaviac::BT_RUNNING;
|
||||
return status_;
|
||||
}
|
||||
|
||||
behaviac::EBTStatus AndroidAgent::DoPursuit()
|
||||
{
|
||||
if (status_ == behaviac::BT_RUNNING) {
|
||||
return status_runing_cb_();
|
||||
}
|
||||
Human* enemy = GetOwner()->room->FindEnemy(GetOwner()->AsHuman());
|
||||
if (!enemy) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
|
||||
a8::Vec2 dir = enemy->GetPos() - GetOwner()->GetPos();
|
||||
dir.Rotate((10 + rand() % 360)/ 180.0f);
|
||||
dir.Normalize();
|
||||
GetOwner()->SetMoveDir(dir);
|
||||
GetOwner()->SetAttackDir(dir);
|
||||
bool shot_ok = false;
|
||||
a8::Vec2 shot_dir = dir;
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
|
||||
long long last_frameno = GetOwner()->room->GetFrameNo();
|
||||
status_runing_cb_ =
|
||||
[this, last_frameno] ()
|
||||
{
|
||||
if (GetOwner()->room->GetFrameNo() - last_frameno > SERVER_FRAME_RATE * 3) {
|
||||
status_ = behaviac::BT_SUCCESS;
|
||||
return behaviac::BT_SUCCESS;
|
||||
} else {
|
||||
bool shot_ok = false;
|
||||
a8::Vec2 shot_dir = GetOwner()->GetAttackDir();
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
|
||||
return behaviac::BT_RUNNING;
|
||||
}
|
||||
};
|
||||
|
||||
status_ = behaviac::BT_RUNNING;
|
||||
return status_;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public:
|
||||
behaviac::EBTStatus DoRandomWalk();
|
||||
behaviac::EBTStatus DoRandomShot();
|
||||
behaviac::EBTStatus DoAttack();
|
||||
behaviac::EBTStatus DoPursuit();
|
||||
|
||||
private:
|
||||
Android* owner_ = nullptr;
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "base_agent.h"
|
||||
#include "room.h"
|
||||
#include "creature.h"
|
||||
|
||||
BaseAgent::BaseAgent():behaviac::Agent()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user