Skip to content

Commit

Permalink
suit voice fix + tweaks
Browse files Browse the repository at this point in the history
- fix voice queue not cleared on respawn
- fix batteries given at spawn triggering the suit voice
- deduplicate battery level messages (at most 1 in queue and 1 playing)
- play "power level less than 5%" warning when flashlight is low, not when getting a bit of armor
- add "ammo depleted" messages for egon, gauss, rpg and displacer
- add "extreme heat damage" for swimming in lava
- add "armor compromised" when armor is hits 0%
- add "hev damage sustained" when armor is hit for 50+ points at once

also fix a warning
  • Loading branch information
wootguy committed Dec 23, 2024
1 parent 6942229 commit b59d02e
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 18 deletions.
3 changes: 2 additions & 1 deletion dlls/item/CItemBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class CItemBattery : public CItem
if (pct > 0)
pct--;

snprintf(szcharge, 64, "!HEV_%1dP", pct);
if (pct > 0)
snprintf(szcharge, 64, "!HEV_%1dP", pct);

//EMIT_SOUND_SUIT(ENT(pev), szcharge);
pPlayer->SetSuitUpdate(szcharge, FALSE, SUIT_NEXT_IN_30SEC);
Expand Down
4 changes: 3 additions & 1 deletion dlls/monster/CBodyGuard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,10 @@ Schedule_t* CBodyGuard::GetScheduleOfType(int Type)
}
return &slGruntRangeAttack1C[0]; // prevent crouching or angry idle animations
default:
return wasSpinning ? &slMinigunSpindown[0] : CBaseGrunt::GetScheduleOfType(Type);
break;
}

return wasSpinning ? &slMinigunSpindown[0] : CBaseGrunt::GetScheduleOfType(Type);
}

int CBodyGuard::GetActivitySequence(Activity NewActivity) {
Expand Down
71 changes: 57 additions & 14 deletions dlls/player/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ int CBasePlayer :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker,
float flArmor;

flArmor = (flDamage - flNew) * flBonus;

float oldArmor = pev->armorvalue;

// Does this use more armor than we have?
if (flArmor > pev->armorvalue)
Expand All @@ -456,6 +458,15 @@ int CBasePlayer :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker,
pev->armorvalue -= flArmor;

flDamage = flNew;


if (oldArmor > 0 && pev->armorvalue < 1) {
SetSuitUpdate("!HEV_E0", FALSE, SUIT_NEXT_IN_30SEC); // armor compromised
}
else if (oldArmor - pev->armorvalue > 50) {
// heavy hit
SetSuitUpdate("!HEV_E4", FALSE, SUIT_NEXT_IN_30SEC); // hev damage sustained
}
}

// this cast to INT is critical!!! If a player ends up with 0.5 health, the engine will get that
Expand Down Expand Up @@ -1426,6 +1437,7 @@ void CBasePlayer::WaterMove()
{
if (pev->dmgtime < gpGlobals->time) {
TakeDamage(VARS(eoNullEntity), VARS(eoNullEntity), 10 * pev->waterlevel, DMG_BURN);
SetSuitUpdate("!HEV_FIRE", FALSE, SUIT_NEXT_IN_1MIN); // extreme heat damage
pev->dmgtime = gpGlobals->time + 1.0f;
}
}
Expand Down Expand Up @@ -2881,7 +2893,13 @@ void CBasePlayer::CheckSuitUpdate()
m_flSuitUpdate = 0;
}
}


bool IsBatteryUpdateSuitSentence(const char* name) {
int len = strlen(name);
return len >= 7 && len <= 8 && strstr(name, "!HEV_") == name
&& isdigit(name[5]) && ((isdigit(name[6]) && name[7] == 'P') || name[6] == 'P');
}

// add sentence to suit playlist queue. if fgroup is true, then
// name is a sentence group (HEV_AA), otherwise name is a specific
// sentence name ie: !HEV_AA0. If iNoRepeat is specified in
Expand All @@ -2893,25 +2911,23 @@ void CBasePlayer::SetSuitUpdate(const char *name, int fgroup, int iNoRepeatTime)
int isentence;
int iempty = -1;


// Ignore suit updates if no suit
if ( !(pev->weapons & (1<<WEAPON_SUIT)) )
return;

if (!mp_hevsuit_voice.value)
{
// due to static channel design, etc. We don't play HEV sounds in multiplayer right now.
return;
}

// if name == NULL, then clear out the queue

