Skip to content

Commit

Permalink
flinch tweaks
Browse files Browse the repository at this point in the history
- tor flinches 33% of the time from heavy damage, down from 100%
- hwgrunt spins down if flinched while spinning up
  • Loading branch information
wootguy committed Dec 23, 2024
1 parent 8e35ecb commit 6942229
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
25 changes: 15 additions & 10 deletions dlls/monster/CBaseGrunt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void CBaseGrunt :: PrescheduleThink ( void )
{
if (HasEquipment(MEQUIP_MINIGUN)) {
if (minigunSpinState == 2) {
EMIT_SOUND_DYN(edict(), CHAN_ITEM, "hassault/hw_spin.wav", 0.7f, ATTN_STATIC, SND_CHANGE_PITCH, 100);
EMIT_SOUND_DYN(edict(), CHAN_ITEM, "hassault/hw_spin.wav", 0.8f, ATTN_STATIC, SND_CHANGE_PITCH, 100);
}
if (pev->sequence == minigunShootSeq && gpGlobals->time >= nextMinigunShoot) {
pev->nextthink = nextMinigunShoot = gpGlobals->time + 0.07f;
Expand Down Expand Up @@ -1122,6 +1122,10 @@ void CBaseGrunt::BaseSpawn()
InitModel();
SetSize(VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX);

if (HasEquipment(MEQUIP_MINIGUN)) {
m_flinchChance = 33;
}

MonsterInit();

InitAiFlags();
Expand Down Expand Up @@ -1261,6 +1265,9 @@ void CBaseGrunt :: StartTask ( Task_t *pTask )
case TASK_GRUNT_MINIGUN_SPINUP:
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, "hassault/hw_spinup.wav", 1.0, ATTN_NORM, 0, 90);

m_IdealActivity = m_Activity = ACT_THREAT_DISPLAY;

// doing this because SetActivity is playing idle animations sometimes
pev->sequence = LookupActivity(ACT_THREAT_DISPLAY);
pev->frame = 0;
m_rpgAimTime = gpGlobals->time;
Expand Down Expand Up @@ -1307,7 +1314,6 @@ void CBaseGrunt :: RunTask ( Task_t *pTask )
break;
case TASK_GRUNT_MINIGUN_SPINUP:
if (pev->frame > 180) {
EMIT_SOUND_DYN(edict(), CHAN_ITEM, "hassault/hw_spin.wav", 0.7f, ATTN_STATIC, SND_CHANGE_PITCH, 100);
minigunSpinState = 2;
TaskComplete();
}
Expand Down Expand Up @@ -2361,19 +2367,18 @@ Schedule_t* CBaseGrunt::GetMonsterStateSchedule(void) {

if (HasConditions(bits_COND_HEAVY_DAMAGE))
{
// flinch for heavy damage but not too often
if (RANDOM_LONG(0, 2) == 0) {
return GetScheduleOfType(SCHED_SMALL_FLINCH);
}
else {
ClearConditions(bits_COND_HEAVY_DAMAGE);
return CTalkSquadMonster::GetSchedule();
// flinch for heavy damage and reset minigun spinup if not already spinning
if (minigunSpinState == 1) {
minigunSpinState = 0;
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, "hassault/hw_spindown.wav", 1.0, ATTN_NORM, 0, 90);
}
return GetScheduleOfType(SCHED_SMALL_FLINCH);
}
else if (HasConditions(bits_COND_LIGHT_DAMAGE))
{
ClearConditions(bits_COND_LIGHT_DAMAGE);
// never flinch or retreat from light damage
ClearConditions(bits_COND_LIGHT_DAMAGE);

return CTalkSquadMonster::GetSchedule();
}
}
Expand Down
12 changes: 10 additions & 2 deletions dlls/monster/CBaseMonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,13 @@ void CBaseMonster::MonsterInit(void)
m_flDistLook = 2048.0;
}

if (m_flinchChance == 0) {
m_flinchChance = 100;
}
else if (m_flinchChance < 0) {
m_flinchChance = 0;
}

m_lastInterpOrigin = pev->origin;

// set eye position
Expand Down Expand Up @@ -4598,8 +4605,9 @@ int CBaseMonster::TakeDamage(entvars_t* pevInflictor, entvars_t* pevAttacker, fl

// HL sets this to 20, but monsters are getting stunlocked often in co-op
int flinchAmount = (m_IdealMonsterState == MONSTERSTATE_COMBAT) ? 50 : 20;

if (flDamage >= flinchAmount)
bool flinchChance = RANDOM_LONG(0, 99) < m_flinchChance;

if (flDamage >= flinchAmount && flinchChance)
{
SetConditions(bits_COND_HEAVY_DAMAGE);
}
Expand Down
2 changes: 2 additions & 0 deletions dlls/monster/CBaseMonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class EXPORT CBaseMonster : public CBaseToggle

Vector m_lastInterpOrigin; // for interpolated origin calculation

int m_flinchChance; // 0-100 chance the HEAVY_DAMAGE condition is set (0 = 100, -1 = 0)

virtual int GetEntindexPriority() { return ENTIDX_PRIORITY_HIGH; }
virtual int ObjectCaps(void) { return CBaseEntity::ObjectCaps() | FCAP_IMPULSE_USE; }
virtual int Save( CSave &save );
Expand Down
1 change: 1 addition & 0 deletions dlls/monster/CTor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ void CTor::Spawn()

summon_cname = ALLOC_STRING(SUMMON_CLASSNAME);
numChildren = 0;
m_flinchChance = 33;

MonsterInit();

Expand Down

0 comments on commit 6942229

Please sign in to comment.