base_player: Add Death() method that'll let the client know when to render

the 'Deathcam'. Also add the mentioned UpdateDeathcam().
This commit is contained in:
Marco Cawthorne 2022-03-02 20:37:40 -08:00
parent 3882611087
commit 93124fa6de
Signed by: eukara
GPG key ID: C196CD8BA993248A
7 changed files with 73 additions and 4 deletions

View file

@ -407,6 +407,8 @@ CSQC_UpdateView(float w, float h, float focus)
View_DrawViewModel(); View_DrawViewModel();
} else if (pl.health > 0) { } else if (pl.health > 0) {
View_DrawViewModel(); View_DrawViewModel();
} else if (getplayerkeyvalue(pl.entnum-1, "*dead") == "1") {
pl.UpdateDeathcam();
} }
/* this is running whenever we're doing 'buildcubemaps' */ /* this is running whenever we're doing 'buildcubemaps' */

View file

@ -8,6 +8,7 @@ base_client:NSSurfacePropEntity
virtual void(void) ClientInputFrame; virtual void(void) ClientInputFrame;
#ifdef CLIENT #ifdef CLIENT
virtual void(void) UpdateDeathcam;
virtual float(void) predraw; virtual float(void) predraw;
#endif #endif
}; };

View file

@ -5,6 +5,16 @@ base_client::ClientInputFrame(void)
} }
#ifdef CLIENT #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 float
base_client::predraw(void) base_client::predraw(void)
{ {

View file

@ -19,6 +19,7 @@
float Math_LerpAngle(float fStart, float fEnd, float fAmount); float Math_LerpAngle(float fStart, float fEnd, float fAmount);
float Math_Lerp(float fA, float fB, float fPercent); float Math_Lerp(float fA, float fB, float fPercent);
float Math_FixDelta(float fDelta); float Math_FixDelta(float fDelta);
vector Math_FixDeltaVector(vector);
vector Math_Reflect(vector v1, vector v2); vector Math_Reflect(vector v1, vector v2);
vector Math_RandomVector(float flyup); vector Math_RandomVector(float flyup);
vector Math_RotateAroundPivot(vector pos, vector pivot, float degr); vector Math_RotateAroundPivot(vector pos, vector pivot, float degr);

View file

@ -14,6 +14,7 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* lerping function that accounts for negative degrees */
float float
Math_LerpAngle(float fStart, float fEnd, float fAmount) Math_LerpAngle(float fStart, float fEnd, float fAmount)
{ {
@ -21,12 +22,15 @@ Math_LerpAngle(float fStart, float fEnd, float fAmount)
return shortest_angle * fAmount; return shortest_angle * fAmount;
} }
/* linear lerp function */
float float
Math_Lerp(float fA, float fB, float fPercent) Math_Lerp(float fA, float fB, float fPercent)
{ {
return (fA * (1 - fPercent)) + (fB * 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 float
Math_FixDelta(float fDelta) Math_FixDelta(float fDelta)
{ {
@ -35,15 +39,28 @@ Math_FixDelta(float fDelta)
} else if (fDelta <= -180) { } else if (fDelta <= -180) {
fDelta += 360; fDelta += 360;
} }
return fDelta; 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 vector
Math_Reflect(vector v1, vector v2) Math_Reflect(vector v1, vector v2)
{ {
return v1 - 2 * dotproduct(v1, v2) * 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 vector
Math_RandomVector(float fFlyUp) Math_RandomVector(float fFlyUp)
{ {
@ -60,6 +77,7 @@ Math_RandomVector(float fFlyUp)
return tmp * 2.0f; return tmp * 2.0f;
} }
/* takes a position and a pivot point and rotates point by X degrees around the pivot (YAW) */
vector vector
Math_RotateAroundPivot(vector pos, vector pivot, float degr) Math_RotateAroundPivot(vector pos, vector pivot, float degr)
{ {

View file

@ -89,6 +89,7 @@ base_player:base_client
virtual void(void) EvaluateEntity; virtual void(void) EvaluateEntity;
virtual float(entity, float) SendEntity; virtual float(entity, float) SendEntity;
virtual void(void) Death;
virtual void(void) MakePlayer; virtual void(void) MakePlayer;
virtual void(void) MakeTempSpectator; virtual void(void) MakeTempSpectator;
#endif #endif

View file

@ -361,7 +361,7 @@ base_player::Respawn(void)
} }
/* /*
=================* =================
base_player::MakeTempSpectator base_player::MakeTempSpectator
This is what dead players in round matches become, or when we spawn This is what dead players in round matches become, or when we spawn
@ -384,10 +384,45 @@ base_player::MakeTempSpectator(void)
maxspeed = 250; maxspeed = 250;
takedamage = DAMAGE_NO; takedamage = DAMAGE_NO;
forceinfokey(this, "*spec", "2"); 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 base_player::MakeTempSpectator
This is what dead players in round matches become, or when we spawn This is what dead players in round matches become, or when we spawn
@ -410,6 +445,7 @@ base_player::MakePlayer(void)
movetype = MOVETYPE_WALK; movetype = MOVETYPE_WALK;
takedamage = DAMAGE_YES; takedamage = DAMAGE_YES;
forceinfokey(this, "*spec", "0"); forceinfokey(this, "*spec", "0");
forceinfokey(this, "*dead", "0");
viewzoom = 1.0; viewzoom = 1.0;
vehicle = __NULL__; vehicle = __NULL__;
velocity = [0,0,0]; velocity = [0,0,0];