major update to detecting objects around bot but probably not done

This commit is contained in:
Christian 2020-10-18 22:54:22 +02:00
parent 8b5c002961
commit 20c19c925f

View File

@ -219,10 +219,59 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
int flags = GetEntityFlags(client);
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP))
{
float Vel[3];
float Vel[3], feet_origin[3], ground_pos[3], downwards[3];
//TODO
float velocity_addition_z_axis = 300.0;
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
Vel[2] += velocity_addition_z_axis;
GetClientAbsOrigin(present, feet_origin);
downwards[0] = 90.0;
downwards[1] = 0.0;
downwards[2] = 0.0;
TR_TraceRayFilter(feet_origin, downwards, MASK_PLAYERSOLID, RayType_Infinite, TraceRayDontHitSelf, present);
if (TR_DidHit())
{
TR_GetEndPosition(ground_pos);
feet_origin[2] -= 10.0;
float ground_distance = GetVectorDistance(feet_origin, ground_pos);
if (ground_distance > 80)
{
float angles_eye[3];
GetClientEyeAngles(present, angles_eye);
feet_origin[2] += 10.0;
TR_TraceRayFilter(feet_origin, angles_eye, MASK_PLAYERSOLID, RayType_Infinite, TraceRayDontHitSelf, present);
if (TR_DidHit())
{
TR_GetEndPosition(ground_pos);
feet_origin[2] -= 10.0;
float forward_distance = GetVectorDistance(feet_origin, ground_pos);
if (forward_distance > 280)
{
if (IsValidClient(targethuman))
{
float feet_origin_pre[3], human_feet_origin[3];
GetClientAbsOrigin(present, feet_origin_pre);
GetClientAbsOrigin(targethuman, human_feet_origin);
//target human is below, get down to them
if (feet_origin_pre[2] - 200 > human_feet_origin[2])
{
buttons_old = buttons;
flags_old = flags;
return;
}
}
float angles_abs[3];
GetClientAbsAngles(present, angles_abs);
if (angles_abs[1] < 0)
angles_abs[1] += 180.0;
else
angles_abs[1] -= 180.0;
TeleportEntity(present, NULL_VECTOR, angles_abs, NULL_VECTOR);
}
}
}
}
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel);
}
buttons_old = buttons;
@ -266,9 +315,9 @@ public Action recursive_pressing(Handle timer, any data)
reset_target_human_tp_coord();
return Plugin_Continue;
}
target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2);
targethuman = GetClosestClient_option1(targeteam == 2 ? 2 : 3);
float enemy_distance = -1.0;
target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2);
float dist_target = -1.0;
float pos[3];
if (IsValidClient(targethuman))
@ -281,9 +330,14 @@ public Action recursive_pressing(Handle timer, any data)
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
enemy_distance = get_power_distance(present, pos);
}
float enemey_cap = 900.0;
if ((0 < enemy_distance < enemey_cap && targeteam == 2) || dist_target < 0 < enemy_distance)
if ((0 < enemy_distance && targeteam == 2) || dist_target < 0 < enemy_distance)
{
float feet_origin[3], enemy_feet_origin[3];
GetClientAbsOrigin(present, feet_origin);
GetClientAbsOrigin(target_enemy, enemy_feet_origin);
if (feet_origin[2] + 100 > enemy_feet_origin[2])
face_call(target_enemy);
}
else if (0 < dist_target)
face_call(targethuman);
trace_hulling_bot();
@ -306,8 +360,12 @@ public Action recursive_pressing(Handle timer, any data)
public void trace_hulling_bot()
{
char message[generic_length * 3];
float feet_origin[3], mins[3], maxs[3];
float step_cap = 18.0;
float crouch_min = 48.0;
float stand_min = 63.0;
float feet_origin[3], mins[3], maxs[3], eye_position[3];
int BOUNDINGBOX_INFLATION_OFFSET = 3;
GetClientEyePosition(present, eye_position);
GetClientAbsOrigin(present, feet_origin);
GetClientMins(present, mins);
GetClientMaxs(present, maxs);
@ -322,41 +380,72 @@ public void trace_hulling_bot()
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
if (TR_DidHit())
{
GetClientAbsOrigin(present, feet_origin);
//check 0.0 to 48.0 units starting from feet
feet_origin[2] -= BOUNDINGBOX_INFLATION_OFFSET;
mins[2] = 0.0;
maxs[2] = 48.0;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
maxs[2] = crouch_min;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit()))
{
//can crouch
Format(message, sizeof(message), "hull info:crouch");
send_socket_msg(message, strlen(message));
return;
}
//something blocks floor crouch
eye_position[2] += 5.0;
TR_TraceHullFilter(eye_position, eye_position, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit()))
{
//should not block jump level
Format(message, sizeof(message), "hull info:jump");
send_socket_msg(message, strlen(message));
return;
}
else
{
mins[2] = 75.0;
maxs[2] = 100.0;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
if (!(TR_DidHit()))
//still potentially crouch hole in wall or one side jumpable
mins[2] = step_cap;
float iterator = step_cap;
while (iterator < stand_min)
{
mins[2] = 0.0;
maxs[2] = 75.0;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
if (TR_DidHit())
maxs[2] = iterator;
iterator += step_cap;
for (int jj = 0; jj < 2; jj++)
for (int ij = 0; ij < 2; ij++)
{
if (jj == 0)
mins[ij] += BOUNDINGBOX_INFLATION_OFFSET;
else
maxs[ij] -= BOUNDINGBOX_INFLATION_OFFSET;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit()))
{
Format(message, sizeof(message), "hull info:jump");
send_socket_msg(message, strlen(message));
return;
}
}
else
TR_TraceHullFilter(eye_position, eye_position, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit()))
{
//hit wall
Format(message, sizeof(message), "hull info:jump");
send_socket_msg(message, strlen(message));
return;
}
if (jj == 0)
mins[ij] -= BOUNDINGBOX_INFLATION_OFFSET;
else
maxs[ij] += BOUNDINGBOX_INFLATION_OFFSET;
}
}
//currently detects when two walls meet and create a corner
float move_angles[3];
GetClientEyeAngles(present, move_angles);
move_angles[0] = 0.0;
move_angles[1] += 15;
move_angles[1] += 35.0;
move_angles[2] = 0.0;
TeleportEntity(present, NULL_VECTOR, move_angles, NULL_VECTOR);
}
return;
}
}
}
@ -458,7 +547,7 @@ public int GetClosestClient_option1(int targeteam)
{
if (!IsAbleToSee(present, i))
continue;
if (is_client_stuck_or_afk(i))
if (is_client_stuck_or_afk(i) && GetClientTeam(i) == GetClientTeam(present))
{
if (i != targethuman)
continue;
@ -474,6 +563,13 @@ public int GetClosestClient_option1(int targeteam)
float pos[3];
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(present, pos);
if (GetClientTeam(present) == 3 && IsValidClient(target_enemy) && targeteam == 3)
{
float enemey_cap = 1500.0;
float enemy_dist = get_power_distance(target_enemy, pos);
if (enemy_dist < enemey_cap)
dist_target += enemey_cap;
}
if (admins[i] || vips[i] || i == targethuman || i == target_enemy)
dist_target /= 5;
if (nearestdistance < 0 || dist_target < nearestdistance)