2016-12-03 19:25:03 +00:00
|
|
|
/*
|
2018-06-14 10:05:23 +00:00
|
|
|
Copyright 2016-2018 Marco "eukara" Hladik
|
|
|
|
|
|
|
|
MIT LICENSE
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person
|
|
|
|
obtaining a copy of this software and associated documentation
|
|
|
|
files (the "Software"), to deal in the Software without
|
|
|
|
restriction, including without limitation the rights to use,
|
|
|
|
copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
sell copies of the Software, and to permit persons to whom the
|
|
|
|
Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
2016-12-03 19:25:03 +00:00
|
|
|
*/
|
|
|
|
|
2016-12-13 19:15:09 +00:00
|
|
|
#define MATH_PI 3.1415926
|
|
|
|
|
2016-12-03 19:25:03 +00:00
|
|
|
float Math_LerpAngle( float fStart, float fEnd, float fAmount ) {
|
|
|
|
float shortest_angle = ( ( ( ( fEnd - fStart ) % 360 ) + 540 ) % 360 ) - 180;
|
|
|
|
return shortest_angle * fAmount;
|
|
|
|
}
|
|
|
|
|
2017-07-03 02:12:45 +00:00
|
|
|
float Math_Lerp( float fA, float fB, float fPercent ) {
|
|
|
|
return ( fA * ( 1 - fPercent ) ) + ( fB * fPercent );
|
|
|
|
}
|
|
|
|
|
2017-11-15 21:36:55 +00:00
|
|
|
float Math_VectorNormalize( vector v ) {
|
|
|
|
float length, ilength;
|
|
|
|
|
|
|
|
length = v_x*v_x + v_y*v_y + v_z*v_z;
|
|
|
|
length = sqrt( length ); // FIXME
|
|
|
|
|
|
|
|
if ( length ) {
|
|
|
|
ilength = 1 / length;
|
|
|
|
v[0] *= ilength;
|
|
|
|
v[1] *= ilength;
|
|
|
|
v[2] *= ilength;
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Math_VectorScale( vector in, float scale, __inout vector out ) {
|
|
|
|
out_x = in_x * scale;
|
|
|
|
out_y = in_y * scale;
|
|
|
|
out_z = in_z * scale;
|
|
|
|
}
|
|
|
|
|
2017-07-03 02:12:45 +00:00
|
|
|
float Math_FixDelta( float fDelta ) {
|
|
|
|
if ( fDelta >= 180 ) {
|
|
|
|
fDelta -= 360;
|
|
|
|
} else if ( fDelta <= -180 ) {
|
|
|
|
fDelta += 360;
|
|
|
|
}
|
|
|
|
return fDelta;
|
|
|
|
}
|
|
|
|
|
2016-12-03 19:25:03 +00:00
|
|
|
float Math_CRandom( void ) {
|
|
|
|
return 2 * ( random() - 0.5 );
|
|
|
|
}
|
2017-11-16 22:53:02 +00:00
|
|
|
|
|
|
|
#if defined(SSQC) || defined(CSQC)
|
|
|
|
#ifdef SSQC
|
|
|
|
void Damage_Apply( entity eTarget, entity eAttacker, int iDamage, vector vHitPos, int iSkipArmor );
|
|
|
|
#endif
|
2018-09-20 20:38:01 +00:00
|
|
|
|
|
|
|
//.vector basevelocity;
|
|
|
|
int QPhysics_IsStuck( entity eTarget, vector vOffset, vector vecMins, vector vecMaxs )
|
|
|
|
{
|
|
|
|
if ( eTarget.solid != SOLID_SLIDEBOX ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
tracebox( eTarget.origin + vOffset, vecMins, vecMaxs, eTarget.origin + vOffset, FALSE, eTarget );
|
|
|
|
return trace_startsolid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QPhysics_Jump ( entity eTarget )
|
|
|
|
{
|
|
|
|
if ( !( eTarget.flags & FL_ONGROUND ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( !( eTarget.flags & FL_JUMPRELEASED ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
eTarget.velocity_z = eTarget.velocity_z + 270;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QPhysics_Run ( entity eTarget )
|
|
|
|
{
|
|
|
|
int iFixCrouch = FALSE;
|
|
|
|
float flFallVel = ( self.flags & FL_ONGROUND ) ? 0 : -self.velocity_z;
|
|
|
|
|
|
|
|
// We didn't get any basevelocity this frame, remove the flag
|
|
|
|
/*if ( vlen( eTarget.basevelocity ) ) {
|
|
|
|
eTarget.flags -= ( eTarget.flags & FL_BASEVELOCITY );
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if ( input_buttons & INPUT_BUTTON8 ) {
|
|
|
|
eTarget.flags |= FL_CROUCHING;
|
|
|
|
} else {
|
|
|
|
// If we aren't holding down duck anymore and 'attempt' to stand up, prevent it
|
|
|
|
if ( eTarget.flags & FL_CROUCHING ) {
|
|
|
|
if ( QPhysics_IsStuck( eTarget, '0 0 36', VEC_HULL_MIN, VEC_HULL_MAX ) == FALSE ) {
|
|
|
|
eTarget.flags -= ( eTarget.flags & FL_CROUCHING );
|
|
|
|
iFixCrouch = TRUE;
|
2018-06-09 16:37:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-09-20 20:38:01 +00:00
|
|
|
eTarget.flags -= ( eTarget.flags & FL_CROUCHING );
|
2018-06-09 16:37:42 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-20 20:38:01 +00:00
|
|
|
|
|
|
|
if ( input_buttons & INPUT_BUTTON2 ) {
|
|
|
|
QPhysics_Jump( eTarget );
|
|
|
|
input_buttons -= ( input_buttons & INPUT_BUTTON2 );
|
|
|
|
eTarget.flags -= ( eTarget.flags & FL_JUMPRELEASED );
|
|
|
|
eTarget.flags -= ( eTarget.flags & FL_ONGROUND );
|
2018-06-09 16:37:42 +00:00
|
|
|
} else {
|
2018-09-20 20:38:01 +00:00
|
|
|
eTarget.flags |= FL_JUMPRELEASED;
|
2018-06-09 16:37:42 +00:00
|
|
|
}
|
2018-06-10 09:40:44 +00:00
|
|
|
|
2018-09-20 20:38:01 +00:00
|
|
|
if ( eTarget.flags & FL_CROUCHING ) {
|
|
|
|
setsize( eTarget, VEC_CHULL_MIN, VEC_CHULL_MAX );
|
2018-06-09 16:37:42 +00:00
|
|
|
#ifdef SSQC
|
2018-09-20 20:38:01 +00:00
|
|
|
eTarget.view_ofs = VEC_PLAYER_CVIEWPOS;
|
2018-06-09 16:37:42 +00:00
|
|
|
#endif
|
2018-09-20 20:38:01 +00:00
|
|
|
} else {
|
|
|
|
setsize( eTarget, VEC_HULL_MIN, VEC_HULL_MAX );
|
|
|
|
if ( iFixCrouch && QPhysics_IsStuck( eTarget, '0 0 0', VEC_HULL_MIN, VEC_HULL_MAX ) ) {
|
|
|
|
for ( int i = 0; i < 36; i++ ) {
|
|
|
|
eTarget.origin_z += 1;
|
|
|
|
if ( QPhysics_IsStuck( eTarget, '0 0 0', eTarget.mins, eTarget.maxs ) == FALSE ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setorigin( eTarget, eTarget.origin );
|
2018-06-09 16:37:42 +00:00
|
|
|
#ifdef SSQC
|
2018-09-20 20:38:01 +00:00
|
|
|
eTarget.view_ofs = VEC_PLAYER_VIEWPOS;
|
2018-06-09 16:37:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
2018-09-20 20:38:01 +00:00
|
|
|
|
|
|
|
eTarget.maxspeed = Game_GetMaxSpeed( eTarget );
|
|
|
|
runstandardplayerphysics( eTarget );
|
|
|
|
|
|
|
|
#ifdef SSQC
|
|
|
|
if ( ( self.flags & FL_ONGROUND ) && self.movetype == MOVETYPE_WALK && ( flFallVel > 580 )) {
|
2018-12-27 22:53:24 +00:00
|
|
|
float fFallDamage = ( flFallVel - 580 ) * ( 100 / ( 1024 - 580 ) );
|
2018-09-20 20:38:01 +00:00
|
|
|
Damage_Apply( self, world, fFallDamage, self.origin, FALSE );
|
|
|
|
}
|
|
|
|
#endif
|
2017-11-16 22:53:02 +00:00
|
|
|
}
|
|
|
|
#endif
|