Bunch of refactoring and walking, AI needs a ton of tweaking to use the new logic

This commit is contained in:
KimLS
2018-10-12 00:03:58 -07:00
parent 29ea65a71e
commit 1785120796
17 changed files with 787 additions and 474 deletions
-187
View File
@@ -22,193 +22,6 @@ void AdjustRoute(std::list<IPathfinder::IPathNode> &nodes, int flymode, float of
}
}
glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &WaypointChanged, bool &NodeReached)
{
glm::vec3 To(ToX, ToY, ToZ);
if (Speed <= 0) {
return To;
}
glm::vec3 From(GetX(), GetY(), GetZ());
if (DistanceSquared(To, From) < 1.0f) {
WaypointChanged = false;
NodeReached = true;
Route.clear();
return To;
}
if (Route.empty()) {
bool partial = false;
bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetZOffset());
PathingDestination = To;
WaypointChanged = true;
NodeReached = false;
if (stuck) {
return HandleStuckPath(To, From);
}
if (Route.empty()) {
return To;
}
else {
return (*Route.begin()).pos;
}
}
else {
if (PathRecalcTimer->Check()) {
bool SameDestination = DistanceSquared(To, PathingDestination) < 100.0f;
if (!SameDestination) {
//We had a route but our target position moved too much
bool partial = false;
bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetZOffset());
PathingDestination = To;
WaypointChanged = true;
NodeReached = false;
if (stuck) {
return HandleStuckPath(To, From);
}
if (Route.empty()) {
return To;
}
else {
return (*Route.begin()).pos;
}
}
}
if (!IsRooted()) {
bool AtPrevNode = DistanceSquared(From, PathingLastPosition) < 1.0f;
if (AtPrevNode) {
PathingLoopCount++;
auto front = (*Route.begin()).pos;
if (PathingLoopCount > 5) {
Teleport(front); //todo new teleport
SendPosition();
Route.pop_front();
WaypointChanged = true;
NodeReached = true;
PathingLoopCount = 0;
}
return front;
}
else {
PathingLastPosition = From;
PathingLoopCount = 0;
}
}
else {
PathingLastPosition = From;
PathingLoopCount = 0;
}
bool AtNextNode = false;
if (flymode == GravityBehavior::Flying) {
AtNextNode = DistanceSquared(From, (*Route.begin()).pos) < 4.0f;
}
else {
float z_dist = From.z - (*Route.begin()).pos.z;
z_dist *= z_dist;
AtNextNode = DistanceSquaredNoZ(From, (*Route.begin()).pos) < 4.0f && z_dist < 25.0f;
}
if (AtNextNode) {
WaypointChanged = false;
NodeReached = true;
Route.pop_front();
if (Route.empty()) {
bool partial = false;
bool stuck = false;
Route = zone->pathing->FindRoute(From, To, partial, stuck);
AdjustRoute(Route, flymode, GetZOffset());
PathingDestination = To;
WaypointChanged = true;
if (stuck) {
return HandleStuckPath(To, From);
}
if(Route.empty()) {
return To;
}
else {
return (*Route.begin()).pos;
}
}
else {
auto node = *Route.begin();
if (node.teleport) {
Route.pop_front();
if (Route.empty()) {
return To;
}
auto nextNode = *Route.begin();
Teleport(nextNode.pos);
Route.pop_front();
if (Route.empty()) {
return To;
}
return (*Route.begin()).pos;
}
return node.pos;
}
}
else {
WaypointChanged = false;
NodeReached = false;
return (*Route.begin()).pos;
}
}
return To;
}
glm::vec3 Mob::HandleStuckPath(const glm::vec3 &To, const glm::vec3 &From)
{
bool partial = false;
bool stuck = false;
auto r = zone->pathing->FindRoute(To, From, partial, stuck);
Route.clear();
if (r.size() < 1) {
Teleport(To);
return To;
}
auto iter = r.rbegin();
auto final_node = (*iter);
Teleport(final_node.pos);
if (r.size() < 2) {
return final_node.pos;
}
else {
iter++;
return (*iter).pos;
}
}
void CullPoints(std::vector<FindPerson_Point> &points) {
if (!zone->HasMap()) {
return;