Skip to content

Commit

Permalink
* Misc. fixes to the pig
Browse files Browse the repository at this point in the history
Still broken....
  • Loading branch information
iProgramMC committed Dec 7, 2023
1 parent 3443349 commit 23444c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
26 changes: 15 additions & 11 deletions source/world/entity/Mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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)
Expand All @@ -844,7 +848,7 @@ void Mob::updateAi()

if (isInWater() || isInLava())
{
field_B0C = m_random.nextInt() < 0.8f;
field_B0C = m_random.nextFloat() < 0.8f;
}
}

Expand Down
33 changes: 10 additions & 23 deletions source/world/entity/PathfinderMob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion source/world/level/path/PathFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 23444c2

Please sign in to comment.