From 3f3e91655d2d774920c75b644b1508997e89d4bf Mon Sep 17 00:00:00 2001 From: NeonKnightOA Date: Wed, 13 Mar 2024 12:10:21 -0300 Subject: [PATCH] cgame: New getters for health and armor. (#189) * New function: CG_GetHealth(), returns the current health amount. * Removal of unnecessary function CG_ColorForHealth(). It only called another function that more or less did the same job. * New function: CG_GetArmor(), returns actual amount of armor. * Update CHANGELOG.md --- CHANGELOG.md | 1 + code/cgame/cg_draw.c | 8 ++++---- code/cgame/cg_drawtools.c | 14 -------------- code/cgame/cg_local.h | 4 +++- code/cgame/cg_main.c | 20 ++++++++++++++++++++ code/cgame/cg_newdraw.c | 4 ++-- code/cgame/cg_playerstate.c | 2 +- code/cgame/cg_view.c | 4 ++-- 8 files changed, 33 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1117dcce..ee955642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ * Tons of other bug fixes. ### Extended version +* New functions CG_GetHealth() and CG_GetArmor in cgame return the current health and armor amounts. * New cvar: bot_developer, for bot-based debugging. * Missionpack/UI3 backend refactors. * "You Have Been Mined" message outright displays the counter instead of delaying it. diff --git a/code/cgame/cg_draw.c b/code/cgame/cg_draw.c index ecb824a5..a51eb38b 100644 --- a/code/cgame/cg_draw.c +++ b/code/cgame/cg_draw.c @@ -715,7 +715,7 @@ static void CG_DrawStatusBar(void) { // stretch the health up when taking damage CG_DrawField(185, 432, 3, value); - CG_ColorForHealth(hcolor); + CG_GetColorForHealth( CG_GetHealth(), CG_GetArmor(), hcolor ); trap_R_SetColor(hcolor); @@ -1979,7 +1979,7 @@ static int CG_DrawPickupItem(int y) { int value; float *fadeColor; - if (cg.snap->ps.stats[STAT_HEALTH] <= 0) { + if (CG_GetHealth() <= 0) { return y; } @@ -2716,7 +2716,7 @@ static void CG_DrawCrosshair(void) { if (cg_crosshairHealth.integer) { vec4_t hcolor; - CG_ColorForHealth(hcolor); + CG_GetColorForHealth( CG_GetHealth(), CG_GetArmor(), hcolor ); trap_R_SetColor(hcolor); } else { vec4_t color; @@ -3505,7 +3505,7 @@ static void CG_Draw2D(stereoFrame_t stereoFrame) { CG_DrawCrosshairNames(); } else { // don't draw any status if dead or the scoreboard is being explicitly shown - if (!cg.showScores && cg.snap->ps.stats[STAT_HEALTH] > 0) { + if (!cg.showScores && CG_GetHealth() > 0) { #ifdef MISSIONPACK if (cg_drawStatus.integer) { diff --git a/code/cgame/cg_drawtools.c b/code/cgame/cg_drawtools.c index dd515ba4..80ef0daf 100644 --- a/code/cgame/cg_drawtools.c +++ b/code/cgame/cg_drawtools.c @@ -422,20 +422,6 @@ void CG_GetColorForHealth( int health, int armor, vec4_t hcolor ) { } } -/* -================= -CG_ColorForHealth -================= -*/ -void CG_ColorForHealth( vec4_t hcolor ) { - - CG_GetColorForHealth( cg.snap->ps.stats[STAT_HEALTH], - cg.snap->ps.stats[STAT_ARMOR], hcolor ); -} - - - - // bk001205 - code below duplicated in q3_ui/ui-atoms.c // bk001205 - FIXME: does this belong in ui_shared.c? /* diff --git a/code/cgame/cg_local.h b/code/cgame/cg_local.h index ab62f6fa..4c22504e 100644 --- a/code/cgame/cg_local.h +++ b/code/cgame/cg_local.h @@ -1553,7 +1553,6 @@ int CG_DrawStrlen( const char *str ); float *CG_FadeColor( int startMsec, int totalMsec ); float *CG_TeamColor( int team ); void CG_TileClear( void ); -void CG_ColorForHealth( vec4_t hcolor ); void CG_GetColorForHealth( int health, int armor, vec4_t hcolor ); void UI_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color ); @@ -2043,4 +2042,7 @@ qboolean CG_IsATeamGametype(int check); /* Whether the gametype is team-based or qboolean CG_UsesTeamFlags(int check); /* Whether the gametype uses the red and blue flags. */ qboolean CG_UsesTheWhiteFlag(int check); /* Whether the gametype uses the neutral flag. */ qboolean CG_IsARoundBasedGametype(int check); /* Whether the gametype uses the neutral flag. */ + +int CG_GetHealth(void); /* Returns the current health amount. */ +int CG_GetArmor(void); /* Returns the current health amount. */ /* /Neon_Knight */ diff --git a/code/cgame/cg_main.c b/code/cgame/cg_main.c index d2c45b0a..ec4db6ee 100644 --- a/code/cgame/cg_main.c +++ b/code/cgame/cg_main.c @@ -2746,4 +2746,24 @@ Checks if the gametype has a round-based system. qboolean CG_IsARoundBasedGametype(int check) { return GAMETYPE_IS_ROUND_BASED(check); } +/* +=================== +CG_GetHealth + +Returns the current health amount. +=================== + */ +int CG_GetHealth(void) { + return cg.snap->ps.stats[STAT_HEALTH]; +} +/* +=================== +CG_GetArmor + +Returns the current armor amount. +=================== + */ +int CG_GetArmor(void) { + return cg.snap->ps.stats[STAT_ARMOR]; +} /* /Neon_Knight */ diff --git a/code/cgame/cg_newdraw.c b/code/cgame/cg_newdraw.c index 4a125235..fcfa4a41 100644 --- a/code/cgame/cg_newdraw.c +++ b/code/cgame/cg_newdraw.c @@ -1159,13 +1159,13 @@ qboolean CG_OwnerDrawVisible(int flags) } if (flags & CG_SHOW_HEALTHCRITICAL) { - if (cg.snap->ps.stats[STAT_HEALTH] < 25) { + if (CG_GetHealth() < 25) { return qtrue; } } if (flags & CG_SHOW_HEALTHOK) { - if (cg.snap->ps.stats[STAT_HEALTH] >= 25) { + if (CG_GetHealth() >= 25) { return qtrue; } } diff --git a/code/cgame/cg_playerstate.c b/code/cgame/cg_playerstate.c index b981de45..219a56f4 100644 --- a/code/cgame/cg_playerstate.c +++ b/code/cgame/cg_playerstate.c @@ -98,7 +98,7 @@ void CG_DamageFeedback( int yawByte, int pitchByte, int damage ) { cg.attackerTime = cg.time; // the lower on health you are, the greater the view kick will be - health = cg.snap->ps.stats[STAT_HEALTH]; + health = CG_GetHealth(); if ( health < 40 ) { scale = 1; } else { diff --git a/code/cgame/cg_view.c b/code/cgame/cg_view.c index 28c6d262..6236c39d 100644 --- a/code/cgame/cg_view.c +++ b/code/cgame/cg_view.c @@ -423,7 +423,7 @@ static void CG_OffsetFirstPersonView( void ) { angles = cg.refdefViewAngles; // if dead, fix the angle and don't add any kick - if ( cg.snap->ps.stats[STAT_HEALTH] <= 0 ) { + if ( CG_GetHealth() <= 0 ) { angles[ROLL] = 40; angles[PITCH] = -15; angles[YAW] = cg.snap->ps.stats[STAT_DEAD_YAW]; @@ -982,7 +982,7 @@ void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demo } else { cg.renderingThirdPerson = cg.snap->ps.persistant[PERS_TEAM] != TEAM_SPECTATOR - && (cg_thirdPerson.integer || (cg.snap->ps.stats[STAT_HEALTH] <= 0)); + && (cg_thirdPerson.integer || (CG_GetHealth() <= 0)); } // build cg.refdef