Moved SelectDefaultTeam the function to CHalfLifeMultiplay.

This commit is contained in:
s1lentq 2016-06-15 20:10:40 +07:00
parent aaf1d9648e
commit 21b0689030
7 changed files with 48 additions and 64 deletions

View File

@ -790,8 +790,7 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
team = BOT_TEAM_CT; team = BOT_TEAM_CT;
else else
{ {
TeamName defaultTeam = SelectDefaultTeam(); TeamName defaultTeam = CSGameRules()->SelectDefaultTeam();
if (defaultTeam == TERRORIST) if (defaultTeam == TERRORIST)
team = BOT_TEAM_T; team = BOT_TEAM_T;
@ -1175,7 +1174,7 @@ bool CCSBotManager::AddBot(const BotProfile *profile, BotProfileTeamType team)
if (nTeamSlot == UNASSIGNED) if (nTeamSlot == UNASSIGNED)
{ {
nTeamSlot = SelectDefaultTeam(); nTeamSlot = CSGameRules()->SelectDefaultTeam();
} }
if (nTeamSlot == UNASSIGNED || CSGameRules()->TeamFull(nTeamSlot)) if (nTeamSlot == UNASSIGNED || CSGameRules()->TeamFull(nTeamSlot))

View File

@ -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() void CheckStartMoney()
{ {
int money = int(startmoney.value); int money = int(startmoney.value);
@ -1594,8 +1537,7 @@ BOOL __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *player, int slot)
case MENU_SLOT_TEAM_RANDOM: case MENU_SLOT_TEAM_RANDOM:
{ {
// Attempt to auto-select a team // Attempt to auto-select a team
team = SelectDefaultTeam(); team = CSGameRules()->SelectDefaultTeam();
if (team == UNASSIGNED) if (team == UNASSIGNED)
{ {
if (cv_bot_auto_vacate.value > 0.0f && !player->IsBot()) if (cv_bot_auto_vacate.value > 0.0f && !player->IsBot())

View File

@ -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 ShowVGUIMenu_(CBasePlayer *pPlayer, int MenuType, int BitMask, char *szOldMenu);
void ListPlayers(CBasePlayer *current); void ListPlayers(CBasePlayer *current);
void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer); void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer);
TeamName SelectDefaultTeam();
void CheckStartMoney(); void CheckStartMoney();
void ClientPutInServer(edict_t *pEntity); void ClientPutInServer(edict_t *pEntity);
int Q_strlen_(const char *str); int Q_strlen_(const char *str);

View File

@ -632,6 +632,7 @@ public:
// BOMB MAP FUNCTIONS // BOMB MAP FUNCTIONS
VFUNC BOOL IsThereABomber(); VFUNC BOOL IsThereABomber();
VFUNC BOOL IsThereABomb(); VFUNC BOOL IsThereABomb();
VFUNC TeamName SelectDefaultTeam();
bool IsMatchStarted() { return (m_fTeamCount != 0.0f || m_fCareerRoundMenuTime != 0.0f || m_fCareerMatchMenuTime != 0.0f); } bool IsMatchStarted() { return (m_fTeamCount != 0.0f || m_fCareerRoundMenuTime != 0.0f || m_fCareerMatchMenuTime != 0.0f); }
void SendMOTDToClient(edict_t *client); void SendMOTDToClient(edict_t *client);

View File

@ -4879,3 +4879,45 @@ void CHalfLifeMultiplay::ServerActivate()
ReadMultiplayCvars(); ReadMultiplayCvars();
CheckMapConditions(); 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;
}

View File

@ -421,6 +421,7 @@ public:
// BOMB MAP FUNCTIONS // BOMB MAP FUNCTIONS
virtual BOOL IsThereABomber() = 0; virtual BOOL IsThereABomber() = 0;
virtual BOOL IsThereABomb() = 0; virtual BOOL IsThereABomb() = 0;
virtual TeamName SelectDefaultTeam() = 0;
virtual bool HasRoundTimeExpired() = 0; virtual bool HasRoundTimeExpired() = 0;
virtual bool IsBombPlanted() = 0; virtual bool IsBombPlanted() = 0;

View File

@ -272,7 +272,7 @@ FunctionHook g_FunctionHooks[] =
{ 0x01D64260, "_Z11ListPlayersP11CBasePlayer", (size_t)&ListPlayers }, { 0x01D64260, "_Z11ListPlayersP11CBasePlayer", (size_t)&ListPlayers },
{ 0x01D64460, "CountTeamPlayers", (size_t)&CountTeamPlayers }, //extern c func { 0x01D64460, "CountTeamPlayers", (size_t)&CountTeamPlayers }, //extern c func
{ 0x01D64580, "_Z15ProcessKickVoteP11CBasePlayerS0_", (size_t)&ProcessKickVote }, { 0x01D64580, "_Z15ProcessKickVoteP11CBasePlayerS0_", (size_t)&ProcessKickVote },
{ 0x01D64920, "_Z17SelectDefaultTeamv", (size_t)&SelectDefaultTeam }, //{ 0x01D64920, "_Z17SelectDefaultTeamv", (size_t)&SelectDefaultTeam },
{ 0x01D649A0, "_Z15CheckStartMoneyv", (size_t)&CheckStartMoney }, { 0x01D649A0, "_Z15CheckStartMoneyv", (size_t)&CheckStartMoney },
{ 0x01D649F0, "_Z17ClientPutInServerP7edict_s", (size_t)&ClientPutInServer }, { 0x01D649F0, "_Z17ClientPutInServerP7edict_s", (size_t)&ClientPutInServer },
{ 0x01D64F00, "Q_strlen", (size_t)&Q_strlen_ }, { 0x01D64F00, "Q_strlen", (size_t)&Q_strlen_ },