Skip to content

Commit

Permalink
Fixes & tweaks (#41)
Browse files Browse the repository at this point in the history
fixes:
    alien slave playing the powerup effect again after the attack
    apache and osprey not firing sound trigger condition
    some potential null pointer dereference

tweaked:
    added apache and osprey monsterstate when they have an enemy
    added 'Ignore Player' flag for xen light stalk
    added 'Drop to Floor' flag for xen plants
  • Loading branch information
RedSprend authored and wootguy committed Dec 9, 2024
1 parent d15a8fa commit 83c3cc7
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 19 deletions.
9 changes: 9 additions & 0 deletions dlls/monster/CActAnimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ void CActAnimating::SetActivity(Activity act)
ResetSequenceInfo();
}
}

void CActAnimating::DropToFloor()
{
if( DROP_TO_FLOOR(ENT( pev ) ) == 0 )
{
ALERT(at_error, "Entity %s fell out of level at %f,%f,%f\n", STRING( pev->classname ), pev->origin.x, pev->origin.y, pev->origin.z);
UTIL_Remove( this );
}
}
4 changes: 4 additions & 0 deletions dlls/monster/CActAnimating.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "CBaseAnimating.h"

#define SF_XEN_PLANT_DROP_TO_FLOOR 2

class CActAnimating : public CBaseAnimating
{
public:
Expand All @@ -13,6 +15,8 @@ class CActAnimating : public CBaseAnimating
virtual int Restore(CRestore& restore);
static TYPEDESCRIPTION m_SaveData[];

protected:
void DropToFloor();
private:
Activity m_Activity;
};
38 changes: 36 additions & 2 deletions dlls/monster/CApache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,15 @@ void CApache :: Spawn( void )

if (pev->spawnflags & SF_WAITFORTRIGGER)
{
SetThink( &CApache::NullThink );
SetUse( &CApache::StartupUse );
}
else
{
SetThink( &CApache::HuntThink );
SetTouch( &CApache::FlyTouch );
pev->nextthink = gpGlobals->time + 1.0;
}
pev->nextthink = gpGlobals->time + 1.0;

m_iRockets = 10;
}
Expand Down Expand Up @@ -488,8 +489,20 @@ void CApache :: HuntThink( void )
{
Look( 4092 );
m_hEnemy = BestVisibleEnemy( );

//If i have an enemy i'm in combat, otherwise i'm patrolling.
if (m_hEnemy != NULL)
{
m_MonsterState = MONSTERSTATE_COMBAT;
}
else
{
m_MonsterState = MONSTERSTATE_ALERT;
}
}

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

// generic speed up
if (m_flGoalSpeed < 800)
m_flGoalSpeed += 5;
Expand Down Expand Up @@ -943,7 +956,28 @@ int CApache :: TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, floa
*/

// ALERT( at_console, "%.0f\n", flDamage );
return CBaseEntity::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
//Are we damaged at all?
if (pev->health < pev->max_health)
{
//Took some damage.
SetConditions(bits_COND_LIGHT_DAMAGE);
if (pev->health < (pev->max_health / 2))
{
//Seriously damaged now.
SetConditions(bits_COND_HEAVY_DAMAGE);
}
else
{
//Maybe somebody healed us somehow (trigger_hurt with negative damage?), clear this.
ClearConditions(bits_COND_HEAVY_DAMAGE);
}
}
else
{
//Maybe somebody healed us somehow (trigger_hurt with negative damage?), clear this.
ClearConditions(bits_COND_LIGHT_DAMAGE);
}
return CBaseEntity::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}


Expand Down
2 changes: 1 addition & 1 deletion dlls/monster/CGargantua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ CBaseEntity* CGargantua::GargantuaCheckTraceHullAttack(float flDist, int iDamage
{
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );

if ( iDamage > 0 )
if ( pEntity && iDamage > 0 )
{
pEntity->TakeDamage( pev, pev, iDamage, iDmgType );
}
Expand Down
2 changes: 1 addition & 1 deletion dlls/monster/CGonome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,4 @@ void CGonomeSpit::Touch(CBaseEntity* pOther)

SetThink(&CGonomeSpit::SUB_Remove);
pev->nextthink = gpGlobals->time;
}
}
6 changes: 5 additions & 1 deletion dlls/monster/CISlave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const char* CISlave::DisplayName() {

int CISlave::IRelationship( CBaseEntity *pTarget )
{
if ( (pTarget->IsPlayer()) )
if( ( pTarget && pTarget->IsPlayer() ) )
if ( (pev->spawnflags & SF_MONSTER_WAIT_UNTIL_PROVOKED ) && ! (m_afMemory & bits_MEMORY_PROVOKED ))
return R_NO;
return CBaseMonster::IRelationship( pTarget );
Expand Down Expand Up @@ -375,6 +375,10 @@ void CISlave :: HandleAnimEvent( MonsterEvent_t *pEvent )

case ISLAVE_AE_ZAP_POWERUP:
{
// Hack to prevent the event from playing again when the animation ends
if (m_iTaskStatus == TASKSTATUS_COMPLETE)
break;

CSoundEnt::InsertSound(bits_SOUND_COMBAT, pev->origin, NORMAL_GUN_VOLUME, 3.0);

pev->framerate = gSkillData.sk_islave_speed_zap;
Expand Down
32 changes: 22 additions & 10 deletions dlls/monster/COsprey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ class COsprey : public CBaseMonster
void EXPORT DyingThink( void );
void EXPORT CommandUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );

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

EHANDLE m_hGoalEnt;
Vector m_vel1;
Expand Down Expand Up @@ -370,8 +371,7 @@ void COsprey :: HoverThink( void )

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

Expand Down Expand Up @@ -410,7 +410,6 @@ void COsprey::UpdateGoal( )
void COsprey::FlyThink( void )
{
StudioFrameAdvance( );
FCheckAITrigger();
UpdateShockEffect();
pev->nextthink = gpGlobals->time + 0.1;

Expand All @@ -433,7 +432,7 @@ void COsprey::FlyThink( void )
}

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


Expand Down Expand Up @@ -526,11 +525,18 @@ void COsprey::HitTouch( CBaseEntity *pOther )
pev->nextthink = gpGlobals->time + 2.0;
}

void COsprey::Update()
{
Look(4092); // Look around so AI triggers work.
Listen(); // Listen for sounds so AI triggers work.

ShowDamage();
FCheckAITrigger();
}

/*
int COsprey::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
{
if (m_flRotortilt <= -90)
/* if (m_flRotortilt <= -90)
{
m_flRotortilt = 0;
}
Expand All @@ -539,9 +545,15 @@ int COsprey::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float
m_flRotortilt -= 45;
}
SetBoneController( 0, m_flRotortilt );
return 0;
return 0;*/

//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);
}
*/



