//==================================================
void VectorAngles (const float * forward, float * view)
{
if(!forward[1]==0 && !forward[0]==0)
{
view[0] = (float)((atan2(forward[2],(sqrt(forward[0]*forward[0]+forward[1]*forward[1])))* 57.295779513082320876846364344191f));
view[1] = (float)((atan2(forward[1],forward[0])* 57.295779513082320876846364344191f));
view[2] = 0;
}
}
int Visible(int ax)
{
int power = 2;
float pWall[3];
pWall[0] = me.pmEyePos[0], pWall[1] = me.pmEyePos[1], pWall[2] = me.pmEyePos[2];
vec3_t vecEnd, up, right, forward, playerAngles;
playerAngles[0] = 0, playerAngles[1] = vPlayers[ax].getEnt()->angles[1], playerAngles[2] = 0;
pmtrace_t tr;
cl_entity_s* ent = vPlayers[ax].getEnt();
pmtrace_t pmtrace;
pmtrace_t* tr2 = (pmtrace_t*) &pmtrace;
gEngfuncs.pfnAngleVectors (playerAngles, forward, right, up);
gEngfuncs.pEventAPI->EV_SetTraceHull( 2 );
gEngfuncs.pEventAPI->EV_PlayerTrace( me.pmEyePos, vPlayers[ax].getEnt()->origin, PM_GLASS_IGNORE, me.ent->index, &tr );
tr2->startsolid = true;
forward[2] = -forward[2];
while (power)
{
if( !tr2->startsolid ) power--;
tr2 = gEngfuncs.PM_TraceLine( pWall, vPlayers[ax].getEnt()->origin, PM_TRACELINE_PHYSENTSONLY, 2, -1);
if( tr2->fraction==1.0f) return 1;
if( tr2->allsolid ) return 0;
switch (vPlayers[ax].getEnt()->curstate.gaitsequence)
{
default:
pWall[0] = tr2->endpos[0] + (vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - dR)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - dR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - dR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - dF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - dF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - dH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - dH))) * 8.0f;
pWall[1] = tr2->endpos[1] + (vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - dF)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - dR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - dR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - dF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - dF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - dH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - dH))) * 8.0f;
pWall[2] = tr2->endpos[2] + (vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - dH)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - dR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - dR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - dF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - dF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - dH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - dH))) * 8.0f;
break;
case 6:
pWall[0] = tr2->endpos[0] + (vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - jR)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - jR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - jR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - jF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - jF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - jH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - jH))) * 8.0f;
pWall[1] = tr2->endpos[1] + (vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - jF)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - jR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - jR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - jF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - jF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - jH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - jH))) * 8.0f;
pWall[2] = tr2->endpos[2] + (vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - jH)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - jR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - jR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - jF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - jF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - jH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - jH))) * 8.0f;
break;
case 0:
pWall[0] = tr2->endpos[0] + (vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - sR)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - sR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - sR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - sF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - sF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - sH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - sH))) * 8.0f;
pWall[1] = tr2->endpos[1] + (vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - sF)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - sR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - sR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - sF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - sF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - sH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - sH))) * 8.0f;
pWall[2] = tr2->endpos[2] + (vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - sH)) / (float)sqrt((vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - sR))*(vPlayers[ax].getEnt()->origin[0] - (me.pmEyePos[0] - sR))+(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - sF))*(vPlayers[ax].getEnt()->origin[1] - (me.pmEyePos[1] - sF))+(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - sH))*(vPlayers[ax].getEnt()->origin[2] - (me.pmEyePos[2] - sH))) * 8.0f;
break;
}
}
return 0;
}
void FindTarget()
{
for (int ax=0;ax<vPlayers.size();ax++)
if ( vPlayers[ax].getPVS() && me.team != vPlayers[ax].team && Visible(ax) && target == -1)
target = ax;
}
}
void CalcViewAngles()
{
vec3_t view,up,right,forward,playerAngles,EntViewOrg;
playerAngles[0]=0;
playerAngles[1]=vPlayers[target].getEnt()->angles[1];
playerAngles[2]=0;
gEngfuncs.pfnAngleVectors (playerAngles, forward, right, up);
forward[2] = -forward[2];
cl_entity_s* ent = vPlayers[target].getEnt();
if(vPlayers[target].getPVS())
{
switch (vPlayers[target].getEnt()->curstate.gaitsequence) {
default:
view[0] = (vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - dR)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - dR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - dR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - dF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - dF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - dH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - dH)));
view[1] = (vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - dF)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - dR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - dR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - dF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - dF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - dH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - dH)));
view[2] = (vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - dH)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - dR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - dR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - dF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - dF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - dH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - dH)));
break;
case 6:
view[0] = (vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - jR)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - jR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - jR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - jF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - jF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - jH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - jH)));
view[1] = (vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - jF)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - jR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - jR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - jF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - jF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - jH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - jH)));
view[2] = (vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - jH)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - jR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - jR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - jF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - jF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - jH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - jH)));
break;
case 0:
view[0] = (vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - sR)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - sR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - sR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - sF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - sF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - sH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - sH)));
view[1] = (vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - sF)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - sR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - sR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - sF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - sF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - sH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - sH)));
view[2] = (vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - sH)) / (float)sqrt((vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - sR))*(vPlayers[target].getEnt()->origin[0] - (me.pmEyePos[0] - sR))+(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - sF))*(vPlayers[target].getEnt()->origin[1] - (me.pmEyePos[1] - sF))+(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - sH))*(vPlayers[target].getEnt()->origin[2] - (me.pmEyePos[2] - sH)));
break;
}
}
//==================================================