From 95578c3602b377f734ad038dd30b9c5b16201e3a Mon Sep 17 00:00:00 2001 From: mittorn Date: Sun, 6 Nov 2016 18:44:46 +0000 Subject: [PATCH] Hide all coop code under cvars --- dlls/barney.cpp | 5 +- dlls/client.cpp | 54 +++++++------ dlls/combat.cpp | 25 +++--- dlls/doors.cpp | 5 +- dlls/game.cpp | 4 + dlls/game.h | 3 + dlls/items.cpp | 3 +- dlls/multiplay_gamerules.cpp | 147 ++++++++++++++++++----------------- dlls/plats.cpp | 3 +- dlls/scientist.cpp | 5 +- 10 files changed, 140 insertions(+), 114 deletions(-) diff --git a/dlls/barney.cpp b/dlls/barney.cpp index e9cb309d..e0a1ff0c 100644 --- a/dlls/barney.cpp +++ b/dlls/barney.cpp @@ -27,6 +27,7 @@ #include "scripted.h" #include "weapons.h" #include "soundent.h" +#include "game.h" //========================================================= // Monster's Anim Events Go Here @@ -512,9 +513,7 @@ int CBarney::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float // Alright, now I'm pissed! PlaySentence( "BA_MAD", 4, VOL_NORM, ATTN_NORM ); - if( pevAttacker->health <= 10 ) - Forget( bits_MEMORY_PROVOKED ); - else + if( !mp_coop_noangry.value ) Remember( bits_MEMORY_PROVOKED ); StopFollowing( TRUE ); } diff --git a/dlls/client.cpp b/dlls/client.cpp index 7dd65b3e..bfbdba33 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -78,7 +78,7 @@ called when a player connects to a server */ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) { - if( pEntity ) + if( mp_coop.value && pEntity ) { CBasePlayer *pl = (CBasePlayer *)CBaseEntity::Instance( pEntity ) ; if( pl ) @@ -86,12 +86,9 @@ BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddres pl->m_state = STATE_UNINITIALIZED; pl->RemoveAllItems( TRUE ); BecomeSpectator( pl ); - //ClientPutInServer( pl->edict() ); } } - //g_engfuncs.pfnQueryClientCvarValue2( pEntity, "touch_enable", 111 ); - return g_pGameRules->ClientConnected( pEntity, pszName, pszAddress, szRejectReason ); // a client connecting during an intermission can cause problems @@ -139,9 +136,12 @@ void ClientDisconnect( edict_t *pEntity ) UTIL_SetOrigin ( &pEntity->v, pEntity->v.origin ); g_pGameRules->ClientDisconnected( pEntity ); - CBasePlayer *pPlayer = (CBasePlayer*)CBaseEntity::Instance( pEntity ); - if( pPlayer ) - pPlayer->m_state = STATE_UNINITIALIZED; + if( mp_coop.value ) + { + CBasePlayer *pPlayer = (CBasePlayer*)CBaseEntity::Instance( pEntity ); + if( pPlayer ) + pPlayer->m_state = STATE_UNINITIALIZED; + } } @@ -216,7 +216,7 @@ void ClientPutInServer( edict_t *pEntity ) pPlayer = GetClassPtr((CBasePlayer *)pev); pPlayer->SetCustomDecalFrames(-1); // Assume none; - if( pPlayer->m_state == STATE_UNINITIALIZED ) + if( mp_coop.value && pPlayer->m_state == STATE_UNINITIALIZED ) g_engfuncs.pfnQueryClientCvarValue2( pEntity, "touch_enable", 111 ); pPlayer->m_state = STATE_CONNECTED; @@ -224,8 +224,12 @@ void ClientPutInServer( edict_t *pEntity ) // Allocate a CBasePlayer for pev, and call spawn pPlayer->Spawn(); - pPlayer->RemoveAllItems( TRUE ); - BecomeSpectator( pPlayer ); + // AGHL-like spectator + if( mp_spectator.value ) + { + pPlayer->RemoveAllItems( TRUE ); + BecomeSpectator( pPlayer ); + } // Reset interpolation during first frame pPlayer->pev->effects |= EF_NOINTERP; @@ -530,27 +534,31 @@ void ClientCommand( edict_t *pEntity ) else if( FStrEq(pcmd, "m1")) { #define MENU_STR(VAR) (#VAR) - CLIENT_COMMAND( pEntity, - MENU_STR(touch_addbutton "_coops" "*black" "" 0.15 0.1 0.4 0.72 0 0 0 128 334\ntouch_addbutton "_coopst" "#COOP MENU" "" 0.16 0.11 0.41 0.3 0 255 0 255 78 1.5\nm2\n) - ); + if( mp_coop.value ) + CLIENT_COMMAND( pEntity, + MENU_STR(touch_addbutton "_coops" "*black" "" 0.15 0.1 0.4 0.72 0 0 0 128 334\ntouch_addbutton "_coopst" "#COOP MENU" "" 0.16 0.11 0.41 0.3 0 255 0 255 78 1.5\nm2\n) + ); } else if( FStrEq(pcmd, "m2")) { - CLIENT_COMMAND( pEntity, - MENU_STR(touch_addbutton "_coops1" "#1. Join coop" "menuselect 1;touch_hide _coops*" 0.16 0.21 0.39 0.3 255 255 255 255 334 1.5\ntouch_addbutton "_coops2" "#2. Become spectator" "menuselect 2;touch_hide _coops*" 0.16 0.31 0.39 0.4 255 255 255 255 334 1.5\nm3\n) - ); + if( mp_coop.value ) + CLIENT_COMMAND( pEntity, + MENU_STR(touch_addbutton "_coops1" "#1. Join coop" "menuselect 1;touch_hide _coops*" 0.16 0.21 0.39 0.3 255 255 255 255 334 1.5\ntouch_addbutton "_coops2" "#2. Become spectator" "menuselect 2;touch_hide _coops*" 0.16 0.31 0.39 0.4 255 255 255 255 334 1.5\nm3\n) + ); } else if( FStrEq(pcmd, "m3")) { - CLIENT_COMMAND( pEntity, - MENU_STR(touch_addbutton "_coops3" "#" "menuselect 3;touch_hide _coops*" 0.16 0.41 0.39 0.5 255 255 255 255 335 1.5\ntouch_addbutton "_coops4" "#" "menuselect 4;touch_hide _coops*" 0.16 0.51 0.39 0.6 255 255 255 255 335 1.5\nm4\n) - ); + if( mp_coop.value ) + CLIENT_COMMAND( pEntity, + MENU_STR(touch_addbutton "_coops3" "#" "menuselect 3;touch_hide _coops*" 0.16 0.41 0.39 0.5 255 255 255 255 335 1.5\ntouch_addbutton "_coops4" "#" "menuselect 4;touch_hide _coops*" 0.16 0.51 0.39 0.6 255 255 255 255 335 1.5\nm4\n) + ); } else if( FStrEq(pcmd, "m4")) { - CLIENT_COMMAND( pEntity, - MENU_STR(touch_addbutton "_coops5" "#" "menuselect 5;touch_hide _coops*" 0.16 0.61 0.39 0.7 255 255 255 255 335 1.5;wait;slot10\n) -); + if( mp_coop.value ) + CLIENT_COMMAND( pEntity, + MENU_STR(touch_addbutton "_coops5" "#" "menuselect 5;touch_hide _coops*" 0.16 0.61 0.39 0.7 255 255 255 255 335 1.5;wait;slot10\n) + ); } else { @@ -1891,7 +1899,7 @@ void CreateInstancedBaselines ( void ) void CvarValue2( const edict_t *pEnt, int requestID, const char *cvarName, const char *value ) { - if( pEnt && requestID == 111 && FStrEq( cvarName , "touch_enable" ) && atoi( value) ) + if( mp_coop.value && pEnt && requestID == 111 && FStrEq( cvarName , "touch_enable" ) && atoi( value) ) { CBasePlayer *player = (CBasePlayer * ) CBaseEntity::Instance( (edict_t*)pEnt ); player->m_fTouchMenu = !!atof( value ); diff --git a/dlls/combat.cpp b/dlls/combat.cpp index 83e8188a..4224da9b 100644 --- a/dlls/combat.cpp +++ b/dlls/combat.cpp @@ -592,7 +592,7 @@ void CBaseMonster::Killed( entvars_t *pevAttacker, int iGib ) { unsigned int cCount = 0; BOOL fDone = FALSE; - int classs = Classify(); + if( HasMemory( bits_MEMORY_KILLED ) ) { @@ -604,19 +604,22 @@ void CBaseMonster::Killed( entvars_t *pevAttacker, int iGib ) Remember( bits_MEMORY_KILLED ); CBaseEntity *activator = CBaseEntity::Instance( pevAttacker ); - if( classs == CLASS_HUMAN_PASSIVE || classs == CLASS_PLAYER_ALLY ) + if( mp_coop.value ) { - if( activator && activator->IsPlayer() ) + int classs = Classify(); + if( !mp_coop_nofriendlyfire.value && classs == CLASS_HUMAN_PASSIVE || classs == CLASS_PLAYER_ALLY ) { - activator->pev->frags -= 30; - activator->AddPoints( 0, true ); - activator->pev->frags -= 50; + if( activator && activator->IsPlayer() ) + { + activator->pev->frags -= 30; + activator->AddPoints( 0, true ); + } + } + else if( classs >= 5 ) + { + if( activator && activator->IsPlayer() ) + activator->AddPoints( 1, true ); } - } - else if( classs >= 5 ) - { - if( activator && activator->IsPlayer() ) - activator->AddPoints( 1, true ); } // clear the deceased's sound channels.(may have been firing or reloading when killed) diff --git a/dlls/doors.cpp b/dlls/doors.cpp index 341d139a..145e292b 100644 --- a/dlls/doors.cpp +++ b/dlls/doors.cpp @@ -595,9 +595,10 @@ void CBaseDoor::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE use // allow open door that closed sometime if( pev->size.x < 50 || pev->size.y < 50 ) m_fActivated = true; + if( !pev->target && m_savedtarget ) + pev->target = m_savedtarget, m_savedtarget = 0; } - if( !pev->target && m_savedtarget ) - pev->target = m_savedtarget, m_savedtarget = 0; + DoorActivate(); } } diff --git a/dlls/game.cpp b/dlls/game.cpp index a223c9b7..dc27ab40 100644 --- a/dlls/game.cpp +++ b/dlls/game.cpp @@ -55,8 +55,10 @@ cvar_t mp_coop_changelevel = { "mp_coop_changelevel", "0", FCVAR_SERVER }; cvar_t mp_coop_nofriendlyfire = { "mp_coop_nofriendlyfire", "0", FCVAR_SERVER }; cvar_t mp_coop_disabledmap = { "mp_coop_disabledmap", "", FCVAR_SERVER }; cvar_t mp_coop_reconnect_hack = { "mp_coop_reconnect_hack", "0", FCVAR_SERVER }; +cvar_t mp_coop_noangry = { "mp_coop_noangry", "0", FCVAR_SERVER }; cvar_t mp_unduck = { "mp_unduck", "0", FCVAR_SERVER }; cvar_t mp_semclip = { "mp_semclip", "0", FCVAR_SERVER }; +cvar_t mp_spectator = { "mp_spectator", "0", FCVAR_SERVER }; // Engine Cvars cvar_t *g_psv_gravity = NULL; @@ -506,6 +508,8 @@ void GameDLLInit( void ) CVAR_REGISTER( &mp_unduck ); CVAR_REGISTER( &mp_semclip ); CVAR_REGISTER( &mp_coop_reconnect_hack ); + CVAR_REGISTER( &mp_coop_noangry ); + CVAR_REGISTER( &mp_spectator ); CVAR_REGISTER( &mp_chattime ); diff --git a/dlls/game.h b/dlls/game.h index 18b07deb..c5a61d9a 100644 --- a/dlls/game.h +++ b/dlls/game.h @@ -55,6 +55,9 @@ extern cvar_t mp_coop_disabledmap; extern cvar_t mp_unduck; extern cvar_t mp_semclip; extern cvar_t mp_coop_reconnect_hack; +extern cvar_t mp_coop_noangry; +extern cvar_t mp_spectator; + extern bool g_fSavedDuck; extern bool g_fPause; diff --git a/dlls/items.cpp b/dlls/items.cpp index 5c56ea60..9dfd1b8b 100644 --- a/dlls/items.cpp +++ b/dlls/items.cpp @@ -177,7 +177,8 @@ CBaseEntity* CItem::Respawn( void ) SetThink( &CItem::Materialize ); pev->nextthink = g_pGameRules->FlItemRespawnTime( this ); - pev->target = 0; + if( mp_coop.value) + pev->target = 0; return this; } diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index e3ccd6a9..ce08e7ca 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -225,72 +225,75 @@ BOOL CHalfLifeMultiplay::ClientCommand( CBasePlayer *pPlayer, const char *pcmd ) if( g_VoiceGameMgr.ClientCommand( pPlayer, pcmd ) ) return TRUE; #endif - if( FStrEq( pcmd, "joincoop" ) ) + if( mp_coop.value ) { - if( pPlayer->m_state == STATE_SPECTATOR_BEGIN ) - SpawnPlayer( pPlayer ); - else - ClientPrint( pPlayer->pev, HUD_PRINTCONSOLE, "You cannot use joincoop now!\n\n" ); - - return TRUE; - } - if( FStrEq( pcmd, "menuselect" ) ) - { - int imenu = atoi( CMD_ARGV( 1 ) ); + if( FStrEq( pcmd, "joincoop" ) ) + { + if( pPlayer->m_state == STATE_SPECTATOR_BEGIN ) + SpawnPlayer( pPlayer ); + else + ClientPrint( pPlayer->pev, HUD_PRINTCONSOLE, "You cannot use joincoop now!\n\n" ); - switch( pPlayer->m_state ) + return TRUE; + } + if( FStrEq( pcmd, "menuselect" ) ) { - case STATE_SPECTATOR_BEGIN: - case STATE_SPECTATOR: - if( imenu == 1 ) - { - SpawnPlayer( pPlayer ); - pPlayer->m_state = STATE_SPAWNED; - } - if( imenu == 2 ) - { - pPlayer->m_state = STATE_SPECTATOR; - CLIENT_COMMAND( pPlayer->edict(), "touch_show _coopm*\n" ); - } - break; - case STATE_SPAWNED: - if( g_iMenu ) - { - CoopProcessMenu( pPlayer, imenu ); - return TRUE; - } - if( imenu == 1 ) - { - pPlayer->RemoveAllItems( TRUE ); - SpawnPlayer( pPlayer ); - } - if( imenu == 2 ) - { - UTIL_CleanSpawnPoint( pPlayer->pev->origin, 150 ); - } - if( imenu == 3 ) - { - pPlayer->RemoveAllItems( TRUE ); - BecomeSpectator( pPlayer ); - pPlayer->m_state = STATE_SPECTATOR; - } - if( imenu == 4 ) - { - CoopVoteMenu( pPlayer ); - } - default: - break; + int imenu = atoi( CMD_ARGV( 1 ) ); + + switch( pPlayer->m_state ) + { + case STATE_SPECTATOR_BEGIN: + case STATE_SPECTATOR: + if( imenu == 1 ) + { + SpawnPlayer( pPlayer ); + pPlayer->m_state = STATE_SPAWNED; + } + if( imenu == 2 ) + { + pPlayer->m_state = STATE_SPECTATOR; + CLIENT_COMMAND( pPlayer->edict(), "touch_show _coopm*\n" ); + } + break; + case STATE_SPAWNED: + if( g_iMenu ) + { + CoopProcessMenu( pPlayer, imenu ); + return TRUE; + } + if( imenu == 1 ) + { + pPlayer->RemoveAllItems( TRUE ); + SpawnPlayer( pPlayer ); + } + if( imenu == 2 ) + { + UTIL_CleanSpawnPoint( pPlayer->pev->origin, 150 ); + } + if( imenu == 3 ) + { + pPlayer->RemoveAllItems( TRUE ); + BecomeSpectator( pPlayer ); + pPlayer->m_state = STATE_SPECTATOR; + } + if( imenu == 4 ) + { + CoopVoteMenu( pPlayer ); + } + default: + break; + } + return TRUE; } - return TRUE; - } - if( FStrEq( pcmd, "coopmenu" ) ) - { - if( !g_iMenu ) - CoopMenu( pPlayer ); - else - ClientPrint( pPlayer->pev, HUD_PRINTCONSOLE, "You cannot use coopmenu now!\n\n" ); + if( FStrEq( pcmd, "coopmenu" ) ) + { + if( !g_iMenu ) + CoopMenu( pPlayer ); + else + ClientPrint( pPlayer->pev, HUD_PRINTCONSOLE, "You cannot use coopmenu now!\n\n" ); - return TRUE; + return TRUE; + } } return CGameRules::ClientCommand( pPlayer, pcmd ); @@ -652,16 +655,20 @@ void CHalfLifeMultiplay::InitHUD( CBasePlayer *pl ) if( pl->m_state <= STATE_CONNECTED ) ClientPutInServer( pl->edict() ); - if( pl->m_state == STATE_SPECTATOR_BEGIN ) + if( mp_coop.value ) { - if( mp_coop.value ) + if( pl->m_state == STATE_SPECTATOR_BEGIN ) { - const char *menu[] = { - "Join coop", - "Join spectators" - }; - ShowMenu( pl, "COOP SERVER", ARRAYSIZE( menu ), menu ); + + if( mp_coop.value ) + { + const char *menu[] = { + "Join coop", + "Join spectators" + }; + ShowMenu( pl, "COOP SERVER", ARRAYSIZE( menu ), menu ); + } } } @@ -781,7 +788,7 @@ void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer ) return; } - if( pPlayer->m_state == STATE_CONNECTED ) + if( mp_spectator.value && pPlayer->m_state == STATE_CONNECTED ) { pPlayer->m_state = STATE_SPECTATOR_BEGIN; pPlayer->RemoveAllItems( TRUE ); @@ -789,7 +796,7 @@ void CHalfLifeMultiplay::PlayerSpawn( CBasePlayer *pPlayer ) return; } - if( pPlayer->m_state == STATE_POINT_SELECT && !(pPlayer->pev->flags & FL_SPECTATOR) ) + if( mp_coop.value && pPlayer->m_state == STATE_POINT_SELECT && !(pPlayer->pev->flags & FL_SPECTATOR) ) { pPlayer->RemoveAllItems( TRUE ); BecomeSpectator( pPlayer ); diff --git a/dlls/plats.cpp b/dlls/plats.cpp index 606aac8c..55825e2f 100644 --- a/dlls/plats.cpp +++ b/dlls/plats.cpp @@ -760,7 +760,8 @@ void CFuncTrain::Next( void ) SetBits(pev->effects, EF_NOINTERP); UTIL_SetOrigin(pev, pTarg->pev->origin - (pev->mins + pev->maxs)* 0.5); Wait(); // Get on with doing the next path corner. - pev->iuser1++; // Invalidate state for coop + if( mp_coop_changelevel.value ) + pev->iuser1++; // Invalidate state for coop } else { diff --git a/dlls/scientist.cpp b/dlls/scientist.cpp index dc37a2b3..5a870774 100644 --- a/dlls/scientist.cpp +++ b/dlls/scientist.cpp @@ -26,6 +26,7 @@ #include "scripted.h" #include "animation.h" #include "soundent.h" +#include "game.h" #define NUM_SCIENTIST_HEADS 4 // four heads available for scientist model @@ -745,9 +746,7 @@ int CScientist::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, flo { if( pevInflictor && pevInflictor->flags & FL_CLIENT ) { - if( pevAttacker->health <= 10 ) - Forget( bits_MEMORY_PROVOKED ); - else + if( !mp_coop_noangry.value ) Remember( bits_MEMORY_PROVOKED ); StopFollowing( TRUE );