Expand Down Expand Up @@ -590,7 +602,7 @@ void COsprey :: DyingThink( void )
if (m_startTime > gpGlobals->time )
{
UTIL_MakeAimVectors( pev->angles );
ShowDamage( );
ShowDamage();

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

Expand Down
3 changes: 3 additions & 0 deletions dlls/monster/CXenHair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ void CXenHair::Spawn(void)
pev->solid = SOLID_NOT;
pev->movetype = MOVETYPE_NONE;
pev->nextthink = gpGlobals->time + RANDOM_FLOAT(0.1, 0.4); // Load balance these a bit

if (FBitSet(pev->spawnflags, SF_XEN_PLANT_DROP_TO_FLOOR))
DropToFloor();
}


Expand Down
17 changes: 14 additions & 3 deletions dlls/monster/CXenPLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "effects.h"
#include "CActAnimating.h"

#define SF_XEN_PLANT_LIGHT_IGNORE_PLAYER 64

#define XEN_PLANT_GLOW_SPRITE "sprites/flare3.spr"
#define XEN_PLANT_HIDE_TIME 5

Expand Down Expand Up @@ -47,10 +49,19 @@ void CXenPLight::Spawn(void)
SetActivity(ACT_IDLE);
pev->nextthink = gpGlobals->time + 0.1;
pev->frame = RANDOM_FLOAT(0, 255);

if (FBitSet(pev->spawnflags, SF_XEN_PLANT_DROP_TO_FLOOR))
DropToFloor();

if (FBitSet(pev->flags, FL_KILLME))
return;

m_pGlow = CSprite::SpriteCreate(XEN_PLANT_GLOW_SPRITE, pev->origin + Vector(0, 0, (pev->mins.z + pev->maxs.z) * 0.5), FALSE);
m_pGlow->SetTransparency(kRenderGlow, pev->rendercolor.x, pev->rendercolor.y, pev->rendercolor.z, pev->renderamt, pev->renderfx);
m_pGlow->SetAttachment(edict(), 1);
if (m_pGlow)
{
m_pGlow->SetTransparency(kRenderGlow, pev->rendercolor.x, pev->rendercolor.y, pev->rendercolor.z, pev->renderamt, pev->renderfx);
m_pGlow->SetAttachment(edict(), 1);
}
}


Expand Down Expand Up @@ -98,7 +109,7 @@ void CXenPLight::Think(void)

void CXenPLight::Touch(CBaseEntity* pOther)
{
if (pOther->IsPlayer())
if( !FBitSet(pev->spawnflags, SF_XEN_PLANT_LIGHT_IGNORE_PLAYER) && pOther->IsPlayer() )
{
pev->dmgtime = gpGlobals->time + XEN_PLANT_HIDE_TIME;
if (GetActivity() == ACT_IDLE || GetActivity() == ACT_STAND)
Expand Down
3 changes: 3 additions & 0 deletions dlls/monster/CXenSpore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ void CXenSpore::Spawn(void)
pev->framerate = RANDOM_FLOAT(0.7, 1.4);
ResetSequenceInfo();
pev->nextthink = gpGlobals->time + RANDOM_FLOAT(0.1, 0.4); // Load balance these a bit

if (FBitSet(pev->spawnflags, SF_XEN_PLANT_DROP_TO_FLOOR))
DropToFloor();
}

const char* CXenSpore::pModelNames[] =
Expand Down
9 changes: 8 additions & 1 deletion dlls/monster/CXenTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,19 @@ void CXenTree::Spawn(void)
pev->frame = RANDOM_FLOAT(0, 255);
pev->framerate = RANDOM_FLOAT(0.7, 1.4);

if (FBitSet(pev->spawnflags, SF_XEN_PLANT_DROP_TO_FLOOR))
DropToFloor();

if (FBitSet(pev->flags, FL_KILLME))
return;

Vector triggerPosition;
UTIL_MakeVectorsPrivate(pev->angles, triggerPosition, NULL, NULL);
triggerPosition = pev->origin + (triggerPosition * 64);
// Create the trigger
m_pTrigger = CXenTreeTrigger::TriggerCreate(edict(), triggerPosition);
UTIL_SetSize(m_pTrigger->pev, Vector(-24, -24, 0), Vector(24, 24, 128));
if (m_pTrigger)
UTIL_SetSize(m_pTrigger->pev, Vector(-24, -24, 0), Vector(24, 24, 128));
}

const char* CXenTree::pAttackHitSounds[] =
Expand Down

0 comments on commit 83c3cc7

Please sign in to comment.