From ad70d2c7c83a682527e5392a43614b431de86652 Mon Sep 17 00:00:00 2001 From: LegendaryGuard Date: Sun, 10 Sep 2023 12:59:42 +0200 Subject: [PATCH] cgame: Implement crosshair blob effect and cg_crosshairHealth on hit --- docs/bfp_cvars_task.md | 2 +- source/cgame/cg_draw.c | 18 ++++++++++++------ source/cgame/cg_event.c | 2 +- source/cgame/cg_local.h | 6 ++++-- source/cgame/cg_playerstate.c | 1 + 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/docs/bfp_cvars_task.md b/docs/bfp_cvars_task.md index b5ecad7..7b03457 100644 --- a/docs/bfp_cvars_task.md +++ b/docs/bfp_cvars_task.md @@ -47,7 +47,6 @@ - g_hitStun [0/1]: turn on or off the melee hit stun. - cg_drawKiWarning [0/1]: turn on or off the low ki warning. -- cg_crosshairhealth [0/1]: turn on or off the feature that makes the crosshair turn red when you score a hit. #### Cvar Gametypes: @@ -77,6 +76,7 @@ - [x] ~~cg_yrgolroxor~~ - [x] ~~cg_thirdPersonHeight~~ - [x] ~~cg_crosshairColor~~ +- [x] ~~cg_crosshairHealth~~ #### Cvar Gametypes: diff --git a/source/cgame/cg_draw.c b/source/cgame/cg_draw.c index 910e0d8..581463a 100644 --- a/source/cgame/cg_draw.c +++ b/source/cgame/cg_draw.c @@ -1721,6 +1721,7 @@ static void CG_DrawCrosshair(void) { } #endif +#if 0 // set color based on health if ( cg_crosshairHealth.integer ) { vec4_t hcolor; @@ -1728,17 +1729,22 @@ static void CG_DrawCrosshair(void) { CG_ColorForHealth( hcolor ); trap_R_SetColor( hcolor ); } +#endif CG_SetCrosshairColor(); // BFP - Crosshair color w = h = cg_crosshairSize.value; - // pulse the size of the crosshair when picking up items - f = cg.time - cg.itemPickupBlendTime; - if ( f > 0 && f < ITEM_BLOB_TIME ) { - f /= ITEM_BLOB_TIME; - w *= ( 1 + f ); - h *= ( 1 + f ); + // BFP - pulse the size of the crosshair when hitting someone (before: when picking up items) + f = cg.time - cg.opponentHitBlendTime; + if ( f > 0 && f < HIT_BLOB_TIME ) { + f /= HIT_BLOB_TIME; + // BFP - Make crosshair size starting from biggest to current + w = LERP( w*2, w, f ); // before: w *= ( 1 + f ); + h = LERP( h*2, h, f ); // before: h *= ( 1 + f ); + if ( cg_crosshairHealth.integer && f <= 0.35f ) { // BFP - BFP crosshair health feature + trap_R_SetColor( colorRed ); + } } x = cg_crosshairX.integer; diff --git a/source/cgame/cg_event.c b/source/cgame/cg_event.c index 0fe6c7d..dc3c179 100644 --- a/source/cgame/cg_event.c +++ b/source/cgame/cg_event.c @@ -347,7 +347,7 @@ A new item was picked up this frame static void CG_ItemPickup( int itemNum ) { cg.itemPickup = itemNum; cg.itemPickupTime = cg.time; - cg.itemPickupBlendTime = cg.time; + // cg.itemPickupBlendTime = cg.time; // BFP - BFP doesn't use the item pickup effect for the crosshair, now it's reused for when some opponent is being hit // see if it should be the grabbed weapon if ( bg_itemlist[itemNum].giType == IT_WEAPON ) { // select it immediately diff --git a/source/cgame/cg_local.h b/source/cgame/cg_local.h index 5dff684..d46ecab 100644 --- a/source/cgame/cg_local.h +++ b/source/cgame/cg_local.h @@ -47,7 +47,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define WEAPON_SELECT_TIME 1400 #define ITEM_SCALEUP_TIME 1000 #define ZOOM_TIME 150 -#define ITEM_BLOB_TIME 200 +#define HIT_BLOB_TIME 200 // BFP - For crosshair health, before ITEM_BLOB_TIME #define MUZZLE_FLASH_TIME 20 #define SINK_TIME 1000 // time for fragments to sink into ground before going away #define ATTACKER_HEAD_TIME 10000 @@ -590,7 +590,9 @@ typedef struct { int itemPickup; int itemPickupTime; - int itemPickupBlendTime; // the pulse around the crosshair is timed seperately + + // BFP - before itemPickupBlendTime + int opponentHitBlendTime; // the pulse around the crosshair is timed seperately int weaponSelectTime; int weaponAnimation; diff --git a/source/cgame/cg_playerstate.c b/source/cgame/cg_playerstate.c index f528a0e..9eb34d2 100644 --- a/source/cgame/cg_playerstate.c +++ b/source/cgame/cg_playerstate.c @@ -310,6 +310,7 @@ void CG_CheckLocalSounds( playerState_t *ps, playerState_t *ops ) { // hit changes if ( ps->persistant[PERS_HITS] > ops->persistant[PERS_HITS] ) { + cg.opponentHitBlendTime = cg.time + 0.5f; // BFP - For crosshair opponent hit effect armor = ps->persistant[PERS_ATTACKEE_ARMOR] & 0xff; health = ps->persistant[PERS_ATTACKEE_ARMOR] >> 8; trap_S_StartLocalSound( cgs.media.hitSound, CHAN_LOCAL_SOUND );