Browse Source

Move global vote class to coop.c

gravgun
mittorn 6 years ago
parent
commit
d249bbfa23
  1. 73
      dlls/coop.cpp
  2. 28
      dlls/coop_util.h
  3. 13
      dlls/triggers.cpp

73
dlls/coop.cpp

@ -5,8 +5,6 @@
#include "coop_util.h" #include "coop_util.h"
#include "gravgunmod.h" #include "gravgunmod.h"
GlobalMenu g_GlobalMenu;
struct SavedCoords g_SavedCoords, s_SavedCoords; 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 ) if( pPlayer->pev->flags & FL_SPECTATOR )
return; return;
if( gpGlobals->time - m_flTime > 30 ) if( gpGlobals->time - m_flTime > 30 )
{ {
g_iMenu = 0; g_iVote = 0;
return; return;
} }
switch( g_iMenu ) switch( g_iVote )
{ {
case 1: // touch blue trigger case 1: // touch blue trigger
m_iVoteCount++; m_iVoteCount++;
@ -371,7 +390,7 @@ void GlobalMenu::Process( CBasePlayer *pPlayer, int imenu )
break; 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; int count2 = 0;
@ -398,7 +417,7 @@ void GlobalMenu::ShowGlobalMenu( const char *title, int count, const char **menu
m_iBanCount = 0; 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 ) /*if( g_iMenu && gpGlobals->time - m_flTime < 30 )
return; // wait 30s before new confirm vote return; // wait 30s before new confirm vote
@ -409,7 +428,7 @@ void GlobalMenu::ConfirmMenu( CBasePlayer *pPlayer, CBaseEntity *trigger, const
UTIL_CoopLocalConfirmMenu( pPlayer ); UTIL_CoopLocalConfirmMenu( pPlayer );
return; return;
}*/ }*/
g_iMenu = 1; g_iVote = 1;
m_flTime = gpGlobals->time; m_flTime = gpGlobals->time;
m_pTrigger = trigger; m_pTrigger = trigger;
m_pPlayer = pPlayer; 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 ) 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_iVote = 0;
g_GlobalMenu.m_iConfirm = 0; g_GlobalVote.m_iConfirm = 0;
} }
if( g_iMenu != 1 ) if( g_iVote != 1 )
{ {
if( !UTIL_CoopIsBadPlayer( pActivator ) ) if( !UTIL_CoopIsBadPlayer( pActivator ) )
g_GlobalMenu.ConfirmMenu( (CBasePlayer*)pActivator, pTrigger, mapname ); g_GlobalVote.ConfirmMenu( (CBasePlayer*)pActivator, pTrigger, mapname );
return false; return false;
} }
if( g_GlobalMenu.m_iConfirm < count2 ) if( g_GlobalVote.m_iConfirm < count2 )
return false; return false;
if( mp_coop_strongcheckpoints.value ) if( mp_coop_strongcheckpoints.value )
{ {
// do not allow go back if there are checkpoints, but not near changelevel // 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 ) 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!"); UTIL_CoopPlayerMessage( pActivator, 1, 5, 0xFF0000FF, 0xFF0000FF, 0, 0.7, "Changelevel back locked by checkpoint\nCheckpoint here to activate trigger!");
return false; return false;
} }
@ -805,14 +824,20 @@ bool UTIL_CoopConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int co
return true; 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 ) 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_iVote = 0;
g_GlobalMenu.m_iConfirm = 0; g_GlobalVote.m_iConfirm = 0;
} }
if( g_iMenu != 1 ) if( g_iVote != 1 )
{ {
if( !UTIL_CoopIsBadPlayer( pActivator ) ) if( !UTIL_CoopIsBadPlayer( pActivator ) )
{ {
@ -828,18 +853,18 @@ bool COOP_ConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int count2
.Show(); .Show();
} }
else else
g_GlobalMenu.ConfirmMenu(pPlayer, pTrigger, mapname ); g_GlobalVote.ConfirmMenu(pPlayer, pTrigger, mapname );
} }
return false; return false;
} }
if( g_GlobalMenu.m_iConfirm < count2 ) if( g_GlobalVote.m_iConfirm < count2 )
return false; return false;
if( mp_coop_strongcheckpoints.value ) if( mp_coop_strongcheckpoints.value )
{ {
// do not allow go back if there are checkpoints, but not near changelevel // 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 ) 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!"); UTIL_CoopPlayerMessage( pActivator, 1, 5, 0xFF0000FF, 0xFF0000FF, 0, 0.7, "Changelevel back locked by checkpoint\nCheckpoint here to activate trigger!");
return false; return false;
} }
@ -967,7 +992,7 @@ bool COOP_ClientCommand( edict_t *pEntity )
else if( FStrEq( pcmd, "votemenu" ) ) else if( FStrEq( pcmd, "votemenu" ) )
{ {
int i = atoi( CMD_ARGV(1) ); int i = atoi( CMD_ARGV(1) );
g_GlobalMenu.Process(pPlayer, i); g_GlobalVote.Process(pPlayer, i);
} }
return false; return false;

