Skip to content

Commit

Permalink
Get rid of scientist_total_heads value. Calculate the number of heads…
Browse files Browse the repository at this point in the history
… at runtime
  • Loading branch information
FreeSlave committed Jul 6, 2023
1 parent 2420287 commit e8bfc11
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
29 changes: 29 additions & 0 deletions dlls/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,32 @@ int GetBodygroup( void *pmodel, entvars_t *pev, int iGroup )

return iCurrent;
}

int GetBodyCount( void *pmodel )
{
studiohdr_t *pstudiohdr = (studiohdr_t *)pmodel;
if( !pstudiohdr )
return 0;

int bodiesNum = 1;
mstudiobodyparts_t *pbodypart = (mstudiobodyparts_t *)( (byte *)pstudiohdr + pstudiohdr->bodypartindex );

for (int j=0; j<pstudiohdr->numbodyparts; ++j)
{
bodiesNum = bodiesNum * pbodypart[j].nummodels;
}
return bodiesNum;
}

int GetBodygroupNumModels(void *pmodel , int iGroup)
{
studiohdr_t *pstudiohdr = (studiohdr_t *)pmodel;
if( !pstudiohdr )
return 0;

if( iGroup > pstudiohdr->numbodyparts )
return 0;

mstudiobodyparts_t *pbodypart = (mstudiobodyparts_t *)( (byte *)pstudiohdr + pstudiohdr->bodypartindex ) + iGroup;
return pbodypart->nummodels;
}
2 changes: 2 additions & 0 deletions dlls/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void SequencePrecache( void *pmodel, const char *pSequenceName );
int FindTransition( void *pmodel, int iEndingAnim, int iGoalAnim, int *piDir );
void SetBodygroup( void *pmodel, entvars_t *pev, int iGroup, int iValue );
int GetBodygroup( void *pmodel, entvars_t *pev, int iGroup );
int GetBodyCount( void *pmodel );
int GetBodygroupNumModels( void *pmodel, int iGroup );

int GetAnimationEvent(void *pmodel, entvars_t *pev, MonsterEvent_t *pMonsterEvent, float flStart, float flEnd, int index, int& latestAnimEventFrame , int minAnimEventFrame);
int ExtractBbox( void *pmodel, int sequence, float *mins, float *maxs );
Expand Down
2 changes: 0 additions & 2 deletions dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ ModFeatures::ModFeatures()
shockroach_racex_classify = false;

scientist_random_heads = 4;
scientist_total_heads = FEATURE_OPFOR_SPECIFIC ? 6 : scientist_random_heads;

vortigaunt_coil_attack = true;
vortigaunt_idle_effects = false;
Expand Down Expand Up @@ -141,7 +140,6 @@ bool ModFeatures::SetValue(const char *key, const char *value)
}

KeyValueDefinition<int> integers[] = {
KEY_VALUE_DEF(scientist_total_heads),
KEY_VALUE_DEF(scientist_random_heads),
};

Expand Down
1 change: 0 additions & 1 deletion dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ struct ModFeatures
bool racex_dislike_alien_monsters;
bool shockroach_racex_classify;

int scientist_total_heads;
int scientist_random_heads;

bool vortigaunt_coil_attack;
Expand Down
37 changes: 36 additions & 1 deletion dlls/scientist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class CScientist : public CTalkMonster
int GetDefaultVoicePitch();
void Spawn( void );
void Precache( void );
void CalcTotalHeadCount();

void SetYawSpeed( void );
int DefaultClassify( void );
Expand Down Expand Up @@ -135,7 +136,7 @@ class CScientist : public CTalkMonster
return g_modFeatures.scientist_random_heads;
}
virtual int TotalHeadCount() {
return g_modFeatures.scientist_total_heads;
return m_totalHeadCount > 0 ? m_totalHeadCount : 4;
}
bool NeedleIsEquiped() {
return pev->body >= TotalHeadCount();
Expand All @@ -153,6 +154,9 @@ class CScientist : public CTalkMonster
float m_painTime;
float m_healTime;
float m_fearTime;

// Don't save
int m_totalHeadCount;
};

LINK_ENTITY_TO_CLASS( monster_scientist, CScientist )
Expand Down Expand Up @@ -768,6 +772,7 @@ int CScientist::GetDefaultVoicePitch()
void CScientist::Spawn()
{
SciSpawnHelper("models/scientist.mdl", gSkillData.scientistHealth);
CalcTotalHeadCount();

// White hands
pev->skin = 0;
Expand Down Expand Up @@ -795,6 +800,17 @@ void CScientist::Precache( void )
CTalkMonster::Precache();
RegisterTalkMonster();
RegisterMedic();

CalcTotalHeadCount();
}

void CScientist::CalcTotalHeadCount()
{
if (pev->modelindex)
{
// Divide by 2 to account for body variants with the needle
m_totalHeadCount = GetBodyCount( GET_MODEL_PTR(ENT(pev)) ) / 2;
}
}

void CScientist::PrecacheSounds()
Expand Down Expand Up @@ -1343,6 +1359,7 @@ void CSittingScientist::SciSpawnHelper(const char* modelName)
void CSittingScientist::Spawn( )
{
SciSpawnHelper("models/scientist.mdl");
CalcTotalHeadCount();
// Luther is black, make his hands black
if ( pev->body == HEAD_LUTHER )
pev->skin = 1;
Expand All @@ -1353,6 +1370,7 @@ void CSittingScientist::Precache( void )
m_baseSequence = LookupSequence( "sitlookleft" );
TalkInit();
RegisterTalkMonster(false);
CalcTotalHeadCount();
}

//=========================================================
Expand Down Expand Up @@ -1521,6 +1539,21 @@ int CSittingScientist::FIdleSpeak( void )
class CCleansuitScientist : public CScientist
{
public:
int GetDefaultVoicePitch()
{
switch( pev->body )
{
default:
case HEAD_GLASSES:
return 105;
case HEAD_EINSTEIN:
return 100;
case HEAD_LUTHER:
return 95;
case HEAD_SLICK:
return 100;
}
}
void Spawn();
void Precache();
bool IsEnabledInMod() { return g_modFeatures.IsMonsterEnabled("cleansuit_scientist"); }
Expand Down Expand Up @@ -1634,6 +1667,7 @@ void CRosenberg::Spawn()
SciSpawnHelper("models/scientist_rosenberg.mdl", gSkillData.scientistHealth * 2);
#else
SciSpawnHelper("models/scientist.mdl", gSkillData.scientistHealth * 2);
CalcTotalHeadCount();
pev->body = 3;
#endif
TalkMonsterInit();
Expand All @@ -1645,6 +1679,7 @@ void CRosenberg::Precache()
PrecacheMyModel("models/scientist_rosenberg.mdl");
#else
PrecacheMyModel("models/scientist.mdl");
CalcTotalHeadCount();
#endif
PRECACHE_SOUND( "rosenberg/ro_pain0.wav" );
PRECACHE_SOUND( "rosenberg/ro_pain1.wav" );
Expand Down
3 changes: 0 additions & 3 deletions features/featureful_server.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ shockroach_racex_classify false
// SCIENTISTS
/////////
// Total scientist head count. Used when calculating the right body state (with or without needle on). Set it to 6 for Opposing Force scientist model.
scientist_total_heads 4
// Scientist head count used for randomizing when body is set to -1
scientist_random_heads 4
Expand Down

0 comments on commit e8bfc11

Please sign in to comment.