Skip to content

Commit

Permalink
cgame: New getters for health and armor. (#189)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NeonKnightOA authored Mar 13, 2024
1 parent a1497c3 commit 3f3e916
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions code/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 0 additions & 14 deletions code/cgame/cg_drawtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?
/*
Expand Down
4 changes: 3 additions & 1 deletion code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 */
20 changes: 20 additions & 0 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions code/cgame/cg_newdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_playerstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions code/cgame/cg_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3f3e916

Please sign in to comment.