#include "precompile.h" #include "android_agent.h" #include "android.h" #include "room.h" AndroidAgent::AndroidAgent() { } AndroidAgent::~AndroidAgent() { } State_e AndroidAgent::GetState() { return kPreBattle; } behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time) { if (status_ == behaviac::BT_RUNNING) { return status_runing_cb_(); } int idle_time = a8::RandEx(min_time, max_time); xtimer_list* timer = GetOwner()->room->xtimer.AddDeadLineTimerAndAttach ( idle_time / FRAME_RATE_MS, a8::XParams(), [] (const a8::XParams& param) { }, &GetOwner()->xtimer_attacher.timer_list_); std::weak_ptr timer_ptr = GetOwner()->room->xtimer.GetTimerPtr(timer); status_runing_cb_ = [this, timer_ptr] () { if (timer_ptr.lock()) { return behaviac::BT_RUNNING; } else { status_ = behaviac::BT_SUCCESS; return behaviac::BT_SUCCESS; } }; status_ = behaviac::BT_RUNNING; return status_; } behaviac::EBTStatus AndroidAgent::DoRandomWalk() { if (status_ == behaviac::BT_RUNNING) { return status_runing_cb_(); } a8::Vec2 dir = GetOwner()->GetMoveDir(); dir.Rotate((10 + rand() % 360)/ 180.0f); dir.Normalize(); GetOwner()->GetMoveHelper()->CalcTargetPos(500); if (GetOwner()->GetMoveHelper()->GetPathSize() <= 0) { return behaviac::BT_FAILURE; } status_runing_cb_ = [this] () { if (GetOwner()->GetMoveHelper()->GetPathSize() <= 0) { status_ = behaviac::BT_SUCCESS; return behaviac::BT_SUCCESS; } else { return behaviac::BT_RUNNING; } }; status_ = behaviac::BT_RUNNING; return status_; } behaviac::EBTStatus AndroidAgent::DoRandomShot() { return behaviac::BT_SUCCESS; } behaviac::EBTStatus AndroidAgent::DoAttack() { return behaviac::BT_SUCCESS; }