diff --git a/source/world/entity/Mob.cpp b/source/world/entity/Mob.cpp index b2825ec1..aba9f038 100644 --- a/source/world/entity/Mob.cpp +++ b/source/world/entity/Mob.cpp @@ -661,8 +661,11 @@ void Mob::lookAt(Entity* pEnt, float a3, float a4) float diffX = pEnt->m_pos.x - m_pos.x; float diffZ = pEnt->m_pos.z - m_pos.z; + float q1 = (pEnt->m_hitbox.min.y + pEnt->m_hitbox.max.y) / 2 - (m_pos.y + getHeadHeight()); + float p1 = Mth::sqrt(diffX * diffX + diffZ * diffZ); + float x1 = atan2f(diffZ, diffX); - float x2 = atan2f((pEnt->m_hitbox.min.y + pEnt->m_hitbox.max.y) / 2 - m_pos.y - getHeadHeight(), Mth::sqrt(diffX * diffX + diffZ * diffZ)); + float x2 = atan2f(q1, p1); m_pitch = -rotlerp(m_pitch, x2 * 180.0f / float(M_PI), a4); m_yaw = rotlerp(m_yaw, x1 * 180.0f / float(M_PI) - 90.0f, a3); @@ -792,18 +795,15 @@ void Mob::updateAi() if (removeWhenFarAway() && nearestPlayer) { float distSqr = nearestPlayer->distanceToSqr_inline(m_pos.x, m_pos.y, m_pos.z); - if (distSqr > 16384.0f) + if (distSqr > 9216.0f) remove(); - if (field_AFC > 600) + if (field_AFC > 600 && m_random.nextInt(800) == 0) { - if (m_random.nextInt(800) == 0) - { - if (distSqr >= 1024.0f) - remove(); - else - field_AFC = 0; - } + if (distSqr >= 1024.0f) + remove(); + else + field_AFC = 0; } } @@ -819,6 +819,10 @@ void Mob::updateAi() field_120 = m_random.nextInt(20) + 10; } + else + { + field_B08 = (m_random.nextFloat() - 0.5f) * 20.0f; + } } if (m_pEntLookedAt) @@ -844,7 +848,7 @@ void Mob::updateAi() if (isInWater() || isInLava()) { - field_B0C = m_random.nextInt() < 0.8f; + field_B0C = m_random.nextFloat() < 0.8f; } } diff --git a/source/world/entity/PathfinderMob.cpp b/source/world/entity/PathfinderMob.cpp index 570c952b..75302470 100644 --- a/source/world/entity/PathfinderMob.cpp +++ b/source/world/entity/PathfinderMob.cpp @@ -137,30 +137,17 @@ void PathfinderMob::updateAi() m_pLevel->findPath(&m_path, this, m_pAttackTarget, 16.0f); } - // @TODO: fix gotos - - if (!field_BA0) + if (!field_BA0 && m_pAttackTarget && (m_path.empty() || m_random.nextInt(20) != 0)) { - if (m_pAttackTarget) - { - if (m_path.empty() || m_random.nextInt(20) == 0 || m_random.nextInt(20) == 0) - { - m_pLevel->findPath(&m_path, this, m_pAttackTarget, 16.0f); - goto label_1; - } - - if (field_BA0) - goto label_1; - } - - if ((m_path.empty() && m_random.nextInt(180) == 0) || m_random.nextInt(120) == 0 || (field_BA4 > 0 && (field_BA4 & 7) == 1)) - { - if (field_AFC < 100) - findRandomStrollLocation(); - } + m_pLevel->findPath(&m_path, this, m_pAttackTarget, 16.0f); + } + else if (!field_BA0 && ((m_path.empty() && m_random.nextInt(180) == 0) || field_BA4 > 0 || m_random.nextInt(120) == 0)) + { + if (field_AFC < 100) + findRandomStrollLocation(); } -label_1: + m_pitch = 0.0f; if (m_path.empty() || m_random.nextInt(100) == 0) @@ -199,6 +186,8 @@ void PathfinderMob::updateAi() float ang = Mth::atan2(nodePos.z - m_pos.z, nodePos.x - m_pos.x) * 180.0f / float(M_PI) - 90.0f; float heightDiff = nodePos.y - Mth::floor(m_hitbox.min.y + 0.5f); + field_B04 = field_B14; + float angDiff = ang - m_yaw; while (angDiff < -180.0f) angDiff += 360.0f; while (angDiff >= 180.0f) angDiff -= 360.0f; @@ -222,8 +211,6 @@ void PathfinderMob::updateAi() field_B04 = field_B04 * Mth::cos(thing); } - field_B04 = field_B14; - if (heightDiff > 0.0f) field_B0C = true; } diff --git a/source/world/level/path/PathFinder.cpp b/source/world/level/path/PathFinder.cpp index 89ab0783..596d37d3 100644 --- a/source/world/level/path/PathFinder.cpp +++ b/source/world/level/path/PathFinder.cpp @@ -47,7 +47,7 @@ int PathFinder::isFree(Entity* pEntity, int x, int y, int z, const Node* node) for (int z1 = z; z1 < z + node->m_z; z1++) { TileID id = m_pLevel->getTile(x1, y1, z1); - if (id < 0) + if (id <= 0) continue; if (id == Tile::door_iron->m_ID || id == Tile::door_wood->m_ID)