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); int flags = GetEntityFlags(client);
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP)) 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; float velocity_addition_z_axis = 300.0;
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel); GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
Vel[2] += velocity_addition_z_axis; 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); TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel);
} }
buttons_old = buttons; buttons_old = buttons;
@ -232,82 +281,91 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
public Action recursive_pressing(Handle timer, any data) public Action recursive_pressing(Handle timer, any data)
{ {
if (IsValidClient(present)) if (IsValidClient(present))
{ {
if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0) if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0)
{ {
ChangeClientTeam(present, 2); ChangeClientTeam(present, 2);
return Plugin_Continue; return Plugin_Continue;
} }
if (IsPlayerAlive(present)) if (IsPlayerAlive(present))
{ {
if (GetEntityMoveType(present) == MOVETYPE_LADDER) if (GetEntityMoveType(present) == MOVETYPE_LADDER)
return Plugin_Continue; return Plugin_Continue;
int targeteam = 0; int targeteam = 0;
if (GetClientTeam(present) != 3) if (GetClientTeam(present) != 3)
{ {
//2 = autismo is zm and should follow closest moving zm //2 = autismo is zm and should follow closest moving zm
targeteam = 2; targeteam = 2;
} }
else else
{ {
//3 = autismo is human and should follow closest moving ct //3 = autismo is human and should follow closest moving ct
targeteam = 3; targeteam = 3;
} }
if (targethuman_teleported[0] != 0.0) if (targethuman_teleported[0] != 0.0)
{ {
float ClientPos[3]; float ClientPos[3];
float Result[3]; float Result[3];
GetClientEyePosition(present, ClientPos); GetClientEyePosition(present, ClientPos);
MakeVectorFromPoints(ClientPos, targethuman_teleported, Result); MakeVectorFromPoints(ClientPos, targethuman_teleported, Result);
GetVectorAngles(Result, Result); GetVectorAngles(Result, Result);
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR); TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
if (!distance_check()) if (!distance_check())
reset_target_human_tp_coord(); reset_target_human_tp_coord();
return Plugin_Continue; return Plugin_Continue;
} }
targethuman = GetClosestClient_option1(targeteam == 2 ? 2 : 3); target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2);
float enemy_distance = -1.0; targethuman = GetClosestClient_option1(targeteam == 2 ? 2 : 3);
target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2); float enemy_distance = -1.0;
float dist_target = -1.0; float dist_target = -1.0;
float pos[3]; float pos[3];
if (IsValidClient(targethuman)) if (IsValidClient(targethuman))
{ {
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos); GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
dist_target = get_power_distance(present, pos); dist_target = get_power_distance(present, pos);
} }
if (IsValidClient(target_enemy)) if (IsValidClient(target_enemy))
{ {
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos); GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
enemy_distance = get_power_distance(present, pos); enemy_distance = get_power_distance(present, pos);
} }
float enemey_cap = 900.0; if ((0 < enemy_distance && targeteam == 2) || dist_target < 0 < enemy_distance)
if ((0 < enemy_distance < enemey_cap && targeteam == 2) || dist_target < 0 < enemy_distance) {
face_call(target_enemy); float feet_origin[3], enemy_feet_origin[3];
else if (0 < dist_target) GetClientAbsOrigin(present, feet_origin);
face_call(targethuman); GetClientAbsOrigin(target_enemy, enemy_feet_origin);
trace_hulling_bot(); if (feet_origin[2] + 100 > enemy_feet_origin[2])
char message[generic_length * 7]; face_call(target_enemy);
if (IsValidClient(targethuman)) }
Format(message, sizeof(message), "dist_target: %f targethuman: %N enemy_distance: %f targeteam: %i", dist_target, targethuman, enemy_distance, targeteam); else if (0 < dist_target)
else face_call(targethuman);
Format(message, sizeof(message), "dist_target: %f targethuman: none enemy_distance: %f targeteam: %i", dist_target, enemy_distance, targeteam); trace_hulling_bot();
if (IsValidClient(target_enemy)) char message[generic_length * 7];
Format(message, sizeof(message), "%s target_enemy: %N", message, target_enemy); if (IsValidClient(targethuman))
else Format(message, sizeof(message), "dist_target: %f targethuman: %N enemy_distance: %f targeteam: %i", dist_target, targethuman, enemy_distance, targeteam);
Format(message, sizeof(message), "%s target_enemy: none", message); else
send_socket_msg(message, strlen(message)); Format(message, sizeof(message), "dist_target: %f targethuman: none enemy_distance: %f targeteam: %i", dist_target, enemy_distance, targeteam);
} if (IsValidClient(target_enemy))
} Format(message, sizeof(message), "%s target_enemy: %N", message, target_enemy);
return Plugin_Continue; else
Format(message, sizeof(message), "%s target_enemy: none", message);
send_socket_msg(message, strlen(message));
}
}
return Plugin_Continue;
} }
//https://developer.valvesoftware.com/wiki/Dimensions //https://developer.valvesoftware.com/wiki/Dimensions
public void trace_hulling_bot() public void trace_hulling_bot()
{ {
char message[generic_length * 3]; 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; int BOUNDINGBOX_INFLATION_OFFSET = 3;
GetClientEyePosition(present, eye_position);
GetClientAbsOrigin(present, feet_origin); GetClientAbsOrigin(present, feet_origin);
GetClientMins(present, mins); GetClientMins(present, mins);
GetClientMaxs(present, maxs); GetClientMaxs(present, maxs);
@ -322,41 +380,72 @@ public void trace_hulling_bot()
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf); TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
if (TR_DidHit()) 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; mins[2] = 0.0;
maxs[2] = 48.0; maxs[2] = crouch_min;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf); TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit())) if (!(TR_DidHit()))
{ {
//can crouch
Format(message, sizeof(message), "hull info:crouch"); Format(message, sizeof(message), "hull info:crouch");
send_socket_msg(message, strlen(message)); 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 else
{ {
mins[2] = 75.0; //still potentially crouch hole in wall or one side jumpable
maxs[2] = 100.0; mins[2] = step_cap;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf); float iterator = step_cap;
if (!(TR_DidHit())) while (iterator < stand_min)
{ {
mins[2] = 0.0; maxs[2] = iterator;
maxs[2] = 75.0; iterator += step_cap;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf); for (int jj = 0; jj < 2; jj++)
if (TR_DidHit()) for (int ij = 0; ij < 2; ij++)
{ {
Format(message, sizeof(message), "hull info:jump"); if (jj == 0)
send_socket_msg(message, strlen(message)); mins[ij] += BOUNDINGBOX_INFLATION_OFFSET;
} else
} maxs[ij] -= BOUNDINGBOX_INFLATION_OFFSET;
else TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
{ if (!(TR_DidHit()))
//hit wall {
float move_angles[3]; Format(message, sizeof(message), "hull info:jump");
GetClientEyeAngles(present, move_angles); send_socket_msg(message, strlen(message));
move_angles[0] = 0.0; return;
move_angles[1] += 15; }
move_angles[2] = 0.0; TR_TraceHullFilter(eye_position, eye_position, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
TeleportEntity(present, NULL_VECTOR, move_angles, NULL_VECTOR); if (!(TR_DidHit()))
{
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] += 35.0;
move_angles[2] = 0.0;
TeleportEntity(present, NULL_VECTOR, move_angles, NULL_VECTOR);
return;
} }
} }
} }
@ -456,32 +545,39 @@ public int GetClosestClient_option1(int targeteam)
for (int i = 1; i <= MaxClients; i++) for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present) if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
{ {
if (!IsAbleToSee(present, i)) if (!IsAbleToSee(present, i))
continue; continue;
if (is_client_stuck_or_afk(i)) if (is_client_stuck_or_afk(i) && GetClientTeam(i) == GetClientTeam(present))
{ {
if (i != targethuman) if (i != targethuman)
continue; continue;
target_human_afk_counter++; target_human_afk_counter++;
if (target_human_afk_counter > 5) if (target_human_afk_counter > 5)
{ {
target_human_afk_counter = 0; target_human_afk_counter = 0;
continue; continue;
} }
} }
else if (i == targethuman) else if (i == targethuman)
target_human_afk_counter = 0; target_human_afk_counter = 0;
float pos[3]; float pos[3];
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(present, pos); float dist_target = get_power_distance(present, pos);
if (admins[i] || vips[i] || i == targethuman || i == target_enemy) if (GetClientTeam(present) == 3 && IsValidClient(target_enemy) && targeteam == 3)
dist_target /= 5; {
if (nearestdistance < 0 || dist_target < nearestdistance) float enemey_cap = 1500.0;
{ float enemy_dist = get_power_distance(target_enemy, pos);
nearest = i; if (enemy_dist < enemey_cap)
nearestdistance = dist_target; dist_target += enemey_cap;
} }
} if (admins[i] || vips[i] || i == targethuman || i == target_enemy)
dist_target /= 5;
if (nearestdistance < 0 || dist_target < nearestdistance)
{
nearest = i;
nearestdistance = dist_target;
}
}
return nearest; return nearest;
} }
@ -742,4 +838,4 @@ public bool IsRectangleVisible(const float start[3], const float end[3], const f
if (IsPointVisible(start, vRectangle[i])) if (IsPointVisible(start, vRectangle[i]))
return true; return true;
return false; return false;
} }