From d249bbfa23889e3a2d1a1c8df53c7f55e1ed6d5c Mon Sep 17 00:00:00 2001 From: mittorn Date: Mon, 30 Jul 2018 02:34:57 +0700 Subject: [PATCH] Move global vote class to coop.c --- dlls/coop.cpp | 73 +++++++++++++++++++++++++++++++---------------- dlls/coop_util.h | 28 ++---------------- dlls/triggers.cpp | 13 ++------- 3 files changed, 55 insertions(+), 59 deletions(-) diff --git a/dlls/coop.cpp b/dlls/coop.cpp index 3368c56b..3df88f85 100644 --- a/dlls/coop.cpp +++ b/dlls/coop.cpp @@ -5,8 +5,6 @@ #include "coop_util.h" #include "gravgunmod.h" -GlobalMenu g_GlobalMenu; - struct SavedCoords g_SavedCoords, s_SavedCoords; @@ -327,19 +325,40 @@ void UTIL_CoopApplyData( void ) } -int g_iMenu; +int g_iVote; -void GlobalMenu::Process( CBasePlayer *pPlayer, int imenu ) +// Show to all spawned players: voting, etc.. +class GlobalVote +{ +public: + + int m_iConfirm; + int m_iVoteCount; + int m_iMaxCount; + int m_iBanCount; + float m_flTime; + const char *maps[5]; + int votes[5]; + EHANDLE m_pTrigger; + EHANDLE m_pPlayer; + void ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const char *mapname ); + void ShowGlobalMenu( const char *title, int count, const char **menu ); + void Process( CBasePlayer *pPlayer, int imenu ); +}; + +GlobalVote g_GlobalVote; + +void GlobalVote::Process( CBasePlayer *pPlayer, int imenu ) { if( pPlayer->pev->flags & FL_SPECTATOR ) return; if( gpGlobals->time - m_flTime > 30 ) { - g_iMenu = 0; + g_iVote = 0; return; } - switch( g_iMenu ) + switch( g_iVote ) { case 1: // touch blue trigger m_iVoteCount++; @@ -371,7 +390,7 @@ void GlobalMenu::Process( CBasePlayer *pPlayer, int imenu ) break; } } -void GlobalMenu::ShowGlobalMenu( const char *title, int count, const char **menu ) +void GlobalVote::ShowGlobalMenu( const char *title, int count, const char **menu ) { int count2 = 0; @@ -398,7 +417,7 @@ void GlobalMenu::ShowGlobalMenu( const char *title, int count, const char **menu m_iBanCount = 0; } -void GlobalMenu::ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const char *mapname ) +void GlobalVote::ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const char *mapname ) { /*if( g_iMenu && gpGlobals->time - m_flTime < 30 ) return; // wait 30s before new confirm vote @@ -409,7 +428,7 @@ void GlobalMenu::ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const UTIL_CoopLocalConfirmMenu( pPlayer ); return; }*/ - g_iMenu = 1; + g_iVote = 1; m_flTime = gpGlobals->time; m_pTrigger = trigger; m_pPlayer = pPlayer; @@ -777,25 +796,25 @@ void UTIL_CoopShowMenu( CBasePlayer *pPlayer, const char *title, int count, cons bool UTIL_CoopConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int count2, char *mapname ) { - if( gpGlobals->time - g_GlobalMenu.m_flTime > 30 ) + if( gpGlobals->time - g_GlobalVote.m_flTime > 30 ) { - g_iMenu = 0; - g_GlobalMenu.m_iConfirm = 0; + g_iVote = 0; + g_GlobalVote.m_iConfirm = 0; } - if( g_iMenu != 1 ) + if( g_iVote != 1 ) { if( !UTIL_CoopIsBadPlayer( pActivator ) ) - g_GlobalMenu.ConfirmMenu( (CBasePlayer*)pActivator, pTrigger, mapname ); + g_GlobalVote.ConfirmMenu( (CBasePlayer*)pActivator, pTrigger, mapname ); return false; } - if( g_GlobalMenu.m_iConfirm < count2 ) + if( g_GlobalVote.m_iConfirm < count2 ) return false; if( mp_coop_strongcheckpoints.value ) { // do not allow go back if there are checkpoints, but not near changelevel if( g_checkpoints[0].time && (g_checkpoints[0].origin - VecBModelOrigin(pTrigger->pev)).Length() > 150 ) { - g_GlobalMenu.m_iConfirm = 0; + g_GlobalVote.m_iConfirm = 0; UTIL_CoopPlayerMessage( pActivator, 1, 5, 0xFF0000FF, 0xFF0000FF, 0, 0.7, "Changelevel back locked by checkpoint\nCheckpoint here to activate trigger!"); return false; } @@ -805,14 +824,20 @@ bool UTIL_CoopConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int co return true; } +void COOP_ResetVote( void ) +{ + g_iVote = 0; + g_GlobalVote.m_iConfirm = 0; +} + bool COOP_ConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int count2, char *mapname ) { - if( gpGlobals->time - g_GlobalMenu.m_flTime > 30 ) + if( gpGlobals->time - g_GlobalVote.m_flTime > 30 ) { - g_iMenu = 0; - g_GlobalMenu.m_iConfirm = 0; + g_iVote = 0; + g_GlobalVote.m_iConfirm = 0; } - if( g_iMenu != 1 ) + if( g_iVote != 1 ) { if( !UTIL_CoopIsBadPlayer( pActivator ) ) { @@ -828,18 +853,18 @@ bool COOP_ConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int count2 .Show(); } else - g_GlobalMenu.ConfirmMenu(pPlayer, pTrigger, mapname ); + g_GlobalVote.ConfirmMenu(pPlayer, pTrigger, mapname ); } return false; } - if( g_GlobalMenu.m_iConfirm < count2 ) + if( g_GlobalVote.m_iConfirm < count2 ) return false; if( mp_coop_strongcheckpoints.value ) { // do not allow go back if there are checkpoints, but not near changelevel if( g_checkpoints[0].time && (g_checkpoints[0].origin - VecBModelOrigin(pTrigger->pev)).Length() > 150 ) { - g_GlobalMenu.m_iConfirm = 0; + g_GlobalVote.m_iConfirm = 0; UTIL_CoopPlayerMessage( pActivator, 1, 5, 0xFF0000FF, 0xFF0000FF, 0, 0.7, "Changelevel back locked by checkpoint\nCheckpoint here to activate trigger!"); return false; } @@ -967,7 +992,7 @@ bool COOP_ClientCommand( edict_t *pEntity ) else if( FStrEq( pcmd, "votemenu" ) ) { int i = atoi( CMD_ARGV(1) ); - g_GlobalMenu.Process(pPlayer, i); + g_GlobalVote.Process(pPlayer, i); } return false; diff --git a/dlls/coop_util.h b/dlls/coop_util.h index a9a6b3d4..2c7cf484 100644 --- a/dlls/coop_util.h +++ b/dlls/coop_util.h @@ -65,8 +65,9 @@ bool UTIL_CoopPlayerDeath( CBasePlayer *pPlayer ); void COOP_RegisterCVars( void ); bool COOP_ClientCommand( edict_t *pEntity ); bool COOP_ConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int count2, char *mapname ); +void COOP_ResetVote( void ); -#ifdef PLAYER_H +class CBasePlayer; void UTIL_CoopKickPlayer(CBaseEntity *pPlayer); bool UTIL_CoopIsBadPlayer( CBaseEntity *plr ); void UTIL_CoopNewCheckpoint( entvars_t *pevPlayer ); @@ -78,29 +79,7 @@ void UTIL_CoopCheckpointMenu( CBasePlayer *pPlayer ); void UTIL_CoopVoteMenu( CBasePlayer *pPlayer ); void UTIL_CoopShowMenu( CBasePlayer *pPlayer, const char *title, int count, const char **slot, signed char time = -1 ); bool UTIL_CoopConfirmMenu( CBaseEntity *pTrigger, CBaseEntity *pActivator, int count2, char *mapname ); -extern int g_iMenu; - -// Show to all spawned players: voting, etc.. -class GlobalMenu -{ -public: - - int m_iConfirm; - int m_iVoteCount; - int m_iMaxCount; - int m_iBanCount; - float m_flTime; - const char *maps[5]; - int votes[5]; - EHANDLE m_pTrigger; - EHANDLE m_pPlayer; - void ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const char *mapname ); - void ShowGlobalMenu( const char *title, int count, const char **menu ); - void Process( CBasePlayer *pPlayer, int imenu ); -}; - -extern GlobalMenu g_GlobalMenu; - +extern int g_iVote; class CWeaponList { char weapons[64][256]; @@ -113,7 +92,6 @@ public: extern CWeaponList g_WeaponList; -#endif extern struct SavedCoords g_SavedCoords, s_SavedCoords; #endif // COOP_UTIL_H diff --git a/dlls/triggers.cpp b/dlls/triggers.cpp index 48059e2f..0ac093a9 100644 --- a/dlls/triggers.cpp +++ b/dlls/triggers.cpp @@ -1524,9 +1524,9 @@ void CChangeLevel::UpdateColor( void ) CBaseEntity *pPlayer; pev->nextthink = gpGlobals->time + 30; - if( !m_fIsBack && (pPlayer = UTIL_FindEntityByClassname( NULL, "info_player_start" )) ) + /*if( !m_fIsBack && (pPlayer = UTIL_FindEntityByClassname( NULL, "info_player_start" )) ) if( (origin - pPlayer->pev->origin).Length() < 500 ) - m_fIsBack = true; + m_fIsBack = true;*/ if( !m_fIsBack && UTIL_CoopGetSpawnPoint( &point, &angles ) ) if( (origin - point).Length() < 500 ) m_fIsBack = true; @@ -1535,12 +1535,6 @@ void CChangeLevel::UpdateColor( void ) pev->rendercolor.z = 255; else pev->rendercolor.y = 255; - if( gpGlobals->time - g_GlobalMenu.m_flTime > 30 ) - { - g_iMenu = 0; - g_GlobalMenu.m_iConfirm = 0; - } - } // If some player is on train with global state, save id @@ -1811,8 +1805,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) //ALERT( at_console, "Level touches %d levels\n", ChangeList( levels, 16 ) ); ALERT( at_console, "CHANGE LEVEL: %s %s\n", st_szNextMap, st_szNextSpot ); - g_iMenu = 0; - g_GlobalMenu.m_iConfirm = 0; + COOP_ResetVote(); // loop through all clients, reset state if( mp_coop_changelevel.value ) {