Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid intro camera switching when only 1 trigger_camera available #873

Merged
merged 4 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3673,7 +3673,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