Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=========================================================
- #include "stdafx.h"
- //=========================================================
- /*
- ladies and gentlemen, may I present to you the WORST
- bullet penetration code I have ever seen in a game.
- credits to tatsur0, his team of disabled people,
- and his dead dad. none of this would be possible otherwise.
- */
- //=========================================================
- void __stdcall UTIL_TraceLine ( vec3_t& src, vec3_t& dest, int mask, base_entity* ignore, int group, trace_t* tr )
- {
- CRay ray;
- dword filter[3];
- if ( !tr )
- return;
- ray.Init ( src, dest );
- hook->CTraceFilterSimple ( filter, ignore, group );
- enginetrace->TraceRay ( ray, mask, (ITraceFilter*)&filter, tr );
- }
- //=========================================================
- float __stdcall NT_GetDensityFromMaterial ( int props )
- {
- surfacedata_t* data = surfaceprops->GetSurfaceData ( props );
- if ( !data )
- return 0.0f;
- switch ( data->material ) {
- case 0x43:
- return 0.3f;
- case 0x4D:
- case 0x50:
- case 0x54:
- return 0.5f;
- case 0x47:
- case 0x56:
- case 0x57:
- return 0.75f;
- case 0x44:
- case 0x4E:
- return 0.2f;
- case 0x59:
- return 0.9f;
- case 0x4C:
- case 0x4F:
- return 0.8f;
- case 0x46:
- return 0.6f;
- default:
- return 1.0f;
- }
- }
- //=========================================================
- bool __stdcall NT_PathFree ( vec3_t& dest, int target, bool ignore )
- {
- int i;
- trace_t tr;
- vec3_t start, end, dir, hit, penetrationExit;
- float fLength, fPower, fDensity, tmpLen;
- // this is the only FileWeaponInfo_t member we nead.
- fPower = cl.wpnInfo.fPenetration;
- // setup vectors.
- VectorCopy ( cl.eyepos, start );
- VectorSubtract ( (float*)dest, start, dir );
- // distance to target.
- fLength = VectorNormalize ( dir );
- // iterate each surface.
- for ( i = 0; i < 9; i++ )
- {
- // extend this trace by max range (why aren't they iteratively reducing the range?)
- VectorMA ( start, dir, WEAPON_MAX_RANGE, end );
- // trace forward from our (current) start position.
- UTIL_TraceLine ( start, end, 0x4600400B, cl.player, 0, &tr );
- VectorCopy ( tr.endpos, hit );
- // check if we've reached our desired endpoint.
- if ( ignore ) {
- if ( VectorDistance ( cl.eyepos, hit ) >= fLength )
- return true;
- }
- if ( tr.pEnt ) {
- // check if we reached our target.
- if ( target != -1 ) {
- if ( tr.pEnt->GetClientNetworkable()->entindex() == target )
- return true;
- } else {
- if ( !ignore && CL_IsValidTarget ( tr.pEnt ) )
- return true;
- }
- // can't shoot through players.
- if ( tr.pEnt->IsPlayer() )
- break;
- }
- // trace didn't hit anything, give up.
- if ( (tr.fraction == 1.0f) || !CVAR( AIM_AUTOWALL ) )
- break;
- // assume we've hit a wall; try to penetrate it.
- fDensity = NT_GetDensityFromMaterial ( tr.surfaceProps );
- VectorMA ( hit, dir, min(fPower * fDensity, 12.0f), penetrationExit );
- UTIL_TraceLine ( penetrationExit, hit, 0x4600400B, cl.player, 0, &tr );
- // this is really dumb, why isn't Studio Radi-8 checking startsolid?
- if ( tr.fraction == 1.0f )
- break;
- // is the surface too thick?
- tmpLen = VectorDistance ( hit, tr.endpos );
- fPower -= tmpLen / fDensity;
- if ( fPower <= 0.0f )
- break;
- // copy the other side of the wall to our starting position.
- VectorCopy ( tr.endpos, start );
- }
- return false;
- }
- //=========================================================
Advertisement
Add Comment
Please, Sign In to add comment