Skip to content

Commit

Permalink
Fixes & tweaks (#41)
Browse files Browse the repository at this point in the history
fixes:
    monsters on moving platforms
    tentacle interpolation
    osprey twitching
    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 Dec 9, 2024
1 parent d15a8fa commit 99ae78c
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 27 deletions.
12 changes: 8 additions & 4 deletions cl_dll/StudioModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ void CStudioModelRenderer::StudioSetUpTransform (int trivial_accept)
{
float f = 0;
float d;
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pCurrentEntity->curstate.sequence;//acess to studio flags

// don't do it if the goalstarttime hasn't updated in a while.

Expand All @@ -471,10 +472,13 @@ void CStudioModelRenderer::StudioSetUpTransform (int trivial_accept)
f = 0;
}

for (i = 0; i < 3; i++)
{
modelpos[i] += (m_pCurrentEntity->origin[i] - m_pCurrentEntity->latched.prevorigin[i]) * f;
}
#if 1
if (pseqdesc->motiontype & STUDIO_LX || m_pCurrentEntity->curstate.eflags & EFLAG_SLERP)
#endif
for( i = 0; i < 3; i++ )
{
modelpos[i] += ( m_pCurrentEntity->origin[i] - m_pCurrentEntity->latched.prevorigin[i] ) * f;
}

// NOTE: Because multiplayer lag can be relatively large, we don't want to cap
// f at 1.5 anymore.
Expand Down
1 change: 1 addition & 0 deletions dlls/CBaseEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CKeyValue GetEntvarsKeyvalue(entvars_t* pev, const char* keyName);
TYPEDESCRIPTION CBaseEntity::m_SaveData[] =
{
DEFINE_FIELD(CBaseEntity, m_hGoalEnt, FIELD_EHANDLE),
DEFINE_FIELD(CBaseEntity, m_EFlags, FIELD_CHARACTER),

DEFINE_FIELD(CBaseEntity, m_pfnThink, FIELD_FUNCTION), // UNDONE: Build table of these!!!
DEFINE_FIELD(CBaseEntity, m_pfnTouch, FIELD_FUNCTION),
Expand Down
4 changes: 3 additions & 1 deletion dlls/CBaseEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class EXPORT CBaseEntity

// path corners
EHANDLE m_hGoalEnt;// path corner we are heading towards
EHANDLE m_hLink;// used for temporary link-list operations.
EHANDLE m_hLink;// used for temporary link-list operations.

byte m_EFlags;

// initialization functions
virtual void Spawn(void) { return; }
Expand Down
12 changes: 11 additions & 1 deletion dlls/hooks/hlds_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,14 +1310,24 @@ int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *h

// This non-player entity is being moved by the game .dll and not the physics simulation system
// make sure that we interpolate it's position on the client if it moves
if ( !player &&
#if 0
if( !player &&
ent->v.animtime &&
ent->v.velocity[ 0 ] == 0 &&
ent->v.velocity[ 1 ] == 0 &&
ent->v.velocity[ 2 ] == 0 )
{
state->eflags |= EFLAG_SLERP;
}
#else
if(ent->v.flags & FL_FLY )
state->eflags |= EFLAG_SLERP;
else state->eflags &= ~EFLAG_SLERP;

CBaseEntity* pEntity = (CBaseEntity*)GET_PRIVATE(ent);
if (pEntity)
state->eflags |= pEntity->m_EFlags;
#endif

state->scale = ent->v.scale;
state->solid = ent->v.solid;
Expand Down
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
2 changes: 1 addition & 1 deletion dlls/monster/CNihilanth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void CNihilanth :: Spawn( void )
SetSize(Vector( -32, -32, 0), Vector(32, 32, 64));
UTIL_SetOrigin( pev, pev->origin );

pev->flags |= FL_MONSTER;
pev->flags |= FL_MONSTER | FL_FLY;
pev->takedamage = DAMAGE_AIM;
SetHealth();
pev->view_ofs = Vector( 0, 0, 300 );
Expand Down
34 changes: 23 additions & 11 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 @@ -154,7 +155,7 @@ void COsprey :: Spawn( void )
SetSize(Vector( -480, -480, -100), Vector(480, 480, 64));
UTIL_SetOrigin( pev, pev->origin );

pev->flags |= FL_MONSTER;
pev->flags |= FL_MONSTER | FL_FLY;
pev->takedamage = DAMAGE_YES;

SetHealth();
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
2 changes: 2 additions & 0 deletions dlls/monster/CTentacle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ void CTentacle :: Spawn( )
SetHealth();
pev->sequence = 0;

m_EFlags |= EFLAG_SLERP; //Always interpolate tentacles since they don't actually move.

m_spawnHealth = pev->health;

InitModel();
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
Loading

0 comments on commit 99ae78c

Please sign in to comment.