Needs modified if you want to use the Quakeguy (this has been modified for custom player model)
Code: Select all
/*
==================
CL_Footsteps Stuff
==================
*/
#define SURFACE_NORMAL 0 // Generic Stone
#define SURFACE_CARPET 1 // Carpet
#define SURFACE_GRAVEL 2 // Gravel
#define SURFACE_METAL 3 // Metal
#define SURFACE_SNOW 4 // Snow
#define SURFACE_WOODEN 5 // Wood
#define SURFACE_DIRT 6 // Dirt n mud
char *nodename = " "; // lel nothing xD
float plr_surfacetype;
int RecursiveNodePoint (mnode_t *node, vec3_t start, vec3_t end)
{
float front, back, frac;
vec3_t mid;
loc0:
if (node->contents < 0)
return false; // didn't hit anything
// calculate mid point
if (node->plane->type < 3)
{
front = start[node->plane->type] - node->plane->dist;
back = end[node->plane->type] - node->plane->dist;
}
else
{
front = DotProduct(start, node->plane->normal) - node->plane->dist;
back = DotProduct(end, node->plane->normal) - node->plane->dist;
}
// optimized recursion
if ((back < 0) == (front < 0))
{
node = node->children[front < 0];
goto loc0;
}
frac = front / (front-back);
mid[0] = start[0] + (end[0] - start[0]) * frac;
mid[1] = start[1] + (end[1] - start[1]) * frac;
mid[2] = start[2] + (end[2] - start[2]) * frac;
// go down front side
if (RecursiveNodePoint(node->children[front < 0], start, mid))
{
return true; // hit something
}
else
{
int i, ds, dt;
msurface_t *surf;
surf = cl.worldmodel->surfaces + node->firstsurface;
for (i = 0 ; i < node->numsurfaces ; i++, surf++)
{
ds = (int)((float)DotProduct (mid, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]);
dt = (int)((float)DotProduct (mid, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]);
if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
continue;
ds -= surf->texturemins[0];
dt -= surf->texturemins[1];
if (ds > surf->extents[0] || dt > surf->extents[1])
continue;
//nodename = (surf->texinfo->texture->name);
if (!Q_strncmp(surf->texinfo->texture->name,"carpet",6))
plr_surfacetype = SURFACE_CARPET;
else if (!Q_strncmp(surf->texinfo->texture->name,"ground",6))
plr_surfacetype = SURFACE_GRAVEL;
else if (!Q_strncmp(surf->texinfo->texture->name,"metal",5))
plr_surfacetype = SURFACE_METAL;
else if (!Q_strncmp(surf->texinfo->texture->name,"snow",4))
plr_surfacetype = SURFACE_SNOW;
else if (!Q_strncmp(surf->texinfo->texture->name,"wood",4))
plr_surfacetype = SURFACE_WOODEN;
else if (!Q_strncmp(surf->texinfo->texture->name,"wet",3))
plr_surfacetype = SURFACE_DIRT;
else
plr_surfacetype = SURFACE_NORMAL;
return true;
}
return RecursiveNodePoint (node->children[front >= 0], mid, end);
}
}
void GetNodePoint (vec3_t p, vec3_t end)
{
RecursiveNodePoint (cl.worldmodel->nodes, p, end);
Con_DPrintf(nodename);
Con_DPrintf("\n");
}
extern sfx_t *cl_sfx_st_carpet1;
extern sfx_t *cl_sfx_st_carpet2;
extern sfx_t *cl_sfx_st_dirt1;
extern sfx_t *cl_sfx_st_dirt2;
extern sfx_t *cl_sfx_st_gravel1;
extern sfx_t *cl_sfx_st_gravel2;
extern sfx_t *cl_sfx_st_metal1;
extern sfx_t *cl_sfx_st_metal2;
extern sfx_t *cl_sfx_st_snow1;
extern sfx_t *cl_sfx_st_snow2;
extern sfx_t *cl_sfx_st_stone1;
extern sfx_t *cl_sfx_st_stone2;
extern sfx_t *cl_sfx_st_wood1;
extern sfx_t *cl_sfx_st_wood2;
/*
============
CL_Footsteps
============
*/
void CL_Footsteps(entity_t *ent, int frame)
{
if (ent->steptime > cl.time)
return;
if (TruePointContents(ent->origin) != CONTENTS_EMPTY)// if in water etc.. no sound
return;
//TODO: Add support for the axis soldiers too plz!
if (frame == 2 || frame == 5 || frame == 9|| frame == 15 || frame == 18 || frame == 21)
{
vec3_t dest, forward, right,up;
vec3_t end, downdir = {0, 0, -1};
trace_t trace;
float f;
int i,e;
entity_t *p;
AngleVectors (ent->angles, forward, right, up);
VectorMA (ent->origin, -42, up, dest);//trace down (Halfllife Player Hulls)
//VectorMA (ent->origin, -32, up, dest);//trace down (Quake Player Hulls)
memset (&trace, 0, sizeof(trace_t));
trace.fraction = 1;
SV_RecursiveHullCheck(cl.worldmodel->hulls, 0, 0, 1, ent->origin, dest, &trace);
VectorMA(ent->origin, 128, downdir, end); //change the 128 for different distances
GetNodePoint(ent->origin, end);
if (trace.fraction == 1) //if we didnt hit anything solid dont make a sound
{
ent->steptime = cl.time + 0.1;//since the player model animates at 10 frames per sec, no need to come back here until time + 1/10...
//Con_Printf ("trace.fraction == 1\n");
return;
}
e = (int)cl.viewentity;//emit the sound at our location
f = (rand()%4)+1;
if (plr_surfacetype == SURFACE_NORMAL)
{
if (f == 1)
S_StartSound(0, 0, cl_sfx_st_stone1, ent->origin, 0.60f, 1.0f);
else
S_StartSound(0, 0, cl_sfx_st_stone2, ent->origin, 0.60f, 1.0f);
}
if (plr_surfacetype == SURFACE_CARPET)
{
if (f == 1)
S_StartSound(0, 0, cl_sfx_st_carpet1, ent->origin, 0.60f, 1.0f);
else
S_StartSound(0, 0, cl_sfx_st_carpet2, ent->origin, 0.60f, 1.0f);
}
if (plr_surfacetype == SURFACE_GRAVEL)
{
if (f == 1)
S_StartSound(0, 0, cl_sfx_st_gravel1, ent->origin, 0.60f, 1.0f);
else
S_StartSound(0, 0, cl_sfx_st_gravel2, ent->origin, 0.60f, 1.0f);
}
if (plr_surfacetype == SURFACE_METAL)
{
if (f == 1)
S_StartSound(0, 0, cl_sfx_st_metal1, ent->origin, 0.60f, 1.0f);
else
S_StartSound(0, 0, cl_sfx_st_metal2, ent->origin, 0.60f, 1.0f);
}
if (plr_surfacetype == SURFACE_SNOW)
{
if (f == 1)
S_StartSound(0, 0, cl_sfx_st_snow1, ent->origin, 0.60f, 1.0f);
else
S_StartSound(0, 0, cl_sfx_st_snow2, ent->origin, 0.60f, 1.0f);
}
if (plr_surfacetype == SURFACE_DIRT)
{
if (f == 1)
S_StartSound(0, 0, cl_sfx_st_dirt1, ent->origin, 0.60f, 1.0f);
else
S_StartSound(0, 0, cl_sfx_st_dirt2, ent->origin, 0.60f, 1.0f);
}
if (plr_surfacetype == SURFACE_WOODEN)
{
if (f == 1)
S_StartSound(0, 0, cl_sfx_st_wood1, ent->origin, 0.60f, 1.0f);
else
S_StartSound(0, 0, cl_sfx_st_wood2, ent->origin, 0.60f, 1.0f);
}
ent->steptime = cl.time + 0.3;
}
}