Skip to content

Commit

Permalink
Avoid intro camera switching when only 1 trigger_camera available (#873)
Browse files Browse the repository at this point in the history
* Add UTIL_CountEntities, adjust m_fIntroCamTime assignation
* Moved camera count caching to CheckLevelInitialized
  • Loading branch information
dystopm authored Nov 26, 2023
1 parent 193c1ed commit fba9a33
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
9 changes: 8 additions & 1 deletion regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ class CHalfLifeMultiplay: public CGameRules
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
Expand Down
18 changes: 6 additions & 12 deletions regamedll/dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
6 changes: 5 additions & 1 deletion regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
11 changes: 11 additions & 0 deletions regamedll/dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);
Expand Down

0 comments on commit fba9a33

Please sign in to comment.