hlsdk-xash3d/dlls/teamplay_gamerules.cpp

635 lines
16 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
//
// teamplay_gamerules.cpp
//
2016-06-04 15:24:23 +02:00
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "player.h"
#include "weapons.h"
#include "gamerules.h"
#include "teamplay_gamerules.h"
#include "game.h"
static char team_names[MAX_TEAMS][MAX_TEAMNAME_LENGTH];
static int team_scores[MAX_TEAMS];
static int num_teams = 0;
extern DLL_GLOBAL BOOL g_fGameOver;
2016-07-31 15:48:50 +02:00
CHalfLifeTeamplay::CHalfLifeTeamplay()
2016-06-04 15:24:23 +02:00
{
m_DisableDeathMessages = FALSE;
m_DisableDeathPenalty = FALSE;
memset( team_names, 0, sizeof(team_names) );
memset( team_scores, 0, sizeof(team_scores) );
num_teams = 0;
// Copy over the team from the server config
m_szTeamList[0] = 0;
// Cache this because the team code doesn't want to deal with changing this in the middle of a game
2022-11-14 04:47:47 +01:00
strncpy( m_szTeamList, teamlist.string, TEAMPLAY_TEAMLISTLENGTH - 1 );
m_szTeamList[TEAMPLAY_TEAMLISTLENGTH - 1] = '\0';
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
edict_t *pWorld = INDEXENT( 0 );
if( pWorld && pWorld->v.team )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( teamoverride.value )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
const char *pTeamList = STRING( pWorld->v.team );
2019-09-24 00:00:37 +02:00
if( pTeamList && pTeamList[0] != '\0' )
2016-06-04 15:24:23 +02:00
{
2022-11-14 04:47:47 +01:00
strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH - 1 );
m_szTeamList[TEAMPLAY_TEAMLISTLENGTH - 1] = '\0';
2016-06-04 15:24:23 +02:00
}
}
}
// Has the server set teams
2019-09-24 00:00:37 +02:00
if( m_szTeamList[0] != '\0' )
2016-06-04 15:24:23 +02:00
m_teamLimit = TRUE;
else
m_teamLimit = FALSE;
RecountTeams();
}
extern cvar_t timeleft, fragsleft;
2021-06-07 02:05:58 +02:00
#if !NO_VOICEGAMEMGR
2016-06-04 15:24:23 +02:00
#include "voice_gamemgr.h"
2016-07-31 15:48:50 +02:00
extern CVoiceGameMgr g_VoiceGameMgr;
2016-06-12 22:43:32 +02:00
#endif
2016-07-31 15:48:50 +02:00
void CHalfLifeTeamplay::Think( void )
2016-06-04 15:24:23 +02:00
{
///// Check game rules /////
static int last_frags;
static int last_time;
int frags_remaining = 0;
int time_remaining = 0;
2021-06-07 02:05:58 +02:00
#if !NO_VOICEGAMEMGR
2016-06-04 15:24:23 +02:00
g_VoiceGameMgr.Update(gpGlobals->frametime);
2016-06-12 22:43:32 +02:00
#endif
2016-07-31 15:48:50 +02:00
if( g_fGameOver ) // someone else quit the game already
2016-06-04 15:24:23 +02:00
{
CHalfLifeMultiplay::Think();
return;
}
2016-07-31 15:48:50 +02:00
float flTimeLimit = CVAR_GET_FLOAT( "mp_timelimit" ) * 60;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
time_remaining = (int)( flTimeLimit ? ( flTimeLimit - gpGlobals->time ) : 0 );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( flTimeLimit != 0 && gpGlobals->time >= flTimeLimit )
2016-06-04 15:24:23 +02:00
{
GoToIntermission();
return;
}
float flFragLimit = fraglimit.value;
2016-07-31 15:48:50 +02:00
if( flFragLimit )
2016-06-04 15:24:23 +02:00
{
int bestfrags = 9999;
int remain;
// check if any team is over the frag limit
2016-07-31 15:48:50 +02:00
for( int i = 0; i < num_teams; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( team_scores[i] >= flFragLimit )
2016-06-04 15:24:23 +02:00
{
GoToIntermission();
return;
}
2017-06-29 15:56:03 +02:00
remain = (int)( flFragLimit - team_scores[i] );
2016-07-31 15:48:50 +02:00
if( remain < bestfrags )
2016-06-04 15:24:23 +02:00
{
bestfrags = remain;
}
}
frags_remaining = bestfrags;
}
// Updates when frags change
2016-07-31 15:48:50 +02:00
if( frags_remaining != last_frags )
2016-06-04 15:24:23 +02:00
{
g_engfuncs.pfnCvar_DirectSet( &fragsleft, UTIL_VarArgs( "%i", frags_remaining ) );
}
// Updates once per second
2016-07-31 15:48:50 +02:00
if( timeleft.value != last_time )
2016-06-04 15:24:23 +02:00
{
g_engfuncs.pfnCvar_DirectSet( &timeleft, UTIL_VarArgs( "%i", time_remaining ) );
}
last_frags = frags_remaining;
2016-07-31 15:48:50 +02:00
last_time = time_remaining;
2016-06-04 15:24:23 +02:00
}
//=========================================================
// ClientCommand
// the user has typed a command which is unrecognized by everything else;
// this check to see if the gamerules knows anything about the command
//=========================================================
2016-07-31 15:48:50 +02:00
BOOL CHalfLifeTeamplay::ClientCommand( CBasePlayer *pPlayer, const char *pcmd )
2016-06-04 15:24:23 +02:00
{
2021-06-07 02:05:58 +02:00
#if !NO_VOICEGAMEMGR
2016-07-31 15:48:50 +02:00
if( g_VoiceGameMgr.ClientCommand( pPlayer, pcmd ) )
2016-06-04 15:24:23 +02:00
return TRUE;
2016-06-12 22:43:32 +02:00
#endif
2016-07-31 15:48:50 +02:00
if( FStrEq( pcmd, "menuselect" ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( CMD_ARGC() < 2 )
2016-06-04 15:24:23 +02:00
return TRUE;
2017-06-29 15:56:03 +02:00
//int slot = atoi( CMD_ARGV( 1 ) );
2016-06-04 15:24:23 +02:00
// select the item from the current menu
return TRUE;
}
return FALSE;
}
extern int gmsgGameMode;
extern int gmsgSayText;
extern int gmsgTeamInfo;
extern int gmsgTeamNames;
extern int gmsgScoreInfo;
2016-07-31 15:48:50 +02:00
void CHalfLifeTeamplay::UpdateGameMode( CBasePlayer *pPlayer )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgGameMode, NULL, pPlayer->edict() );
WRITE_BYTE( 1 ); // game mode teamplay
MESSAGE_END();
}
const char *CHalfLifeTeamplay::SetDefaultPlayerTeam( CBasePlayer *pPlayer )
{
// copy out the team name from the model
char *mdls = g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model" );
2022-11-14 04:47:47 +01:00
strncpy( pPlayer->m_szTeamName, mdls, TEAM_NAME_LENGTH - 1 );
pPlayer->m_szTeamName[TEAM_NAME_LENGTH - 1] = '\0';
2016-06-04 15:24:23 +02:00
RecountTeams();
// update the current player of the team he is joining
2016-07-31 15:48:50 +02:00
if( pPlayer->m_szTeamName[0] == '\0' || !IsValidTeam( pPlayer->m_szTeamName ) || defaultteam.value )
2016-06-04 15:24:23 +02:00
{
const char *pTeamName = NULL;
2016-07-31 15:48:50 +02:00
if( defaultteam.value )
2016-06-04 15:24:23 +02:00
{
pTeamName = team_names[0];
}
else
{
pTeamName = TeamWithFewestPlayers();
}
2022-11-14 04:47:47 +01:00
strncpy( pPlayer->m_szTeamName, pTeamName, TEAM_NAME_LENGTH - 1 );
pPlayer->m_szTeamName[TEAM_NAME_LENGTH - 1] = '\0';
2016-06-04 15:24:23 +02:00
}
return pPlayer->m_szTeamName;
}
//=========================================================
// InitHUD
//=========================================================
void CHalfLifeTeamplay::InitHUD( CBasePlayer *pPlayer )
{
int i;
SetDefaultPlayerTeam( pPlayer );
CHalfLifeMultiplay::InitHUD( pPlayer );
// Send down the team names
MESSAGE_BEGIN( MSG_ONE, gmsgTeamNames, NULL, pPlayer->edict() );
WRITE_BYTE( num_teams );
2016-07-31 15:48:50 +02:00
for( i = 0; i < num_teams; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
WRITE_STRING( team_names[i] );
2016-06-04 15:24:23 +02:00
}
MESSAGE_END();
RecountTeams();
char *mdls = g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model" );
// update the current player of the team he is joining
char text[1024];
2016-07-31 15:48:50 +02:00
if( !strcmp( mdls, pPlayer->m_szTeamName ) )
2016-06-04 15:24:23 +02:00
{
sprintf( text, "* you are on team \'%s\'\n", pPlayer->m_szTeamName );
}
else
{
sprintf( text, "* assigned to team %s\n", pPlayer->m_szTeamName );
}
ChangePlayerTeam( pPlayer, pPlayer->m_szTeamName, FALSE, FALSE );
UTIL_SayText( text, pPlayer );
2017-06-29 15:56:03 +02:00
//int clientIndex = pPlayer->entindex();
2016-06-04 15:24:23 +02:00
RecountTeams();
// update this player with all the other players team info
// loop through all active players and send their team info to the new client
2016-07-31 15:48:50 +02:00
for( i = 1; i <= gpGlobals->maxClients; i++ )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *plr = UTIL_PlayerByIndex( i );
2016-07-31 15:48:50 +02:00
if( plr && IsValidTeam( plr->TeamID() ) )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgTeamInfo, NULL, pPlayer->edict() );
WRITE_BYTE( plr->entindex() );
WRITE_STRING( plr->TeamID() );
MESSAGE_END();
}
}
}
void CHalfLifeTeamplay::ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib )
{
int damageFlags = DMG_GENERIC;
int clientIndex = pPlayer->entindex();
2016-07-31 15:48:50 +02:00
if( !bGib )
2016-06-04 15:24:23 +02:00
{
damageFlags |= DMG_NEVERGIB;
}
else
{
damageFlags |= DMG_ALWAYSGIB;
}
2016-07-31 15:48:50 +02:00
if( bKill )
2016-06-04 15:24:23 +02:00
{
// kill the player, remove a death, and let them start on the new team
m_DisableDeathMessages = TRUE;
m_DisableDeathPenalty = TRUE;
2016-07-31 15:48:50 +02:00
entvars_t *pevWorld = VARS( INDEXENT( 0 ) );
2016-06-04 15:24:23 +02:00
pPlayer->TakeDamage( pevWorld, pevWorld, 900, damageFlags );
m_DisableDeathMessages = FALSE;
m_DisableDeathPenalty = FALSE;
}
// copy out the team name from the model
2016-06-05 10:17:09 +02:00
if( pPlayer->m_szTeamName != pTeamName )
2022-11-14 04:47:47 +01:00
{
strncpy( pPlayer->m_szTeamName, pTeamName, TEAM_NAME_LENGTH - 1 );
pPlayer->m_szTeamName[TEAM_NAME_LENGTH - 1] = '\0';
}
2016-06-04 15:24:23 +02:00
g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model", pPlayer->m_szTeamName );
g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "team", pPlayer->m_szTeamName );
// notify everyone's HUD of the team change
MESSAGE_BEGIN( MSG_ALL, gmsgTeamInfo );
WRITE_BYTE( clientIndex );
WRITE_STRING( pPlayer->m_szTeamName );
MESSAGE_END();
MESSAGE_BEGIN( MSG_ALL, gmsgScoreInfo );
WRITE_BYTE( clientIndex );
2017-06-29 15:56:03 +02:00
WRITE_SHORT( (int)pPlayer->pev->frags );
2016-06-04 15:24:23 +02:00
WRITE_SHORT( pPlayer->m_iDeaths );
WRITE_SHORT( 0 );
WRITE_SHORT( g_pGameRules->GetTeamIndex( pPlayer->m_szTeamName ) + 1 );
MESSAGE_END();
}
//=========================================================
// ClientUserInfoChanged
//=========================================================
void CHalfLifeTeamplay::ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer )
{
char text[1024];
// prevent skin/color/model changes
char *mdls = g_engfuncs.pfnInfoKeyValue( infobuffer, "model" );
2016-07-31 15:48:50 +02:00
if( !stricmp( mdls, pPlayer->m_szTeamName ) )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( defaultteam.value )
2016-06-04 15:24:23 +02:00
{
int clientIndex = pPlayer->entindex();
g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model", pPlayer->m_szTeamName );
g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "team", pPlayer->m_szTeamName );
sprintf( text, "* Not allowed to change teams in this game!\n" );
UTIL_SayText( text, pPlayer );
return;
}
2016-07-31 15:48:50 +02:00
if( defaultteam.value || !IsValidTeam( mdls ) )
2016-06-04 15:24:23 +02:00
{
int clientIndex = pPlayer->entindex();
g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model", pPlayer->m_szTeamName );
sprintf( text, "* Can't change team to \'%s\'\n", mdls );
UTIL_SayText( text, pPlayer );
sprintf( text, "* Server limits teams to \'%s\'\n", m_szTeamList );
UTIL_SayText( text, pPlayer );
return;
}
// notify everyone of the team change
sprintf( text, "* %s has changed to team \'%s\'\n", STRING(pPlayer->pev->netname), mdls );
UTIL_SayTextAll( text, pPlayer );
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" joined team \"%s\"\n",
2016-07-31 15:48:50 +02:00
STRING( pPlayer->pev->netname ),
2016-06-04 15:24:23 +02:00
GETPLAYERUSERID( pPlayer->edict() ),
GETPLAYERAUTHID( pPlayer->edict() ),
pPlayer->m_szTeamName,
mdls );
ChangePlayerTeam( pPlayer, mdls, TRUE, TRUE );
2016-06-04 15:24:23 +02:00
// recound stuff
RecountTeams( TRUE );
pPlayer->SetPrefsFromUserinfo( infobuffer );
2016-06-04 15:24:23 +02:00
}
extern int gmsgDeathMsg;
//=========================================================
// Deathnotice.
//=========================================================
void CHalfLifeTeamplay::DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor )
{
2016-07-31 15:48:50 +02:00
if( m_DisableDeathMessages )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( pVictim && pKiller && pKiller->flags & FL_CLIENT )
2016-06-04 15:24:23 +02:00
{
CBasePlayer *pk = (CBasePlayer*) CBaseEntity::Instance( pKiller );
2016-07-31 15:48:50 +02:00
if( pk )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( ( pk != pVictim ) && ( PlayerRelationship( pVictim, pk ) == GR_TEAMMATE ) )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ALL, gmsgDeathMsg );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( ENTINDEX( ENT( pKiller ) ) ); // the killer
WRITE_BYTE( ENTINDEX( pVictim->edict() ) ); // the victim
2016-06-04 15:24:23 +02:00
WRITE_STRING( "teammate" ); // flag this as a teammate kill
MESSAGE_END();
return;
}
}
}
CHalfLifeMultiplay::DeathNotice( pVictim, pKiller, pevInflictor );
}
//=========================================================
//=========================================================
2016-07-31 15:48:50 +02:00
void CHalfLifeTeamplay::PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !m_DisableDeathPenalty )
2016-06-04 15:24:23 +02:00
{
CHalfLifeMultiplay::PlayerKilled( pVictim, pKiller, pInflictor );
RecountTeams();
}
}
//=========================================================
// IsTeamplay
//=========================================================
BOOL CHalfLifeTeamplay::IsTeamplay( void )
{
return TRUE;
}
BOOL CHalfLifeTeamplay::FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker )
{
2016-07-31 15:48:50 +02:00
if( pAttacker && PlayerRelationship( pPlayer, pAttacker ) == GR_TEAMMATE )
2016-06-04 15:24:23 +02:00
{
// my teammate hit me.
2016-07-31 15:48:50 +02:00
if( ( friendlyfire.value == 0 ) && ( pAttacker != pPlayer ) )
2016-06-04 15:24:23 +02:00
{
// friendly fire is off, and this hit came from someone other than myself, then don't get hurt
return FALSE;
}
}
return CHalfLifeMultiplay::FPlayerCanTakeDamage( pPlayer, pAttacker );
}
//=========================================================
//=========================================================
int CHalfLifeTeamplay::PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget )
{
// half life multiplay has a simple concept of Player Relationships.
// you are either on another player's team, or you are not.
2016-07-31 15:48:50 +02:00
if( !pPlayer || !pTarget || !pTarget->IsPlayer() )
2016-06-04 15:24:23 +02:00
return GR_NOTTEAMMATE;
2016-07-31 15:48:50 +02:00
if( ( *GetTeamID( pPlayer ) != '\0' ) && ( *GetTeamID( pTarget ) != '\0' ) && !stricmp( GetTeamID( pPlayer ), GetTeamID( pTarget ) ) )
2016-06-04 15:24:23 +02:00
{
return GR_TEAMMATE;
}
return GR_NOTTEAMMATE;
}
//=========================================================
//=========================================================
BOOL CHalfLifeTeamplay::ShouldAutoAim( CBasePlayer *pPlayer, edict_t *target )
{
// always autoaim, unless target is a teammate
CBaseEntity *pTgt = CBaseEntity::Instance( target );
2016-07-31 15:48:50 +02:00
if( pTgt && pTgt->IsPlayer() )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( PlayerRelationship( pPlayer, pTgt ) == GR_TEAMMATE )
2016-06-04 15:24:23 +02:00
return FALSE; // don't autoaim at teammates
}
return CHalfLifeMultiplay::ShouldAutoAim( pPlayer, target );
}
//=========================================================
//=========================================================
int CHalfLifeTeamplay::IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled )
{
2016-07-31 15:48:50 +02:00
if( !pKilled )
2016-06-04 15:24:23 +02:00
return 0;
2016-07-31 15:48:50 +02:00
if( !pAttacker )
2016-06-04 15:24:23 +02:00
return 1;
2016-07-31 15:48:50 +02:00
if( pAttacker != pKilled && PlayerRelationship( pAttacker, pKilled ) == GR_TEAMMATE )
2016-06-04 15:24:23 +02:00
return -1;
return 1;
}
//=========================================================
//=========================================================
const char *CHalfLifeTeamplay::GetTeamID( CBaseEntity *pEntity )
{
2016-07-31 15:48:50 +02:00
if( pEntity == NULL || pEntity->pev == NULL )
2016-06-04 15:24:23 +02:00
return "";
// return their team name
return pEntity->TeamID();
}
int CHalfLifeTeamplay::GetTeamIndex( const char *pTeamName )
{
2016-07-31 15:48:50 +02:00
if( pTeamName && *pTeamName != 0 )
2016-06-04 15:24:23 +02:00
{
// try to find existing team
2016-07-31 15:48:50 +02:00
for( int tm = 0; tm < num_teams; tm++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !stricmp( team_names[tm], pTeamName ) )
2016-06-04 15:24:23 +02:00
return tm;
}
}
2016-06-04 15:24:23 +02:00
return -1; // No match
}
const char *CHalfLifeTeamplay::GetIndexedTeamName( int teamIndex )
{
2016-07-31 15:48:50 +02:00
if( teamIndex < 0 || teamIndex >= num_teams )
2016-06-04 15:24:23 +02:00
return "";
2016-07-31 15:48:50 +02:00
return team_names[teamIndex];
2016-06-04 15:24:23 +02:00
}
BOOL CHalfLifeTeamplay::IsValidTeam( const char *pTeamName )
{
2016-07-31 15:48:50 +02:00
if( !m_teamLimit ) // Any team is valid if the teamlist isn't set
2016-06-04 15:24:23 +02:00
return TRUE;
return ( GetTeamIndex( pTeamName ) != -1 ) ? TRUE : FALSE;
}
const char *CHalfLifeTeamplay::TeamWithFewestPlayers( void )
{
int i;
int minPlayers = MAX_TEAMS;
2016-08-02 13:59:22 +02:00
int teamCount[MAX_TEAMS] = {0};
2016-06-04 15:24:23 +02:00
char *pTeamName = NULL;
// loop through all clients, count number of players on each team
2016-07-31 15:48:50 +02:00
for( i = 1; i <= gpGlobals->maxClients; i++ )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *plr = UTIL_PlayerByIndex( i );
2016-07-31 15:48:50 +02:00
if( plr )
2016-06-04 15:24:23 +02:00
{
int team = GetTeamIndex( plr->TeamID() );
2016-07-31 15:48:50 +02:00
if( team >= 0 )
teamCount[team]++;
2016-06-04 15:24:23 +02:00
}
}
// Find team with least players
2016-07-31 15:48:50 +02:00
for( i = 0; i < num_teams; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( teamCount[i] < minPlayers )
2016-06-04 15:24:23 +02:00
{
minPlayers = teamCount[i];
pTeamName = team_names[i];
}
}
return pTeamName;
}
//=========================================================
//=========================================================
void CHalfLifeTeamplay::RecountTeams( bool bResendInfo )
{
2016-07-31 15:48:50 +02:00
char *pName;
char teamlist[TEAMPLAY_TEAMLISTLENGTH];
2016-06-04 15:24:23 +02:00
// loop through all teams, recounting everything
num_teams = 0;
// Copy all of the teams from the teamlist
// make a copy because strtok is destructive
strcpy( teamlist, m_szTeamList );
pName = teamlist;
pName = strtok( pName, ";" );
2016-07-31 15:48:50 +02:00
while( pName != NULL && *pName )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( GetTeamIndex( pName ) < 0 )
2016-06-04 15:24:23 +02:00
{
strcpy( team_names[num_teams], pName );
num_teams++;
}
pName = strtok( NULL, ";" );
}
2016-07-31 15:48:50 +02:00
if( num_teams < 2 )
2016-06-04 15:24:23 +02:00
{
num_teams = 0;
m_teamLimit = FALSE;
}
// Sanity check
memset( team_scores, 0, sizeof(team_scores) );
// loop through all clients
2016-07-31 15:48:50 +02:00
for( int i = 1; i <= gpGlobals->maxClients; i++ )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *plr = UTIL_PlayerByIndex( i );
2016-07-31 15:48:50 +02:00
if( plr )
2016-06-04 15:24:23 +02:00
{
const char *pTeamName = plr->TeamID();
2016-06-04 15:24:23 +02:00
// try add to existing team
int tm = GetTeamIndex( pTeamName );
2016-07-31 15:48:50 +02:00
if( tm < 0 ) // no team match found
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !m_teamLimit )
2016-06-04 15:24:23 +02:00
{
// add to new team
tm = num_teams;
num_teams++;
team_scores[tm] = 0;
2022-11-14 04:47:47 +01:00
strncpy( team_names[tm], pTeamName, MAX_TEAMNAME_LENGTH - 1 );
team_names[tm][MAX_TEAMNAME_LENGTH - 1] = '\0';
2016-06-04 15:24:23 +02:00
}
}
2016-07-31 15:48:50 +02:00
if( tm >= 0 )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
team_scores[tm] += (int)plr->pev->frags;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( bResendInfo ) //Someone's info changed, let's send the team info again.
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( plr && IsValidTeam( plr->TeamID() ) )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ALL, gmsgTeamInfo, NULL );
WRITE_BYTE( plr->entindex() );
WRITE_STRING( plr->TeamID() );
MESSAGE_END();
}
}
}
}
}