mirror of
https://github.com/fortressforever/fortressforever-2013.git
synced 2024-11-10 07:11:45 +00:00
start implementing actual team joinage action extreme
(added basic con command clientside wrapper that sends to engine->ServerCmd for this) team finding & joining logic is in the team manager.. not player, might make too much sense! auto-join is WIP
This commit is contained in:
parent
5e5f2a4914
commit
9c56bd60c3
7 changed files with 219 additions and 68 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "SoundEmitterSystem/isoundemittersystembase.h"
|
||||
|
||||
#include "ilagcompensationmanager.h"
|
||||
#include "ff_sh_team_manager.h"
|
||||
|
||||
// Don't alias here
|
||||
#if defined( CFF_SH_Player )
|
||||
|
@ -947,78 +948,25 @@ void CFF_SV_Player::ChangeTeam( int iTeam )
|
|||
}
|
||||
}
|
||||
|
||||
bool CFF_SV_Player::HandleCommand_JoinTeam( int team )
|
||||
{
|
||||
if ( !GetGlobalTeam( team ) || team == 0 )
|
||||
{
|
||||
Warning( "HandleCommand_JoinTeam( %d ) - invalid team index.\n", team );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( team == TEAM_SPECTATOR )
|
||||
{
|
||||
// Prevent this is the cvar is set
|
||||
if ( !mp_allowspectators.GetInt() )
|
||||
{
|
||||
ClientPrint( this, HUD_PRINTCENTER, "#Cannot_Be_Spectator" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( GetTeamNumber() != TEAM_UNASSIGNED && !IsDead() )
|
||||
{
|
||||
m_fNextSuicideTime = gpGlobals->curtime; // allow the suicide to work
|
||||
|
||||
CommitSuicide();
|
||||
|
||||
// add 1 to frags to balance out the 1 subtracted for killing yourself
|
||||
IncrementFragCount( 1 );
|
||||
}
|
||||
|
||||
ChangeTeam( TEAM_SPECTATOR );
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
StopObserverMode();
|
||||
State_Transition(STATE_ACTIVE);
|
||||
}
|
||||
|
||||
// Switch their actual team...
|
||||
ChangeTeam( team );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFF_SV_Player::ClientCommand( const CCommand &args )
|
||||
{
|
||||
if ( FStrEq( args[0], "spectate" ) )
|
||||
if ( FStrEq( args[0], "spectate" ) || FStrEq( args[0], "team" ) )
|
||||
{
|
||||
if ( ShouldRunRateLimitedCommand( args ) )
|
||||
{
|
||||
// instantly join spectators
|
||||
HandleCommand_JoinTeam( TEAM_SPECTATOR );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ( FStrEq( args[0], "jointeam" ) )
|
||||
{
|
||||
if ( args.ArgC() < 2 )
|
||||
{
|
||||
Warning( "Player sent bad jointeam syntax\n" );
|
||||
}
|
||||
const char *team;
|
||||
|
||||
if ( ShouldRunRateLimitedCommand( args ) )
|
||||
{
|
||||
int iTeam = atoi( args[1] );
|
||||
HandleCommand_JoinTeam( iTeam );
|
||||
if ( args.ArgC() < 2) // || FStrEq( args[0], "spectate" ) )
|
||||
return false;
|
||||
if ( FStrEq( args[0], "spectate" ) )
|
||||
team = "spec";
|
||||
else
|
||||
team = args[1];
|
||||
// let the team manager earn its namesake and handle that crap
|
||||
return CFF_SH_TeamManager::HandlePlayerTeamCommand( *this, team );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ( FStrEq( args[0], "joingame" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return BaseClass::ClientCommand( args );
|
||||
}
|
||||
|
@ -1590,3 +1538,26 @@ bool CFF_SV_Player::CanHearAndReadChatFrom( CBasePlayer *pPlayer )
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// called by team manager once a valid team is found, but before switching,
|
||||
// do any eg class cleanup here etc
|
||||
void CFF_SV_Player::PreChangeTeam( int iOldTeam, int iNewTeam )
|
||||
{
|
||||
// set team unassigned
|
||||
// set class unassigned
|
||||
// remove items
|
||||
// special infection stuff,
|
||||
// force uncloak lol
|
||||
// clear state (might do w/ player func)
|
||||
// check kill
|
||||
// lua player_killed
|
||||
}
|
||||
|
||||
// called by team manager once a valid team is found, and after new team set
|
||||
// do any init and respawn etc
|
||||
void CFF_SV_Player::PostChangeTeam( int iOldTeam, int iNewTeam )
|
||||
{
|
||||
// reset state
|
||||
// spawn called
|
||||
}
|
|
@ -58,7 +58,7 @@ public:
|
|||
virtual void PreThink( void );
|
||||
virtual void PlayerDeathThink( void );
|
||||
virtual void SetAnimation( PLAYER_ANIM playerAnim );
|
||||
virtual bool HandleCommand_JoinTeam( int team );
|
||||
//virtual bool HandleCommand_Class( const char* className );
|
||||
virtual bool ClientCommand( const CCommand &args );
|
||||
virtual void CreateViewModel( int viewmodelindex = 0 );
|
||||
virtual bool BecomeRagdollOnClient( const Vector &force );
|
||||
|
@ -137,7 +137,10 @@ public:
|
|||
|
||||
virtual bool CanHearAndReadChatFrom( CBasePlayer *pPlayer );
|
||||
|
||||
|
||||
// called by team manager once a valid team is found, but before switching
|
||||
void PreChangeTeam( int iOldTeam, int iNewTeam );
|
||||
// called by team manager once a valid team is found, and after new team set
|
||||
void PostChangeTeam( int iOldTeam, int iNewTeam );
|
||||
private:
|
||||
|
||||
CNetworkQAngle( m_angEyeAngles );
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "ff_sv_player.h"
|
||||
#endif
|
||||
|
||||
#include "ff_sh_playercommands.h"
|
||||
#include "engine/IEngineSound.h"
|
||||
#include "SoundEmitterSystem/isoundemittersystembase.h"
|
||||
|
||||
|
|
26
mp/src/game/shared/ff/ff_sh_playercommands.h
Normal file
26
mp/src/game/shared/ff/ff_sh_playercommands.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include "cbase.h"
|
||||
#include "ff_sh_player.h"
|
||||
#include <string>
|
||||
|
||||
#define FF_COMMAND(cmd, desc) \
|
||||
void CliCmdFunc_##cmd(const CCommand &args) \
|
||||
{ \
|
||||
std::string fullcmd; \
|
||||
for(int i = 0; i < args.ArgC(); i++) \
|
||||
{ \
|
||||
if(i > 0) \
|
||||
fullcmd += ' '; \
|
||||
fullcmd += args.Arg(i); \
|
||||
} \
|
||||
engine->ServerCmd(fullcmd.c_str()); \
|
||||
} \
|
||||
static ConCommand CliCmd_##cmd(#cmd, CliCmdFunc_##cmd, desc );
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
FF_COMMAND(team, "join a team");
|
||||
FF_COMMAND(class, "set player class");
|
||||
#endif
|
||||
//FF_AUTO_COMMAND(ff_testcmd, TestCommand_f, "a test command", FCV
|
||||
//ConCommand cc_ff_testcmd("ff_testcmd",
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
#ifdef GAME_DLL
|
||||
|
||||
static void ClassRestrictionChange( IConVar *var, const char *pOldString, float fOldVal );
|
||||
|
@ -59,7 +58,7 @@ static void ClassRestrictionChange( IConVar *var, const char *pOldString, float
|
|||
int idx = -1;
|
||||
for ( int i = 0; i < CLASS_COUNT; i ++)
|
||||
{
|
||||
if ( Q_strcmp( conVar->GetName(), classRestrictionCvars[i].GetName() ) == 0 )
|
||||
if ( FStrEq( conVar->GetName(), classRestrictionCvars[i].GetName() ) )
|
||||
{
|
||||
idx = i;
|
||||
break;
|
||||
|
@ -223,6 +222,148 @@ int CFF_SH_TeamManager::GetTeamLimits( void )
|
|||
return m_iMaxPlayers;
|
||||
}
|
||||
|
||||
#ifdef GAME_DLL
|
||||
bool CFF_SH_TeamManager::HandlePlayerTeamCommand( CFF_SV_Player &pPlayer, const char *pTeamName )
|
||||
{
|
||||
if ( !pTeamName )
|
||||
return false;
|
||||
|
||||
int iOldTeam = pPlayer.GetTeamNumber();
|
||||
int iTeam = TEAM_UNASSIGNED;
|
||||
|
||||
if ( FStrEq( pTeamName, "auto" ) )
|
||||
{
|
||||
iTeam = PickAutoJoinTeam( );
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "spec" ) )
|
||||
{
|
||||
iTeam = TEAM_SPECTATOR;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "red" ) )
|
||||
{
|
||||
iTeam = TEAM_RED;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "blue" ) )
|
||||
{
|
||||
iTeam = TEAM_BLUE;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "yellow" ) )
|
||||
{
|
||||
iTeam = TEAM_YELLOW;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "green" ) )
|
||||
{
|
||||
iTeam = TEAM_GREEN;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "custom1" ) )
|
||||
{
|
||||
iTeam = TEAM_CUSTOM1;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "custom2" ) )
|
||||
{
|
||||
iTeam = TEAM_CUSTOM2;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "custom3" ) )
|
||||
{
|
||||
iTeam = TEAM_CUSTOM3;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "custom4" ) )
|
||||
{
|
||||
iTeam = TEAM_CUSTOM4;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "custom5" ) )
|
||||
{
|
||||
iTeam = TEAM_CUSTOM5;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "custom6" ) )
|
||||
{
|
||||
iTeam = TEAM_CUSTOM6;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "custom7" ) )
|
||||
{
|
||||
iTeam = TEAM_CUSTOM7;
|
||||
}
|
||||
else if ( FStrEq( pTeamName, "custom8" ) )
|
||||
{
|
||||
iTeam = TEAM_CUSTOM8;
|
||||
}
|
||||
else
|
||||
{
|
||||
// no known hardcoded team name,
|
||||
// try to find team by current team names just for the hell of it
|
||||
for ( int i = 0; i < g_Teams.Count(); ++i )
|
||||
{
|
||||
if (!g_Teams[i])
|
||||
continue;
|
||||
if ( FStrEq( g_Teams[i]->GetName(), pTeamName ) )
|
||||
{
|
||||
iTeam = g_Teams[i]->GetTeamNumber( );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( iTeam == TEAM_UNASSIGNED )
|
||||
{
|
||||
// TODO: say nothin' found poor sap
|
||||
return false;
|
||||
}
|
||||
|
||||
// check stupid stuff first
|
||||
if ( iOldTeam == iTeam )
|
||||
{
|
||||
// wants to join same team
|
||||
return false;
|
||||
}
|
||||
|
||||
CFF_SH_TeamManager *pTeam = GetGlobalFFTeam( iTeam );
|
||||
if ( !pTeam )
|
||||
{
|
||||
// non active team or something fucked
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure isnt full
|
||||
if ( pTeam->IsTeamFull() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Lua player_switchteam predicate here
|
||||
|
||||
// refactored this, so each step of the process is seperate chunks,
|
||||
// since so much per-class state is handled in each
|
||||
pPlayer.PreChangeTeam( iOldTeam, iTeam );
|
||||
pPlayer.ChangeTeam( iTeam );
|
||||
pPlayer.PostChangeTeam( iOldTeam, iTeam );
|
||||
return true;
|
||||
}
|
||||
|
||||
// fun fact, on ep1 code this was called UTIL_PickRandomTeam, but it wasnt random, it was auto join
|
||||
int CFF_SH_TeamManager::PickAutoJoinTeam( )
|
||||
{
|
||||
// TODO:
|
||||
return TEAM_BLUE;
|
||||
}
|
||||
|
||||
bool CFF_SH_TeamManager::IsTeamFull() const
|
||||
{
|
||||
if (m_iMaxPlayers == 0)
|
||||
return false;
|
||||
|
||||
int numActive = 0;
|
||||
for( int i = 1; i <= gpGlobals->maxClients; i++ )
|
||||
{
|
||||
CFF_SV_Player *pPlayer = (CFF_SV_Player *) UTIL_PlayerByIndex( i );
|
||||
if( pPlayer && pPlayer->GetTeamNumber( ) == GetTeamNumber( ) )
|
||||
numActive++;
|
||||
}
|
||||
|
||||
return numActive > m_iMaxPlayers;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//ConCommand ff_team( "ff_team",
|
||||
//ConCommand ff_team( "ffdbg_dump_teams",
|
||||
#if defined (_DEBUG) && defined (GAME_DLL)
|
||||
|
@ -246,3 +387,5 @@ void DebugSetTeamName_f( const CCommand &args )
|
|||
}
|
||||
ConCommand cc_ffdbg_setteamname("ffdbg_set_team_name", DebugSetTeamName_f);
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "cbase.h"
|
||||
#include "ff_sh_shareddefs.h"
|
||||
|
||||
#ifdef GAME_DLL
|
||||
#include "team.h"
|
||||
#include "ff_sv_player.h"
|
||||
#else
|
||||
#include "c_team.h"
|
||||
#define CTeam C_Team
|
||||
|
@ -61,6 +63,10 @@ public:
|
|||
void UpdateClassLimit( int idx );
|
||||
void UpdateAllClassLimits( void );
|
||||
|
||||
static bool HandlePlayerTeamCommand( CFF_SV_Player &pPlayer, const char* pTeam );
|
||||
static int PickAutoJoinTeam( );
|
||||
|
||||
bool IsTeamFull() const;
|
||||
#endif // GAME_DLL
|
||||
|
||||
// shared getters
|
||||
|
|
|
@ -27,6 +27,7 @@ $Project
|
|||
{
|
||||
$File "$SRCDIR\game\shared\ff\ff_sh_player.cpp"
|
||||
$File "$SRCDIR\game\shared\ff\ff_sh_player.h"
|
||||
$File "$SRCDIR\game\shared\ff\ff_sh_playercommands.h"
|
||||
}
|
||||
$Folder "Game"
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue