From e2c90c0b0e67d14a0439944cc66ea99cf7d9564a Mon Sep 17 00:00:00 2001 From: Pinsplash <39359267+Pinsplash@users.noreply.github.com> Date: Sun, 11 Jun 2023 23:31:22 -0500 Subject: [PATCH] small tidying --- sp/src/game/server/hl2/hl2_player.cpp | 32 +++++++++++---------------- sp/src/game/server/hl2/hl2_player.h | 1 + 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/sp/src/game/server/hl2/hl2_player.cpp b/sp/src/game/server/hl2/hl2_player.cpp index 400ec912..c3f755cf 100644 --- a/sp/src/game/server/hl2/hl2_player.cpp +++ b/sp/src/game/server/hl2/hl2_player.cpp @@ -1170,20 +1170,24 @@ void CHL2_Player::Event_PreSaveGameLoaded(char const *pSaveName, bool bInGame) //might end up not being able to see anything engine->ClientCommand(engine->PEntityOfEntIndex(1), "r_lockpvs 0; exec portalsopenall\n"); } - -void CHL2_Player::ResetVotes() +int CHL2_Player::FindWeightSum() { - g_iVoteNumber++; int iWeightSum = 0; + CChaosEffect *pEffect; for (int i = 1; i < NUM_EFFECTS; i++) { - if (chaos_print_rng.GetBool()) Msg("i %i, %s %i += %i\n", i, STRING(g_ChaosEffects[i]->m_strGeneralName), iWeightSum, g_ChaosEffects[i]->m_iCurrentWeight); - iWeightSum += g_ChaosEffects[i]->m_iCurrentWeight; + pEffect = g_ChaosEffects[i]; + if (chaos_print_rng.GetBool()) Msg("i %i, %s %i += %i\n", i, STRING(pEffect->m_strGeneralName), iWeightSum, pEffect->m_iCurrentWeight); + iWeightSum += pEffect->m_iCurrentWeight; //recover weight for recent effects //add a fraction of the maximum weight on every interval - if (!EffectOrGroupAlreadyActive(i) && g_ChaosEffects[i]->m_iCurrentWeight < g_ChaosEffects[i]->m_iMaxWeight) - g_ChaosEffects[i]->m_iCurrentWeight = min(g_ChaosEffects[i]->m_iCurrentWeight + g_ChaosEffects[i]->m_iMaxWeight * 0.2, g_ChaosEffects[i]->m_iMaxWeight); + if (!EffectOrGroupAlreadyActive(i) && pEffect->m_iCurrentWeight < pEffect->m_iMaxWeight) + pEffect->m_iCurrentWeight = min(pEffect->m_iCurrentWeight + pEffect->m_iMaxWeight * 0.2, pEffect->m_iMaxWeight); } +} +void CHL2_Player::ResetVotes() +{ + int iWeightSum = FindWeightSum(); //choose effects to nominate for (int i = 0; i < 4; i++) { @@ -1251,23 +1255,13 @@ void CHL2_Player::PreThink(void) int nID = 0; if (!chaos_vote_enable.GetBool()) { - int iWeightSum = 0; - CChaosEffect *pEffect; - for (int i = 1; i < NUM_EFFECTS; i++) - { - pEffect = g_ChaosEffects[i]; - if (chaos_print_rng.GetBool()) Msg("i %i, %s %i += %i\n", i, STRING(pEffect->m_strGeneralName), iWeightSum, pEffect->m_iCurrentWeight); - iWeightSum += pEffect->m_iCurrentWeight; - //recover weight for recent effects - //add a fraction of the maximum weight on every interval - if (!EffectOrGroupAlreadyActive(i) && pEffect->m_iCurrentWeight < pEffect->m_iMaxWeight) - pEffect->m_iCurrentWeight = min(pEffect->m_iCurrentWeight + pEffect->m_iMaxWeight * 0.2, pEffect->m_iMaxWeight); - } + int iWeightSum = FindWeightSum(); nID = PickEffect(iWeightSum); } else { nID = GetVoteWinnerEffect(); + //TODO: ResetVotes should probably be in here } g_flEffectThinkRem = 0; //send to HUD diff --git a/sp/src/game/server/hl2/hl2_player.h b/sp/src/game/server/hl2/hl2_player.h index ed5c586e..77422f7f 100644 --- a/sp/src/game/server/hl2/hl2_player.h +++ b/sp/src/game/server/hl2/hl2_player.h @@ -106,6 +106,7 @@ public: void ReplaceEffects(); void RemoveDeadEnts(); void SpawnStoredEnts(); + int FindWeightSum(); CHL2_Player(); ~CHL2_Player( void );