Avoid intro camera switching when only 1 trigger_camera available (#873)

* Add UTIL_CountEntities, adjust m_fIntroCamTime assignation
* Moved camera count caching to CheckLevelInitialized
This commit is contained in:
Francisco Muñoz 2023-11-26 01:25:08 -03:00 committed by GitHub
parent 193c1ed52a
commit fba9a335da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 15 deletions

View File

@ -673,10 +673,12 @@ void EXT_FUNC ClientPutInServer(edict_t *pEntity)
CBaseEntity *pTarget = nullptr;
pPlayer->m_pIntroCamera = UTIL_FindEntityByClassname(nullptr, "trigger_camera");
#ifndef REGAMEDLL_FIXES
if (g_pGameRules && g_pGameRules->IsMultiplayer())
{
CSGameRules()->m_bMapHasCameras = (pPlayer->m_pIntroCamera != nullptr);
}
#endif
if (pPlayer->m_pIntroCamera)
{
@ -694,7 +696,12 @@ void EXT_FUNC ClientPutInServer(edict_t *pEntity)
pPlayer->pev->angles = CamAngles;
pPlayer->pev->v_angle = pPlayer->pev->angles;
pPlayer->m_fIntroCamTime = gpGlobals->time + 6;
pPlayer->m_fIntroCamTime =
#ifdef REGAMEDLL_FIXES
(CSGameRules()->m_bMapHasCameras <= 1) ? 0.0 : // no need to refresh cameras if map has only one
#endif
gpGlobals->time + 6;
pPlayer->pev->view_ofs = g_vecZero;
}
#ifndef REGAMEDLL_FIXES

View File

@ -779,7 +779,7 @@ public:
bool m_bMapHasEscapeZone;
BOOL m_bMapHasVIPSafetyZone; // TRUE = has VIP safety zone, FALSE = does not have VIP safetyzone
BOOL m_bMapHasCameras;
int m_bMapHasCameras;
int m_iC4Timer;
int m_iC4Guy; // The current Terrorist who has the C4.
int m_iLoserBonus; // the amount of money the losing team gets. This scales up as they lose more rounds in a row

View File

@ -382,7 +382,7 @@ CHalfLifeMultiplay::CHalfLifeMultiplay()
m_iNumTerrorist = 0;
m_iNumSpawnableCT = 0;
m_iNumSpawnableTerrorist = 0;
m_bMapHasCameras = FALSE;
m_bMapHasCameras = -1;
m_iLoserBonus = m_rgRewardAccountRules[RR_LOSER_BONUS_DEFAULT];
m_iNumConsecutiveCTLoses = 0;
@ -3086,17 +3086,11 @@ void CHalfLifeMultiplay::CheckLevelInitialized()
{
// Count the number of spawn points for each team
// This determines the maximum number of players allowed on each
CBaseEntity *pEnt = nullptr;
m_iSpawnPointCount_Terrorist = 0;
m_iSpawnPointCount_CT = 0;
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "info_player_deathmatch")))
m_iSpawnPointCount_Terrorist++;
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "info_player_start")))
m_iSpawnPointCount_CT++;
m_iSpawnPointCount_Terrorist = UTIL_CountEntities("info_player_deathmatch");
m_iSpawnPointCount_CT = UTIL_CountEntities("info_player_start");
#ifdef REGAMEDLL_FIXES
m_bMapHasCameras = UTIL_CountEntities("trigger_camera");
#endif
m_bLevelInitialized = true;
}
}

View File

@ -3666,7 +3666,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(JoiningThink)()
}
}
if (m_pIntroCamera && gpGlobals->time >= m_fIntroCamTime)
if (m_pIntroCamera && gpGlobals->time >= m_fIntroCamTime
#ifdef REGAMEDLL_FIXES
&& m_fIntroCamTime > 0.0 // update only if cameras are available
#endif
)
{
// find the next another camera
m_pIntroCamera = UTIL_FindEntityByClassname(m_pIntroCamera, "trigger_camera");

View File

@ -1758,6 +1758,17 @@ int UTIL_GetNumPlayers()
return nNumPlayers;
}
int UTIL_CountEntities(const char *szName)
{
int count = 0;
CBaseEntity *pEnt = nullptr;
while ((pEnt = UTIL_FindEntityByClassname(pEnt, szName)))
count++;
return count;
}
bool UTIL_IsSpawnPointOccupied(CBaseEntity *pSpot)
{
if (!pSpot)

View File

@ -297,6 +297,7 @@ bool UTIL_AreBotsAllowed();
bool UTIL_IsBeta();
bool UTIL_AreHostagesImprov();
int UTIL_GetNumPlayers();
int UTIL_CountEntities(const char *szName);
bool UTIL_IsSpawnPointOccupied(CBaseEntity *pSpot);
void MAKE_STRING_CLASS(const char *str, entvars_t *pev);
void NORETURN Sys_Error(const char *error, ...);