From 21b0689030ea393b1b57b8a73faef90a96f304dd Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 15 Jun 2016 20:10:40 +0700 Subject: [PATCH] Moved SelectDefaultTeam the function to CHalfLifeMultiplay. --- regamedll/dlls/bot/cs_bot_manager.cpp | 5 +-- regamedll/dlls/client.cpp | 60 +------------------------- regamedll/dlls/client.h | 1 - regamedll/dlls/gamerules.h | 1 + regamedll/dlls/multiplay_gamerules.cpp | 42 ++++++++++++++++++ regamedll/extra/cssdk/dlls/gamerules.h | 1 + regamedll/hookers/6153_hooker.cpp | 2 +- 7 files changed, 48 insertions(+), 64 deletions(-) diff --git a/regamedll/dlls/bot/cs_bot_manager.cpp b/regamedll/dlls/bot/cs_bot_manager.cpp index dfe51683..9a253759 100644 --- a/regamedll/dlls/bot/cs_bot_manager.cpp +++ b/regamedll/dlls/bot/cs_bot_manager.cpp @@ -790,8 +790,7 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole) team = BOT_TEAM_CT; else { - TeamName defaultTeam = SelectDefaultTeam(); - + TeamName defaultTeam = CSGameRules()->SelectDefaultTeam(); if (defaultTeam == TERRORIST) team = BOT_TEAM_T; @@ -1175,7 +1174,7 @@ bool CCSBotManager::AddBot(const BotProfile *profile, BotProfileTeamType team) if (nTeamSlot == UNASSIGNED) { - nTeamSlot = SelectDefaultTeam(); + nTeamSlot = CSGameRules()->SelectDefaultTeam(); } if (nTeamSlot == UNASSIGNED || CSGameRules()->TeamFull(nTeamSlot)) diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 4a96587b..236600d7 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -388,63 +388,6 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer) } } -TeamName SelectDefaultTeam() -{ - TeamName team = UNASSIGNED; - - if (CSGameRules()->m_iNumTerrorist < CSGameRules()->m_iNumCT) - { - team = TERRORIST; - } - else if (CSGameRules()->m_iNumTerrorist > CSGameRules()->m_iNumCT) - { - team = CT; - } - // Choose the team that's losing - else if (CSGameRules()->m_iNumTerroristWins < CSGameRules()->m_iNumCTWins) - { - team = TERRORIST; - } - else if (CSGameRules()->m_iNumCTWins < CSGameRules()->m_iNumTerroristWins) - { - team = CT; - } - else - { - // Teams and scores are equal, pick a random team - if (RANDOM_LONG(0, 1) == 0) - { - team = CT; - } - else - { - team = TERRORIST; - } - } - - if (CSGameRules()->TeamFull(team)) - { - // Pick the opposite team - if (team == TERRORIST) - { - team = CT; - } - else - { - team = TERRORIST; - } - - // No choices left - if (CSGameRules()->TeamFull(team)) - { - return UNASSIGNED; - } - } - - return team; - -} - void CheckStartMoney() { int money = int(startmoney.value); @@ -1594,8 +1537,7 @@ BOOL __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *player, int slot) case MENU_SLOT_TEAM_RANDOM: { // Attempt to auto-select a team - team = SelectDefaultTeam(); - + team = CSGameRules()->SelectDefaultTeam(); if (team == UNASSIGNED) { if (cv_bot_auto_vacate.value > 0.0f && !player->IsBot()) diff --git a/regamedll/dlls/client.h b/regamedll/dlls/client.h index 5163d4c8..3d5ab561 100644 --- a/regamedll/dlls/client.h +++ b/regamedll/dlls/client.h @@ -125,7 +125,6 @@ void ShowVGUIMenu(CBasePlayer *pPlayer, int MenuType, int BitMask, char *szOldMe void ShowVGUIMenu_(CBasePlayer *pPlayer, int MenuType, int BitMask, char *szOldMenu); void ListPlayers(CBasePlayer *current); void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer); -TeamName SelectDefaultTeam(); void CheckStartMoney(); void ClientPutInServer(edict_t *pEntity); int Q_strlen_(const char *str); diff --git a/regamedll/dlls/gamerules.h b/regamedll/dlls/gamerules.h index b2f61658..f927e376 100644 --- a/regamedll/dlls/gamerules.h +++ b/regamedll/dlls/gamerules.h @@ -632,6 +632,7 @@ public: // BOMB MAP FUNCTIONS VFUNC BOOL IsThereABomber(); VFUNC BOOL IsThereABomb(); + VFUNC TeamName SelectDefaultTeam(); bool IsMatchStarted() { return (m_fTeamCount != 0.0f || m_fCareerRoundMenuTime != 0.0f || m_fCareerMatchMenuTime != 0.0f); } void SendMOTDToClient(edict_t *client); diff --git a/regamedll/dlls/multiplay_gamerules.cpp b/regamedll/dlls/multiplay_gamerules.cpp index 7bca3561..e8257c77 100644 --- a/regamedll/dlls/multiplay_gamerules.cpp +++ b/regamedll/dlls/multiplay_gamerules.cpp @@ -4879,3 +4879,45 @@ void CHalfLifeMultiplay::ServerActivate() ReadMultiplayCvars(); CheckMapConditions(); } + +TeamName CHalfLifeMultiplay::SelectDefaultTeam() +{ + TeamName team = UNASSIGNED; + if (m_iNumTerrorist < m_iNumCT) + { + team = TERRORIST; + } + else if (m_iNumTerrorist > m_iNumCT) + { + team = CT; + } + // Choose the team that's losing + else if (m_iNumTerroristWins < m_iNumCTWins) + { + team = TERRORIST; + } + else if (m_iNumCTWins < m_iNumTerroristWins) + { + team = CT; + } + else + { + // Teams and scores are equal, pick a random team + team = (RANDOM_LONG(0, 1) == 0) ? CT : TERRORIST; + } + + if (TeamFull(team)) + { + // Pick the opposite team + team = (team == TERRORIST) ? CT : TERRORIST; + + // No choices left + if (TeamFull(team)) + { + return UNASSIGNED; + } + } + + return team; + +} \ No newline at end of file diff --git a/regamedll/extra/cssdk/dlls/gamerules.h b/regamedll/extra/cssdk/dlls/gamerules.h index 16e01d59..f57a3faf 100644 --- a/regamedll/extra/cssdk/dlls/gamerules.h +++ b/regamedll/extra/cssdk/dlls/gamerules.h @@ -421,6 +421,7 @@ public: // BOMB MAP FUNCTIONS virtual BOOL IsThereABomber() = 0; virtual BOOL IsThereABomb() = 0; + virtual TeamName SelectDefaultTeam() = 0; virtual bool HasRoundTimeExpired() = 0; virtual bool IsBombPlanted() = 0; diff --git a/regamedll/hookers/6153_hooker.cpp b/regamedll/hookers/6153_hooker.cpp index 206f2eef..de701693 100644 --- a/regamedll/hookers/6153_hooker.cpp +++ b/regamedll/hookers/6153_hooker.cpp @@ -272,7 +272,7 @@ FunctionHook g_FunctionHooks[] = { 0x01D64260, "_Z11ListPlayersP11CBasePlayer", (size_t)&ListPlayers }, { 0x01D64460, "CountTeamPlayers", (size_t)&CountTeamPlayers }, //extern c func { 0x01D64580, "_Z15ProcessKickVoteP11CBasePlayerS0_", (size_t)&ProcessKickVote }, - { 0x01D64920, "_Z17SelectDefaultTeamv", (size_t)&SelectDefaultTeam }, + //{ 0x01D64920, "_Z17SelectDefaultTeamv", (size_t)&SelectDefaultTeam }, { 0x01D649A0, "_Z15CheckStartMoneyv", (size_t)&CheckStartMoney }, { 0x01D649F0, "_Z17ClientPutInServerP7edict_s", (size_t)&ClientPutInServer }, { 0x01D64F00, "Q_strlen", (size_t)&Q_strlen_ },