projects-jenz/AutismBotIngame/scripting/autism_bot_info.sp

721 lines
20 KiB
SourcePawn
Raw Normal View History

2020-01-23 23:15:26 +01:00
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
2020-06-26 00:11:22 +02:00
#define PLUGIN_VERSION "1.3"
#define generic_length 256
2020-01-23 23:15:26 +01:00
#include <sourcemod>
#include <sdktools>
2020-06-26 00:11:22 +02:00
#include <socket>
2020-01-23 23:15:26 +01:00
2020-06-26 00:11:22 +02:00
//#pragma newdecls required
2020-02-28 22:00:22 +01:00
int present = 0;
2020-02-09 00:26:05 +01:00
int targethuman = 0;
2020-07-26 01:13:39 +02:00
bool client_stuck_g[MAXPLAYERS + 1];
bool round_start_stuck = false;
float bot_old_coords[3];
bool bot_stuck_g = false;
float client_old_coords[MAXPLAYERS + 1][3];
bool bot_forward = false;
bool g_bOnGround[MAXPLAYERS + 1];
bool g_bLastOnGround[MAXPLAYERS + 1];
float g_vCurrent[MAXPLAYERS + 1][3];
float g_vLast[MAXPLAYERS + 1][3];
2020-01-23 23:15:26 +01:00
//admins & vips
bool admins[MAXPLAYERS + 1];
bool vips[MAXPLAYERS + 1];
2020-06-26 00:11:22 +02:00
//socket for bot input
Handle global_socket;
2020-01-23 23:15:26 +01:00
public Plugin myinfo =
{
name = "coordinates for the bot",
author = PLUGIN_AUTHOR,
description = "hello ",
version = PLUGIN_VERSION,
url = ""
};
2020-02-28 22:00:22 +01:00
public void OnPluginStart()
2020-01-23 23:15:26 +01:00
{
//talking
RegConsoleCmd("sm_autism", cmd_talk, "talking to the bot through java application");
2020-02-28 22:00:22 +01:00
//hooks
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
2020-06-26 00:11:22 +02:00
//socket otherwise declare in public OnConfigsExecuted(){}
Handle socket = SocketCreate(SOCKET_UDP, OnSocketError);
SocketSetOption(socket, SocketReuseAddr, 1);
SocketBind(socket, "127.0.0.1", 48475);
2020-06-26 00:11:22 +02:00
connect(socket);
global_socket = socket;
2020-07-26 01:13:39 +02:00
round_start_stuck = true;
bot_forward = false;
targethuman = 0;
2020-01-23 23:15:26 +01:00
}
public Action cmd_talk(int client, int args)
{
2020-06-26 00:11:22 +02:00
char msg[generic_length];
char info[generic_length];
GetCmdArgString(info, sizeof(info));
2020-05-06 01:24:15 +02:00
if (strlen(info) == 0)
{
2020-06-09 23:34:49 +02:00
PrintToChat(client, "Add a message to the command if autism bot is ingame and running on discord");
2020-05-06 01:24:15 +02:00
return Plugin_Handled;
}
2020-06-26 00:11:22 +02:00
Format(msg, sizeof(msg), "clientmessage: %s", info);
send_socket_msg(msg, strlen(msg));
return Plugin_Handled;
}
2020-02-28 22:00:22 +01:00
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
2020-01-23 23:15:26 +01:00
{
round_start_stuck = false;
2020-02-28 22:00:22 +01:00
targethuman = 0;
bot_stuck_g = false;
bot_forward = false;
CreateTimer(7.0, permitStuck);
}
public Action permitStuck(Handle timer, any data)
{
round_start_stuck = true;
return Plugin_Continue;
2020-01-23 23:15:26 +01:00
}
public Action bot_reached_endpoint(Handle timer, any data)
{
bot_forward = false;
return Plugin_Continue;
}
2020-02-28 22:00:22 +01:00
public void OnMapStart()
2020-02-09 00:26:05 +01:00
{
CreateTimer(0.2, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
CreateTimer(1.0, clients_coordinates, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
2020-06-26 00:11:22 +02:00
CreateTimer(10.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
2020-02-09 00:26:05 +01:00
}
public Action clients_coordinates(Handle timer, any data)
{
if (IsValidClient(present) && IsPlayerAlive(present))
{
for (int i = 1; i <= MaxClients; i++)
2020-07-26 01:13:39 +02:00
if (IsValidClient(i) && IsPlayerAlive(i) && i != present && !client_stuck_g[i])
GetEntPropVector(i, Prop_Send, "m_vecOrigin", client_old_coords[i]);
if (!bot_stuck_g)
GetEntPropVector(present, Prop_Send, "m_vecOrigin", bot_old_coords);
}
return Plugin_Continue;
}
2020-06-26 00:11:22 +02:00
public void send_socket_msg(char[] query_msg, int len)
2020-06-09 23:34:49 +02:00
{
2020-06-26 00:11:22 +02:00
if (global_socket != INVALID_HANDLE && SocketIsConnected(global_socket))
SocketSendTo(global_socket, query_msg, len, "127.0.0.1", 48477); //udp
}
public Action bot_check_connect(Handle timer, any data)
{
if (!IsValidClient(present) && GetClientCount(false) < 63)
{
char msg[generic_length];
//PrintToChatAll("sending UDP message...");
Format(msg, sizeof(msg), "connect to ze");
send_socket_msg(msg, strlen(msg));
}
return Plugin_Continue;
}
public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype,
int cmdnum, int tickcount, int seed, const int mouse[2])
{
if (!IsClientInGame(client)) return;
2020-07-26 01:13:39 +02:00
if (client == targethuman && round_start_stuck && IsValidClient(present))
{
char keyinput[generic_length * 5];
if (buttons & IN_JUMP)
Format(keyinput, sizeof(keyinput), "+jump; wait 5; ", keyinput);
if (buttons & IN_DUCK)
Format(keyinput, sizeof(keyinput), "%s +duck; wait 5; ", keyinput);
if (strlen(keyinput) > 0)
{
float pos[3];
2020-07-26 01:13:39 +02:00
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(present, pos);
float dist_cap = 1.0;
if (dist_target < dist_cap)
{
Format(keyinput, sizeof(keyinput), "keyinput: %s dist_target: %f", keyinput, dist_target);
send_socket_msg(keyinput, strlen(keyinput));
}
}
}
}
public Action recursive_pressing(Handle timer, any data)
2020-06-26 00:11:22 +02:00
{
if (IsValidClient(present) && IsPlayerAlive(present))
{
if (bot_forward)
return Plugin_Continue;
char message[generic_length * 7];
float present_bot_coords[3];
GetClientAbsOrigin(present, present_bot_coords);
int targeteam = 0;
if (GetClientTeam(present) != 3)
{
2020-06-09 23:34:49 +02:00
//2 = autismo is zm and should follow closest moving zm
targeteam = 2;
}
else
{
2020-06-09 23:34:49 +02:00
//3 = autismo is human and should follow closest moving ct
targeteam = 3;
}
bool find_closest_match = true;
bool bot_stuck = false;
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman))
{
face_call(targethuman);
find_closest_match = is_client_stuck_or_afk(targethuman);
if (!find_closest_match)
{
face_call(targethuman);
find_closest_match = IsAbleToSee(present, targethuman) ? false : true;
if (find_closest_match)
{
float dist_target = get_power_distance(targethuman, client_old_coords[targethuman]);
float min_required_distance = 1500.0;
if (dist_target > min_required_distance)
{
bot_forward = true;
find_closest_match = false;
CreateTimer(4.0, bot_reached_endpoint);
}
}
}
}
//check ladder = 0, water = 1, in air(surfing) = 2, downhill = 3
int bot_on_type = -1;
if (GetEntityMoveType(present) == MOVETYPE_LADDER)
bot_on_type = 0;
int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel");
if (ilevel >= 2)
bot_on_type = 1;
if (bot_on_type == -1)
bot_on_type = check_bot_surfing_or_downhill();
if (find_closest_match && bot_on_type != 0)
{
targethuman = 0;
targethuman = GetClosestClient_option1(present, targeteam);
}
float enemy_distance = -1.0;
int target_enemy = find_closest_enemy(present, targeteam);
bool chasing_enemy = false;
float dist_target = -1.0;
if (bot_on_type != 0 && bot_on_type != 2)
{
float pos[3];
if (IsValidClient(targethuman))
{
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
dist_target = get_power_distance(present, pos);
}
if (IsValidClient(target_enemy))
2020-07-21 01:20:28 +02:00
{
2020-07-26 01:13:39 +02:00
float min_enemy_distance = 10.0;
int min_distance_mult = 6;
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
enemy_distance = get_power_distance(present, pos);
float min_distance_target_human = 0.2;
//human aiming for zombie
if (targeteam == 3 && dist_target > 0 && dist_target < min_distance_target_human && enemy_distance > min_enemy_distance)
2020-07-21 01:20:28 +02:00
{
chasing_enemy = true;
face_call(target_enemy);
}
//zombie aiming for human
if (0 < enemy_distance <= dist_target)
min_enemy_distance = min_enemy_distance * min_distance_mult;
if (targeteam == 2 && min_enemy_distance * min_distance_mult > enemy_distance && enemy_distance > 0)
{
chasing_enemy = true;
face_call(target_enemy);
2020-07-21 01:20:28 +02:00
}
}
if (IsValidClient(targethuman) && !chasing_enemy)
face_call(targethuman);
if (round_start_stuck)
bot_stuck = is_bot_stuck();
2020-01-23 23:15:26 +01:00
}
//TODO detect gaps and jump perfectly over them
if (IsValidClient(targethuman))
Format(message, sizeof(message), "dist_target: %f targethuman: %N bot_on_type: %i enemy_distance: %f bot_stuck: %i targeteam: %i", dist_target, targethuman, bot_on_type, enemy_distance, bot_stuck, targeteam);
else
Format(message, sizeof(message), "dist_target: %f targethuman: none bot_on_type: %i enemy_distance: %f bot_stuck: %i targeteam: %i", dist_target, bot_on_type, enemy_distance, bot_stuck, targeteam);
send_socket_msg(message, strlen(message));
2020-01-23 23:15:26 +01:00
}
2020-06-26 00:11:22 +02:00
return Plugin_Continue;
2020-01-23 23:15:26 +01:00
}
public int check_bot_surfing_or_downhill()
{
g_bLastOnGround[present] = g_bOnGround[present];
if (GetEntityFlags(present) & FL_ONGROUND)
g_bOnGround[present] = true;
else
g_bOnGround[present] = false;
g_vLast[present][0] = g_vCurrent[present][0];
g_vLast[present][1] = g_vCurrent[present][1];
g_vLast[present][2] = g_vCurrent[present][2];
g_vCurrent[present][0] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[0]");
g_vCurrent[present][1] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[1]");
g_vCurrent[present][2] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[2]");
if (g_bOnGround[present] && !g_bLastOnGround[present])
{
float vPos[3];
float vMins[3];
float vMaxs[3];
GetEntPropVector(present, Prop_Data, "m_vecOrigin", vPos);
GetEntPropVector(present, Prop_Send, "m_vecMins", vMins);
GetEntPropVector(present, Prop_Send, "m_vecMaxs", vMaxs);
float vEndPos[3];
vEndPos[0] = vPos[0];
vEndPos[1] = vPos[1];
vEndPos[2] = vPos[2] - FindConVar("sv_maxvelocity").FloatValue;
TR_TraceHullFilter(vPos, vEndPos, vMins, vMaxs, MASK_PLAYERSOLID_BRUSHONLY, TraceRayDontHitSelf, present);
if (TR_DidHit())
{
//(1.0 = flat ground, < 0.7 = surf ramp)
float vPlane[3];
float vLast[3];
float surf_ramp = 0.7;
float flat_ground = 1.0;
TR_GetPlaneNormal(INVALID_HANDLE, vPlane);
if (vPlane[2] < surf_ramp)
return 2;
if (vPlane[2] < flat_ground)
{
vLast[0] = g_vLast[present][0];
vLast[1] = g_vLast[present][1];
vLast[2] = g_vLast[present][2];
vLast[2] -= (FindConVar("sv_gravity").FloatValue * GetTickInterval() * 0.5);
float fBackOff = GetVectorDotProduct(vLast, vPlane);
float change;
float vVel[3];
for (int i; i < 2; i++)
{
change = vPlane[i] * fBackOff;
vVel[i] = vLast[i] - change;
}
float fAdjust = GetVectorDotProduct(vVel, vPlane);
if (fAdjust < 0.0)
{
for(int i; i < 2; i++)
{
vVel[i] -= (vPlane[i] * fAdjust);
}
}
vVel[2] = 0.0;
vLast[2] = 0.0;
// Make sure the player is going down a ramp by checking if they actually will gain speed from the boost
if(GetVectorLength(vVel) > GetVectorLength(vLast))
return 3;
}
}
}
return -1;
}
public bool TraceRayDontHitSelf(int entity, int mask, any data)
{
return entity != data && !(0 < entity <= MaxClients);
}
public bool is_bot_stuck()
{
2020-07-26 01:13:39 +02:00
if (!round_start_stuck)
return false;
float min_distance_cap = 0.1;
float bot_own_distance = get_power_distance(present, bot_old_coords);
bot_stuck_g = bot_own_distance < min_distance_cap;
return bot_stuck_g;
}
public void face_call(int client)
{
for (int j = 0; j < 5; j++)
faceclient(client);
}
public void faceclient(int target_human)
{
if (IsValidClient(present) && IsValidClient(target_human) && GetEntityMoveType(present) != MOVETYPE_LADDER)
{
float TargetPos[3];
float ClientPos[3];
float Result[3];
GetClientEyePosition(target_human, TargetPos);
GetClientEyePosition(present, ClientPos);
MakeVectorFromPoints(ClientPos, TargetPos, Result);
GetVectorAngles(Result, Result);
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
}
}
2020-01-23 23:15:26 +01:00
stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
return true;
return false;
}
stock bool is_client_stuck_or_afk(int client)
{
if (!round_start_stuck)
return false;
2020-07-26 01:13:39 +02:00
float min_distance_cap = 0.02;
float client_own_distance = get_power_distance(client, client_old_coords[client]);
2020-07-26 01:13:39 +02:00
client_stuck_g[client] = client_own_distance < min_distance_cap;
return client_stuck_g[client];
}
public int find_closest_enemy(int entity, int targeteam)
{
float pos[3];
float nearestdistance = -1.0;
int nearest = -1;
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) != targeteam)
{
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(entity, pos);
bool traceable = false;
if (IsAbleToSee(present, i))
traceable = true;
float trace_advantage = 5.5;
if (traceable)
dist_target = dist_target / trace_advantage;
if (is_client_stuck_or_afk(i))
continue;
if (nearestdistance < 0 || dist_target < nearestdistance)
{
nearest = i;
nearestdistance = dist_target;
}
}
return nearest;
}
public int GetClosestClient_option1(int entity, int targeteam)
{
bool adminpresent = false;
bool vippresent = false;
float nearestdistance = -1.0;
int nearest = -1;
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
{
bool traceable = false;
if (IsAbleToSee(present, i))
traceable = true;
if (is_client_stuck_or_afk(i))
continue;
if (admins[i] && traceable)
{
adminpresent = true;
vippresent = false;
}
else if (vips[i] && !adminpresent && traceable)
{
vippresent = true;
}
if (adminpresent)
{
if (!admins[i])
continue;
}
else if (vippresent)
{
if (!vips[i])
continue;
}
float pos[3];
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float trace_advantage = 5.5;
float dist_target = get_power_distance(entity, pos);
if (traceable)
dist_target = dist_target / trace_advantage;
if (nearestdistance < 0 || dist_target < nearestdistance)
{
nearest = i;
nearestdistance = dist_target;
}
}
return nearest;
}
public float get_power_distance(int target_player, float [3]pos)
{
float vec[3];
GetClientAbsOrigin(target_player, vec);
float x_axis = Pow(vec[0] - pos[0], 2.0);
float y_axis = Pow(vec[1] - pos[1], 2.0);
float z_axis = FloatAbs(Pow(vec[2] - pos[2], 3.0));
float power_distance = SquareRoot(x_axis * x_axis + y_axis * y_axis + z_axis * z_axis);
float defaultcap = 1000.0;
return power_distance / defaultcap;
}
2020-01-23 23:15:26 +01:00
public void OnClientPostAdminCheck(int client)
{
//STEAM_0:1:34783317
//STEAM_0:1:60189040
//[U:1:120378081]
//[U:1:69566635]
2020-01-23 23:15:26 +01:00
char auth[50];
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
if (StrEqual("[U:1:120378081]", auth, false))
{
2020-02-28 22:00:22 +01:00
present = client;
bot_old_coords[0] = 0.0;
bot_old_coords[1] = 0.0;
bot_old_coords[2] = 0.0;
2020-06-26 00:11:22 +02:00
bot_send_connected_msg();
}
2020-02-28 22:00:22 +01:00
else if (StrEqual("STEAM_0:1:60189040", auth, false))
{
2020-02-28 22:00:22 +01:00
present = client;
bot_old_coords[0] = 0.0;
bot_old_coords[1] = 0.0;
bot_old_coords[2] = 0.0;
2020-06-26 00:11:22 +02:00
bot_send_connected_msg();
}
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
admins[client] = true;
else if (CheckCommandAccess(client, "sm_reserved", ADMFLAG_RESERVATION))
vips[client] = true;
client_old_coords[client][0] = 0.0;
client_old_coords[client][1] = 0.0;
client_old_coords[client][2] = 0.0;
2020-07-26 01:13:39 +02:00
client_stuck_g[client] = false;
}
2020-06-26 00:11:22 +02:00
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
{
2020-06-26 00:11:22 +02:00
LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum);
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
}
2020-06-26 00:11:22 +02:00
stock void connect(Handle socket)
{
2020-06-26 00:11:22 +02:00
if (!SocketIsConnected(socket))
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48475);
}
2020-06-26 00:11:22 +02:00
public void OnClientDisconnect(int client)
{
2020-06-26 00:11:22 +02:00
if (present == client)
{
present = 0;
}
admins[client] = false;
vips[client] = false;
client_old_coords[client][0] = 0.0;
client_old_coords[client][1] = 0.0;
client_old_coords[client][2] = 0.0;
2020-07-26 01:13:39 +02:00
client_stuck_g[client] = false;
}
2020-06-26 00:11:22 +02:00
public void bot_send_connected_msg()
{
2020-06-26 00:11:22 +02:00
char msg[generic_length];
Format(msg, sizeof(msg), "autismo connected");
send_socket_msg(msg, strlen(msg));
}
2020-06-26 00:11:22 +02:00
//Socket callback
public OnSocketConnected(Handle socket, any arg)
{
2020-06-26 00:11:22 +02:00
}
2020-06-26 00:11:22 +02:00
//manage message
public OnSocketReceive(Handle socket, char[] receiveData, const dataSize, any hFile)
{
2020-06-26 00:11:22 +02:00
//PrintToChatAll("receiveData: %s", receiveData);
}
public OnSocketDisconnected(Handle socket, any arg)
{
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
2020-06-09 23:34:49 +02:00
}
2020-06-26 00:11:22 +02:00
public Action TimerConnect(Handle timer, any arg)
2020-06-09 23:34:49 +02:00
{
2020-06-26 00:11:22 +02:00
connect(arg);
return Plugin_Handled;
}
public bool IsAbleToSee(int entity, int client)
{
float vecorigin[3];
float vecEyePos[3];
GetClientAbsOrigin(entity, vecorigin);
GetClientEyePosition(client, vecEyePos);
// Check if centre is visible.
if (IsPointVisible(vecEyePos, vecorigin))
return true;
float vecEyePos_ent[3];
float vecEyeAng[3];
GetClientEyeAngles(entity, vecEyeAng);
GetClientEyePosition(entity, vecEyePos_ent);
// Check if weapon tip is visible.
if (IsFwdVecVisible(vecEyePos, vecEyeAng, vecEyePos_ent))
return true;
float mins[3];
float maxs[3];
GetClientMins(client, mins);
GetClientMaxs(client, maxs);
// Check outer 4 corners of player.
if (IsRectangleVisible(vecEyePos, vecorigin, mins, maxs, 1.30))
return true;
// Check inner 4 corners of player.
if (IsRectangleVisible(vecEyePos, vecorigin, mins, maxs, 0.65))
return true;
return false;
}
public bool Filter_NoPlayers(int entity, int mask)
{
return (entity > MaxClients && !(0 < GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity") <= MaxClients));
}
public bool IsPointVisible(const float start[3], const float end[3])
{
2020-07-26 01:13:39 +02:00
TR_TraceRayFilter(start, end, MASK_SOLID, RayType_EndPoint, Filter_NoPlayers);
return TR_GetFraction() == 1.0;
}
public bool IsFwdVecVisible(const float start[3], const float angles[3], const float end[3])
{
float fwd[3];
GetAngleVectors(angles, fwd, NULL_VECTOR, NULL_VECTOR);
ScaleVector(fwd, 50.0);
AddVectors(end, fwd, fwd);
return IsPointVisible(start, fwd);
}
public bool IsRectangleVisible(const float start[3], const float end[3], const float mins[3], const float maxs[3], float scale)
{
float ZpozOffset = maxs[2];
float ZnegOffset = mins[2];
float WideOffset = ((maxs[0] - mins[0]) + (maxs[1] - mins[1])) / 4.0;
// This rectangle is just a point!
if (ZpozOffset == 0.0 && ZnegOffset == 0.0 && WideOffset == 0.0)
return IsPointVisible(start, end);
// Adjust to scale.
ZpozOffset *= scale;
ZnegOffset *= scale;
WideOffset *= scale;
// Prepare rotation matrix.
float angles[3];
float fwd[3];
float right[3];
SubtractVectors(start, end, fwd);
NormalizeVector(fwd, fwd);
GetVectorAngles(fwd, angles);
GetAngleVectors(angles, fwd, right, NULL_VECTOR);
float vRectangle[4][3];
float vTemp[3];
// If the player is on the same level as us, we can optimize by only rotating on the z-axis.
if (FloatAbs(fwd[2]) <= 0.7071)
{
ScaleVector(right, WideOffset);
// Corner 1, 2
vTemp = end;
vTemp[2] += ZpozOffset;
AddVectors(vTemp, right, vRectangle[0]);
SubtractVectors(vTemp, right, vRectangle[1]);
// Corner 3, 4
vTemp = end;
vTemp[2] += ZnegOffset;
AddVectors(vTemp, right, vRectangle[2]);
SubtractVectors(vTemp, right, vRectangle[3]);
}
else if (fwd[2] > 0.0) // Player is below us.
{
fwd[2] = 0.0;
NormalizeVector(fwd, fwd);
ScaleVector(fwd, scale);
ScaleVector(fwd, WideOffset);
ScaleVector(right, WideOffset);
// Corner 1
vTemp = end;
vTemp[2] += ZpozOffset;
AddVectors(vTemp, right, vTemp);
SubtractVectors(vTemp, fwd, vRectangle[0]);
// Corner 2
vTemp = end;
vTemp[2] += ZpozOffset;
SubtractVectors(vTemp, right, vTemp);
SubtractVectors(vTemp, fwd, vRectangle[1]);
// Corner 3
vTemp = end;
vTemp[2] += ZnegOffset;
AddVectors(vTemp, right, vTemp);
AddVectors(vTemp, fwd, vRectangle[2]);
// Corner 4
vTemp = end;
vTemp[2] += ZnegOffset;
SubtractVectors(vTemp, right, vTemp);
AddVectors(vTemp, fwd, vRectangle[3]);
}
else // Player is above us.
{
fwd[2] = 0.0;
NormalizeVector(fwd, fwd);
ScaleVector(fwd, scale);
ScaleVector(fwd, WideOffset);
ScaleVector(right, WideOffset);
// Corner 1
vTemp = end;
vTemp[2] += ZpozOffset;
AddVectors(vTemp, right, vTemp);
AddVectors(vTemp, fwd, vRectangle[0]);
// Corner 2
vTemp = end;
vTemp[2] += ZpozOffset;
SubtractVectors(vTemp, right, vTemp);
AddVectors(vTemp, fwd, vRectangle[1]);
// Corner 3
vTemp = end;
vTemp[2] += ZnegOffset;
AddVectors(vTemp, right, vTemp);
SubtractVectors(vTemp, fwd, vRectangle[2]);
// Corner 4
vTemp = end;
vTemp[2] += ZnegOffset;
SubtractVectors(vTemp, right, vTemp);
SubtractVectors(vTemp, fwd, vRectangle[3]);
}
// Run traces on all corners.
for (new i = 0; i < 4; i++)
if (IsPointVisible(start, vRectangle[i]))
return true;
return false;
2020-01-23 23:15:26 +01:00
}