1
This commit is contained in:
parent
3f0357a46c
commit
0df5dc6b4c
@ -76,14 +76,10 @@ bool BaseAgent::PreEnterCoroutine(int co_id, behaviac::EBTStatus& status)
|
||||
return false;
|
||||
}
|
||||
auto& co = itr->second;
|
||||
if (co->IsAbort()) {
|
||||
status = behaviac::BT_FAILURE;
|
||||
return true;
|
||||
}
|
||||
if (co->status != behaviac::BT_RUNNING) {
|
||||
abort();
|
||||
}
|
||||
co->status = co->runing_cb();
|
||||
co->status = co->runing_cb(co.get());
|
||||
status = co->status;
|
||||
if (co->status != behaviac::BT_RUNNING) {
|
||||
list_del_init(&co->entry);
|
||||
@ -137,8 +133,11 @@ behaviac::EBTStatus BaseAgent::CoTest1(int time)
|
||||
context->time = time;
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoTest1");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if ((GetRoom()->GetFrameNo() - context->frameno) * FRAME_RATE_MS <
|
||||
context->time) {
|
||||
return behaviac::BT_RUNNING;
|
||||
@ -159,8 +158,11 @@ behaviac::EBTStatus BaseAgent::CoTest(int time)
|
||||
context->time = time;
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoTest");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if ((GetRoom()->GetFrameNo() - context->frameno) * FRAME_RATE_MS <
|
||||
context->time) {
|
||||
return behaviac::BT_RUNNING;
|
||||
|
@ -9,7 +9,7 @@ class BtCoroutine
|
||||
{
|
||||
public:
|
||||
|
||||
std::function<behaviac::EBTStatus()> runing_cb;
|
||||
std::function<behaviac::EBTStatus(BtCoroutine*)> runing_cb;
|
||||
long long sleep_end_frameno = 0;
|
||||
int sleep_time = 0;
|
||||
list_head entry;
|
||||
|
@ -255,8 +255,11 @@ behaviac::EBTStatus HeroAgent::RandomSafeZonePoint(int try_count, int step_len)
|
||||
);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "RandomSafeZonePoint");
|
||||
co->runing_cb =
|
||||
[this, context, try_count, step_len] ()
|
||||
[this, context, try_count, step_len] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (owner_->dead) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
@ -406,8 +409,11 @@ behaviac::EBTStatus HeroAgent::CoIdle(int min_val, int max_val)
|
||||
context->time = a8::RandEx(min_val, max_val);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoIdle");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if ((GetRoom()->GetFrameNo() - context->frameno) * FRAME_RATE_MS <
|
||||
context->time) {
|
||||
return behaviac::BT_RUNNING;
|
||||
@ -426,8 +432,11 @@ behaviac::EBTStatus HeroAgent::CoMoveCurrentTargetRaycast()
|
||||
);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoMoveCurrentTargetRaycast");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (!current_target_agent->IsValid()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
@ -450,8 +459,11 @@ behaviac::EBTStatus HeroAgent::CoShotCurrentTargetRaycast()
|
||||
);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoShotCurrentTargetRaycast");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (!current_target_agent->IsValid()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
@ -482,8 +494,11 @@ behaviac::EBTStatus HeroAgent::CoMoveMasterRaycast()
|
||||
&owner_->xtimer_attacher);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoMoveMasterRaycast");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (!context->timer_ptr.expired()) {
|
||||
return behaviac::BT_RUNNING;
|
||||
} else {
|
||||
@ -504,8 +519,11 @@ behaviac::EBTStatus HeroAgent::CoFindPath(const glm::vec3& pos)
|
||||
context->target_pos = pos;
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoFindPath");
|
||||
co->runing_cb =
|
||||
[this, context, pos] ()
|
||||
[this, context, pos] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (owner_->dead) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
@ -538,8 +556,11 @@ behaviac::EBTStatus HeroAgent::CoFindPathEx(const glm::vec3& pos, float distance
|
||||
context->target_pos = pos;
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoFindPathEx");
|
||||
co->runing_cb =
|
||||
[this, context, distance] ()
|
||||
[this, context, distance] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (owner_->dead) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
@ -570,8 +591,11 @@ behaviac::EBTStatus HeroAgent::CoStartMove(int min_val, int max_val)
|
||||
);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoStartMove");
|
||||
co->runing_cb =
|
||||
[this, context, distance] ()
|
||||
[this, context, distance] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (!owner_->dead) {
|
||||
owner_->GetMovement()->CalcTargetPos(distance);
|
||||
}
|
||||
@ -596,8 +620,11 @@ behaviac::EBTStatus HeroAgent::CoSleep(int time)
|
||||
&owner_->xtimer_attacher);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoSleep");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (!context->timer_ptr.expired()) {
|
||||
return behaviac::BT_RUNNING;
|
||||
} else {
|
||||
@ -652,8 +679,11 @@ behaviac::EBTStatus HeroAgent::CoMoveForward(int min_val, int max_val)
|
||||
owner_->GetMovement()->CalcTargetPos(distance);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoMoveForward");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (owner_->GetMovement()->GetPathSize() <= 0) {
|
||||
return behaviac::BT_SUCCESS;
|
||||
} else {
|
||||
@ -945,8 +975,11 @@ behaviac::EBTStatus HeroAgent::CoGetRunAwayPoint()
|
||||
);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoGetRunAwayPoint");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
[this, context] (BtCoroutine* co)
|
||||
{
|
||||
if (co->IsAbort()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (owner_->dead) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user