if (!name)
{
if (!name) {
for (i = 0; i < CSUITPLAYLIST; i++)
m_rgSuitPlayList[i] = 0;
return;
}

// Ignore suit updates if no suit
if ( !(pev->weapons & (1<<WEAPON_SUIT)) )
return;

// get sentence or group number
if (!fgroup)
{
Expand Down Expand Up @@ -2963,11 +2979,31 @@ void CBasePlayer::SetSuitUpdate(const char *name, int fgroup, int iNoRepeatTime)
m_rgflSuitNoRepeatTime[iempty] = iNoRepeatTime + gpGlobals->time;
}

// find empty spot in queue, or overwrite last spot

m_rgSuitPlayList[m_iSuitPlayNext++] = isentence;
if (m_iSuitPlayNext == CSUITPLAYLIST)
m_iSuitPlayNext = 0;
bool replacedExisting = false;
if (IsBatteryUpdateSuitSentence(name)) {
for (int i = 0; i < CSUITPLAYLIST; i++) {
if (!m_rgSuitPlayList[i]) {
continue;
}

char sentence[CBSENTENCENAME_MAX + 1];
strcpy_safe(sentence, "!", CBSENTENCENAME_MAX + 1);
strcat_safe(sentence, gszallsentencenames[m_rgSuitPlayList[i]], CBSENTENCENAME_MAX + 1);

if (IsBatteryUpdateSuitSentence(sentence)) {
m_rgSuitPlayList[i] = isentence;
replacedExisting = true;
break;
}
}
}

if (!replacedExisting) {
// find empty spot in queue, or overwrite last spot
m_rgSuitPlayList[m_iSuitPlayNext++] = isentence;
if (m_iSuitPlayNext == CSUITPLAYLIST)
m_iSuitPlayNext = 0;
}

if (m_flSuitUpdate <= gpGlobals->time)
{
Expand Down Expand Up @@ -3476,6 +3512,9 @@ void CBasePlayer::Spawn( void )

DropAllInventoryItems(false, true);
ApplyEffects();

// don't play suit sounds for items given when spawning
SetSuitUpdate(NULL, FALSE, 0);
}

void CBasePlayer :: Precache( void )
Expand Down Expand Up @@ -4556,6 +4595,10 @@ void CBasePlayer :: UpdateClientData( void )
{
m_flFlashLightTime = FLASH_DRAIN_TIME + gpGlobals->time;
m_iFlashBattery--;

if (m_iFlashBattery < 8) {
SetSuitUpdate("!HEV_0P", FALSE, SUIT_NEXT_IN_1MIN);
}

if (!m_iFlashBattery)
FlashlightTurnOff();
Expand Down
4 changes: 2 additions & 2 deletions dlls/weapon/CDisplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void CDisplacer::FireThink()

if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0)
{
m_pPlayer->SetSuitUpdate("!HEV_AMO0", TRUE, SUIT_REPEAT_OK);
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, SUIT_REPEAT_OK);
}
#endif

Expand Down Expand Up @@ -476,7 +476,7 @@ void CDisplacer::AltFireThink()
//if (0 == GetMagazine1())
{
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
m_pPlayer->SetSuitUpdate("!HEV_AMO0", TRUE, SUIT_REPEAT_OK);
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, SUIT_REPEAT_OK);
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase();
Expand Down
4 changes: 4 additions & 0 deletions dlls/weapon/CEgon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ void CEgon::Holster( int skiplocal /* = 0 */ )
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
SendWeaponAnim( EGON_HOLSTER );

if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0) {
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, SUIT_REPEAT_OK);
}

EndAttack();
}

Expand Down
4 changes: 4 additions & 0 deletions dlls/weapon/CGauss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ void CGauss::Holster( int skiplocal /* = 0 */ )

m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;

if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0) {
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, SUIT_REPEAT_OK);
}

SendWeaponAnim( GAUSS_HOLSTER );
m_fInAttack = 0;
}
Expand Down
4 changes: 4 additions & 0 deletions dlls/weapon/CRpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ void CRpg::Holster( int skiplocal /* = 0 */ )

SendWeaponAnim( RPG_HOLSTER1 );

if (m_iClip == 0 && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0) {
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, SUIT_REPEAT_OK);
}

#ifndef CLIENT_DLL
CLaserSpot* m_pSpot = (CLaserSpot*)m_hSpot.GetEntity();
if (m_pSpot)
Expand Down

0 comments on commit b59d02e

Please sign in to comment.