From 5c77516aab99daecba8dcf04dda4daa5af63c84e Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 7 Mar 2022 13:08:46 +0000 Subject: [PATCH] Cleanup of boss info in anticipation of merger. * Actually add descriptions for the boss-related functions into k_boss.h. * Introduce K_ResetBossInfo, an internal-only function for handling situations where it needs to be cleared. * Fix a bug where bossinfo wasn't reset when using the map command to go to a battle map after having been in a boss. * Fix some bugs where you could provide magnitudes out of the desired range to K_InitBossHealthBar and K_UpdateBossHealthBar. --- src/d_main.c | 6 +----- src/d_netcmd.c | 8 +------- src/k_boss.c | 22 +++++++++++++++++++++ src/k_boss.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/m_menu.c | 8 +------- 5 files changed, 77 insertions(+), 19 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 9910f9e14..6809d09a8 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -930,11 +930,7 @@ void D_StartTitle(void) memset(&grandprixinfo, 0, sizeof(struct grandprixinfo)); // Reset boss info - if (bossinfo.enemyname) - Z_Free(bossinfo.enemyname); - if (bossinfo.subtitle) - Z_Free(bossinfo.subtitle); - memset(&bossinfo, 0, sizeof(struct bossinfo)); + K_ResetBossInfo(); // empty maptol so mario/etc sounds don't play in sound test when they shouldn't maptol = 0; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index f5957ec74..a8646d074 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2749,17 +2749,11 @@ static void Command_Map_f(void) if (newgametype == GT_BATTLE) { grandprixinfo.gp = false; + K_ResetBossInfo(); if (mapheaderinfo[newmapnum-1] && mapheaderinfo[newmapnum-1]->typeoflevel & TOL_BOSS) { - // Reset boss info - if (bossinfo.enemyname) - Z_Free(bossinfo.enemyname); - if (bossinfo.subtitle) - Z_Free(bossinfo.subtitle); - memset(&bossinfo, 0, sizeof(struct bossinfo)); - bossinfo.boss = true; bossinfo.encore = newencoremode; } diff --git a/src/k_boss.c b/src/k_boss.c index 345e09389..0c1217fc4 100644 --- a/src/k_boss.c +++ b/src/k_boss.c @@ -22,6 +22,18 @@ struct bossinfo bossinfo; +/*-------------------------------------------------- + void K_ClearBossInfo(void) + + See header file for description. +--------------------------------------------------*/ +void K_ResetBossInfo(void) +{ + Z_Free(bossinfo.enemyname); + Z_Free(bossinfo.subtitle); + memset(&bossinfo, 0, sizeof(struct bossinfo)); +} + /*-------------------------------------------------- void K_BossInfoTicker(void) @@ -118,6 +130,11 @@ void K_InitBossHealthBar(const char *enemyname, const char *subtitle, sfxenum_t bossinfo.barlen = BOSSHEALTHBARLEN; K_UpdateBossHealthBar(FRACUNIT, 0); + if (pinchmagnitude > FRACUNIT) + pinchmagnitude = FRACUNIT; + else if (pinchmagnitude < 0) + pinchmagnitude = 0; + bossinfo.healthbarpinch = FixedMul(pinchmagnitude, BOSSHEALTHBARLEN*FRACUNIT)>>FRACBITS; // we do this here so we can fudge our working a bit @@ -143,6 +160,11 @@ void K_InitBossHealthBar(const char *enemyname, const char *subtitle, sfxenum_t void K_UpdateBossHealthBar(fixed_t magnitude, tic_t jitterlen) { + if (magnitude > FRACUNIT) + magnitude = FRACUNIT; + else if (magnitude < 0) + magnitude = 0; + if (jitterlen > bossinfo.visualbarimpact) bossinfo.visualbarimpact = jitterlen; bossinfo.healthbar = FixedMul(magnitude, BOSSHEALTHBARLEN); diff --git a/src/k_boss.h b/src/k_boss.h index 838154817..db335bb07 100644 --- a/src/k_boss.h +++ b/src/k_boss.h @@ -55,9 +55,61 @@ extern struct bossinfo char *subtitle; ///< The subtitle under the titlecard } bossinfo; +/*-------------------------------------------------- + void K_ResetBossInfo(void); + + Resets boss information to a clean slate. +--------------------------------------------------*/ + +void K_ResetBossInfo(void); + +/*-------------------------------------------------- + void K_ResetBossInfo(void); + + Updates boss information and timers for this level tic. +--------------------------------------------------*/ + void K_BossInfoTicker(void); + +/*-------------------------------------------------- + void K_InitBossHealthBar(const char *enemyname, const char *subtitle, sfxenum_t titlesound, fixed_t pinchmagnitude, UINT8 divisions); + + Initialises boss information for opponent spawn, including filling the health bar. + + Input Arguments:- + enemyname - Zone memory string for HUD/titlecard name. + subtitle - Zone memory string for titlecard subtitle. + titlesound - Sound effect enum for titlecard typewriting. + pinchmagnitude - 0-FRACUNIT range for healthbar to display pinch status at. + divisions - # of segments on healthbar. +--------------------------------------------------*/ + void K_InitBossHealthBar(const char *enemyname, const char *subtitle, sfxenum_t titlesound, fixed_t pinchmagnitude, UINT8 divisions); + +/*-------------------------------------------------- + void K_UpdateBossHealthBar(fixed_t magnitude, tic_t jitterlen); + + Updates boss healthbar to a new magnitude. + + Input Arguments:- + magnitude - 0-FRACUNIT range for healthbar to update to. + jitterlen - Duration healthbar should vibrate for. +--------------------------------------------------*/ + void K_UpdateBossHealthBar(fixed_t magnitude, tic_t jitterlen); + +/*-------------------------------------------------- + void K_DeclareWeakspot(mobj_t *spot, spottype_t spottype, UINT16 color, boolean minimap); + + Updates the list of Weakspots for the HUD/minimap object tracking. + + Input Arguments:- + spot - mobj_t reference. + spottype - Type of spot. + color - Color of associated UI elements. + minimap - If true, appear on minimap. +--------------------------------------------------*/ + void K_DeclareWeakspot(mobj_t *spot, spottype_t spottype, UINT16 color, boolean minimap); #endif diff --git a/src/m_menu.c b/src/m_menu.c index 324ba3eaf..7ceb7c721 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7839,13 +7839,7 @@ static void M_StartBoss(INT32 choice) M_ClearMenus(true); - // Reset boss info - if (bossinfo.enemyname) - Z_Free(bossinfo.enemyname); - if (bossinfo.subtitle) - Z_Free(bossinfo.subtitle); - memset(&bossinfo, 0, sizeof(struct bossinfo)); - + K_ResetBossInfo(); bossinfo.boss = true; bossinfo.encore = (boolean)(cv_dummygpencore.value);