fix(Core/CreatureAI): revert NPC repositioning and path system (temporarily) (#4274)

This commit is contained in:
Stefano Borzì 2021-01-14 19:17:34 +01:00 committed by GitHub
parent b42f2386c2
commit df600f9946
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 773 additions and 1418 deletions

View file

@ -60,13 +60,12 @@ bool FleeingMovementGenerator<T>::_getPoint(T* owner, float& x, float& y, float&
if (!owner)
return false;
const Map* _map = owner->GetBaseMap();
x = owner->GetPositionX();
y = owner->GetPositionY();
z = owner->GetPositionZ();
float temp_x, temp_y, angle;
const Map* _map = owner->GetBaseMap();
// primitive path-finding
for (uint8 i = 0; i < 18; ++i)
{
@ -152,20 +151,37 @@ bool FleeingMovementGenerator<T>::_getPoint(T* owner, float& x, float& y, float&
temp_x = x + distance * cos(angle);
temp_y = y + distance * sin(angle);
float temp_z = z;
if (_map->CanReachPositionAndGetCoords(owner, temp_x, temp_y, temp_z, true, 3.0f, M_PI/4))
acore::NormalizeMapCoord(temp_x);
acore::NormalizeMapCoord(temp_y);
if (owner->IsWithinLOS(temp_x, temp_y, z))
{
if (!(temp_z - z) || distance / fabs(temp_z - z) > 1.0f)
bool is_water_now = _map->IsInWater(x, y, z);
if (is_water_now && _map->IsInWater(temp_x, temp_y, z))
{
float temp_z_left = _map->GetHeight(owner->GetPhaseMask(), temp_x + 1.0f * cos(angle + static_cast<float>(M_PI / 2)), temp_y + 1.0f * sin(angle + static_cast<float>(M_PI / 2)), z, true);
float temp_z_right = _map->GetHeight(owner->GetPhaseMask(), temp_x + 1.0f * cos(angle - static_cast<float>(M_PI / 2)), temp_y + 1.0f * sin(angle - static_cast<float>(M_PI / 2)), z, true);
if (fabs(temp_z_left - temp_z) < 1.2f && fabs(temp_z_right - temp_z) < 1.2f)
x = temp_x;
y = temp_y;
return true;
}
float new_z = _map->GetHeight(owner->GetPhaseMask(), temp_x, temp_y, z, true);
if (new_z <= INVALID_HEIGHT || fabs(z - new_z) > 3.0f)
continue;
bool is_water_next = _map->IsInWater(temp_x, temp_y, new_z);
if ((is_water_now && !is_water_next && !is_land_ok) || (!is_water_now && is_water_next && !is_water_ok))
continue;
if (!(new_z - z) || distance / fabs(new_z - z) > 1.0f)
{
float new_z_left = _map->GetHeight(owner->GetPhaseMask(), temp_x + 1.0f * cos(angle + static_cast<float>(M_PI / 2)), temp_y + 1.0f * sin(angle + static_cast<float>(M_PI / 2)), z, true);
float new_z_right = _map->GetHeight(owner->GetPhaseMask(), temp_x + 1.0f * cos(angle - static_cast<float>(M_PI / 2)), temp_y + 1.0f * sin(angle - static_cast<float>(M_PI / 2)), z, true);
if (fabs(new_z_left - new_z) < 1.2f && fabs(new_z_right - new_z) < 1.2f)
{
// use new values
x = temp_x;
y = temp_y;
z = temp_z;
z = new_z;
return true;
}
}