void c_anim_sync::find_server_foot_yaw(player_entry_t& entry, lag_record_t* const current, const lag_anim_data_t* const previous) const
{
const auto& bone_cache = entry.m_player->bone_cache();
if (!bone_cache.m_mem.m_ptr || !bone_cache.m_size)
return;
current->m_anim_side = rotate_server;
if (current->m_sim_ticks >= 1 || current->m_sim_ticks <= 17)
{
current->m_anim_side = entry.m_storred_anim_side;
if (previous)
{
auto accelerating = current->m_anim_layers.at(6u).m_weight >= previous->m_anim_layers.at(6u).m_weight &&
current->m_anim_layers.at(6u).m_playback_rate >= previous->m_anim_layers.at(6u).m_playback_rate;
if (!(current->m_flags & valve::on_ground) || !(previous->m_flags & valve::on_ground))
accelerating = false;
if (accelerating)
{
auto best_match = std::make_pair(rotate_server, FLT_MAX);
for (int i = rotate_center; i <= rotate_low_right; i++)
{
if (current->m_anim_sides.at(i).m_anim_layers.at(6u).m_sequence != current->m_anim_layers.at(6u).m_sequence)
continue;
const auto delta_weight = fabsf(current->m_anim_sides.at(i).m_anim_layers.at(6u).m_weight - current->m_anim_layers.at(6u).m_weight);
const auto delta_cycle = fabsf(current->m_anim_sides.at(i).m_anim_layers.at(6u).m_cycle - current->m_anim_layers.at(6u).m_cycle);
const auto delta_rate = fabsf(current->m_anim_sides.at(i).m_anim_layers.at(6u).m_playback_rate - current->m_anim_layers.at(6u).m_playback_rate);
const auto delta_total = delta_weight + delta_cycle + delta_rate;
if (delta_total < best_match.second)
best_match = { static_cast<e_rotate_mode>(i), delta_total };
if (delta_weight < 0.000001f || delta_cycle < 0.000001f || delta_rate < 0.000001f)
best_match = { static_cast<e_rotate_mode>(i), 0.f };
}
if (best_match.second < FLT_MAX)
{
entry.m_storred_anim_side = current->m_anim_side = best_match.first;
entry.m_last_storred_tick = valve::g_global_vars->m_tick_count;
}
}
else
{
if (current->m_velocity.length_2d() <= 1.2f)
{
float feet_delta = math::normalize_angle(math::angle_diff(math::normalize_angle(entry.m_player->lby()), math::normalize_angle(entry.m_player->eye_angles().y)));
if (std::abs(feet_delta) >= 35.f)
{
entry.m_storred_anim_side = current->m_anim_side = feet_delta > 0.f ? rotate_left : rotate_right;
entry.m_last_storred_tick = valve::g_global_vars->m_tick_count;
}
}
}
}
else
{
if (g_context->wpn_data())
{
const auto left_pos = current->m_anim_sides.at(rotate_left).m_bones[entry.m_player->lookup_bone(xorstr_("head_0"))].get_origin();
const auto right_pos = current->m_anim_sides.at(rotate_right).m_bones[entry.m_player->lookup_bone(xorstr_("head_0"))].get_origin();
const auto left_info = g_auto_wall->fire_bullet(valve::g_local_player, entry.m_player, g_context->wpn_data(), false, g_context->shoot_pos(), left_pos);
const auto right_info = g_auto_wall->fire_bullet(valve::g_local_player, entry.m_player, g_context->wpn_data(), false, g_context->shoot_pos(), right_pos);
if (left_info.m_dmg > right_info.m_dmg)
entry.m_storred_anim_side = current->m_anim_side = rotate_left;
else if (left_info.m_dmg < right_info.m_dmg)
entry.m_storred_anim_side = current->m_anim_side = rotate_right;
else
entry.m_storred_anim_side = current->m_anim_side = rotate_center;
}
}
}
if (entry.m_misses)
{
switch(entry.m_brute_side)
{
case rotate_server:
current->m_anim_side = (rand() % 2) ? rotate_right : rotate_left;
break;
case rotate_center:
current->m_anim_side = (rand() % 2) ? rotate_right : rotate_left;
if (entry.m_was_first_bruteforce)
current->m_anim_side = rotate_right;
else if (entry.m_was_second_bruteforce)
current->m_anim_side = rotate_left;
else if (entry.m_was_first_low_bruteforce)
current->m_anim_side = rotate_low_right;
else if (entry.m_was_second_low_bruteforce)
current->m_anim_side = rotate_low_left;
entry.m_was_first_bruteforce = false;
entry.m_was_second_bruteforce = false;
entry.m_was_first_low_bruteforce = false;
entry.m_was_second_low_bruteforce = false;
break;
case rotate_left:
current->m_anim_side = entry.m_was_second_bruteforce ? rotate_center : rotate_right;
entry.m_was_first_bruteforce = true;
break;
case rotate_right:
current->m_anim_side = entry.m_was_first_low_bruteforce ? rotate_center : rotate_left;
entry.m_was_second_bruteforce = true;
break;
case rotate_low_left:
current->m_anim_side = entry.m_was_second_low_bruteforce ? rotate_center : rotate_low_right;
entry.m_was_first_low_bruteforce = true;
break;
case rotate_low_right:
current->m_anim_side = entry.m_was_first_low_bruteforce ? rotate_center : rotate_low_left;
entry.m_was_second_low_bruteforce = true;
break;
}
}
}