Skip to content

Commit

Permalink
Fix Black Ops Osprey crashing if it has no valid target Resolves Valv…
Browse files Browse the repository at this point in the history
…eSoftware/halflife#3259

Fix Black Ops Osprey teleporting to world origin if it isn't moving at all Resolves ValveSoftware/halflife#3260
Fix Black Ops Osprey not firing trigger targets Resolves ValveSoftware/halflife#3261
  • Loading branch information
SamVanheer committed Mar 15, 2022
1 parent eaca957 commit 18312ed
Showing 1 changed file with 53 additions and 18 deletions.
71 changes: 53 additions & 18 deletions dlls/blkop_osprey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ class CBlackOpsOsprey : public CBaseMonster
void EXPORT DyingThink();
void EXPORT CommandUse(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value);

// int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType ) override;
bool TakeDamage(entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType) override;
void TraceAttack(entvars_t* pevAttacker, float flDamage, Vector vecDir, TraceResult* ptr, int bitsDamageType) override;
void ShowDamage();
void Update();

CBaseEntity* m_pGoalEnt;
Vector m_vel1;
Expand Down Expand Up @@ -158,6 +159,7 @@ void CBlackOpsOsprey::Spawn()
m_flRightHealth = 200;
m_flLeftHealth = 200;
pev->health = 400;
pev->max_health = pev->health;

m_flFieldOfView = 0; // 180 degrees

Expand Down Expand Up @@ -341,7 +343,7 @@ void CBlackOpsOsprey::HoverThink()

pev->nextthink = gpGlobals->time + 0.1;
UTIL_MakeAimVectors(pev->angles);
ShowDamage();
Update();
}


Expand Down Expand Up @@ -396,35 +398,44 @@ void CBlackOpsOsprey::FlyThink()

if (gpGlobals->time > m_startTime + m_dTime)
{
if (m_pGoalEnt->pev->speed == 0)
if (m_pGoalEnt != nullptr)
{
SetThink(&CBlackOpsOsprey::DeployThink);
if (m_pGoalEnt->pev->speed == 0)
{
SetThink(&CBlackOpsOsprey::DeployThink);
}
do
{
m_pGoalEnt = CBaseEntity::Instance(FIND_ENTITY_BY_TARGETNAME(NULL, STRING(m_pGoalEnt->pev->target)));
} while (m_pGoalEnt->pev->speed < 400 && !HasDead());
UpdateGoal();
}
do
{
m_pGoalEnt = CBaseEntity::Instance(FIND_ENTITY_BY_TARGETNAME(NULL, STRING(m_pGoalEnt->pev->target)));
} while (m_pGoalEnt->pev->speed < 400 && !HasDead());
UpdateGoal();
}

Flight();
ShowDamage();
Update();
}


void CBlackOpsOsprey::Flight()
{
float t = (gpGlobals->time - m_startTime);
float scale = 1.0 / m_dTime;

float f = UTIL_SplineFraction(t * scale, 1.0);
//Only update if delta time is non-zero. It's zero if we're not moving at all (usually because we have no target).
if (m_dTime != 0)
{
float scale = 1.0 / m_dTime;

float f = UTIL_SplineFraction(t * scale, 1.0);

Vector pos = (m_pos1 + m_vel1 * t) * (1.0 - f) + (m_pos2 - m_vel2 * (m_dTime - t)) * f;
Vector ang = (m_ang1) * (1.0 - f) + (m_ang2)*f;
m_velocity = m_vel1 * (1.0 - f) + m_vel2 * f;
Vector pos = (m_pos1 + m_vel1 * t) * (1.0 - f) + (m_pos2 - m_vel2 * (m_dTime - t)) * f;
Vector ang = (m_ang1) * (1.0 - f) + (m_ang2)*f;
m_velocity = m_vel1 * (1.0 - f) + m_vel2 * f;

UTIL_SetOrigin(pev, pos);
pev->angles = ang;
}

UTIL_SetOrigin(pev, pos);
pev->angles = ang;
UTIL_MakeAimVectors(pev->angles);
float flSpeed = DotProduct(gpGlobals->v_forward, m_velocity);

Expand Down Expand Up @@ -527,6 +538,7 @@ void CBlackOpsOsprey::Killed(entvars_t* pevAttacker, int iGib)
pev->nextthink = gpGlobals->time + 0.1;
pev->health = 0;
pev->takedamage = DAMAGE_NO;
pev->deadflag = DEAD_DYING;

m_startTime = gpGlobals->time + 4.0;
}
Expand Down Expand Up @@ -555,7 +567,7 @@ void CBlackOpsOsprey::DyingThink()
if (m_startTime > gpGlobals->time)
{
UTIL_MakeAimVectors(pev->angles);
ShowDamage();
Update();

Vector vecSpot = pev->origin + pev->velocity * 0.2;

Expand Down Expand Up @@ -767,6 +779,29 @@ void CBlackOpsOsprey::ShowDamage()
}
}

void CBlackOpsOsprey::Update()
{
//Look around so AI triggers work.
Look(4092);

//Listen for sounds so AI triggers work.
Listen();

ShowDamage();
FCheckAITrigger();
}

bool CBlackOpsOsprey::TakeDamage(entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType)
{
//Set enemy to last attacker.
//Ospreys are not capable of fighting so they'll get angry at whatever shoots at them, not whatever looks like an enemy.
m_hEnemy = Instance(pevAttacker);

//It's on now!
m_MonsterState = MONSTERSTATE_COMBAT;

return CBaseMonster::TakeDamage(pevInflictor, pevAttacker, flDamage, bitsDamageType);
}

void CBlackOpsOsprey::TraceAttack(entvars_t* pevAttacker, float flDamage, Vector vecDir, TraceResult* ptr, int bitsDamageType)
{
Expand Down

0 comments on commit 18312ed

Please sign in to comment.