Skip to content

Commit

Permalink
Hostage minor fixes
Browse files Browse the repository at this point in the history
Minor cleanup
  • Loading branch information
s1lentq committed Dec 14, 2024
1 parent 1579273 commit f63ad67
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
1 change: 0 additions & 1 deletion regamedll/dlls/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ BOOL gDisplayTitle;
bool g_bIsBeta = false;
bool g_bIsCzeroGame = false;
bool g_bAllowedCSBot = false;
bool g_bHostageImprov = false;
1 change: 0 additions & 1 deletion regamedll/dlls/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ extern BOOL gDisplayTitle;
extern bool g_bIsBeta;
extern bool g_bIsCzeroGame;
extern bool g_bAllowedCSBot;
extern bool g_bHostageImprov;
41 changes: 26 additions & 15 deletions regamedll/dlls/hostage/hostage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "precompiled.h"

cvar_t cv_hostage_ai_enable = { "hostage_ai_enable", "1", 0, 1.0f, nullptr };
cvar_t cv_hostage_ai_enable = { "hostage_ai_enable", "0", 0, 0.0f, nullptr };
cvar_t cv_hostage_debug = { "hostage_debug", "0", FCVAR_SERVER, 0.0f, nullptr };
cvar_t cv_hostage_stop = { "hostage_stop", "0", FCVAR_SERVER, 0.0f, nullptr };

Expand Down Expand Up @@ -269,36 +269,41 @@ void CHostage::Spawn()

void CHostage::Precache()
{
if (AreImprovAllowed())
if (cv_hostage_ai_enable.value)
{
string_t model = iStringNull;

static int which = 0;
switch (which)
{
default:
case REGULAR_GUY:
pev->model = MAKE_STRING("models/hostageA.mdl");
model = MAKE_STRING("models/hostageA.mdl");
break;
case OLD_GUY:
pev->model = MAKE_STRING("models/hostageB.mdl");
model = MAKE_STRING("models/hostageB.mdl");
break;
case BLACK_GUY:
pev->model = MAKE_STRING("models/hostageC.mdl");
model = MAKE_STRING("models/hostageC.mdl");
break;
case GOOFY_GUY:
pev->model = MAKE_STRING("models/hostageD.mdl");
model = MAKE_STRING("models/hostageD.mdl");
break;
}

m_whichModel = static_cast<ModelType>(which);

if (++which > 3)
which = 0;
if (++which > GOOFY_GUY)
which = REGULAR_GUY;

if (!g_pFileSystem->FileExists(pev->model))
if (g_pFileSystem->FileExists(model))
{
pev->model = model;
}
else
{
// It seems that the model is missing, so use classic hostages
g_bHostageImprov = false;
pev->model = iStringNull;
CVAR_SET_FLOAT("hostage_ai_enable", 0);
}
}

Expand Down Expand Up @@ -347,7 +352,7 @@ void CHostage::IdleThink()
const float giveUpTime = (1 / 30.0f);
float const updateRate = 0.1f;

if (AreImprovAllowed() && !TheNavAreaList.empty())
if (cv_hostage_ai_enable.value && !TheNavAreaList.empty())
{
if (!m_improv)
{
Expand Down Expand Up @@ -776,7 +781,7 @@ void CHostage::SetDeathActivity()
return;
}

if (AreImprovAllowed())
if (cv_hostage_ai_enable.value)
{
switch (m_LastHitGroup)
{
Expand Down Expand Up @@ -1402,7 +1407,7 @@ void Hostage_RegisterCVars()
{
// These cvars are only used in czero
#ifdef REGAMEDLL_FIXES
if (!AreImprovAllowed())
if (!cv_hostage_ai_enable.value)
return;
#endif

Expand Down Expand Up @@ -1437,7 +1442,7 @@ void CHostageManager::ServerActivate()
AddHostage(pHostage);
}

if (AreImprovAllowed())
if (cv_hostage_ai_enable.value)
{
for (auto& snd : hostageSoundStruct) {
m_chatter.AddSound(snd.type, snd.fileName);
Expand Down Expand Up @@ -1573,6 +1578,9 @@ void SimpleChatter::AddSound(HostageChatterType type, char *filename)

Q_snprintf(actualFilename, sizeof(actualFilename), "sound\\%s", filename);

if (!g_pFileSystem->FileExists(actualFilename))
return;

chatter->file[chatter->count].filename = CloneString(filename);
chatter->file[chatter->count].duration = (double)GET_APPROX_WAVE_PLAY_LEN(actualFilename) / 1000.0;

Expand Down Expand Up @@ -1610,6 +1618,9 @@ void SimpleChatter::Shuffle(ChatterSet *chatter)
char *SimpleChatter::GetSound(HostageChatterType type, float *duration)
{
ChatterSet *chatter = &m_chatter[type];
if (chatter->count == 0)
return nullptr;

char *sound;

Shuffle(chatter);
Expand Down
6 changes: 0 additions & 6 deletions regamedll/dlls/hostage/hostage.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,5 @@ class CHostageManager
SimpleChatter m_chatter;
};

// Determine whether hostage improv can be used or not
inline bool AreImprovAllowed()
{
return g_bHostageImprov;
}

void Hostage_RegisterCVars();
void InstallHostageManager();
2 changes: 1 addition & 1 deletion regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4173,7 +4173,7 @@ void CBasePlayer::PlayerUse()
}
}

bool useNewHostages = !TheNavAreaList.empty() && AreImprovAllowed();
bool useNewHostages = !TheNavAreaList.empty() && cv_hostage_ai_enable.value;
CBaseEntity *pObject = nullptr;
CBaseEntity *pClosest = nullptr;
Vector vecLOS;
Expand Down
1 change: 0 additions & 1 deletion regamedll/regamedll/regamedll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ void Regamedll_Game_Init()
g_bIsBeta = UTIL_IsBeta();
g_bIsCzeroGame = UTIL_IsGame("czero");
g_bAllowedCSBot = UTIL_AreBotsAllowed(); // determine whether bots can be used or not
g_bHostageImprov = UTIL_AreHostagesImprov(); // determine whether hostage improv can be used or not

WeaponInfoReset();
}

0 comments on commit f63ad67

Please sign in to comment.