From 93124fa6ded362c5b16f02b3c2b950527e007273 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Wed, 2 Mar 2022 20:37:40 -0800 Subject: [PATCH] base_player: Add Death() method that'll let the client know when to render the 'Deathcam'. Also add the mentioned UpdateDeathcam(). --- src/client/entry.qc | 2 ++ src/shared/client.h | 1 + src/shared/client.qc | 10 ++++++++++ src/shared/math.h | 3 ++- src/shared/math.qc | 20 +++++++++++++++++++- src/shared/player.h | 1 + src/shared/player.qc | 40 ++++++++++++++++++++++++++++++++++++++-- 7 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/client/entry.qc b/src/client/entry.qc index be66ce22..38ecde4b 100644 --- a/src/client/entry.qc +++ b/src/client/entry.qc @@ -407,6 +407,8 @@ CSQC_UpdateView(float w, float h, float focus) View_DrawViewModel(); } else if (pl.health > 0) { View_DrawViewModel(); + } else if (getplayerkeyvalue(pl.entnum-1, "*dead") == "1") { + pl.UpdateDeathcam(); } /* this is running whenever we're doing 'buildcubemaps' */ diff --git a/src/shared/client.h b/src/shared/client.h index eee2e2d6..031b8e5c 100644 --- a/src/shared/client.h +++ b/src/shared/client.h @@ -8,6 +8,7 @@ base_client:NSSurfacePropEntity virtual void(void) ClientInputFrame; #ifdef CLIENT + virtual void(void) UpdateDeathcam; virtual float(void) predraw; #endif }; diff --git a/src/shared/client.qc b/src/shared/client.qc index f12794e9..14e5feb8 100644 --- a/src/shared/client.qc +++ b/src/shared/client.qc @@ -5,6 +5,16 @@ base_client::ClientInputFrame(void) } #ifdef CLIENT +void +base_client::UpdateDeathcam(void) +{ + /* death cam */ + view_angles[2] = 45.0f; + setproperty(VF_ORIGIN, pSeat->m_vecPredictedOrigin); + setproperty(VF_CL_VIEWANGLES, view_angles); + setproperty(VF_ANGLES, view_angles); +} + float base_client::predraw(void) { diff --git a/src/shared/math.h b/src/shared/math.h index 4d2ee63b..d864a3c0 100644 --- a/src/shared/math.h +++ b/src/shared/math.h @@ -19,6 +19,7 @@ float Math_LerpAngle(float fStart, float fEnd, float fAmount); float Math_Lerp(float fA, float fB, float fPercent); float Math_FixDelta(float fDelta); +vector Math_FixDeltaVector(vector); vector Math_Reflect(vector v1, vector v2); vector Math_RandomVector(float flyup); -vector Math_RotateAroundPivot(vector pos, vector pivot, float degr); \ No newline at end of file +vector Math_RotateAroundPivot(vector pos, vector pivot, float degr); diff --git a/src/shared/math.qc b/src/shared/math.qc index c1408927..e6b2c5fd 100644 --- a/src/shared/math.qc +++ b/src/shared/math.qc @@ -14,6 +14,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +/* lerping function that accounts for negative degrees */ float Math_LerpAngle(float fStart, float fEnd, float fAmount) { @@ -21,12 +22,15 @@ Math_LerpAngle(float fStart, float fEnd, float fAmount) return shortest_angle * fAmount; } +/* linear lerp function */ float Math_Lerp(float fA, float fB, float fPercent) { return (fA * (1 - fPercent)) + (fB * fPercent); } +/* tries to make sure an angle value stays within certain constraints... + * however it doesn't account for much larger discrepancies */ float Math_FixDelta(float fDelta) { @@ -35,15 +39,28 @@ Math_FixDelta(float fDelta) } else if (fDelta <= -180) { fDelta += 360; } + return fDelta; } +vector +Math_FixDeltaVector(vector in) +{ + in[0] = Math_FixDelta(in[0]); + in[1] = Math_FixDelta(in[1]); + in[2] = Math_FixDelta(in[2]); + return in; +} + +/* takes an impact angle and a plane normal, returns a new trajectory */ vector Math_Reflect(vector v1, vector v2) { return v1 - 2 * dotproduct(v1, v2) * v2; } +/* returns a random vector, if the first paramete is true it'll make + * sure that vertical velocity is ALWAYS positive */ vector Math_RandomVector(float fFlyUp) { @@ -60,6 +77,7 @@ Math_RandomVector(float fFlyUp) return tmp * 2.0f; } +/* takes a position and a pivot point and rotates point by X degrees around the pivot (YAW) */ vector Math_RotateAroundPivot(vector pos, vector pivot, float degr) { @@ -67,4 +85,4 @@ Math_RotateAroundPivot(vector pos, vector pivot, float degr) new[0] = pivot[0] + (pos[0] - pivot[0]) * cos(degr) - (pos[1] - pivot[1]) * sin(degr); new[1] = pivot[1] + (pos[0] - pivot[0]) * sin(degr) + (pos[1] - pivot[1]) * cos(degr); return new; -} \ No newline at end of file +} diff --git a/src/shared/player.h b/src/shared/player.h index 32376467..26c45abf 100644 --- a/src/shared/player.h +++ b/src/shared/player.h @@ -89,6 +89,7 @@ base_player:base_client virtual void(void) EvaluateEntity; virtual float(entity, float) SendEntity; + virtual void(void) Death; virtual void(void) MakePlayer; virtual void(void) MakeTempSpectator; #endif diff --git a/src/shared/player.qc b/src/shared/player.qc index 6c7c1da8..539e9b6d 100644 --- a/src/shared/player.qc +++ b/src/shared/player.qc @@ -361,7 +361,7 @@ base_player::Respawn(void) } /* -=================* +================= base_player::MakeTempSpectator This is what dead players in round matches become, or when we spawn @@ -384,10 +384,45 @@ base_player::MakeTempSpectator(void) maxspeed = 250; takedamage = DAMAGE_NO; forceinfokey(this, "*spec", "2"); + forceinfokey(this, "*dead", "0"); } /* -=================* +================= +base_player::MakeDead + +Sets all the appropriate attributes to make sure we're dead +================= + */ +void +base_player::Death(void) +{ + classname = "player"; + health = max_health = 0; + armor = 0; + g_items = 0; + activeweapon = 0; + effects = 0; + alpha = 1.0f; + SetModelindex(0); + SetMovetype(MOVETYPE_NONE); + SetSolid(SOLID_NOT); + takedamage = DAMAGE_NO; + forceinfokey(this, "*spec", "0"); + forceinfokey(this, "*dead", "1"); + viewzoom = 1.0; + view_ofs = [0,0,0]; + vehicle = __NULL__; + velocity = [0,0,0]; + gravity = __NULL__; + customphysics = Empty; + iBleeds = FALSE; + forceinfokey(this, "*deaths", ftos(deaths)); + setsize(this, [0,0,0], [0,0,0]); +} + +/* +================= base_player::MakeTempSpectator This is what dead players in round matches become, or when we spawn @@ -410,6 +445,7 @@ base_player::MakePlayer(void) movetype = MOVETYPE_WALK; takedamage = DAMAGE_YES; forceinfokey(this, "*spec", "0"); + forceinfokey(this, "*dead", "0"); viewzoom = 1.0; vehicle = __NULL__; velocity = [0,0,0];