Skip to content

Commit

Permalink
Add environment suicide as a suicide, add disconnect check
Browse files Browse the repository at this point in the history
  • Loading branch information
nullsystem committed Aug 18, 2024
1 parent 81cba34 commit ace93d0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 37 deletions.
84 changes: 47 additions & 37 deletions mp/src/game/shared/neo/neo_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,58 +1760,65 @@ static CNEO_Player* FetchAssists(CNEO_Player* attacker, CNEO_Player* victim)
return NULL;
}

#ifdef GAME_DLL
void CNEORules::CheckIfCapPrevent(CNEO_Player *capPreventerPlayer)
{
// If this is the only player alive left before the suicide/disconnect and the other team was holding
// the ghost, reward the other team an XP to the next rank as a ghost cap was prevented.
if (neo_sv_suicide_prevent_cap_punish.GetBool() && m_nRoundStatus == NeoRoundStatus::RoundLive &&
!m_bTeamBeenAwardedDueToCapPrevent)
{
bool bOtherTeamPlayingGhost = false;
int iTallyAlive[TEAM__TOTAL] = {};
const int iPreventerTeam = capPreventerPlayer->GetTeamNumber();
// Santiy check: Make sure it's only Jinrai/NSF players
if (iPreventerTeam == TEAM_JINRAI || iPreventerTeam == TEAM_NSF)
{
for (int i = 1; i <= gpGlobals->maxClients; ++i)
{
auto *player = static_cast<CNEO_Player*>(UTIL_PlayerByIndex(i));
if (!player || player->entindex() == capPreventerPlayer->entindex())
{
continue;
}

const int iPlayerTeam = player->GetTeamNumber();
iTallyAlive[iPlayerTeam] += player->IsAlive();
if (iPlayerTeam != iPreventerTeam && player->IsCarryingGhost())
{
bOtherTeamPlayingGhost = true;
}
}

const int iOppositeTeam = (iPreventerTeam == TEAM_JINRAI) ? TEAM_NSF : TEAM_JINRAI;
m_bTeamBeenAwardedDueToCapPrevent = (bOtherTeamPlayingGhost &&
iTallyAlive[iPreventerTeam] == 0 && iTallyAlive[iOppositeTeam] > 0);
}
}
}
#endif

void CNEORules::PlayerKilled(CBasePlayer *pVictim, const CTakeDamageInfo &info)
{
BaseClass::PlayerKilled(pVictim, info);

auto attacker = dynamic_cast<CNEO_Player*>(info.GetAttacker());
auto victim = dynamic_cast<CNEO_Player*>(pVictim);

if (!attacker || !pVictim)
if (!victim)
{
return;
}

// Suicide
if (attacker == victim)
// Suicide (or suicide by environment)
if ((attacker == victim) || (!attacker && victim))
{
attacker->m_iXP.GetForModify() -= 1;
victim->m_iXP.GetForModify() -= 1;
#ifdef GAME_DLL
// If this is the only player alive left before the suicide and the other team was holding
// the ghost, reward the other team an XP to the next rank as a ghost cap was prevented.
if (neo_sv_suicide_prevent_cap_punish.GetBool() && m_nRoundStatus == NeoRoundStatus::RoundLive &&
!m_bTeamBeenAwardedDueToCapPrevent)
{
bool bOtherTeamPlayingGhost = false;
int iTallyAlive[TEAM__TOTAL] = {};
const int iAttackerTeam = attacker->GetTeamNumber();
// Santiy check: Make sure it's only Jinrai/NSF players
if (iAttackerTeam == TEAM_JINRAI || iAttackerTeam == TEAM_NSF)
{
for (int i = 1; i <= gpGlobals->maxClients; ++i)
{
auto *player = static_cast<CNEO_Player*>(UTIL_PlayerByIndex(i));
if (!player || player->entindex() == attacker->entindex())
{
continue;
}

const int iPlayerTeam = player->GetTeamNumber();
iTallyAlive[iPlayerTeam] += player->IsAlive();
if (iPlayerTeam != iAttackerTeam && player->IsCarryingGhost())
{
bOtherTeamPlayingGhost = true;
}
}

const int iOppositeTeam = (iAttackerTeam == TEAM_JINRAI) ? TEAM_NSF : TEAM_JINRAI;
m_bTeamBeenAwardedDueToCapPrevent = (bOtherTeamPlayingGhost &&
iTallyAlive[iAttackerTeam] == 0 && iTallyAlive[iOppositeTeam] > 0);
}
}
CheckIfCapPrevent(victim);
#endif
}
else
else if (attacker)
{
// Team kill
if (attacker->GetTeamNumber() == victim->GetTeamNumber())
Expand Down Expand Up @@ -2117,6 +2124,9 @@ void CNEORules::ClientDisconnected(edict_t* pClient)
}
}
}

// Check if this is done to prevent ghost cap
CheckIfCapPrevent(pNeoPlayer);
}

BaseClass::ClientDisconnected(pClient);
Expand Down
3 changes: 3 additions & 0 deletions mp/src/game/shared/neo/neo_gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class CNEORules : public CHL2MPRules, public CGameEventListener

float GetRoundRemainingTime();

#ifdef GAME_DLL
void CheckIfCapPrevent(CNEO_Player *capPreventerPlayer);
#endif
virtual void PlayerKilled(CBasePlayer *pVictim, const CTakeDamageInfo &info) OVERRIDE;

// IGameEventListener interface:
Expand Down

0 comments on commit ace93d0

Please sign in to comment.