28
dlls/coop_util.h

@ -65,8 +65,9 @@ bool UTIL_CoopPlayerDeath( CBasePlayer *pPlayer );
void COOP_RegisterCVars( void ); void COOP_RegisterCVars( void );
bool COOP_ClientCommand( edict_t *pEntity ); bool COOP_ClientCommand( edict_t *pEntity );
bool COOP_ConfirmMenu(CBaseEntity *pTrigger, CBaseEntity *pActivator, int count2, char *mapname ); 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); void UTIL_CoopKickPlayer(CBaseEntity *pPlayer);
bool UTIL_CoopIsBadPlayer( CBaseEntity *plr ); bool UTIL_CoopIsBadPlayer( CBaseEntity *plr );
void UTIL_CoopNewCheckpoint( entvars_t *pevPlayer ); void UTIL_CoopNewCheckpoint( entvars_t *pevPlayer );
@ -78,29 +79,7 @@ void UTIL_CoopCheckpointMenu( CBasePlayer *pPlayer );
void UTIL_CoopVoteMenu( CBasePlayer *pPlayer ); void UTIL_CoopVoteMenu( CBasePlayer *pPlayer );
void UTIL_CoopShowMenu( CBasePlayer *pPlayer, const char *title, int count, const char **slot, signed char time = -1 ); 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 ); bool UTIL_CoopConfirmMenu( CBaseEntity *pTrigger, CBaseEntity *pActivator, int count2, char *mapname );
extern int g_iMenu; extern int g_iVote;
// 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;
class CWeaponList class CWeaponList
{ {
char weapons[64][256]; char weapons[64][256];
@ -113,7 +92,6 @@ public:
extern CWeaponList g_WeaponList; extern CWeaponList g_WeaponList;
#endif
extern struct SavedCoords g_SavedCoords, s_SavedCoords; extern struct SavedCoords g_SavedCoords, s_SavedCoords;
#endif // COOP_UTIL_H #endif // COOP_UTIL_H

13
dlls/triggers.cpp

@ -1524,9 +1524,9 @@ void CChangeLevel::UpdateColor( void )
CBaseEntity *pPlayer; CBaseEntity *pPlayer;
pev->nextthink = gpGlobals->time + 30; 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 ) if( (origin - pPlayer->pev->origin).Length() < 500 )
m_fIsBack = true; m_fIsBack = true;*/
if( !m_fIsBack && UTIL_CoopGetSpawnPoint( &point, &angles ) ) if( !m_fIsBack && UTIL_CoopGetSpawnPoint( &point, &angles ) )
if( (origin - point).Length() < 500 ) if( (origin - point).Length() < 500 )
m_fIsBack = true; m_fIsBack = true;
@ -1535,12 +1535,6 @@ void CChangeLevel::UpdateColor( void )
pev->rendercolor.z = 255; pev->rendercolor.z = 255;
else else
pev->rendercolor.y = 255; 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 // 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, "Level touches %d levels\n", ChangeList( levels, 16 ) );
ALERT( at_console, "CHANGE LEVEL: %s %s\n", st_szNextMap, st_szNextSpot ); ALERT( at_console, "CHANGE LEVEL: %s %s\n", st_szNextMap, st_szNextSpot );
g_iMenu = 0; COOP_ResetVote();
g_GlobalMenu.m_iConfirm = 0;
// loop through all clients, reset state // loop through all clients, reset state
if( mp_coop_changelevel.value ) if( mp_coop_changelevel.value )
{ {

Loading…
Cancel
Save