This commit is contained in:
aozhiwei 2022-12-02 10:59:49 +08:00
parent 8d63f2dee8
commit eec0c16a72
2 changed files with 114 additions and 1 deletions

View File

@ -314,6 +314,7 @@ void AndroidAI::UpdateIdle()
void AndroidAI::UpdateThinking() void AndroidAI::UpdateThinking()
{ {
#if MAP3D
Human* hum = (Human*)owner; Human* hum = (Human*)owner;
if (hum->room->GetGasData().GetGasMode() == GasInactive || if (hum->room->GetGasData().GetGasMode() == GasInactive ||
hum->room->IsWaitingStart() || hum->room->IsWaitingStart() ||
@ -343,6 +344,37 @@ void AndroidAI::UpdateThinking()
} }
} }
} }
#else
Human* hum = (Human*)owner;
if (hum->room->GetGasData().GetGasMode() == GasInactive ||
hum->room->IsWaitingStart() ||
hum->HasBuffEffect(kBET_Jump) ||
hum->HasBuffEffect(kBET_PeaceMode) ||
a8::HasBitFlag(hum->status, CS_DisableAttack)) {
if (hum->room->IsWaitingStart()) {
ChangeToStateNewAI(ASE_Idle);
} else {
ChangeToStateNewAI(ASE_RandomWalk);
}
} else {
Creature* target = GetTarget();
if (target) {
node_->target.Attach(target);
ChangeToStateNewAI(ASE_Attack);
} else {
if (hum->room->GetFrameNo() >= node_->next_random_move_frameno) {
if ((rand() % 7) < 4) {
ChangeToStateNewAI(ASE_Idle);
} else {
ChangeToStateNewAI(ASE_RandomWalk);
}
} else {
ChangeToStateNewAI(ASE_Idle);
node_->param1 = node_->next_random_move_frameno - hum->room->GetFrameNo();
}
}
}
#endif
} }
void AndroidAI::UpdateAttack() void AndroidAI::UpdateAttack()
@ -435,9 +467,12 @@ void AndroidAI::UpdatePursuit()
distance < GetAttackRange()) { distance < GetAttackRange()) {
ChangeToStateNewAI(ASE_Attack); ChangeToStateNewAI(ASE_Attack);
} else { } else {
#ifdef MAP3D
#else
if (node_->exec_frame_num > 100 * 2) { if (node_->exec_frame_num > 100 * 2) {
ChangeToStateNewAI(ASE_RandomWalk); ChangeToStateNewAI(ASE_RandomWalk);
} }
#endif
} }
} else { } else {
ChangeToStateNewAI(ASE_RandomWalk); ChangeToStateNewAI(ASE_RandomWalk);
@ -567,6 +602,11 @@ Creature* AndroidAI::GetTarget()
( (
[myself, &target] (Creature* hum, bool& stop) [myself, &target] (Creature* hum, bool& stop)
{ {
#if MAP3D
if (hum->IsPlayer()) {
target = hum;
}
#else
if (hum->HasBuffEffect(kBET_Camouflage)) { if (hum->HasBuffEffect(kBET_Camouflage)) {
return; return;
} }
@ -584,14 +624,18 @@ Creature* AndroidAI::GetTarget()
} else { } else {
target = hum; target = hum;
} }
#endif
}); });
if (target) { if (target) {
node_->nearest_human.Attach(target); node_->nearest_human.Attach(target);
node_->last_check_nearest_human_frameno = myself->room->GetFrameNo(); node_->last_check_nearest_human_frameno = myself->room->GetFrameNo();
float distance = myself->GetPos().Distance(target->GetPos()); float distance = myself->GetPos().Distance(target->GetPos());
#ifdef MAP3D
#else
if (distance > GetAttackRange()) { if (distance > GetAttackRange()) {
target = nullptr; target = nullptr;
} }
#endif
} }
return target; return target;
} }

View File

@ -1,5 +1,7 @@
#include "precompile.h" #include "precompile.h"
#include "DetourCommon.h"
#include "mapinstance.h" #include "mapinstance.h"
#include "mapservice.h" #include "mapservice.h"
#include "gridservice.h" #include "gridservice.h"
@ -672,7 +674,74 @@ int MapInstance::FindStraightPath(int layer,
const a8::Vec3& end, const a8::Vec3& end,
std::vector<a8::Vec3>& paths) std::vector<a8::Vec3>& paths)
{ {
return 0; float spos[3];
spos[0] = start.x;
spos[1] = start.y;
spos[2] = start.z;
float epos[3];
epos[0] = end.x;
epos[1] = end.y;
epos[2] = end.z;
dtQueryFilter filter;
filter.setIncludeFlags(0xffff);
filter.setExcludeFlags(0);
const float extents[3] = {2.f, 4.f, 2.f};
dtPolyRef startRef = INVALID_NAVMESH_POLYREF;
dtPolyRef endRef = INVALID_NAVMESH_POLYREF;
float startNearestPt[3];
float endNearestPt[3];
navmesh_query_->findNearestPoly(spos, extents, &filter, &startRef, startNearestPt);
navmesh_query_->findNearestPoly(epos, extents, &filter, &endRef, endNearestPt);
if (!startRef || !endRef) {
return NAV_ERROR_NEARESTPOLY;
}
dtPolyRef polys[MAX_POLYS];
int npolys;
float straightPath[MAX_POLYS * 3];
unsigned char straightPathFlags[MAX_POLYS];
dtPolyRef straightPathPolys[MAX_POLYS];
int nstraightPath;
int pos = 0;
navmesh_query_->findPath(startRef, endRef, startNearestPt, endNearestPt, &filter, polys, &npolys, MAX_POLYS);
nstraightPath = 0;
if (npolys) {
float epos1[3];
dtVcopy(epos1, endNearestPt);
if (polys[npolys-1] != endRef) {
navmesh_query_->closestPointOnPoly(polys[npolys-1], endNearestPt, epos1, 0);
}
navmesh_query_->findStraightPath(startNearestPt,
endNearestPt,
polys,
npolys,
straightPath,
straightPathFlags,
straightPathPolys,
&nstraightPath,
MAX_POLYS);
for(int i = 0; i < nstraightPath * 3; ) {
a8::Vec3 currpos;
currpos.x = straightPath[i++];
currpos.y = straightPath[i++];
currpos.z = straightPath[i++];
paths.push_back(currpos);
pos++;
}
}
return pos;
} }
int MapInstance::FindRandomPointAroundCircle(int layer, int MapInstance::FindRandomPointAroundCircle(int layer,