Skip to content

Commit 9761d3a

Browse files
committed
Add automatic protagonist support to HL2MP player
1 parent e9908d2 commit 9761d3a

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

src/game/server/hl2/hl2_player.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,6 +4604,15 @@ void CHL2_Player::SetProtagonist( const char *pszProtagonist )
46044604
return;
46054605
}
46064606

4607+
#ifdef HL2MP
4608+
int nTeam = g_ProtagonistSystem.GetProtagonist_Team( nIndex );
4609+
if (nTeam != GetTeamNumber() && GetTeamNumber() != TEAM_UNASSIGNED && nTeam != TEAM_ANY)
4610+
{
4611+
// Not an acceptable team
4612+
return;
4613+
}
4614+
#endif
4615+
46074616
if (m_nProtagonistIndex != -1)
46084617
{
46094618
// Flush any pre-existing data

src/game/server/hl2mp/hl2mp_player.cpp

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ ConVar hl2mp_spawn_frag_fallback_radius( "hl2mp_spawn_frag_fallback_radius", "48
4242

4343
#define HL2MP_COMMAND_MAX_RATE 0.3
4444

45+
#ifdef MAPBASE
46+
ConVar sv_hl2mp_protagonist_select( "sv_hl2mp_protagonist_select", "0", FCVAR_NONE, "Allows players to select any valid protagonist, rather than being limited to default HL2:DM models." );
47+
#endif
48+
4549
void DropPrimedFragGrenade( CHL2MP_Player *pPlayer, CBaseCombatWeapon *pGrenade );
4650

4751
LINK_ENTITY_TO_CLASS( player, CHL2MP_Player );
@@ -403,6 +407,23 @@ void CHL2MP_Player::Spawn(void)
403407

404408
bool CHL2MP_Player::ValidatePlayerModel( const char *pModel )
405409
{
410+
#ifdef MAPBASE
411+
if (pModel[0] == '#')
412+
{
413+
if (!sv_hl2mp_protagonist_select.GetBool())
414+
{
415+
ClientPrint( this, HUD_PRINTTALK, "Server does not allow direct protagonist selection" );
416+
return false;
417+
}
418+
419+
int nProtagonist = g_ProtagonistSystem.FindProtagonistIndex( pModel + 1 );
420+
if (nProtagonist != -1)
421+
{
422+
return true;
423+
}
424+
}
425+
#endif
426+
406427
int iModels = ARRAYSIZE( g_ppszRandomCitizenModels );
407428
int i;
408429

@@ -444,7 +465,11 @@ void CHL2MP_Player::SetPlayerTeamModel( void )
444465

445466
int modelIndex = modelinfo->GetModelIndex( szModelName );
446467

468+
#ifdef MAPBASE
469+
if ( (modelIndex == -1 && szModelName[0] != '#') || ValidatePlayerModel(szModelName) == false)
470+
#else
447471
if ( modelIndex == -1 || ValidatePlayerModel( szModelName ) == false )
472+
#endif
448473
{
449474
szModelName = "models/Combine_Soldier.mdl";
450475
m_iModelType = TEAM_COMBINE;
@@ -479,8 +504,34 @@ void CHL2MP_Player::SetPlayerTeamModel( void )
479504

480505
m_iModelType = TEAM_REBELS;
481506
}
482-
507+
508+
#ifdef MAPBASE
509+
if ( szModelName[0] == '#' )
510+
{
511+
// Protagonist name. Was already validated above
512+
SetProtagonist( szModelName + 1 );
513+
}
514+
else
515+
{
516+
// Find out if we have a protagonist for this model
517+
const char *pszProtagonistName = g_ProtagonistSystem.FindProtagonistByModel( szModelName );
518+
if (pszProtagonistName)
519+
{
520+
SetProtagonist( pszProtagonistName );
521+
522+
// Fall back if not accepted
523+
if ( GetProtagonistIndex() == -1 )
524+
SetModel( szModelName );
525+
}
526+
else
527+
{
528+
SetModel( szModelName );
529+
}
530+
}
531+
#else
483532
SetModel( szModelName );
533+
#endif
534+
484535
SetupPlayerSoundsByModel( szModelName );
485536

486537
m_flNextModelChangeTime = gpGlobals->curtime + MODEL_CHANGE_INTERVAL;
@@ -543,6 +594,18 @@ void CHL2MP_Player::SetPlayerModel( void )
543594
}
544595
}
545596

597+
#ifdef MAPBASE
598+
if (szModelName[0] == '#')
599+
{
600+
// Protagonist name. Was already validated above
601+
SetProtagonist( szModelName + 1 );
602+
}
603+
else
604+
{
605+
ResetProtagonist();
606+
}
607+
#endif
608+
546609
int modelIndex = modelinfo->GetModelIndex( szModelName );
547610

548611
if ( modelIndex == -1 )
@@ -556,7 +619,28 @@ void CHL2MP_Player::SetPlayerModel( void )
556619
engine->ClientCommand ( edict(), szReturnString );
557620
}
558621

622+
#ifdef MAPBASE
623+
if (GetProtagonistIndex() == -1)
624+
{
625+
// Find out if we have a protagonist for this model
626+
const char *pszProtagonistName = g_ProtagonistSystem.FindProtagonistByModel( szModelName );
627+
if (pszProtagonistName)
628+
{
629+
SetProtagonist( pszProtagonistName );
630+
631+
// Fall back if not accepted
632+
if ( GetProtagonistIndex() <= -1 )
633+
SetModel( szModelName );
634+
}
635+
else
636+
{
637+
SetModel( szModelName );
638+
}
639+
}
640+
#else
559641
SetModel( szModelName );
642+
#endif
643+
560644
SetupPlayerSoundsByModel( szModelName );
561645

562646
m_flNextModelChangeTime = gpGlobals->curtime + MODEL_CHANGE_INTERVAL;

src/game/shared/hl2mp/hl2mp_gamerules.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "hl2mp_cvars.h"
3636
#ifdef MAPBASE
3737
#include "bot/hl2mp_bot_manager.h"
38+
#include "mapbase/protagonist_system.h"
3839
#endif
3940

4041
extern void respawn(CBaseEntity *pEdict, bool fCopyCorpse);
@@ -878,6 +879,26 @@ void CHL2MPRules::ClientSettingsChanged( CBasePlayer *pPlayer )
878879
}
879880
else
880881
{
882+
#ifdef MAPBASE
883+
if (szModelName[0] == '#')
884+
{
885+
int nProtagonist = g_ProtagonistSystem.FindProtagonistIndex( szModelName + 1 );
886+
if (nProtagonist != -1)
887+
{
888+
int nTeam = g_ProtagonistSystem.GetProtagonist_Team( nProtagonist );
889+
if ( nTeam == TEAM_REBELS )
890+
{
891+
pHL2Player->ChangeTeam( TEAM_REBELS );
892+
}
893+
else if ( nTeam == TEAM_COMBINE )
894+
{
895+
pHL2Player->ChangeTeam( TEAM_COMBINE );
896+
}
897+
}
898+
}
899+
else
900+
#endif
901+
881902
if ( Q_stristr( szModelName, "models/human") )
882903
{
883904
pHL2Player->ChangeTeam( TEAM_REBELS );

0 commit comments

Comments
 (0)